From baa66de6d788873c994b802d88a4658bc0e8b85a Mon Sep 17 00:00:00 2001 From: bordoni Date: Fri, 21 Jul 2017 23:47:39 -0300 Subject: [PATCH 01/19] Changelog section and Version bump to 0.4.9 --- fakerpress.php | 2 +- inc/class-fp-plugin.php | 2 +- readme.md | 3 +++ readme.txt | 4 ++++ 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/fakerpress.php b/fakerpress.php index 4364815..18870a8 100644 --- a/fakerpress.php +++ b/fakerpress.php @@ -3,7 +3,7 @@ * Plugin Name: FakerPress * Plugin URI: https://fakerpress.com * Description: FakerPress is a clean way to generate fake data to your WordPress instalation, great for developers who need testing - * Version: 0.4.8 + * Version: 0.4.9 * Author: Gustavo Bordoni * Author URI: http://bordoni.me * Text Domain: fakerpress diff --git a/inc/class-fp-plugin.php b/inc/class-fp-plugin.php index ab8518e..dc892e5 100644 --- a/inc/class-fp-plugin.php +++ b/inc/class-fp-plugin.php @@ -13,7 +13,7 @@ class Plugin { * @since 0.1.0 * @var string */ - const version = '0.4.8'; + const version = '0.4.9'; /** * A static variable that holds a dinamic instance of the class diff --git a/readme.md b/readme.md index 3aa52de..c256d74 100644 --- a/readme.md +++ b/readme.md @@ -99,6 +99,9 @@ Thank you for wanting to make FakerPress better for everyone! [We salute you](ht ## Changelog ## +### 0.4.9 — TBD ### +... + ### 0.4.8 — 18 of July, 2017 ### * Feature: Now Comments can be generated with different types, allowing for WooCommerce Notes for example - Thanks [@dibbyo456](https://wordpress.org/support/topic/can-i-create-custom-comments/) * Feature: Comments for Custom Post Types - Thanks [@jasondevine](https://github.com/bordoni/fakerpress/issues/109) diff --git a/readme.txt b/readme.txt index cdbe6da..fae02f6 100644 --- a/readme.txt +++ b/readme.txt @@ -97,6 +97,10 @@ Thank you for wanting to make FakerPress better for everyone! [We salute you](ht == Changelog == += 0.4.9 — TBD = + +... + = 0.4.8 — 18 of July, 2017 = * Feature: Now Comments can be generated with different types, allowing for WooCommerce Notes for example - Thanks [@dibbyo456](https://wordpress.org/support/topic/can-i-create-custom-comments/) From 34267b83b96b4363cd9df4eb21ef706c0a0b55a1 Mon Sep 17 00:00:00 2001 From: bordoni Date: Sat, 22 Jul 2017 13:48:19 -0300 Subject: [PATCH 02/19] Add the Fields for Image Width and Height on the Interface --- inc/class-fp-field.php | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/inc/class-fp-field.php b/inc/class-fp-field.php index d894fbc..4192585 100644 --- a/inc/class-fp-field.php +++ b/inc/class-fp-field.php @@ -814,7 +814,11 @@ public static function type_range( $field, $container = null, $output = 'string' } $min->class = array(); + $min->placeholder = esc_attr__( 'e.g.: 3', 'fakerpress' ); + if ( ! empty( $min->_placeholder_min ) ) { + $min->placeholder = $min->_placeholder_min; + } $max = clone $field; $max->_id[] = 'max'; @@ -825,7 +829,7 @@ public static function type_range( $field, $container = null, $output = 'string' if ( isset( $field->max ) && is_numeric( $field->max ) ) { $max->value = $field->max; - } else { + } elseif ( ! isset( $max->_prevent_disable ) || ! $max->_prevent_disable ) { $max->disabled = true; } @@ -838,7 +842,11 @@ public static function type_range( $field, $container = null, $output = 'string' } $max->class = array(); + $max->placeholder = esc_attr__( 'e.g.: 12', 'fakerpress' ); + if ( ! empty( $max->_placeholder_max ) ) { + $max->placeholder = $max->_placeholder_max; + } $content[] = self::type_input( $min, null, 'string', array() ); $content[] = '
'; @@ -1286,10 +1294,36 @@ public static function get_meta_types() { $providers->value = implode( ',', wp_list_pluck( Module\Attachment::get_providers(), 'id' ) ); $providers->{'data-options'} = Module\Attachment::get_providers(); + $size_width = clone $field; + $size_width->_id = array( 'meta', 'size', 'width' ); + $size_width->_name = array( 'meta', 'size', 'width' ); + $size_width->type = 'range'; + $size_width->class = array(); + $size_width->label = __( 'Range of possible width sizes for the image', 'fakerpress' ); + $size_width->_min = 0; + $size_width->_placeholder_min = esc_attr__( 'e.g.: 350', 'fakerpress' ); + $size_width->_placeholder_max = esc_attr__( 'e.g.: 900', 'fakerpress' ); + $size_width->_prevent_disable = true; + + $size_height = clone $field; + $size_height->_id = array( 'meta', 'size', 'height' ); + $size_height->_name = array( 'meta', 'size', 'height' ); + $size_height->type = 'range'; + $size_height->class = array(); + $size_height->label = __( 'Range of possible height sizes for the image', 'fakerpress' ); + $size_height->_min = 0; + $size_height->_placeholder_min = esc_attr__( 'e.g.: 125', 'fakerpress' ); + $size_height->_placeholder_max = esc_attr__( 'e.g.: 650', 'fakerpress' ); + $size_height->_prevent_disable = true; + $html[] = Field::wrapper( Field::type_dropdown( $store, null, 'string' ), $store ); $html[] = Field::wrapper( Field::type_dropdown( $providers, null, 'string' ), $providers ); $html[] = Field::wrapper( Field::type_number( $default->weight, null, 'string' ), $default->weight ); + // Image Dimensions + $html[] = Field::wrapper( Field::type_range( $size_width, null, 'string' ), $size_width ); + $html[] = Field::wrapper( Field::type_range( $size_height, null, 'string' ), $size_height ); + return implode( "\r\n", $html ); }, ); From da84920fe6ca21f4fd5149daec5518c9c5160c96 Mon Sep 17 00:00:00 2001 From: bordoni Date: Sat, 22 Jul 2017 13:48:46 -0300 Subject: [PATCH 03/19] Refactor 500px Provider with more docblocks and add two filters --- providers/image/500px.php | 83 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 6 deletions(-) diff --git a/providers/image/500px.php b/providers/image/500px.php index 25c5897..2dbbc33 100644 --- a/providers/image/500px.php +++ b/providers/image/500px.php @@ -2,21 +2,46 @@ namespace Faker\Provider; use \FakerPress\Plugin; +/** + * Faker provider class for 500px images + * + * @since 0.2.2 + */ class Image500px extends Base { + /** + * The base URL for the 500px API + * + * @var string + */ protected static $base_url = 'https://api.500px.com/v1/'; /** - * @param \Faker\Generator $generator + * Constructor for the 500px provider + * + * @since 0.2.2 + * + * @param \Faker\Generator $generator */ public function __construct( \Faker\Generator $generator ) { $this->generator = $generator; } + /** + * Makes a request to the 500px api + * + * @since 0.2.2 + * + * @see https://github.com/500px/api-documentation For more information on Endpoints + * + * @param string $endpoint Which endpoint we are going to request + * @param array $args Arguments use to request + * @return object|bool The Body of the response or false if fail + */ protected function request( $endpoint = 'photos', $args = array() ){ $key = \FakerPress\Plugin::get( array( '500px', 'key' ), false ); - if ( ! $key ){ + if ( ! $key ) { return false; } @@ -29,9 +54,22 @@ protected function request( $endpoint = 'photos', $args = array() ){ // Determine the Transient Key array_multisort( $args ); $hashed_id = substr( md5( json_encode( $args ) ), 0, 10 ); - $transient_id = Plugin::$slug . '-request-500px-' . $hashed_id; - - if ( false === ( $response = get_transient( $transient_id ) ) ) { + $transient_id = Plugin::$slug . '-request-500px-' . $endpoint . '-' . $hashed_id; + + /** + * Filter how many seconds we keep the 500px requests in a transient + * Set to false or 0 to avoid caching + * + * @since 0.4.9 + * + * @param int $expiration How long we should hold to the a result of images from 500px + * @param string $endpoint Which endpoint we are fetching + * @param array $args Arguments for the Request to 500px + * @param self $provider Instance of the Current class + */ + $expiration = apply_filters( 'fakerpress.provider.image.500px.request_expiration', 6 * HOUR_IN_SECONDS, $endpoint, $args, $this ) + + if ( ! $expiration || false === ( $response = get_transient( $transient_id ) ) ) { $response = wp_remote_get( add_query_arg( $args, self::$base_url . $endpoint ) ); $response = wp_remote_retrieve_body( $response ); @@ -47,16 +85,49 @@ protected function request( $endpoint = 'photos', $args = array() ){ return $response; } + /** + * Fetches a random photo from 500px based on a given search param + * + * @since 0.2.2 + * + * @param array $args The request params for 500px search of photos + * + * @return string The Image url from 500px (external URL) + */ public function image_500px( $args = array() ) { + $categories = array( + 'Abstract', + 'Aerial', + 'Animals', + 'City and Architecture', + 'Food', + 'Landscapes', + 'Macro', + 'Nature', + 'Urban Exploration', + 'Wedding', + ); + $defaults = array( 'feature' => 'editors', 'sort' => 'created_at', 'image_size' => 1080, 'rpp' => 100, - 'only' => urlencode( 'Abstract,Food,Nature,Landscapes,City and Architecture,Animals,Macro' ), + 'exclude_nude' => 1, + 'only' => urlencode( implode( ',', $categories ) ), ); $args = wp_parse_args( $args, $defaults ); + /** + * Allow third party developers to modify params for 500px requests + * + * @since 0.4.9 + * + * @param array $args Arguments for the Request to 500px + * @param self $provider Instance of the Current class + */ + $args = apply_filters( 'fakerpress.provider.image.500px.args', $args, $this ) + $response = $this->request( 'photos', $args ); if ( ! $response ){ From afd2d1df97170b18d1aa3944d4cbfad3b03fb264 Mon Sep 17 00:00:00 2001 From: bordoni Date: Sat, 22 Jul 2017 14:54:02 -0300 Subject: [PATCH 04/19] Add docblocks on 500px provider --- providers/image/500px.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/providers/image/500px.php b/providers/image/500px.php index 2dbbc33..8e1848e 100644 --- a/providers/image/500px.php +++ b/providers/image/500px.php @@ -12,7 +12,9 @@ class Image500px extends Base { /** * The base URL for the 500px API * - * @var string + * @since 0.2.2 + * + * @var string */ protected static $base_url = 'https://api.500px.com/v1/'; @@ -21,7 +23,7 @@ class Image500px extends Base { * * @since 0.2.2 * - * @param \Faker\Generator $generator + * @param \Faker\Generator $generator An instance of the Faker Generator class */ public function __construct( \Faker\Generator $generator ) { $this->generator = $generator; @@ -54,6 +56,8 @@ protected function request( $endpoint = 'photos', $args = array() ){ // Determine the Transient Key array_multisort( $args ); $hashed_id = substr( md5( json_encode( $args ) ), 0, 10 ); + + // Creates as transient key for the 500px request $transient_id = Plugin::$slug . '-request-500px-' . $endpoint . '-' . $hashed_id; /** From 6781eef5c353ed5911e9fe054a83e4e13d6e85d2 Mon Sep 17 00:00:00 2001 From: bordoni Date: Sat, 22 Jul 2017 14:54:51 -0300 Subject: [PATCH 05/19] Add docblocks on LoremPixel --- providers/image/lorempixel.php | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/providers/image/lorempixel.php b/providers/image/lorempixel.php index cccaefd..88e7613 100644 --- a/providers/image/lorempixel.php +++ b/providers/image/lorempixel.php @@ -1,14 +1,35 @@ generator = $generator; } + /** + * Generate an URL for an image from LoremPixel + * + * @since 0.3.2 + * + * @param array|int $width A range for the images that will be generated, if a int is passed + * we use that value always. + * @param float $ratio It makes the logic a few times easier to pass the Ratio instead of + * the height of the image. + * + * @return string Return the URL for the + */ public function lorempixel( $width = array( 200, 640 ), $ratio = 1.25 ) { if ( is_array( $width ) ){ $width = call_user_func_array( array( $this->generator, 'numberBetween' ), $width ); @@ -16,6 +37,7 @@ public function lorempixel( $width = array( 200, 640 ), $ratio = 1.25 ) { $width = absint( $width ); $height = floor( $width / floatval( $ratio ) ); + $categories = array( 'abstract', 'animals', @@ -32,6 +54,14 @@ public function lorempixel( $width = array( 200, 640 ), $ratio = 1.25 ) { 'transport', ); + /** + * Allow developers to filter the Categories, only one will be selected. + * + * @param array $categories The set of categories that can be used from LoremPixel + * @param self $provider An instance of the Provider + */ + $categories = (array) apply_filters( 'fakerpress.provider.image.lorempixel.categories', $categories, $this ); + $url = "http://lorempixel.com/{$width}/{$height}/" . $this->generator->randomElement( $categories ); return $url; } From 9e214ddd7cac82e80bf79c9a0109a592fb3b31b5 Mon Sep 17 00:00:00 2001 From: bordoni Date: Sat, 22 Jul 2017 14:56:09 -0300 Subject: [PATCH 06/19] Add docblocks to the PlaceHoldIt provider --- providers/image/placeholdit.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/providers/image/placeholdit.php b/providers/image/placeholdit.php index 35102a1..7a088d9 100644 --- a/providers/image/placeholdit.php +++ b/providers/image/placeholdit.php @@ -1,14 +1,33 @@ generator = $generator; } + /** + * Generates a URL for Placehold.it + * + * @since 0.1.5 + * + * @param array|int $width A range for the images that will be generated, if a int is passed + * we use that value always. + * @param float $ratio It makes the logic a few times easier to pass the Ratio instead of + * the height of the image. + * + * @return string + */ public function placeholdit( $width = array( 200, 640 ), $ratio = 1.25 ) { if ( is_array( $width ) ){ $width = call_user_func_array( array( $this->generator, 'numberBetween' ), $width ); @@ -20,5 +39,4 @@ public function placeholdit( $width = array( 200, 640 ), $ratio = 1.25 ) { return $url; } - } \ No newline at end of file From f077e803537436158e09c1859acba0adf603a21e Mon Sep 17 00:00:00 2001 From: bordoni Date: Sat, 22 Jul 2017 14:56:42 -0300 Subject: [PATCH 07/19] Docblocks for Unsplash.it provider --- providers/image/unsplashit.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/providers/image/unsplashit.php b/providers/image/unsplashit.php index e9bec82..f5fd865 100644 --- a/providers/image/unsplashit.php +++ b/providers/image/unsplashit.php @@ -1,14 +1,33 @@ generator = $generator; } + /** + * Generates a URL for Unsplash.it + * + * @since 0.4.2 + * + * @param array|int $width A range for the images that will be generated, if a int is passed + * we use that value always. + * @param float $ratio It makes the logic a few times easier to pass the Ratio instead of + * the height of the image. + * + * @return string + */ public function unsplashit( $width = array( 800, 1440 ), $ratio = 1.25 ) { if ( is_array( $width ) ){ $width = call_user_func_array( array( $this->generator, 'numberBetween' ), $width ); From 1f2af16158246410a196651f75aaf8733581dee8 Mon Sep 17 00:00:00 2001 From: bordoni Date: Sat, 5 Aug 2017 17:05:56 -0300 Subject: [PATCH 08/19] Makes Image settings respect Width/Height settings --- providers/image/500px.php | 4 ++-- providers/image/lorempixel.php | 24 +++++++++++++++++------- providers/image/placeholdit.php | 21 +++++++++++++++------ providers/image/unsplashit.php | 20 ++++++++++++++------ providers/wp-attachment.php | 7 ++++--- providers/wp-meta.php | 17 +++++++++++++++-- 6 files changed, 67 insertions(+), 26 deletions(-) diff --git a/providers/image/500px.php b/providers/image/500px.php index 8e1848e..07f6d72 100644 --- a/providers/image/500px.php +++ b/providers/image/500px.php @@ -71,7 +71,7 @@ protected function request( $endpoint = 'photos', $args = array() ){ * @param array $args Arguments for the Request to 500px * @param self $provider Instance of the Current class */ - $expiration = apply_filters( 'fakerpress.provider.image.500px.request_expiration', 6 * HOUR_IN_SECONDS, $endpoint, $args, $this ) + $expiration = apply_filters( 'fakerpress.provider.image.500px.request_expiration', 6 * HOUR_IN_SECONDS, $endpoint, $args, $this ); if ( ! $expiration || false === ( $response = get_transient( $transient_id ) ) ) { $response = wp_remote_get( add_query_arg( $args, self::$base_url . $endpoint ) ); @@ -130,7 +130,7 @@ public function image_500px( $args = array() ) { * @param array $args Arguments for the Request to 500px * @param self $provider Instance of the Current class */ - $args = apply_filters( 'fakerpress.provider.image.500px.args', $args, $this ) + $args = apply_filters( 'fakerpress.provider.image.500px.args', $args, $this ); $response = $this->request( 'photos', $args ); diff --git a/providers/image/lorempixel.php b/providers/image/lorempixel.php index 88e7613..80960d1 100644 --- a/providers/image/lorempixel.php +++ b/providers/image/lorempixel.php @@ -22,21 +22,29 @@ public function __construct( \Faker\Generator $generator ) { * Generate an URL for an image from LoremPixel * * @since 0.3.2 + * @since 0.4.9 On this version we started to accept Array or Int in the Second Param * - * @param array|int $width A range for the images that will be generated, if a int is passed - * we use that value always. - * @param float $ratio It makes the logic a few times easier to pass the Ratio instead of - * the height of the image. + * @param array|int $width A range for the images that will be generated, if a int is passed + * we use that value always. + * @param float|array|int $height Image height, int for fixed size, array for randomized and + * float to use a ratio * - * @return string Return the URL for the + * @return string Return the URL for Lorem Pixel */ - public function lorempixel( $width = array( 200, 640 ), $ratio = 1.25 ) { + public function lorempixel( $width = array( 200, 640 ), $height = 1.25 ) { if ( is_array( $width ) ){ $width = call_user_func_array( array( $this->generator, 'numberBetween' ), $width ); } + // Makes sure we have an Int $width = absint( $width ); - $height = floor( $width / floatval( $ratio ) ); + + // Check For float (ratio) + if ( is_float( $height ) ) { + $height = floor( $width / floatval( $height ) ); + } elseif ( is_array( $height ) ) { + $height = call_user_func_array( array( $this->generator, 'numberBetween' ), $height ); + } $categories = array( 'abstract', @@ -57,6 +65,8 @@ public function lorempixel( $width = array( 200, 640 ), $ratio = 1.25 ) { /** * Allow developers to filter the Categories, only one will be selected. * + * @since 0.4.9 + * * @param array $categories The set of categories that can be used from LoremPixel * @param self $provider An instance of the Provider */ diff --git a/providers/image/placeholdit.php b/providers/image/placeholdit.php index 7a088d9..3f255fc 100644 --- a/providers/image/placeholdit.php +++ b/providers/image/placeholdit.php @@ -20,21 +20,30 @@ public function __construct( \Faker\Generator $generator ) { * Generates a URL for Placehold.it * * @since 0.1.5 + * @since 0.4.9 On this version we started to accept Array or Int in the Second Param * - * @param array|int $width A range for the images that will be generated, if a int is passed - * we use that value always. - * @param float $ratio It makes the logic a few times easier to pass the Ratio instead of - * the height of the image. + * @param array|int $width A range for the images that will be generated, if a int is passed + * we use that value always. + * @param float|array|int $height Image height, int for fixed size, array for randomized and + * float to use a ratio * * @return string */ - public function placeholdit( $width = array( 200, 640 ), $ratio = 1.25 ) { + public function placeholdit( $width = array( 200, 640 ), $height = 1.25 ) { if ( is_array( $width ) ){ $width = call_user_func_array( array( $this->generator, 'numberBetween' ), $width ); } + // Makes sure we have an Int $width = absint( $width ); - $height = floor( $width / floatval( $ratio ) ); + + // Check For float (ratio) + if ( is_float( $height ) ) { + $height = floor( $width / floatval( $height ) ); + } elseif ( is_array( $height ) ) { + $height = call_user_func_array( array( $this->generator, 'numberBetween' ), $height ); + } + $url = "http://placehold.it/{$width}x{$height}/"; return $url; diff --git a/providers/image/unsplashit.php b/providers/image/unsplashit.php index f5fd865..8fd8cb0 100644 --- a/providers/image/unsplashit.php +++ b/providers/image/unsplashit.php @@ -20,21 +20,29 @@ public function __construct( \Faker\Generator $generator ) { * Generates a URL for Unsplash.it * * @since 0.4.2 + * @since 0.4.9 On this version we started to accept Array or Int in the Second Param * - * @param array|int $width A range for the images that will be generated, if a int is passed - * we use that value always. - * @param float $ratio It makes the logic a few times easier to pass the Ratio instead of - * the height of the image. + * @param array|int $width A range for the images that will be generated, if a int is passed + * we use that value always. + * @param float|array|int $height Image height, int for fixed size, array for randomized and + * float to use a ratio * * @return string */ - public function unsplashit( $width = array( 800, 1440 ), $ratio = 1.25 ) { + public function unsplashit( $width = array( 800, 1440 ), $height = 1.25 ) { if ( is_array( $width ) ){ $width = call_user_func_array( array( $this->generator, 'numberBetween' ), $width ); } + // Makes sure we have an Int $width = absint( $width ); - $height = floor( $width / floatval( $ratio ) ); + + // Check For float (ratio) + if ( is_float( $height ) ) { + $height = floor( $width / floatval( $height ) ); + } elseif ( is_array( $height ) ) { + $height = call_user_func_array( array( $this->generator, 'numberBetween' ), $height ); + } // https://unsplash.it/200/640/?random $url = "https://unsplash.it/{$width}/{$height}/?random"; diff --git a/providers/wp-attachment.php b/providers/wp-attachment.php index f28d236..ca0149c 100644 --- a/providers/wp-attachment.php +++ b/providers/wp-attachment.php @@ -14,15 +14,15 @@ public function post_type() { private static $type_defaults = array( 'placeholdit' => array( 'width' => array( 200, 640 ), - 'ratio' => 1.25, + 'height' => 1.25, ), 'lorempixel' => array( 'width' => array( 200, 640 ), - 'ratio' => 1.25, + 'height' => 1.25, ), 'unsplashit' => array( 'width' => array( 1024, 1440 ), - 'ratio' => 1.5, + 'height' => 1.5, ), '500px' => array() ); @@ -34,6 +34,7 @@ public function attachment_url( $type = '500px', $args = array() ) { if ( ! isset( self::$type_defaults[ $type ] ) ){ return $url; } + $args = wp_parse_args( $args, self::$type_defaults[ $type ] ); if ( 'placeholdit' === $type ){ diff --git a/providers/wp-meta.php b/providers/wp-meta.php index 5a4ec03..c8ca4f7 100644 --- a/providers/wp-meta.php +++ b/providers/wp-meta.php @@ -131,11 +131,24 @@ public function meta_type_wp_query( $query, $weight = 50 ) { return $value; } - public function meta_type_attachment( $type, $providers, $weight = 50 ) { + public function meta_type_attachment( $type, $providers, $weight = 50, $width = array(), $height = array() ) { $providers = array_map( 'esc_attr', array_map( 'trim', explode( ',', $providers ) ) ); + $attachment = FakerPress\Module\Attachment::instance(); + + $arguments = array(); + + // Specially for Meta we do the Randomization here + if ( ! empty( $width ) ) { + $arguments['width'] = $this->meta_parse_qty( $width ); + } + + // Specially for Meta we do the Randomization here + if ( ! empty( $height ) ) { + $arguments['height'] = $this->meta_parse_qty( $height ); + } // Generate the Attachment - $attachment = FakerPress\Module\Attachment::instance()->set( 'attachment_url', $this->generator->randomElement( $providers ) ); + $attachment->set( 'attachment_url', $this->generator->randomElement( $providers ), $arguments ); // If it's meta for a post we need to mark the attachment as child of that post if ( 'post' === $this->meta_object->name ) { From 761899aab292ae49acbf46c7e6ac427c9d7f235b Mon Sep 17 00:00:00 2001 From: bordoni Date: Sat, 5 Aug 2017 17:12:26 -0300 Subject: [PATCH 09/19] Add changelogs --- inc/class-fp-admin.php | 2 +- inc/class-fp-field.php | 8 ++++---- modules/meta.php | 4 ++-- readme.md | 3 ++- readme.txt | 3 ++- view/settings.php | 4 +++- 6 files changed, 14 insertions(+), 10 deletions(-) diff --git a/inc/class-fp-admin.php b/inc/class-fp-admin.php index 9549d59..201d238 100644 --- a/inc/class-fp-admin.php +++ b/inc/class-fp-admin.php @@ -289,7 +289,7 @@ public function _action_admin_notices() { // Plugin class to give the styling 'fakerpress-message', // This is to use WordPress JS to move them above the h2 - 'updated-nag', + 'notice', ); if ( 0 === $k ) { diff --git a/inc/class-fp-field.php b/inc/class-fp-field.php index 4192585..ac1c619 100644 --- a/inc/class-fp-field.php +++ b/inc/class-fp-field.php @@ -1295,8 +1295,8 @@ public static function get_meta_types() { $providers->{'data-options'} = Module\Attachment::get_providers(); $size_width = clone $field; - $size_width->_id = array( 'meta', 'size', 'width' ); - $size_width->_name = array( 'meta', 'size', 'width' ); + $size_width->_id = array( 'meta', 'width' ); + $size_width->_name = array( 'meta', 'width' ); $size_width->type = 'range'; $size_width->class = array(); $size_width->label = __( 'Range of possible width sizes for the image', 'fakerpress' ); @@ -1306,8 +1306,8 @@ public static function get_meta_types() { $size_width->_prevent_disable = true; $size_height = clone $field; - $size_height->_id = array( 'meta', 'size', 'height' ); - $size_height->_name = array( 'meta', 'size', 'height' ); + $size_height->_id = array( 'meta', 'height' ); + $size_height->_name = array( 'meta', 'height' ); $size_height->type = 'range'; $size_height->class = array(); $size_height->label = __( 'Range of possible height sizes for the image', 'fakerpress' ); diff --git a/modules/meta.php b/modules/meta.php index 9993285..1582a90 100644 --- a/modules/meta.php +++ b/modules/meta.php @@ -79,7 +79,7 @@ public function generate() { /** * Allow filtering for the value for a Meta - * + * * @since 0.4.8 * * @param mixed $meta_value The Meta value that will be filtered @@ -91,7 +91,7 @@ public function generate() { /** * Allow filtering for the Value of a specific meta value based on it's key - * + * * @since 0.4.8 * * @param mixed $meta_value The Meta value that will be filtered diff --git a/readme.md b/readme.md index c256d74..d546a1e 100644 --- a/readme.md +++ b/readme.md @@ -100,7 +100,8 @@ Thank you for wanting to make FakerPress better for everyone! [We salute you](ht ## Changelog ## ### 0.4.9 — TBD ### -... +* Feature: Allow Attachments to be generated with a given Width and Height range — Thanks [@COLABORATI](https://github.com/bordoni/fakerpress/issues/86) +* Fix: Resolve problems where attachments wouldn't get setup correctly and throw an Empty Message — Thanks [@r083r7 and @oyvind_skjelstad](https://wordpress.org/support/topic/featured-image-not-showing-up-6) ### 0.4.8 — 18 of July, 2017 ### * Feature: Now Comments can be generated with different types, allowing for WooCommerce Notes for example - Thanks [@dibbyo456](https://wordpress.org/support/topic/can-i-create-custom-comments/) diff --git a/readme.txt b/readme.txt index fae02f6..3f5703d 100644 --- a/readme.txt +++ b/readme.txt @@ -99,7 +99,8 @@ Thank you for wanting to make FakerPress better for everyone! [We salute you](ht = 0.4.9 — TBD = -... +* Feature: Allow Attachments to be generated with a given Width and Height range — Thanks [@COLABORATI](https://github.com/bordoni/fakerpress/issues/86) +* Fix: Resolve problems where attachments wouldn't get setup correctly and throw an Empty Message — Thanks [@r083r7 and @oyvind_skjelstad](https://wordpress.org/support/topic/featured-image-not-showing-up-6) = 0.4.8 — 18 of July, 2017 = diff --git a/view/settings.php b/view/settings.php index f8a913f..40f42de 100644 --- a/view/settings.php +++ b/view/settings.php @@ -33,7 +33,9 @@ ), array( 'label' => __( 'Consumer Key', 'fakerpress' ), - 'description' => __( 'Application Consumer Key — 500px Applications', 'fakerpress' ), + 'description' => + __( 'Application Consumer Key — 500px Applications', 'fakerpress' ) . + '
' . __( 'Note: Images generated this provider will not respect meta Width/Height configuration' ), 'actions' => array( 'save_500px' => __( 'Save', 'fakerpress' ), ), From a7222a58b973af6504374a7de34c689692af9d85 Mon Sep 17 00:00:00 2001 From: bordoni Date: Sat, 5 Aug 2017 20:36:52 -0300 Subject: [PATCH 10/19] Resolves #105 --- readme.md | 1 + readme.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/readme.md b/readme.md index d546a1e..c2d8dfa 100644 --- a/readme.md +++ b/readme.md @@ -102,6 +102,7 @@ Thank you for wanting to make FakerPress better for everyone! [We salute you](ht ### 0.4.9 — TBD ### * Feature: Allow Attachments to be generated with a given Width and Height range — Thanks [@COLABORATI](https://github.com/bordoni/fakerpress/issues/86) * Fix: Resolve problems where attachments wouldn't get setup correctly and throw an Empty Message — Thanks [@r083r7 and @oyvind_skjelstad](https://wordpress.org/support/topic/featured-image-not-showing-up-6) +* Fix: Allow Term Meta to generate the fields correctly again — Thanks [@stratboy](https://github.com/bordoni/fakerpress/issues/105) ### 0.4.8 — 18 of July, 2017 ### * Feature: Now Comments can be generated with different types, allowing for WooCommerce Notes for example - Thanks [@dibbyo456](https://wordpress.org/support/topic/can-i-create-custom-comments/) diff --git a/readme.txt b/readme.txt index 3f5703d..8dc0a4b 100644 --- a/readme.txt +++ b/readme.txt @@ -101,6 +101,7 @@ Thank you for wanting to make FakerPress better for everyone! [We salute you](ht * Feature: Allow Attachments to be generated with a given Width and Height range — Thanks [@COLABORATI](https://github.com/bordoni/fakerpress/issues/86) * Fix: Resolve problems where attachments wouldn't get setup correctly and throw an Empty Message — Thanks [@r083r7 and @oyvind_skjelstad](https://wordpress.org/support/topic/featured-image-not-showing-up-6) +* Fix: Allow Term Meta to generate the fields correctly again — Thanks [@stratboy](https://github.com/bordoni/fakerpress/issues/105) = 0.4.8 — 18 of July, 2017 = From c65d23f0fab3b9fd553ba891b45800eb55b85023 Mon Sep 17 00:00:00 2001 From: bordoni Date: Sat, 5 Aug 2017 20:53:25 -0300 Subject: [PATCH 11/19] Make sure we are generating post_excerpt for the Post Module --- inc/class-fp-utils.php | 6 +++--- modules/post.php | 1 + providers/wp-post.php | 13 +++++++++++++ readme.md | 1 + readme.txt | 1 + 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/inc/class-fp-utils.php b/inc/class-fp-utils.php index 2984dab..52cbbde 100644 --- a/inc/class-fp-utils.php +++ b/inc/class-fp-utils.php @@ -38,10 +38,10 @@ private function __construct() { /** * From range return a random Integer - * Providing the $elements param will limit the returning integer to the total number of elements + * Providing the $total param will limit the returning integer to the total number of elements * - * @param array|int $qty The range or integer - * @param null|int|array $elements { + * @param array|int $qty The range or integer + * @param null|int|array $total { * @example null Will not limit the Range to a maximum int * @example int Limits the range to this maximum * @example array Counts the elements in array and limit to that diff --git a/modules/post.php b/modules/post.php index 05c8f9e..6973f81 100644 --- a/modules/post.php +++ b/modules/post.php @@ -164,6 +164,7 @@ public function parse_request( $qty, $request = array() ) { $this->set( 'post_date', $date ); $this->set( 'post_parent', $post_parents ); $this->set( 'post_content', $post_content_use_html, array( 'elements' => $post_content_html_tags, 'sources' => $images_origin ) ); + $this->set( 'post_excerpt' ); $this->set( 'post_author', $post_author ); $this->set( 'post_type', $post_types ); $this->set( 'comment_status', $comment_status ); diff --git a/providers/wp-post.php b/providers/wp-post.php index 9b51622..799db5f 100644 --- a/providers/wp-post.php +++ b/providers/wp-post.php @@ -80,6 +80,19 @@ public function post_content( $html = true, $args = array() ) { return $content; } + public function post_excerpt( $qty = array( 25, 75 ), $html = false, $weight = 60 ) { + $words = FakerPress\Utils::instance()->get_qty_from_range( $qty ); + $paragraphs = $this->generator->randomElement( array( 1, 1, 1, 1, 1, 2, 2, 2, 3, 4 ) ); + + for ( $i=0; $i < $paragraphs; $i++ ) { + $excerpt[ $i ] = $this->generator->sentence( $words ); + } + + $excerpt = implode( "\n\n", $excerpt ); + + return $this->generator->optional( $weight, '' )->randomElement( (array) $excerpt ); + } + public function post_author( $haystack = array() ) { if ( empty( $haystack ) ){ $haystack = get_users( diff --git a/readme.md b/readme.md index c2d8dfa..ec0361e 100644 --- a/readme.md +++ b/readme.md @@ -103,6 +103,7 @@ Thank you for wanting to make FakerPress better for everyone! [We salute you](ht * Feature: Allow Attachments to be generated with a given Width and Height range — Thanks [@COLABORATI](https://github.com/bordoni/fakerpress/issues/86) * Fix: Resolve problems where attachments wouldn't get setup correctly and throw an Empty Message — Thanks [@r083r7 and @oyvind_skjelstad](https://wordpress.org/support/topic/featured-image-not-showing-up-6) * Fix: Allow Term Meta to generate the fields correctly again — Thanks [@stratboy](https://github.com/bordoni/fakerpress/issues/105) +* Fix: Makes sure we generate `post_excerpt`, which wasn't happening for some reason — Thanks [@njbarrett](https://github.com/bordoni/fakerpress/issues/104) ### 0.4.8 — 18 of July, 2017 ### * Feature: Now Comments can be generated with different types, allowing for WooCommerce Notes for example - Thanks [@dibbyo456](https://wordpress.org/support/topic/can-i-create-custom-comments/) diff --git a/readme.txt b/readme.txt index 8dc0a4b..3d4c944 100644 --- a/readme.txt +++ b/readme.txt @@ -102,6 +102,7 @@ Thank you for wanting to make FakerPress better for everyone! [We salute you](ht * Feature: Allow Attachments to be generated with a given Width and Height range — Thanks [@COLABORATI](https://github.com/bordoni/fakerpress/issues/86) * Fix: Resolve problems where attachments wouldn't get setup correctly and throw an Empty Message — Thanks [@r083r7 and @oyvind_skjelstad](https://wordpress.org/support/topic/featured-image-not-showing-up-6) * Fix: Allow Term Meta to generate the fields correctly again — Thanks [@stratboy](https://github.com/bordoni/fakerpress/issues/105) +* Fix: Makes sure we generate `post_excerpt`, which wasn't happening for some reason — Thanks [@njbarrett](https://github.com/bordoni/fakerpress/issues/104) = 0.4.8 — 18 of July, 2017 = From b88ef565e8db3fc9f3df3ada5e4748222272bcdb Mon Sep 17 00:00:00 2001 From: bordoni Date: Sat, 5 Aug 2017 20:57:03 -0300 Subject: [PATCH 12/19] Add a docblock for the post_excerpt method --- providers/wp-post.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/providers/wp-post.php b/providers/wp-post.php index 799db5f..7e9cf2f 100644 --- a/providers/wp-post.php +++ b/providers/wp-post.php @@ -80,6 +80,17 @@ public function post_content( $html = true, $args = array() ) { return $content; } + /** + * Configures a Excerpt for the Post + * + * @since 0.4.9 + * + * @param array|int $qty How many words we should generate (range with Array) + * @param boolean $html Should use HTML or not (currently not used) + * @param integer $weight Percentage of times where we will setup a Excerpt + * + * @return string + */ public function post_excerpt( $qty = array( 25, 75 ), $html = false, $weight = 60 ) { $words = FakerPress\Utils::instance()->get_qty_from_range( $qty ); $paragraphs = $this->generator->randomElement( array( 1, 1, 1, 1, 1, 2, 2, 2, 3, 4 ) ); From 28cbfa363a1ca0f5f3886a8aebb72f702e594047 Mon Sep 17 00:00:00 2001 From: bordoni Date: Sat, 5 Aug 2017 21:03:44 -0300 Subject: [PATCH 13/19] Changelog --- readme.md | 1 + readme.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/readme.md b/readme.md index ec0361e..694296c 100644 --- a/readme.md +++ b/readme.md @@ -101,6 +101,7 @@ Thank you for wanting to make FakerPress better for everyone! [We salute you](ht ### 0.4.9 — TBD ### * Feature: Allow Attachments to be generated with a given Width and Height range — Thanks [@COLABORATI](https://github.com/bordoni/fakerpress/issues/86) +* Fix: Better control over Words and Text meta fields — Thanks [@ckpicker](https://github.com/bordoni/fakerpress/issues/115) * Fix: Resolve problems where attachments wouldn't get setup correctly and throw an Empty Message — Thanks [@r083r7 and @oyvind_skjelstad](https://wordpress.org/support/topic/featured-image-not-showing-up-6) * Fix: Allow Term Meta to generate the fields correctly again — Thanks [@stratboy](https://github.com/bordoni/fakerpress/issues/105) * Fix: Makes sure we generate `post_excerpt`, which wasn't happening for some reason — Thanks [@njbarrett](https://github.com/bordoni/fakerpress/issues/104) diff --git a/readme.txt b/readme.txt index 3d4c944..50869b6 100644 --- a/readme.txt +++ b/readme.txt @@ -100,6 +100,7 @@ Thank you for wanting to make FakerPress better for everyone! [We salute you](ht = 0.4.9 — TBD = * Feature: Allow Attachments to be generated with a given Width and Height range — Thanks [@COLABORATI](https://github.com/bordoni/fakerpress/issues/86) +* Fix: Better control over Words and Text meta fields — Thanks [@ckpicker](https://github.com/bordoni/fakerpress/issues/115) * Fix: Resolve problems where attachments wouldn't get setup correctly and throw an Empty Message — Thanks [@r083r7 and @oyvind_skjelstad](https://wordpress.org/support/topic/featured-image-not-showing-up-6) * Fix: Allow Term Meta to generate the fields correctly again — Thanks [@stratboy](https://github.com/bordoni/fakerpress/issues/105) * Fix: Makes sure we generate `post_excerpt`, which wasn't happening for some reason — Thanks [@njbarrett](https://github.com/bordoni/fakerpress/issues/104) From 9c145ac415a82ccaeb8acf4070c704c45662fcc0 Mon Sep 17 00:00:00 2001 From: bordoni Date: Sat, 5 Aug 2017 21:05:06 -0300 Subject: [PATCH 14/19] Changelog for another Feature --- readme.md | 2 +- readme.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 694296c..5f81a34 100644 --- a/readme.md +++ b/readme.md @@ -101,10 +101,10 @@ Thank you for wanting to make FakerPress better for everyone! [We salute you](ht ### 0.4.9 — TBD ### * Feature: Allow Attachments to be generated with a given Width and Height range — Thanks [@COLABORATI](https://github.com/bordoni/fakerpress/issues/86) +* Feature: Generate `post_excerpt` for Posts (how I forgot that is beyond me) — Thanks [@njbarrett](https://github.com/bordoni/fakerpress/issues/104) * Fix: Better control over Words and Text meta fields — Thanks [@ckpicker](https://github.com/bordoni/fakerpress/issues/115) * Fix: Resolve problems where attachments wouldn't get setup correctly and throw an Empty Message — Thanks [@r083r7 and @oyvind_skjelstad](https://wordpress.org/support/topic/featured-image-not-showing-up-6) * Fix: Allow Term Meta to generate the fields correctly again — Thanks [@stratboy](https://github.com/bordoni/fakerpress/issues/105) -* Fix: Makes sure we generate `post_excerpt`, which wasn't happening for some reason — Thanks [@njbarrett](https://github.com/bordoni/fakerpress/issues/104) ### 0.4.8 — 18 of July, 2017 ### * Feature: Now Comments can be generated with different types, allowing for WooCommerce Notes for example - Thanks [@dibbyo456](https://wordpress.org/support/topic/can-i-create-custom-comments/) diff --git a/readme.txt b/readme.txt index 50869b6..065e809 100644 --- a/readme.txt +++ b/readme.txt @@ -100,10 +100,10 @@ Thank you for wanting to make FakerPress better for everyone! [We salute you](ht = 0.4.9 — TBD = * Feature: Allow Attachments to be generated with a given Width and Height range — Thanks [@COLABORATI](https://github.com/bordoni/fakerpress/issues/86) +* Feature: Generate `post_excerpt` for Posts (how I forgot that is beyond me) — Thanks [@njbarrett](https://github.com/bordoni/fakerpress/issues/104) * Fix: Better control over Words and Text meta fields — Thanks [@ckpicker](https://github.com/bordoni/fakerpress/issues/115) * Fix: Resolve problems where attachments wouldn't get setup correctly and throw an Empty Message — Thanks [@r083r7 and @oyvind_skjelstad](https://wordpress.org/support/topic/featured-image-not-showing-up-6) * Fix: Allow Term Meta to generate the fields correctly again — Thanks [@stratboy](https://github.com/bordoni/fakerpress/issues/105) -* Fix: Makes sure we generate `post_excerpt`, which wasn't happening for some reason — Thanks [@njbarrett](https://github.com/bordoni/fakerpress/issues/104) = 0.4.8 — 18 of July, 2017 = From 80de8b37798b39b8a3fdfd8775d1ea0dbe875403 Mon Sep 17 00:00:00 2001 From: bordoni Date: Sat, 5 Aug 2017 23:09:20 -0300 Subject: [PATCH 15/19] Remove the Period in the end of Words + Some docblocks for Meta --- inc/class-fp-utils.php | 10 +++++ modules/meta.php | 89 +++++++++++++++++++++++++++++++++++++++++- providers/wp-meta.php | 4 +- 3 files changed, 100 insertions(+), 3 deletions(-) diff --git a/inc/class-fp-utils.php b/inc/class-fp-utils.php index 52cbbde..6cbb4ba 100644 --- a/inc/class-fp-utils.php +++ b/inc/class-fp-utils.php @@ -35,6 +35,16 @@ private function __construct() { } + /** + * Remove the Period on the end of the Setence from Faker + * + * @param string $sentence Which sentence we should remove the period from + * @return string + */ + public function remove_sentence_period( $sentence ) { + return rtrim( $sentence, '.' ); + } + /** * From range return a random Integer diff --git a/modules/meta.php b/modules/meta.php index 1582a90..dcc24ee 100644 --- a/modules/meta.php +++ b/modules/meta.php @@ -4,9 +4,21 @@ use FakerPress\Variable; use FakerPress\Plugin; - +/** + * Meta Module which will generate one Meta Value at a time + * + * @since 0.3.0 + * + */ class Meta extends Base { + /** + * Which Faker Dependencies this Module will need + * + * @since 0.3.0 + * + * @var array + */ public $dependencies = array( '\Faker\Provider\Base', '\Faker\Provider\Lorem', @@ -19,24 +31,75 @@ class Meta extends Base { '\Faker\Provider\en_US\Person', ); + /** + * Which Faker Provider class we are using here + * + * @since 0.3.0 + * + * @var string + */ public $provider = '\Faker\Provider\WP_Meta'; + /** + * Wether or not FakerPress will generate a page for this + * + * @since 0.3.0 + * + * @var boolean + */ public $page = false; - // Default Object is Posts + /** + * Which type of object we are saving to + * + * @since 0.3.0 + * + * @var string + */ public $object_name = 'post'; + + /** + * Which object we are saving to + * + * @since 0.3.0 + * + * @var integer + */ public $object_id = 0; + /** + * Initalize and Add the correct hooks into the Meta Module + * + * @since 0.3.0 + * + * @return void + */ public function init() { add_filter( "fakerpress.module.{$this->slug}.save", array( $this, 'do_save' ), 10, 3 ); } + /** + * Resets which original object that we will save the meta to + * + * @since 0.3.0 + * + * @return self + */ public function reset() { parent::reset(); $this->object_id = 0; + + return $this; } + /** + * Configure which Object we will save Meta to + * + * @since 0.3.0 + * + * @return self + */ public function object( $id = 0, $name = 'post' ) { $this->object_id = $id; $this->object_name = $name; @@ -44,6 +107,17 @@ public function object( $id = 0, $name = 'post' ) { return $this; } + /** + * Generate the meta based on the Params given + * + * @since 0.3.0 + * + * @param string $type Type of Meta we are dealing with + * @param string $name Name of the Meta, used to save + * @param array $args Arguments used to setup the Meta + * + * @return self + */ public function generate() { // Allow a bunch of params $arguments = func_get_args(); @@ -103,6 +177,17 @@ public function generate() { return $this; } + /** + * Actually save the meta value into the Database + * + * @since 0.3.0 + * + * @param string $return_val Unsed variable that comes from the hook + * @param string $data Data generated, meta_key and meta_value + * @param array $module Arguments used to setup the Meta + * + * @return self + */ public function do_save( $return_val, $data, $module ) { $status = false; diff --git a/providers/wp-meta.php b/providers/wp-meta.php index c8ca4f7..72ffd7d 100644 --- a/providers/wp-meta.php +++ b/providers/wp-meta.php @@ -1,6 +1,7 @@ meta_parse_qty( $qty ); + $sentence = $this->generator->optional( (int) $weight, '' )->sentence( $qty ); - return $this->generator->optional( (int) $weight, null )->sentence( $qty ); + return Utils::instance()->remove_sentence_period( $sentence ); } public function meta_type_text( $type = 'sentences', $qty = 3, $separator = "\r\n\r\n", $weight = 50 ) { From 36be548edfa220cc65d54b1f0176717977536f2b Mon Sep 17 00:00:00 2001 From: bordoni Date: Sun, 6 Aug 2017 13:38:25 -0300 Subject: [PATCH 16/19] Resolve the problem where Fieldset wasn't respecting Index --- ui/js/fields.js | 168 +++++--------------------------------------- ui/js/fields.min.js | 2 +- 2 files changed, 17 insertions(+), 153 deletions(-) diff --git a/ui/js/fields.js b/ui/js/fields.js index 40f926e..7a5892d 100644 --- a/ui/js/fields.js +++ b/ui/js/fields.js @@ -404,31 +404,31 @@ window.fakerpress.fields.range = function( $, _ ){ * @return null */ configure: function( $conf ) { - var config = $conf.data( 'config' ), - $fields = $conf.find( window.fakerpress.fieldset.selector.field ); + var fieldset = this; + var config = $conf.data( 'config' ); + var $fields = $conf.find( window.fakerpress.fieldset.selector.field ); // Reset the Configuration, only happens once! // $conf.removeAttr( 'data-config', false ).data( 'config', {} ); // Loop fields $fields.each( function() { - var $field = $( this ), - name = $field.data( 'name' ), - index = name.length - 1, - key = name[ index ]; - - var $field = $( this ), - $label = $field.next( window.fakerpress.fieldset.selector.label ), - $internal_label = $field.next( window.fakerpress.fieldset.selector.internal_label ), - - __name = $field.data( 'name' ), - __id = $field.data( 'id' ), - id = [], - name = []; + var $field = $( this ); + var $fieldset = $field.parents( fieldset.selector.item ).eq( 0 ); + var $label = $field.next( window.fakerpress.fieldset.selector.label ); + var $internal_label = $field.next( window.fakerpress.fieldset.selector.internal_label ); + + var name = $field.data( 'name' ); + var index = parseInt( $fieldset.find( window.fakerpress.fieldset.selector.order ).val(), 10 ) - 1; + var key = name[ index ]; + var __name = $field.data( 'name' ); + var __id = $field.data( 'id' ); + var id = []; + var name = []; // If didn't find a label inside of the parent element if ( 0 === $label.length ){ - $label = $field.parents( window.fakerpress.fieldset.selector.field_container ).eq(0).find( window.fakerpress.fieldset.selector.label ); + $label = $field.parents( window.fakerpress.fieldset.selector.field_container ).eq( 0 ).find( window.fakerpress.fieldset.selector.label ); } _.each( __id, function( value, key, list ) { @@ -455,7 +455,6 @@ window.fakerpress.fields.range = function( $, _ ){ $field.attr( 'name', window.fakerpress.fieldName( name ) ); } - if ( 'undefined' === typeof config || 'undefined' === typeof config[ key ] ) { return; } @@ -715,138 +714,3 @@ window.fakerpress.fields.range = function( $, _ ){ } ); } ); }( window.jQuery, window._ ) ); - -/* - -// Terms Fields -( function( $, _ ){ - 'use strict'; - $(document).ready(function(){ - $( '.field-select2-terms' ).each(function(){ - var $select = $(this); - - $select.select2({ - width: 400, - multiple: true, - data: {results:[]}, - initSelection : function (element, callback) { - callback(element.data( 'selected' )); - }, - allowClear: true, - ajax: { // instead of writing the function to execute the request we use Select2's convenient helper - dataType: 'json', - type: 'POST', - url: window.ajaxurl, - data: function (term, page) { - return { - action: 'fakerpress.search_terms', - search: term, // search term - page_limit: 10, - page: page, - post_type: null - }; - }, - results: function ( data ) { // parse the results into the format expected by Select2. - $.each( data.results, function( k, result ){ - result.text = _.template('<%= tax %>: <%= term %>')( { tax: data.taxonomies[result.taxonomy].labels.singular_name, term: result.name } ); - result.id = result.term_id; - } ); - return data; - } - }, - }); - }); - }); -}( jQuery, _ ) ); - -// Author fields -( function( $ ){ - 'use strict'; - $(document).ready(function(){ - $( '.field-select2-author' ).each(function(){ - var $select = $(this); - - $select.select2({ - width: 400, - multiple: true, - allowClear: true, - escapeMarkup: function (m) { return m; }, - formatSelection: function ( author ){ - return _.template('<%= roles %>: <%= data.display_name %>')( author ) - }, - formatResult: function ( author ){ - return _.template('<%= roles %>: <%= data.display_name %>')( author ) - }, - ajax: { - dataType: 'json', - type: 'POST', - url: window.ajaxurl, - data: function ( author, page ) { - return { - action: 'fakerpress.search_authors', - search: author, // search author - page_limit: 10, - page: page, - }; - }, - results: function ( data ) { // parse the results into the format expected by Select2. - $.each( data.results, function( k, result ){ - result.id = result.data.ID; - result.text = result.data.display_name; - } ); - return data; - } - } - }); - }); - }); -}( jQuery ) ); - -// Post Query for Select2 -( function( $, _ ){ - 'use strict'; - $(document).ready(function(){ - $( '.fp-field-select2-posts' ).each(function(){ - var $select = $(this); - $select.select2({ - width: 400, - multiple: true, - data: {results:[]}, - allowClear: true, - escapeMarkup: function (m) { return m; }, - formatSelection: function ( post ){ - return _.template('<%= post_type.labels.singular_name %>: <%= ID %>')( post ) - }, - formatResult: function ( post ){ - return _.template('<%= post_type.labels.singular_name %>: <%= ID %>')( post ) - }, - ajax: { // instead of writing the function to execute the request we use Select2's convenient helper - dataType: 'json', - type: 'POST', - url: window.ajaxurl, - data: function (search, page) { - return { - action: 'fakerpress.query_posts', - query: { - s: search, - posts_per_page: 10, - paged: page, - post_type: _.pluck( _.where( $( '.field-post_type.select2-offscreen' ).data( 'value' ), { hierarchical: true } ) , 'id' ) - } - }; - }, - results: function ( data ) { // parse the results into the format expected by Select2. - $.each( data.results, function( k, result ){ - result.id = result.ID; - } ); - return data; - } - }, - }); - }); - }); -}( jQuery, _ ) ); - - - -*/ \ No newline at end of file diff --git a/ui/js/fields.min.js b/ui/js/fields.min.js index 639b93a..28a3f2d 100644 --- a/ui/js/fields.min.js +++ b/ui/js/fields.min.js @@ -1 +1 @@ -"undefined"==typeof window.fakerpress&&(window.fakerpress={}),window.fakerpress.fields={},window.fakerpress.ready_class="fp-js-ready",window.fakerpress.plugin="fakerpress",window.fakerpress.abbr="fp",window.fakerpress.fieldName=function(a){return a=a.map(function(a){return new String(a)}),this.plugin+"["+a.join("][")+"]"},window.fakerpress.fieldId=function(a){return this.plugin+"-field-"+a.join("-")},window.fakerpress.searchId=function(a){var b=null;return"undefined"!=typeof a.id?b=a.id:"undefined"!=typeof a.ID?b=a.ID:"undefined"!=typeof a.value&&(b=a.value),void 0==a?null:b},window.fakerpress.fields.dates=function(a){"use strict";var b={after:["attr"],constrainInput:!1,dateFormat:"yy-mm-dd"};a(".fp-type-date").not(".hasDatepicker").datepicker(b),a(".fp-type-interval-wrap").each(function(){var b=a(this),c=b.find(".fp-type-dropdown"),d=b.find('[data-type="min"]'),e=b.find('[data-type="max"]');b.hasClass(window.fakerpress.ready_class)||(b.addClass(window.fakerpress.ready_class),d.on({change:function(){d.parents(".fp-field-wrap").find('[data-type="max"]').datepicker("option","minDate",a(this).val()).datepicker("refresh"),a(".fp-type-date.hasDatepicker").datepicker("refresh")}}),e.on({change:function(){e.parents(".fp-field-wrap").find('[data-type="min"]').datepicker("option","maxDate",a(this).val()).datepicker("refresh"),a(".fp-type-date.hasDatepicker").datepicker("refresh")}}),c.on({change:function(){var a=c.find(":selected"),b=a.attr("min"),f=a.attr("max");d.datepicker("setDate",b),e.datepicker("setDate",f)}}).trigger("change"))})},window.fakerpress.fields.dropdown=function(a,b){"use strict";var c=a(".fp-type-dropdown").not(".select2-offscreen, .select2-container"),d={wp_query_title:[]};d.wp_query_title.push("ID: "<%= ID %>""),d.wp_query_title.push("Title: "<%= post_title %>""),d.wp_query_title.push("Post Type: "<%= post_type.labels.singular_name %>""),d.wp_query_title.push("Author: "<%= post_author %>""),c.each(function(){var c=a(this),e={width:420};if(c.is("[multiple]")?(e.multiple=!0,c.is("[data-tags]")||(e.data=function(){return{results:c.data("options")}}),e.tokenSeparators=b.isArray(c.data("separator"))?c.data("separator"):[c.data("separator")],e.separator=c.data("separator"),e.regexSeparatorElements=["^("],e.regexSplitElements=["(?:"],a.each(e.tokenSeparators,function(a,b){e.regexSeparatorElements.push("[^"+b+"]+"),e.regexSplitElements.push("["+b+"]")}),e.regexSeparatorElements.push(")$"),e.regexSplitElements.push(")"),e.regexSeparatorString=e.regexSeparatorElements.join(""),e.regexSplitString=e.regexSplitElements.join(""),e.regexToken=new RegExp(e.regexSeparatorString,"ig"),e.regexSplit=new RegExp(e.regexSplitString,"ig"),e.id=window.fakerpress.searchId):e.width=200,e.matcher=function(a,c){var d=0==c.toUpperCase().indexOf(a.toUpperCase());if(!d&&"undefined"!=typeof e.tags){var f=b.where(e.tags,{text:c});if(e.tags.length>0&&b.isObject(f)){var g=window.fakerpress.searchId(f[0]);d=0==g.toUpperCase().indexOf(a.toUpperCase())}}return d},c.is("[data-tags]")&&(e.tags=c.data("options"),e.initSelection=function(c,d){var f=[];a(c.val().split(e.regexSplit)).each(function(){var a={id:this,text:this};if(e.tags.length>0&&b.isObject(e.tags[0])){var c=b.where(e.tags,{value:this});c.length>0&&(a=c[0],a={id:a.value,text:a.text})}f.push(a)}),d(f)},e.createSearchChoice=function(a){return a.match(e.regexToken)?{id:a,text:a}:void 0},0===e.tags.length&&(e.formatNoMatches=function(){return c.attr("placeholder")})),c.is("[data-source]")){var f=c.data("source");e.data={results:[]},e.allowClear=!0,e.escapeMarkup=function(a){return a},e.ajax={dataType:"json",type:"POST",url:window.ajaxurl,results:function(b){return a.each(b.results,function(a,b){b.id=b.ID}),b}},"WP_Query"===f?(e.formatSelection=function(a){return b.template('<%= post_type.labels.singular_name %>: <%= ID %>')(a)},e.formatResult=function(a){return b.template('<%= post_type.labels.singular_name %>: <%= ID %> [ <%= post_title %> ]')(a)},e.ajax.data=function(c,d){var e=b.intersection(a("#fakerpress-field-post_types").val().split(","),b.pluck(b.where(a("#fakerpress-field-post_types").data("options"),{hierarchical:!0}),"id"));return{action:"fakerpress.select2-"+f,query:{s:c,posts_per_page:10,paged:d,post_type:e}}}):(e.ajax.data=function(b,d){var e=c.parents(".fp-table-taxonomy").eq(0);return{action:"fakerpress.select2-"+f,search:b,page:d,page_limit:25,taxonomies:e.find(".fp-taxonomies").select2("val"),exclude:a(this).select2("val")}},e.formatSelection=function(a){return b.template("<%= taxonomy %>: <%= name %>")(a)},e.formatResult=function(a){return b.template("<%= taxonomy %>: <%= name %>")(a)})}c.select2(e)}).on("change",function(c){var d=a(this),e=a(this).data("value");d.is("[multiple]")&&d.is("[data-source]")&&(c.added?b.isArray(e)?e.push(c.added):e=[c.added]:e=b.isArray(e)?b.without(e,c.removed):[],d.data("value",e).attr("data-value",JSON.stringify(e)))})},window.fakerpress.fields.range=function(a){"use strict";a(".fp-type-range-wrap").each(function(){var b=a(this),c=b.find('.fp-type-number[data-type="min"]'),d=b.find('.fp-type-number[data-type="max"]');b.hasClass(window.fakerpress.ready_class)||(b.addClass(window.fakerpress.ready_class),c.on({"change keyup":function(){a.isNumeric(a(this).val())?(d.removeAttr("disabled"),d.val()&&a(this).val()>=d.val()&&a(this).val("")):a(this).val("")}}))})},function(a){a(document).ready(function(){a.each(window.fakerpress.fields,function(a,b){b(window.jQuery,window._)})})}(jQuery),function(a,b){"use strict";window.fakerpress.fieldset={items:[{name:"meta",$:{},selector:{container:".fp-type-meta-container",item:".fp-table-meta",type_container:".fp-meta_type-container",type:".fp-meta_type",name_container:".fp-meta_name-container",name:".fp-meta_name",conf_container:".fp-meta_conf-container"},update:function(a){this.render(a)},render:function(b){{var c,d,e=this,f=b.find(e.selector.type),g=f.select2("val"),h=b.find(e.selector.name),i=(h.val(),b.find(e.selector.name_container)),j=(b.find(e.selector.type_container),b.find(e.selector.conf_container)),k=j.find(window.fakerpress.fieldset.selector.wrap);j.data("config")}g instanceof jQuery&&(g=g.val()),c=a(".fp-template-"+g).filter('[data-rel="'+e.$.container.attr("id")+'"]').filter("[data-callable]"),d=c.html(),d&&g!==j.data("type")&&(j.data("type",g),k.empty().append(d),this.configure(j)),g?(i.removeClass("fp-last-child"),j.show()):(i.addClass("fp-last-child"),j.hide())},configure:function(c){var d=c.data("config"),e=c.find(window.fakerpress.fieldset.selector.field);e.each(function(){var c=a(this),e=c.data("name"),f=e.length-1,g=e[f],c=a(this),h=c.next(window.fakerpress.fieldset.selector.label),i=c.next(window.fakerpress.fieldset.selector.internal_label),j=c.data("name"),k=c.data("id"),l=[],e=[];0===h.length&&(h=c.parents(window.fakerpress.fieldset.selector.field_container).eq(0).find(window.fakerpress.fieldset.selector.label)),b.each(k,function(a){l.push(a),("meta"===a||"taxonomy"===a)&&l.push(f)}),b.each(j,function(a){e.push(a),("meta"===a||"taxonomy"===a)&&e.push(f)}),0!==l.length&&(c.attr("id",window.fakerpress.fieldId(l)),h.attr("for",window.fakerpress.fieldId(l)),i.attr("for",window.fakerpress.fieldId(l))),0!==e.length&&c.attr("name",window.fakerpress.fieldName(e)),"undefined"!=typeof d&&"undefined"!=typeof d[g]&&c.val(d[g])})},is_removeable:function(){if(1===this.$.items.length){var a=this.$.items.eq(0);return b.isEmpty(a.find(this.selector.type).select2("val"))?!0:!1}return!1},setup:function(){var b=this;b.$.container.on("change",b.selector.type,[],function(){var c=a(this);b.render(c),window.fakerpress.fieldset.update(b,!1)})},reset:function(){}},{name:"taxonomy",$:{},selector:{container:".fp-type-taxonomy-container",item:".fp-table-taxonomy",taxonomies_container:".fp-taxonomies-container",taxonomies:".fp-taxonomies",terms_container:".fp-terms-container",terms:".fp-terms",weight_container:".fp-weight-container",weight:".fp-weight"},update:function(){},is_removeable:function(){if(1===this.$.items.length){var a=this.$.items.eq(0);return b.isEmpty(a.find(this.selector.taxonomies).select2("val"))&&b.isEmpty(a.find(this.selector.terms).val())?!0:!1}return!1},setup:function(){},reset:function(){}}],selector:{wrap:".fp-field-wrap",duplicate:".fp-action-duplicate",remove:".fp-action-remove",order:".fp-action-order",label:".fp-field-label",internal_label:".fp-internal-label",field:".fp-field",field_container:".fp-field-container"},setup:function(b){var c=a("form").children(".form-table").children("tbody");b.$={},b.$.container=c.children(b.selector.container),b.$.wrap=b.$.container.children(window.fakerpress.fieldset.selector.wrap),b.$.container.on("click",this.selector.duplicate,[],function(){var c=a(this),d=c.parents(b.selector.item),e=d.clone();e.find(".fp-type-date").removeClass("hasDatepicker").end().find(".fp-type-dropdown").removeClass("select2-offscreen").filter(".select2-container").remove(),window.fakerpress.fieldset.reset(b,e),b.$.wrap.append(e),window.fakerpress.fieldset.update(b)}),b.$.container.on("click",this.selector.remove,[],function(){var c=a(this),d=c.parents(b.selector.item);1===b.$.items.length?window.fakerpress.fieldset.reset(b,b.$.items.eq(0)):d.remove(),window.fakerpress.fieldset.update(b)}),b.setup(),this.update(b,!1)},reset:function(b,c){var d=c.find("tbody").find(window.fakerpress.fieldset.selector.field);d.each(function(){var b=a(this);b.val(""),b.hasClass("select2-offscreen")&&b.select2("val","")}),b.reset(c)},update:function(c){c.$.items=c.$.wrap.children(c.selector.item),c.is_removeable()?c.$.items.eq(0).find(window.fakerpress.fieldset.selector.remove).prop("disabled",!0).end().find(c.selector.name).prop("required",!1):c.$.items.find(window.fakerpress.fieldset.selector.remove).prop("disabled",!1).end().find(c.selector.name).prop("required",!0),c.$.items.each(function(d){var e=a(this),f=e.find(window.fakerpress.fieldset.selector.order),g=e.find(window.fakerpress.fieldset.selector.field);f.val(d+1),g.filter("input, textarea, select").each(function(){var c=a(this),e=c.next(window.fakerpress.fieldset.selector.label),f=c.next(window.fakerpress.fieldset.selector.internal_label),g=c.data("name"),h=c.data("id"),i=[],j=[];0===e.length&&(e=c.parents(window.fakerpress.fieldset.selector.field_container).eq(0).find(window.fakerpress.fieldset.selector.label)),b.each(h,function(a){i.push(a),("meta"===a||"taxonomy"===a)&&i.push(d)}),b.each(g,function(a){j.push(a),("meta"===a||"taxonomy"===a)&&j.push(d)}),0!==i.length&&(c.attr("id",window.fakerpress.fieldId(i)),e.attr("for",window.fakerpress.fieldId(i)),f.attr("for",window.fakerpress.fieldId(i))),0!==j.length&&c.attr("name",window.fakerpress.fieldName(j))}),c.update(e)}),a.each(window.fakerpress.fields,function(a,b){b(window.jQuery,window._)})}},a(document).ready(function(){a.each(window.fakerpress.fieldset.items,function(a,b){window.fakerpress.fieldset.setup(b),b.$.container.each(function(){window.fakerpress.fieldset.update(b)})})})}(window.jQuery,window._); \ No newline at end of file +"undefined"==typeof window.fakerpress&&(window.fakerpress={}),window.fakerpress.fields={},window.fakerpress.ready_class="fp-js-ready",window.fakerpress.plugin="fakerpress",window.fakerpress.abbr="fp",window.fakerpress.fieldName=function(a){return a=a.map(function(a){return new String(a)}),this.plugin+"["+a.join("][")+"]"},window.fakerpress.fieldId=function(a){return this.plugin+"-field-"+a.join("-")},window.fakerpress.searchId=function(a){var b=null;return"undefined"!=typeof a.id?b=a.id:"undefined"!=typeof a.ID?b=a.ID:"undefined"!=typeof a.value&&(b=a.value),void 0==a?null:b},window.fakerpress.fields.dates=function(a){"use strict";var b={after:["attr"],constrainInput:!1,dateFormat:"yy-mm-dd"};a(".fp-type-date").not(".hasDatepicker").datepicker(b),a(".fp-type-interval-wrap").each(function(){var b=a(this),c=b.find(".fp-type-dropdown"),d=b.find('[data-type="min"]'),e=b.find('[data-type="max"]');b.hasClass(window.fakerpress.ready_class)||(b.addClass(window.fakerpress.ready_class),d.on({change:function(){d.parents(".fp-field-wrap").find('[data-type="max"]').datepicker("option","minDate",a(this).val()).datepicker("refresh"),a(".fp-type-date.hasDatepicker").datepicker("refresh")}}),e.on({change:function(){e.parents(".fp-field-wrap").find('[data-type="min"]').datepicker("option","maxDate",a(this).val()).datepicker("refresh"),a(".fp-type-date.hasDatepicker").datepicker("refresh")}}),c.on({change:function(){var a=c.find(":selected"),b=a.attr("min"),f=a.attr("max");d.datepicker("setDate",b),e.datepicker("setDate",f)}}).trigger("change"))})},window.fakerpress.fields.dropdown=function(a,b){"use strict";var c=a(".fp-type-dropdown").not(".select2-offscreen, .select2-container"),d={wp_query_title:[]};d.wp_query_title.push("ID: "<%= ID %>""),d.wp_query_title.push("Title: "<%= post_title %>""),d.wp_query_title.push("Post Type: "<%= post_type.labels.singular_name %>""),d.wp_query_title.push("Author: "<%= post_author %>""),c.each(function(){var c=a(this),e={width:420};if(c.is("[multiple]")?(e.multiple=!0,c.is("[data-tags]")||(e.data=function(){return{results:c.data("options")}}),e.tokenSeparators=b.isArray(c.data("separator"))?c.data("separator"):[c.data("separator")],e.separator=c.data("separator"),e.regexSeparatorElements=["^("],e.regexSplitElements=["(?:"],a.each(e.tokenSeparators,function(a,b){e.regexSeparatorElements.push("[^"+b+"]+"),e.regexSplitElements.push("["+b+"]")}),e.regexSeparatorElements.push(")$"),e.regexSplitElements.push(")"),e.regexSeparatorString=e.regexSeparatorElements.join(""),e.regexSplitString=e.regexSplitElements.join(""),e.regexToken=new RegExp(e.regexSeparatorString,"ig"),e.regexSplit=new RegExp(e.regexSplitString,"ig"),e.id=window.fakerpress.searchId):e.width=200,e.matcher=function(a,c){var d=0==c.toUpperCase().indexOf(a.toUpperCase());if(!d&&"undefined"!=typeof e.tags){var f=b.where(e.tags,{text:c});if(e.tags.length>0&&b.isObject(f)){var g=window.fakerpress.searchId(f[0]);d=0==g.toUpperCase().indexOf(a.toUpperCase())}}return d},c.is("[data-tags]")&&(e.tags=c.data("options"),e.initSelection=function(c,d){var f=[];a(c.val().split(e.regexSplit)).each(function(){var a={id:this,text:this};if(e.tags.length>0&&b.isObject(e.tags[0])){var c=b.where(e.tags,{value:this});c.length>0&&(a=c[0],a={id:a.value,text:a.text})}f.push(a)}),d(f)},e.createSearchChoice=function(a){return a.match(e.regexToken)?{id:a,text:a}:void 0},0===e.tags.length&&(e.formatNoMatches=function(){return c.attr("placeholder")})),c.is("[data-source]")){var f=c.data("source");e.data={results:[]},e.allowClear=!0,e.escapeMarkup=function(a){return a},e.ajax={dataType:"json",type:"POST",url:window.ajaxurl,results:function(b){return a.each(b.results,function(a,b){b.id=b.ID}),b}},"WP_Query"===f?(e.formatSelection=function(a){return b.template('<%= post_type.labels.singular_name %>: <%= ID %>')(a)},e.formatResult=function(a){return b.template('<%= post_type.labels.singular_name %>: <%= ID %> [ <%= post_title %> ]')(a)},e.ajax.data=function(c,d){var e=b.intersection(a("#fakerpress-field-post_types").val().split(","),b.pluck(b.where(a("#fakerpress-field-post_types").data("options"),{hierarchical:!0}),"id"));return{action:"fakerpress.select2-"+f,query:{s:c,posts_per_page:10,paged:d,post_type:e}}}):(e.ajax.data=function(b,d){var e=c.parents(".fp-table-taxonomy").eq(0);return{action:"fakerpress.select2-"+f,search:b,page:d,page_limit:25,taxonomies:e.find(".fp-taxonomies").select2("val"),exclude:a(this).select2("val")}},e.formatSelection=function(a){return b.template("<%= taxonomy %>: <%= name %>")(a)},e.formatResult=function(a){return b.template("<%= taxonomy %>: <%= name %>")(a)})}c.select2(e)}).on("change",function(c){var d=a(this),e=a(this).data("value");d.is("[multiple]")&&d.is("[data-source]")&&(c.added?b.isArray(e)?e.push(c.added):e=[c.added]:e=b.isArray(e)?b.without(e,c.removed):[],d.data("value",e).attr("data-value",JSON.stringify(e)))})},window.fakerpress.fields.range=function(a){"use strict";a(".fp-type-range-wrap").each(function(){var b=a(this),c=b.find('.fp-type-number[data-type="min"]'),d=b.find('.fp-type-number[data-type="max"]');b.hasClass(window.fakerpress.ready_class)||(b.addClass(window.fakerpress.ready_class),c.on({"change keyup":function(){a.isNumeric(a(this).val())?(d.removeAttr("disabled"),d.val()&&a(this).val()>=d.val()&&a(this).val("")):a(this).val("")}}))})},function(a){a(document).ready(function(){a.each(window.fakerpress.fields,function(a,b){b(window.jQuery,window._)})})}(jQuery),function(a,b){"use strict";window.fakerpress.fieldset={items:[{name:"meta",$:{},selector:{container:".fp-type-meta-container",item:".fp-table-meta",type_container:".fp-meta_type-container",type:".fp-meta_type",name_container:".fp-meta_name-container",name:".fp-meta_name",conf_container:".fp-meta_conf-container"},update:function(a){this.render(a)},render:function(b){{var c,d,e=this,f=b.find(e.selector.type),g=f.select2("val"),h=b.find(e.selector.name),i=(h.val(),b.find(e.selector.name_container)),j=(b.find(e.selector.type_container),b.find(e.selector.conf_container)),k=j.find(window.fakerpress.fieldset.selector.wrap);j.data("config")}g instanceof jQuery&&(g=g.val()),c=a(".fp-template-"+g).filter('[data-rel="'+e.$.container.attr("id")+'"]').filter("[data-callable]"),d=c.html(),d&&g!==j.data("type")&&(j.data("type",g),k.empty().append(d),this.configure(j)),g?(i.removeClass("fp-last-child"),j.show()):(i.addClass("fp-last-child"),j.hide())},configure:function(c){var d=this,e=c.data("config"),f=c.find(window.fakerpress.fieldset.selector.field);f.each(function(){var c=a(this),f=c.parents(d.selector.item).eq(0),g=c.next(window.fakerpress.fieldset.selector.label),h=c.next(window.fakerpress.fieldset.selector.internal_label),i=c.data("name"),j=parseInt(f.find(window.fakerpress.fieldset.selector.order).val(),10)-1,k=i[j],l=c.data("name"),m=c.data("id"),n=[],i=[];0===g.length&&(g=c.parents(window.fakerpress.fieldset.selector.field_container).eq(0).find(window.fakerpress.fieldset.selector.label)),b.each(m,function(a){n.push(a),("meta"===a||"taxonomy"===a)&&n.push(j)}),b.each(l,function(a){i.push(a),("meta"===a||"taxonomy"===a)&&i.push(j)}),0!==n.length&&(c.attr("id",window.fakerpress.fieldId(n)),g.attr("for",window.fakerpress.fieldId(n)),h.attr("for",window.fakerpress.fieldId(n))),0!==i.length&&c.attr("name",window.fakerpress.fieldName(i)),"undefined"!=typeof e&&"undefined"!=typeof e[k]&&c.val(e[k])})},is_removeable:function(){if(1===this.$.items.length){var a=this.$.items.eq(0);return b.isEmpty(a.find(this.selector.type).select2("val"))?!0:!1}return!1},setup:function(){var b=this;b.$.container.on("change",b.selector.type,[],function(){var c=a(this);b.render(c),window.fakerpress.fieldset.update(b,!1)})},reset:function(){}},{name:"taxonomy",$:{},selector:{container:".fp-type-taxonomy-container",item:".fp-table-taxonomy",taxonomies_container:".fp-taxonomies-container",taxonomies:".fp-taxonomies",terms_container:".fp-terms-container",terms:".fp-terms",weight_container:".fp-weight-container",weight:".fp-weight"},update:function(){},is_removeable:function(){if(1===this.$.items.length){var a=this.$.items.eq(0);return b.isEmpty(a.find(this.selector.taxonomies).select2("val"))&&b.isEmpty(a.find(this.selector.terms).val())?!0:!1}return!1},setup:function(){},reset:function(){}}],selector:{wrap:".fp-field-wrap",duplicate:".fp-action-duplicate",remove:".fp-action-remove",order:".fp-action-order",label:".fp-field-label",internal_label:".fp-internal-label",field:".fp-field",field_container:".fp-field-container"},setup:function(b){var c=a("form").children(".form-table").children("tbody");b.$={},b.$.container=c.children(b.selector.container),b.$.wrap=b.$.container.children(window.fakerpress.fieldset.selector.wrap),b.$.container.on("click",this.selector.duplicate,[],function(){var c=a(this),d=c.parents(b.selector.item),e=d.clone();e.find(".fp-type-date").removeClass("hasDatepicker").end().find(".fp-type-dropdown").removeClass("select2-offscreen").filter(".select2-container").remove(),window.fakerpress.fieldset.reset(b,e),b.$.wrap.append(e),window.fakerpress.fieldset.update(b)}),b.$.container.on("click",this.selector.remove,[],function(){var c=a(this),d=c.parents(b.selector.item);1===b.$.items.length?window.fakerpress.fieldset.reset(b,b.$.items.eq(0)):d.remove(),window.fakerpress.fieldset.update(b)}),b.setup(),this.update(b,!1)},reset:function(b,c){var d=c.find("tbody").find(window.fakerpress.fieldset.selector.field);d.each(function(){var b=a(this);b.val(""),b.hasClass("select2-offscreen")&&b.select2("val","")}),b.reset(c)},update:function(c){c.$.items=c.$.wrap.children(c.selector.item),c.is_removeable()?c.$.items.eq(0).find(window.fakerpress.fieldset.selector.remove).prop("disabled",!0).end().find(c.selector.name).prop("required",!1):c.$.items.find(window.fakerpress.fieldset.selector.remove).prop("disabled",!1).end().find(c.selector.name).prop("required",!0),c.$.items.each(function(d){var e=a(this),f=e.find(window.fakerpress.fieldset.selector.order),g=e.find(window.fakerpress.fieldset.selector.field);f.val(d+1),g.filter("input, textarea, select").each(function(){var c=a(this),e=c.next(window.fakerpress.fieldset.selector.label),f=c.next(window.fakerpress.fieldset.selector.internal_label),g=c.data("name"),h=c.data("id"),i=[],j=[];0===e.length&&(e=c.parents(window.fakerpress.fieldset.selector.field_container).eq(0).find(window.fakerpress.fieldset.selector.label)),b.each(h,function(a){i.push(a),("meta"===a||"taxonomy"===a)&&i.push(d)}),b.each(g,function(a){j.push(a),("meta"===a||"taxonomy"===a)&&j.push(d)}),0!==i.length&&(c.attr("id",window.fakerpress.fieldId(i)),e.attr("for",window.fakerpress.fieldId(i)),f.attr("for",window.fakerpress.fieldId(i))),0!==j.length&&c.attr("name",window.fakerpress.fieldName(j))}),c.update(e)}),a.each(window.fakerpress.fields,function(a,b){b(window.jQuery,window._)})}},a(document).ready(function(){a.each(window.fakerpress.fieldset.items,function(a,b){window.fakerpress.fieldset.setup(b),b.$.container.each(function(){window.fakerpress.fieldset.update(b)})})})}(window.jQuery,window._); \ No newline at end of file From 3f0c8d8aef53adff9501cf028b27b776e4f2b360 Mon Sep 17 00:00:00 2001 From: bordoni Date: Sun, 6 Aug 2017 13:40:58 -0300 Subject: [PATCH 17/19] Improve changelog --- readme.md | 2 +- readme.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 5f81a34..02782f2 100644 --- a/readme.md +++ b/readme.md @@ -102,7 +102,7 @@ Thank you for wanting to make FakerPress better for everyone! [We salute you](ht ### 0.4.9 — TBD ### * Feature: Allow Attachments to be generated with a given Width and Height range — Thanks [@COLABORATI](https://github.com/bordoni/fakerpress/issues/86) * Feature: Generate `post_excerpt` for Posts (how I forgot that is beyond me) — Thanks [@njbarrett](https://github.com/bordoni/fakerpress/issues/104) -* Fix: Better control over Words and Text meta fields — Thanks [@ckpicker](https://github.com/bordoni/fakerpress/issues/115) +* Fix: Meta field rules were not respecting Configurations due to a JavaScript bug on indexing the fields — Thanks [@ckpicker](https://github.com/bordoni/fakerpress/issues/115) * Fix: Resolve problems where attachments wouldn't get setup correctly and throw an Empty Message — Thanks [@r083r7 and @oyvind_skjelstad](https://wordpress.org/support/topic/featured-image-not-showing-up-6) * Fix: Allow Term Meta to generate the fields correctly again — Thanks [@stratboy](https://github.com/bordoni/fakerpress/issues/105) diff --git a/readme.txt b/readme.txt index 065e809..f7ec836 100644 --- a/readme.txt +++ b/readme.txt @@ -101,7 +101,7 @@ Thank you for wanting to make FakerPress better for everyone! [We salute you](ht * Feature: Allow Attachments to be generated with a given Width and Height range — Thanks [@COLABORATI](https://github.com/bordoni/fakerpress/issues/86) * Feature: Generate `post_excerpt` for Posts (how I forgot that is beyond me) — Thanks [@njbarrett](https://github.com/bordoni/fakerpress/issues/104) -* Fix: Better control over Words and Text meta fields — Thanks [@ckpicker](https://github.com/bordoni/fakerpress/issues/115) +* Fix: Meta field rules were not respecting Configurations due to a JavaScript bug on indexing the fields — Thanks [@ckpicker](https://github.com/bordoni/fakerpress/issues/115) * Fix: Resolve problems where attachments wouldn't get setup correctly and throw an Empty Message — Thanks [@r083r7 and @oyvind_skjelstad](https://wordpress.org/support/topic/featured-image-not-showing-up-6) * Fix: Allow Term Meta to generate the fields correctly again — Thanks [@stratboy](https://github.com/bordoni/fakerpress/issues/105) From 8aa06ecadc04cd4af70d7d5fff10e26d65c25437 Mon Sep 17 00:00:00 2001 From: bordoni Date: Sun, 6 Aug 2017 13:51:38 -0300 Subject: [PATCH 18/19] Prevent `_encloseme` and `_pingme` meta on posts --- inc/class-fp-ajax.php | 14 ++++++++++++++ readme.md | 1 + readme.txt | 1 + 3 files changed, 16 insertions(+) diff --git a/inc/class-fp-ajax.php b/inc/class-fp-ajax.php index 66525a4..8a057f5 100644 --- a/inc/class-fp-ajax.php +++ b/inc/class-fp-ajax.php @@ -16,6 +16,20 @@ public function __construct() { } public static function module_generate( $request = null ) { + /** + * Allows us to prevent `_encloseme` and `_pingme` meta when generating Posts + * + * @since 0.4.9 + * + * @param bool $prevent_enclose_ping_meta + */ + $prevent_enclose_ping_meta = (bool) apply_filters( 'fakerpress.module.generate.prevent_enclose_ping_meta', true ); + + // This will prevent us having `_encloseme` and `_pingme` + if ( $prevent_enclose_ping_meta ) { + define( 'WP_IMPORTING', true ); + } + $response = (object) array( 'status' => false, 'message' => __( 'Your request has failed', 'fakerpress' ), diff --git a/readme.md b/readme.md index 02782f2..e606907 100644 --- a/readme.md +++ b/readme.md @@ -105,6 +105,7 @@ Thank you for wanting to make FakerPress better for everyone! [We salute you](ht * Fix: Meta field rules were not respecting Configurations due to a JavaScript bug on indexing the fields — Thanks [@ckpicker](https://github.com/bordoni/fakerpress/issues/115) * Fix: Resolve problems where attachments wouldn't get setup correctly and throw an Empty Message — Thanks [@r083r7 and @oyvind_skjelstad](https://wordpress.org/support/topic/featured-image-not-showing-up-6) * Fix: Allow Term Meta to generate the fields correctly again — Thanks [@stratboy](https://github.com/bordoni/fakerpress/issues/105) +* Tweak: Prevent `_encloseme` and `_pingme` for FakerPress generated Posts ### 0.4.8 — 18 of July, 2017 ### * Feature: Now Comments can be generated with different types, allowing for WooCommerce Notes for example - Thanks [@dibbyo456](https://wordpress.org/support/topic/can-i-create-custom-comments/) diff --git a/readme.txt b/readme.txt index f7ec836..6b268a9 100644 --- a/readme.txt +++ b/readme.txt @@ -104,6 +104,7 @@ Thank you for wanting to make FakerPress better for everyone! [We salute you](ht * Fix: Meta field rules were not respecting Configurations due to a JavaScript bug on indexing the fields — Thanks [@ckpicker](https://github.com/bordoni/fakerpress/issues/115) * Fix: Resolve problems where attachments wouldn't get setup correctly and throw an Empty Message — Thanks [@r083r7 and @oyvind_skjelstad](https://wordpress.org/support/topic/featured-image-not-showing-up-6) * Fix: Allow Term Meta to generate the fields correctly again — Thanks [@stratboy](https://github.com/bordoni/fakerpress/issues/105) +* Tweak: Prevent `_encloseme` and `_pingme` for FakerPress generated Posts = 0.4.8 — 18 of July, 2017 = From a2bd820806d101c93f6deeb923f950ce1b8fbc32 Mon Sep 17 00:00:00 2001 From: bordoni Date: Mon, 7 Aug 2017 18:05:26 -0300 Subject: [PATCH 19/19] Changelog date and WordPress version compat --- readme.md | 4 ++-- readme.txt | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index e606907..d8a6a8e 100644 --- a/readme.md +++ b/readme.md @@ -7,7 +7,7 @@ FakerPress is a clean way to generate fake and dummy content to your WordPress, **Contributors:** [bordoni](http://profiles.wordpress.org/bordoni) **Tags:** [generator](http://wordpress.org/plugins/tags/generator), [dummy content](http://wordpress.org/plugins/tags/dummy content), [dummy data](http://wordpress.org/plugins/tags/dummy data), [lorem ipsun](http://wordpress.org/plugins/tags/lorem ipsun), [admin](http://wordpress.org/plugins/tags/admin), [exemples](http://wordpress.org/plugins/tags/exemples), [testing](http://wordpress.org/plugins/tags/testing), [images](http://wordpress.org/plugins/tags/images), [attachments](http://wordpress.org/plugins/tags/attachments), [featured image](http://wordpress.org/plugins/tags/featured image), [taxonomies](http://wordpress.org/plugins/tags/taxonomies), [users](http://wordpress.org/plugins/tags/users), [post type](http://wordpress.org/plugins/tags/post type), [faker](http://wordpress.org/plugins/tags/faker), [fake data](http://wordpress.org/plugins/tags/fake data), [random](http://wordpress.org/plugins/tags/random), [developer](http://wordpress.org/plugins/tags/developer), [dev](http://wordpress.org/plugins/tags/dev), [development](http://wordpress.org/plugins/tags/development), [test](http://wordpress.org/plugins/tags/test), [tests](http://wordpress.org/plugins/tags/tests) **Requires at least:** 3.7 -**Tested up to:** 4.8 +**Tested up to:** 4.8.1 **Stable tag:** trunk (master) **License:** [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html) @@ -99,7 +99,7 @@ Thank you for wanting to make FakerPress better for everyone! [We salute you](ht ## Changelog ## -### 0.4.9 — TBD ### +### 0.4.9 — 07 of August, 2017 ### * Feature: Allow Attachments to be generated with a given Width and Height range — Thanks [@COLABORATI](https://github.com/bordoni/fakerpress/issues/86) * Feature: Generate `post_excerpt` for Posts (how I forgot that is beyond me) — Thanks [@njbarrett](https://github.com/bordoni/fakerpress/issues/104) * Fix: Meta field rules were not respecting Configurations due to a JavaScript bug on indexing the fields — Thanks [@ckpicker](https://github.com/bordoni/fakerpress/issues/115) diff --git a/readme.txt b/readme.txt index 6b268a9..75a2718 100644 --- a/readme.txt +++ b/readme.txt @@ -2,7 +2,7 @@ Contributors: bordoni Tags: generator, dummy content, dummy data, lorem ipsun, admin, exemples, testing, images, attachments, featured image, taxonomies, users, post type, faker, fake data, random, developer, dev, development, test, tests Requires at least: 3.7 -Tested up to: 4.8 +Tested up to: 4.8.1 Stable tag: trunk License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -97,7 +97,7 @@ Thank you for wanting to make FakerPress better for everyone! [We salute you](ht == Changelog == -= 0.4.9 — TBD = += 0.4.9 — 07 of August, 2017 = * Feature: Allow Attachments to be generated with a given Width and Height range — Thanks [@COLABORATI](https://github.com/bordoni/fakerpress/issues/86) * Feature: Generate `post_excerpt` for Posts (how I forgot that is beyond me) — Thanks [@njbarrett](https://github.com/bordoni/fakerpress/issues/104)