Fatal on CPT saving when throws permissions error
-
pre-conditions
– CPT with custom metabox
– WPML + WC + WCML
– current user not allowed to saving this CPT
reproduce
– trying to save CPT item from/post.php?post=123&action=edit&lang=en
WP throws WP_Error and write it as $_POST
When WP trying to show error page, its uses language attributes, which involve this plugin codeadd_filter( 'locale', [ $this, 'update_product_action_locale_check' ] ); public function update_product_action_locale_check( $locale ) { if ( isset( $_POST['action'] ) && 'wpml_translation_dialog_save_job' === $_POST['action'] ) { return $this->sitepress->get_locale( $_POST['job_details']['target'] ); } return $locale; }
Which gaining error “Cannot use object of type WP_Error as array”
Full callstack[23-Mar-2021 13:17:37 UTC] PHP Fatal error: Uncaught Error: Cannot use object of type WP_Error as array in /var/www/html/wp-content/plugins/woocommerce-multilingual/inc/class-wcml-locale.php:60
Stack trace:
#0 /var/www/html/wp-includes/class-wp-hook.php(292): WCML_Locale->update_product_action_locale_check(‘en_US’)
#1 /var/www/html/wp-includes/plugin.php(212): WP_Hook->apply_filters(‘en_US’, Array)
#2 /var/www/html/wp-includes/l10n.php(35): apply_filters(‘locale’, ‘en_US’)
#3 /var/www/html/wp-includes/l10n.php(137): get_locale()
#4 /var/www/html/wp-includes/general-template.php(848): determine_locale()
#5 /var/www/html/wp-includes/general-template.php(4035): get_bloginfo(‘language’)
#6 /var/www/html/wp-includes/functions.php(3486): get_language_attributes()
#7 /var/www/html/wp-includes/functions.php(3421): _default_wp_die_handler(‘<div class=”wp-…’, ‘WordPress &rsaq…’, Array)
#8 /var/www/html/wp-admin/includes/post.php(305): wp_die(‘Sorry, you are …’)
#9 /var/www/html/wp-admin/post.php(227): edit_post()Need to add extra check to update_product_action_locale_check like
is_array($_POST)
or smth
- The topic ‘Fatal on CPT saving when throws permissions error’ is closed to new replies.