diff --git a/images/placeholder.png b/images/placeholder.png new file mode 100644 index 0000000..04d7cd7 Binary files /dev/null and b/images/placeholder.png differ diff --git a/readme.txt b/readme.txt index 5d5b350..7ac1d28 100644 --- a/readme.txt +++ b/readme.txt @@ -3,8 +3,8 @@ Contributors: itthinx Donate link: http://www.itthinx.com/plugins/woocommerce-product-generator/ Tags: automatic, benchmark, example, generator, performance, product, products, sample, test, tester, testing, test-tool, woocommerce Requires at least: 4.0 -Tested up to: 4.1.1 -Stable tag: 1.0.1 +Tested up to: 4.3 +Stable tag: 1.0.2 License: GPLv3 A sample product generator for WooCommerce. @@ -40,6 +40,11 @@ You can install the plugin via FTP, see [Manual Plugin Installation](http://code == Changelog == += 1.0.2 = +* Tested with WordPress 4.3. +* Fixed hardcoded database table reference. +* Added a placeholder image used when GD is missing. + = 1.0.1 = * Tested with WordPress 4.1.1 and WooCommerce 2.3.6. * WordPress-compliant readme.txt added. @@ -50,8 +55,5 @@ You can install the plugin via FTP, see [Manual Plugin Installation](http://code == Upgrade Notice == -= 1.0.1 = -* Tested with latest version of WordPress and WooCommerce, also added a compliant readme.txt. - -= 1.0.0 = -* Initial release. += 1.0.2 = +* Tested with WordPress 4.3, added two fixes. diff --git a/woocommerce-product-generator.php b/woocommerce-product-generator.php index 10bf70a..a308a85 100644 --- a/woocommerce-product-generator.php +++ b/woocommerce-product-generator.php @@ -890,7 +890,9 @@ public static function run( $n = self::MAX_PER_RUN ) { public static function get_product_count() { //$counts = wp_count_posts( 'product' ); // <-- nah ... :| global $wpdb; - return intval( $wpdb->get_var( "SELECT count(*) FROM wp_posts WHERE post_type = 'product' and post_status = 'publish'" ) ); + return intval( $wpdb->get_var( + "SELECT count(*) FROM $wpdb->posts WHERE post_type = 'product' and post_status = 'publish'" + ) ); } public static function create_product() { @@ -1055,33 +1057,41 @@ public static function get_content( $n_lines = 10 ) { * @return string image data */ public static function get_image() { - $width = self::IMAGE_WIDTH; - $height = self::IMAGE_HEIGHT; - - $image = imagecreatetruecolor( $width, $height ); - for( $i = 0; $i <= 11; $i++ ) { - $x = rand( 0, $width ); - $y = rand( 0, $height ); - $w = rand( 1, $width ); - $h = rand( 1, $height ); - $red = rand( 0, 255 ); - $green = rand( 0, 255 ); - $blue = rand( 0, 255 ); - $color = imagecolorallocate( $image, $red, $green, $blue ); - imagefilledrectangle( - $image, - $x - $w / 2, - $y - $h / 2, - $x + $w / 2, - $y + $h / 2, - $color - ); - } + $output = ''; + if ( function_exists( 'imagepng' ) ) { + $width = self::IMAGE_WIDTH; + $height = self::IMAGE_HEIGHT; + + $image = imagecreatetruecolor( $width, $height ); + for( $i = 0; $i <= 11; $i++ ) { + $x = rand( 0, $width ); + $y = rand( 0, $height ); + $w = rand( 1, $width ); + $h = rand( 1, $height ); + $red = rand( 0, 255 ); + $green = rand( 0, 255 ); + $blue = rand( 0, 255 ); + $color = imagecolorallocate( $image, $red, $green, $blue ); + imagefilledrectangle( + $image, + $x - $w / 2, + $y - $h / 2, + $x + $w / 2, + $y + $h / 2, + $color + ); + } - ob_start(); - imagepng( $image ); - $output = ob_get_clean(); - imagedestroy( $image ); + ob_start(); + imagepng( $image ); + $output = ob_get_clean(); + imagedestroy( $image ); + } else { + $image = file_get_contents( WOOPROGEN_PLUGIN_URL . '/images/placeholder.png' ); + ob_start(); + echo $image; + $output = ob_get_clean(); + } return $output; }