fakerpress icon indicating copy to clipboard operation
fakerpress copied to clipboard

error when creating users with custom meta

Open izuio opened this issue 1 year ago • 1 comments

this code WP_Meta.php(27):

$qty = (int) ( is_array( $qty ) && count( $_qty ) > 1 ? call_user_func_array( [ $this->generator, 'numberBetween' ], $qty ) : reset( $_qty ) );

changed to $qty_args = array_values( (array) $qty ); $qty = (int) ( is_array( $qty_args ) && count( $qty_args ) > 1 ? call_user_func_array( [ $this->generator, 'numberBetween' ], $qty_args ) : reset( $qty_args ) );

works so far on a test site, problem exists when trying to write to a custom field (user) occurs using both jetengine and simple php.

recreation

  • Add User meta with php or plugin like jetengine
  • then generate users with Meta Field Rules of Type Text, Name Fake, config sentences (1 or more)

explanation array_values() re‐indexes the array to [0 => value_for_min, 1 => value_for_max], removing the string keys. Now call_user_func_array([...], $qty_args) sees a plain numeric array (e.g., [1, 5]) and calls numberBetween($min = 1, $max = 5) positionally, which works with the standard Faker signature.

debug log [24-Jan-2025 07:27:06 UTC] PHP Fatal error: Uncaught Error: Unknown named parameter $min in /Users/b/Local Sites/carg/app/public/wp-content/plugins/fakerpress/src/FakerPress/Provider/WP_Meta.php:27 Stack trace: #0 /Users/b/Local Sites/carg/app/public/wp-content/plugins/fakerpress/src/FakerPress/Provider/WP_Meta.php(27): call_user_func_array(Array, Array) #1 /Users/b/Local Sites/carg/app/public/wp-content/plugins/fakerpress/src/FakerPress/Provider/WP_Meta.php(105): FakerPress\Provider\WP_Meta->meta_parse_qty(Array) #2 [internal function]: FakerPress\Provider\WP_Meta->meta_type_text('sentences', Array, '\n', 100) #3 /Users/b/Local Sites/carg/app/public/wp-content/plugins/fakerpress/vendor-prefixed/fakerphp/faker/src/Faker/Generator.php(713): call_user_func_array(Array, Array) #4 /Users/b/Local Sites/carg/app/public/wp-content/plugins/fakerpress/vendor-prefixed/fakerphp/faker/src/Faker/Generator.php(978): FakerPress\ThirdParty\Faker\Generator->format('meta_type_text', Array) #5 [internal function]: FakerPress\ThirdParty\Faker\Generator->__call('meta_type_text', Array) #6 /Users/b/Local Sites/carg/app/public/wp-content/plugins/fakerpress/src/FakerPress/Module/Meta.php(145): call_user_func_array(Array, Array) #7 /Users/b/Local Sites/carg/app/public/wp-content/plugins/fakerpress/src/FakerPress/Module/User.php(196): FakerPress\Module\Meta->generate() #8 /Users/b/Local Sites/carg/app/public/wp-content/plugins/fakerpress/src/FakerPress/Ajax.php(83): FakerPress\Module\User->parse_request(4, Array) #9 /Users/b/Local Sites/carg/app/public/wp-includes/class-wp-hook.php(324): FakerPress\Ajax::module_generate('') #10 /Users/b/Local Sites/carg/app/public/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array) #11 /Users/b/Local Sites/carg/app/public/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #12 /Users/b/Local Sites/carg/app/public/wp-admin/admin-ajax.php(192): do_action('wp_ajax_fakerpr...') #13 {main} thrown in /Users/b/Local Sites/carg/app/public/wp-content/plugins/fakerpress/src/FakerPress/Provider/WP_Meta.php on line 27

izuio avatar Jan 25 '25 10:01 izuio

Resolved on 0.7.2

bordoni avatar May 21 '25 01:05 bordoni