diff --git a/fakerpress.php b/fakerpress.php index bdd3000..201d431 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.5 + * Version: 0.4.6 * Author: Gustavo Bordoni * Author URI: http://bordoni.me * Text Domain: fakerpress diff --git a/inc/class-fp-field.php b/inc/class-fp-field.php index ccad69e..8df5137 100644 --- a/inc/class-fp-field.php +++ b/inc/class-fp-field.php @@ -1175,7 +1175,6 @@ public static function get_meta_types() { $range->class = array(); $range->label = __( 'Range of possible numbers', 'fakerpress' ); $range->_min = 0; - $range->_max = 9; $html[] = Field::wrapper( Field::type_range( $range, null, 'string' ), $range ); $html[] = Field::wrapper( Field::type_number( $default->weight, null, 'string' ), $default->weight ); diff --git a/inc/class-fp-plugin.php b/inc/class-fp-plugin.php index 463ccf0..9b6e567 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.5'; + const version = '0.4.6'; /** * A static variable that holds a dinamic instance of the class diff --git a/modules/base.php b/modules/base.php index 7971158..319eda0 100644 --- a/modules/base.php +++ b/modules/base.php @@ -193,6 +193,19 @@ public function generate() { return $this; } + /** + * A method to make it easier to debug which variables will be actually saved + * + * @return array + */ + public function get_values() { + $values = array(); + foreach ( $this->data as $name => $item ) { + $values[ $name ] = $this->data[ $name ]->value; + } + return $values; + } + protected function apply( $item ) { if ( ! isset( $item->generator ) ){ return reset( $item->arguments ); diff --git a/modules/post.php b/modules/post.php index aa5c23a..7582eb8 100644 --- a/modules/post.php +++ b/modules/post.php @@ -171,7 +171,8 @@ public function parse_request( $qty, $request = array() ) { $this->set( 'ping_status' ); $this->set( 'tax_input', $taxonomies_configuration ); - $post_id = $this->generate()->save(); + $generated = $this->generate(); + $post_id = $generated->save(); if ( $post_id && is_numeric( $post_id ) ){ foreach ( $metas as $meta_index => $meta ) { diff --git a/package.json b/package.json index b1ec228..28c0da1 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "fakerpress", "title": "FakerPress", - "version": "0.4.5", + "version": "0.4.6", "homepage": "http://fakerpress.com/", "repository": { "type": "git", diff --git a/providers/wp-meta.php b/providers/wp-meta.php index c0a0a63..0d9c01a 100644 --- a/providers/wp-meta.php +++ b/providers/wp-meta.php @@ -38,7 +38,7 @@ private function meta_parse_separator( $separator ){ public function meta_type_numbers( $number = array( 0, 9 ), $weight = 50 ) { $number = ( is_array( $number ) ? call_user_func_array( array( $this->generator, 'numberBetween' ), $number ) : $number ); - return $this->generator->optional( $weight, null )->randomElement( (array) $number ); + return $this->generator->optional( (int) $weight, null )->randomElement( (array) $number ); } public function meta_type_elements( $elements = '', $qty = 1, $separator = ',', $weight = 50 ) { @@ -47,7 +47,7 @@ public function meta_type_elements( $elements = '', $qty = 1, $separator = ',', $elements = explode( ',', $elements ); $qty = $this->meta_parse_qty( $qty, $elements ); - $value = $this->generator->optional( $weight, null )->randomElements( (array) $elements, $qty ); + $value = $this->generator->optional( (int) $weight, null )->randomElements( (array) $elements, $qty ); if ( is_null( $value ) ) { return $value; } @@ -56,13 +56,13 @@ public function meta_type_elements( $elements = '', $qty = 1, $separator = ',', } public function meta_type_letter( $weight = 50 ) { - return $this->generator->optional( $weight, null )->randomLetter(); + return $this->generator->optional( (int) $weight, null )->randomLetter(); } public function meta_type_words( $qty = 8, $weight = 50 ) { $qty = $this->meta_parse_qty( $qty ); - return $this->generator->optional( $weight, null )->sentence( $qty ); + return $this->generator->optional( (int) $weight, null )->sentence( $qty ); } public function meta_type_text( $type = 'sentences', $qty = 3, $separator = "\r\n\r\n", $weight = 50 ) { @@ -70,9 +70,9 @@ public function meta_type_text( $type = 'sentences', $qty = 3, $separator = "\r\ $qty = $this->meta_parse_qty( $qty ); if ( 'sentences' === $type ){ - $value = $this->generator->optional( $weight, null )->sentences( $qty ); + $value = $this->generator->optional( (int) $weight, null )->sentences( $qty ); } else { - $value = $this->generator->optional( $weight, null )->paragraphs( $qty ); + $value = $this->generator->optional( (int) $weight, null )->paragraphs( $qty ); } if ( is_null( $value ) ) { @@ -86,7 +86,7 @@ public function meta_type_html( $elements, $qty = 6, $weight = 50 ) { $qty = $this->meta_parse_qty( $qty ); $elements = explode( ',', $elements ); - $value = $this->generator->optional( $weight, null )->html_elements( array( + $value = $this->generator->optional( (int) $weight, null )->html_elements( array( 'elements' => $elements, 'qty' => $qty, ) ); @@ -113,31 +113,31 @@ public function meta_type_wp_query( $query, $weight = 50 ) { return null; } - $value = $this->generator->optional( $weight, null )->randomElement( (array) $query->posts ); + $value = $this->generator->optional( (int) $weight, null )->randomElement( (array) $query->posts ); return $value; } public function meta_type_lexify( $template, $weight = 50 ) { - $value = $this->generator->optional( $weight, null )->bothify( (string) $template ); + $value = $this->generator->optional( (int) $weight, null )->bothify( (string) $template ); return $value; } public function meta_type_asciify( $template, $weight = 50 ) { - $value = $this->generator->optional( $weight, null )->asciify( (string) $template ); + $value = $this->generator->optional( (int) $weight, null )->asciify( (string) $template ); return $value; } public function meta_type_regexify( $template, $weight = 50 ) { - $value = $this->generator->optional( $weight, null )->regexify( (string) $template ); + $value = $this->generator->optional( (int) $weight, null )->regexify( (string) $template ); return $value; } public function meta_type_timezone( $weight = 50 ) { - $value = $this->generator->optional( $weight, null )->timezone; + $value = $this->generator->optional( (int) $weight, null )->timezone; return $value; } @@ -177,7 +177,7 @@ public function meta_type_company( $template, $weight = 50 ) { } } - $value = $this->generator->optional( $weight, null )->randomElement( (array) implode( '', $text ) ); + $value = $this->generator->optional( (int) $weight, null )->randomElement( (array) implode( '', $text ) ); return $value; } @@ -217,7 +217,7 @@ public function meta_type_person( $template, $gender = 'female', $weight = 50 ) } } - $value = $this->generator->optional( $weight, null )->randomElement( (array) implode( '', $text ) ); + $value = $this->generator->optional( (int) $weight, null )->randomElement( (array) implode( '', $text ) ); return $value; } @@ -304,7 +304,7 @@ public function meta_type_geo( $template, $weight = 50 ) { } } - $value = $this->generator->optional( $weight, null )->randomElement( (array) implode( '', $text ) ); + $value = $this->generator->optional( (int) $weight, null )->randomElement( (array) implode( '', $text ) ); return $value; } @@ -340,37 +340,37 @@ public function meta_type_date( $interval, $format = 'Y-m-d H:i:s', $weight = 50 $selected = $this->generator->dateTimeBetween( (string) $min, (string) $max )->format( $format ); - $value = $this->generator->optional( $weight, null )->randomElement( (array) $selected ); + $value = $this->generator->optional( (int) $weight, null )->randomElement( (array) $selected ); return $value; } public function meta_type_ip( $weight = 50 ) { - $value = $this->generator->optional( $weight, null )->ipv4; + $value = $this->generator->optional( (int) $weight, null )->ipv4; return $value; } public function meta_type_domain( $weight = 50 ) { - $value = $this->generator->optional( $weight, null )->domainName; + $value = $this->generator->optional( (int) $weight, null )->domainName; return $value; } public function meta_type_email( $weight = 50 ) { - $value = $this->generator->optional( $weight, null )->email; + $value = $this->generator->optional( (int) $weight, null )->email; return $value; } public function meta_type_user_agent( $weight = 50 ) { - $value = $this->generator->optional( $weight, null )->userAgent; + $value = $this->generator->optional( (int) $weight, null )->userAgent; return $value; } public function meta_type_raw( $weight = 100, $value = null, $default = null ) { - if ( $weight >= $this->generator->numberBetween( 0, 100 ) ) { + if ( (int) $weight >= $this->generator->numberBetween( 0, 100 ) ) { return $value; } else { return $default; diff --git a/providers/wp-post.php b/providers/wp-post.php index d39ae23..9b51622 100644 --- a/providers/wp-post.php +++ b/providers/wp-post.php @@ -186,7 +186,7 @@ public function tax_input( $config = null ) { } // Select the elements based on qty - $output[ $taxonomy ] = $this->generator->optional( $rate, null )->randomElements( $terms, $qty ); + $output[ $taxonomy ] = $this->generator->optional( (int) $rate, null )->randomElements( $terms, (int) $qty ); } } diff --git a/readme.md b/readme.md index 9b66f7d..0472ecc 100644 --- a/readme.md +++ b/readme.md @@ -101,6 +101,10 @@ Thank you for wanting to make FakerPress better for everyone! [We salute you](ht ## Changelog ## +### 0.4.6 — 14 of June, 2016 ### +* Fix: Post Meta and taxonomy is finally working again — Thanks [@peachey_a](https://wordpress.org/support/topic/generated-posts-not-assigned-categories) and [@zoeitsolutions](https://wordpress.org/support/topic/user-meta-not-being-generated) +* Fix: Allow Meta Number generation using any type of range, doesn't limit from 0 to 9 + ### 0.4.5 — 11 of June, 2016 ### * Fix: Users Module was using Post Meta methods on flag related methods, preventing the users to be deleted when "Let it Go!" — Thanks [@derpixler](https://github.com/bordoni/fakerpress/issues/84) * Fix: Taxonomy and Meta Modules had a compatibility problem with Faker, preveting users to use Meta and Taxonomy Properly — Thanks [@rayrutjes](https://github.com/bordoni/fakerpress/issues/94) diff --git a/readme.txt b/readme.txt index 86c8802..4b8de43 100644 --- a/readme.txt +++ b/readme.txt @@ -100,6 +100,10 @@ Thank you for wanting to make FakerPress better for everyone! [We salute you](ht == Changelog == += 0.4.6 — 14 of June, 2016 = +* Fix: Post Meta and taxonomy is finally working again — Thanks [@peachey_a](https://wordpress.org/support/topic/generated-posts-not-assigned-categories) and [@zoeitsolutions](https://wordpress.org/support/topic/user-meta-not-being-generated) +* Fix: Allow Meta Number generation using any type of range, doesn't limit from 0 to 9 + = 0.4.5 — 11 of June, 2016 = * Fix: Users Module was using Post Meta methods on flag related methods, preventing the users to be deleted when "Let it Go!" — Thanks [@derpixler](https://github.com/bordoni/fakerpress/issues/84) * Fix: Taxonomy and Meta Modules had a compatibility problem with Faker, preveting users to use Meta and Taxonomy Properly — Thanks [@rayrutjes](https://github.com/bordoni/fakerpress/issues/94) diff --git a/ui/js/module.js b/ui/js/module.js index 8a661e4..1a6f1b9 100644 --- a/ui/js/module.js +++ b/ui/js/module.js @@ -17,6 +17,8 @@ if ( 'undefined' === typeof window.fakerpress ){ attrClass = 'notice is-dismissible ' + attrClass; } + console.log( data, html ); + var noticeContent = _.template( html )( data ), templateVars = { 'attrClass': attrClass, @@ -66,13 +68,15 @@ if ( 'undefined' === typeof window.fakerpress ){ $spinner.removeClass( 'is-active' ); $button.prop( 'disabled', false ); - fp.log( $response, '<%= message %>', { message: jqXHR.responseText }, 'notice-warning' ); + fp.log( $response, '<%= message %>', { message: jqXHR.responseText }, 'notice-error' ); } }, success: function( data, textStatus, jqXHR ) { $spinner.removeClass( 'is-active' ); - - if ( null !== data && data.status ){ + if ( null === data ) { + $button.prop( 'disabled', false ); + fp.log( $response, '<%= message %>', { message: jqXHR.responseText }, 'notice-error' ); + } else if ( data.status ){ if ( data.is_capped && data.offset < data.total ){ _POST.offset = data.offset; _POST.total = data.total; @@ -85,7 +89,7 @@ if ( 'undefined' === typeof window.fakerpress ){ fp.log( $response, 'Faked <%= total %>: <%= message %>', { message: data.message, total: data.results.length }, 'notice-success' ); } else { $button.prop( 'disabled', false ); - fp.log( $response, '<%= message %>', data, 'notice-warning' ); + fp.log( $response, '<%= message %>', data, 'notice-error' ); } } }); diff --git a/ui/js/module.min.js b/ui/js/module.min.js index 8ec3329..c1966c5 100644 --- a/ui/js/module.min.js +++ b/ui/js/module.min.js @@ -1 +1 @@ -"undefined"==typeof window.fakerpress&&(window.fakerpress={}),function(a,b){"use strict";var c=window.fakerpress;c._module_generator=".fp-module-generator",c.log=function(c,d,e,f){f="undefined"==typeof f?"notice is-dismissible":"notice is-dismissible "+f;var g=b.template(d)(e),h={attrClass:f,html:g},i=b.template('

