diff --git a/fakerpress.php b/fakerpress.php index 64f9b30..fe544f4 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 installation, great for developers who need testing - * Version: 0.6.5 + * Version: 0.6.6 * Author: Gustavo Bordoni * Author URI: https://bordoni.me * Text Domain: fakerpress diff --git a/package-lock.json b/package-lock.json index 327f82f..b6912fc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "fakerpress", - "version": "0.6.5", + "version": "0.6.6", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "0.6.5", + "version": "0.6.6", "devDependencies": { "@babel/core": "^7.7.2", "@babel/preset-env": "^7.7.1", diff --git a/package.json b/package.json index 4cd722b..6cf157e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "fakerpress", "title": "FakerPress", - "version": "0.6.5", + "version": "0.6.6", "homepage": "https://fakerpress.com/", "repository": { "type": "git", diff --git a/readme.md b/readme.md index 46c3d67..968ad9e 100644 --- a/readme.md +++ b/readme.md @@ -8,7 +8,7 @@ FakerPress is a clean way to generate fake and dummy content to your WordPress, **Tags:** [generator](http://wordpress.org/plugins/tags/generator), [dummy content](http://wordpress.org/plugins/tags/dummy+content), [lorem ipsun](http://wordpress.org/plugins/tags/lorem+ipsun), [testing](http://wordpress.org/plugins/tags/testing), [developer](http://wordpress.org/plugins/tags/developer) **Requires at least:** 5.5 **Tested up to:** 6.5.2 -**Stable tag:** 0.6.5 +**Stable tag:** 0.6.6 **License:** [GPLv2 or later](http://www.gnu.org/licenses/gpl-2.0.html) **Requires PHP:** 7.4 **Donate link:** https://fakerpress.com/r/sponsor @@ -97,6 +97,10 @@ Thank you for wanting to make FakerPress better for everyone! [We salute you](ht ## Changelog ## +### 0.6.6 — 26 of April 2024 ### +* Fix - Prevent notices related to deprecated usage of Faker methods that were being called as properties. +* Fix - Prevent fatals related to bad typecasting of Faker methods used for meta generation. props @helgatheviking + ### 0.6.5 — 26 of April 2024 ### * Fix - Ensure meta generation for Users, Terms and Comments work since changes made on version `0.6.2`. props @helgatheviking diff --git a/readme.txt b/readme.txt index 9623c11..3b210e5 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: generator, dummy content, lorem ipsun, testing, developer Requires at least: 5.5 Tested up to: 6.5.2 Requires PHP: 7.4 -Stable tag: 0.6.5 +Stable tag: 0.6.6 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Donate link: https://fakerpress.com/r/sponsor @@ -99,6 +99,11 @@ Thank you for wanting to make FakerPress better for everyone! [We salute you](ht == Changelog == += 0.6.6 — 26 of April 2024 = + +* Fix - Prevent notices related to deprecated usage of Faker methods that were being called as properties. +* Fix - Prevent fatals related to bad typecasting of Faker methods used for meta generation. props @helgatheviking + = 0.6.5 — 26 of April 2024 = * Fix - Ensure meta generation for Users, Terms and Comments work since changes made on version `0.6.2`. props @helgatheviking diff --git a/src/FakerPress/Module/Comment.php b/src/FakerPress/Module/Comment.php index c186ac6..4683179 100644 --- a/src/FakerPress/Module/Comment.php +++ b/src/FakerPress/Module/Comment.php @@ -166,7 +166,22 @@ public function parse_request( $qty, $request = [] ) { if ( $comment_id && is_numeric( $comment_id ) ) { foreach ( $metas as $meta_index => $meta ) { - make( Meta::class )->object( $comment_id, 'comment' )->with( $meta['type'], $meta['name'], $meta )->generate()->save(); + if ( ! isset( $meta['type'], $meta['name'] ) ) { + continue; + } + + $type = get( $meta, 'type' ); + $name = get( $meta, 'name' ); + unset( $meta['type'], $meta['name'] ); + + if ( isset( $meta['weight'] ) ) { + $meta['weight'] = absint( $meta['weight'] ); + $meta['weight'] = $meta['weight'] > 0 ? $meta['weight'] : 100; + } else { + $meta['weight'] = 100; + } + + make( Meta::class )->object( $comment_id, 'comment' )->with( $type, $name, $meta )->generate()->save(); } } $results[] = $comment_id; diff --git a/src/FakerPress/Module/Post.php b/src/FakerPress/Module/Post.php index 7cfc6af..093b2ff 100644 --- a/src/FakerPress/Module/Post.php +++ b/src/FakerPress/Module/Post.php @@ -212,7 +212,18 @@ public function parse_request( $qty, $request = [] ) { continue; } - make( Meta::class )->object( $post_id )->with( $meta['type'], $meta['name'], $meta )->generate()->save(); + $type = get( $meta, 'type' ); + $name = get( $meta, 'name' ); + unset( $meta['type'], $meta['name'] ); + + if ( isset( $meta['weight'] ) ) { + $meta['weight'] = absint( $meta['weight'] ); + $meta['weight'] = $meta['weight'] > 0 ? $meta['weight'] : 100; + } else { + $meta['weight'] = 100; + } + + make( Meta::class )->object( $post_id )->with( $type, $name, $meta )->generate()->save(); } } diff --git a/src/FakerPress/Module/Term.php b/src/FakerPress/Module/Term.php index 5d19e09..ee441ed 100644 --- a/src/FakerPress/Module/Term.php +++ b/src/FakerPress/Module/Term.php @@ -133,7 +133,18 @@ public function parse_request( $qty, $request = [] ) { continue; } - make( Meta::class )->object( $term_id, 'term' )->with( $meta['type'], $meta['name'], $meta )->generate()->save(); + $type = get( $meta, 'type' ); + $name = get( $meta, 'name' ); + unset( $meta['type'], $meta['name'] ); + + if ( isset( $meta['weight'] ) ) { + $meta['weight'] = absint( $meta['weight'] ); + $meta['weight'] = $meta['weight'] > 0 ? $meta['weight'] : 100; + } else { + $meta['weight'] = 100; + } + + make( Meta::class )->object( $term_id, 'term' )->with( $type, $name, $meta )->generate()->save(); } } diff --git a/src/FakerPress/Module/User.php b/src/FakerPress/Module/User.php index fc737be..66c7809 100644 --- a/src/FakerPress/Module/User.php +++ b/src/FakerPress/Module/User.php @@ -182,7 +182,18 @@ public function parse_request( $qty, $request = [] ) { continue; } - make( Meta::class )->object( $user_id, 'user' )->with( $meta['type'], $meta['name'], $meta )->generate()->save(); + $type = get( $meta, 'type' ); + $name = get( $meta, 'name' ); + unset( $meta['type'], $meta['name'] ); + + if ( isset( $meta['weight'] ) ) { + $meta['weight'] = absint( $meta['weight'] ); + $meta['weight'] = $meta['weight'] > 0 ? $meta['weight'] : 100; + } else { + $meta['weight'] = 100; + } + + make( Meta::class )->object( $user_id, 'user' )->with( $type, $name, $meta )->generate()->save(); } } $results[] = $user_id; diff --git a/src/FakerPress/Plugin.php b/src/FakerPress/Plugin.php index af7250d..194f9c4 100644 --- a/src/FakerPress/Plugin.php +++ b/src/FakerPress/Plugin.php @@ -12,7 +12,7 @@ class Plugin { * * @var string */ - public const VERSION = '0.6.5'; + public const VERSION = '0.6.6'; /** * @since 0.6.0 diff --git a/src/FakerPress/Provider/WP_Meta.php b/src/FakerPress/Provider/WP_Meta.php index 432c18c..45b14f2 100644 --- a/src/FakerPress/Provider/WP_Meta.php +++ b/src/FakerPress/Provider/WP_Meta.php @@ -65,9 +65,11 @@ private function meta_parse_separator( $separator ) { * @return string|int */ public function meta_type_numbers( $number = [ 0, 9 ], $weight = 50 ) { + $number = array_values( array_map( 'absint', (array) $number ) ); + // If the number is an array, then we assume it's a range. - if ( is_array( $number ) && count( $number ) > 1 ) { - $this->generator->numberBetween( ...$number ); + if ( count( $number ) > 1 ) { + $number = $this->generator->numberBetween( ...$number ); } return $this->generator->optional( $weight / 100, null )->randomElement( (array) $number ); diff --git a/src/FakerPress/Provider/WP_User.php b/src/FakerPress/Provider/WP_User.php index e381f6a..2c5de4d 100644 --- a/src/FakerPress/Provider/WP_User.php +++ b/src/FakerPress/Provider/WP_User.php @@ -34,7 +34,7 @@ public function first_name( ?string $first_name = null, array $gender = [ 'male' * @return string|null */ public function last_name( ?string $last_name = null ): ?string { - return $last_name ?? $this->generator->lastName; + return $last_name ?? $this->generator->lastName(); } /** @@ -48,7 +48,7 @@ public function last_name( ?string $last_name = null ): ?string { * @return string|null */ public function user_login( ?string $login = null ): ?string { - return $login ?? $this->generator->userName; + return $login ?? $this->generator->userName(); } /** @@ -62,7 +62,7 @@ public function user_login( ?string $login = null ): ?string { * @return string|null */ public function user_nicename( ?string $nicename = null ): ?string { - return $nicename ?? $this->generator->userName; + return $nicename ?? $this->generator->userName(); } /** @@ -76,7 +76,7 @@ public function user_nicename( ?string $nicename = null ): ?string { * @return string|null */ public function user_url( ?string $url = null ): ?string { - return $url ?? $this->generator->url; + return $url ?? $this->generator->url(); } /** @@ -90,7 +90,7 @@ public function user_url( ?string $url = null ): ?string { * @return string|null */ public function user_email( ?string $email = null ): ?string { - return $email ?? $this->generator->safeEmail; + return $email ?? $this->generator->safeEmail(); } /** @@ -119,7 +119,7 @@ public function display_name( ?string $display_name = null, array $gender = [ 'm * @return string|null */ public function nickname( ?string $nickname = null ): ?string { - return $nickname ?? $this->generator->userName; + return $nickname ?? $this->generator->userName(); } /** @@ -180,7 +180,7 @@ public function description( $html = true, $args = [] ): ?string { * * @return string */ - public function role( array $role = [] ): string { + public function role( ?array $role = [] ): ?string { return $this->generator->randomElement( $role ?? array_keys( get_editable_roles() ) ); } diff --git a/src/data/readme.php b/src/data/readme.php index f3f9251..b73c939 100644 --- a/src/data/readme.php +++ b/src/data/readme.php @@ -1 +1 @@ -