<%= html %>

')(h),j=a(i);return j.on("click.wp-dismiss-notice",".notice-dismiss",function(b){b.preventDefault(),j.fadeTo(100,0,function(){a(this).slideUp(100,function(){a(this).remove()})})}),c.append(j)},c.moduleGenerate=function(b,d){"undefined"==typeof d&&(d=Qs.parse(b.serialize())),d.action="fakerpress.module_generate";var e=b.find(".fp-submit"),f=e.find(".spinner"),g=e.find(".button-primary"),h=e.find(".fp-response");f.hasClass("is-active")||(f.addClass("is-active"),g.prop("disabled",!0),a.ajax({dataType:"json",type:"POST",url:window.ajaxurl,data:d,complete:function(a,b){"success"!==b&&(f.removeClass("is-active"),g.prop("disabled",!1),c.log(h,"<%= message %>",{message:a.responseText},"notice-warning"))},success:function(a){f.removeClass("is-active"),null!==a&&a.status?(a.is_capped&&a.offset: <%= message %>",{message:a.message,total:a.results.length},"notice-success")):(g.prop("disabled",!1),c.log(h,"<%= message %>",a,"notice-warning"))}}))},a(document).ready(function(){a(c._module_generator).each(function(){var b=a(this);b.on("submit",function(a){c.moduleGenerate(b),a.preventDefault()})})})}(jQuery,_); \ No newline at end of file +"undefined"==typeof window.fakerpress&&(window.fakerpress={}),function(a,b){"use strict";var c=window.fakerpress;c._module_generator=".fp-module-generator",c.log=function(c,d,e,f){f="undefined"==typeof f?"notice is-dismissible":"notice is-dismissible "+f,console.log(e,d);var g=b.template(d)(e),h={attrClass:f,html:g},i=b.template('

<%= html %>

')(h),j=a(i);return j.on("click.wp-dismiss-notice",".notice-dismiss",function(b){b.preventDefault(),j.fadeTo(100,0,function(){a(this).slideUp(100,function(){a(this).remove()})})}),c.append(j)},c.moduleGenerate=function(b,d){"undefined"==typeof d&&(d=Qs.parse(b.serialize())),d.action="fakerpress.module_generate";var e=b.find(".fp-submit"),f=e.find(".spinner"),g=e.find(".button-primary"),h=e.find(".fp-response");f.hasClass("is-active")||(f.addClass("is-active"),g.prop("disabled",!0),a.ajax({dataType:"json",type:"POST",url:window.ajaxurl,data:d,complete:function(a,b){"success"!==b&&(f.removeClass("is-active"),g.prop("disabled",!1),c.log(h,"<%= message %>",{message:a.responseText},"notice-error"))},success:function(a,e,i){f.removeClass("is-active"),null===a?(g.prop("disabled",!1),c.log(h,"<%= message %>",{message:i.responseText},"notice-error")):a.status?(a.is_capped&&a.offset: <%= message %>",{message:a.message,total:a.results.length},"notice-success")):(g.prop("disabled",!1),c.log(h,"<%= message %>",a,"notice-error"))}}))},a(document).ready(function(){a(c._module_generator).each(function(){var b=a(this);b.on("submit",function(a){c.moduleGenerate(b),a.preventDefault()})})})}(jQuery,_); \ No newline at end of file