Skip Navigation

Resolved

Reported for: WPML Multilingual CMS 4.6.3

Resolved in: WPML 4.6.5

Topic Tags: Bug

Overview of the issue

We have identified an issue where WPML notices can sometimes result in fatal errors. This problem is caused by a corruption in the wpml_notices key within the database. You may encounter a similar error message as a result:

Fatal error: Uncaught TypeError: array_key_exists(): Argument #2 ($array) must be of type array, null given in ...\wp-content\plugins\sitepress-multilingual-cms\classes\notices\class-wpml-notices.php:373 Stack trace: #0 ...\wp-content\plugins\sitepress-multilingual-cms\classes\notices\class-wpml-notices.php(159): WPML_Notices->group_and_id_exist('taxonomy-term-h...', 'brand') #1 ...\wp-content\plugins\sitepress-multilingual-cms\classes\notices\class-wpml-notices.php(112): WPML_Notices->notice_exists(Object(WPML_Notice)) #2 ...\wp-content\plugins\sitepress-multilingual-cms\classes\taxonomy-term-translation\class-wpml-taxonomy-translation-help-notice.php(111): WPML_Notices->add_notice(Object(WPML_Notice)) #3 ...\wp-content\plugins\sitepress-multilingual-cms\classes\taxonomy-term-translation\class-wpml-taxonomy-translation-help-notice.php(70): WPML_Taxonomy_Translation_Help_Notice->add_term_help_notice_to_admin_notices() #4 ...\wp-includes\class-wp-hook.php(308): WPML_Taxonomy_Translation_Help_Notice->add_help_notice('') #5 ...\wp-includes\class-wp-hook.php(332): WP_Hook->apply_filters(NULL, Array) #6 ...\wp-includes\plugin.php(517): WP_Hook->do_action(Array) #7 ...\wp-admin\admin.php(175): do_action('admin_init') #8 ...\wp-admin\edit-tags.php(10): require_once('...') #9 {main} thrown in ...\wp-content\plugins\sitepress-multilingual-cms\classes\notices\class-wpml-notices.php on line 373

Workaround

The current workaround for this issue is to remove the wpml_notices key from the options table.

  • Be sure of having a full backup of your site before proceeding.
  • Access to your database.
  • Open wp_options table.
  • Look for the wpml_notices key.
  • Remove it.
    It will regenerated automatically and the error should disappear.

 

2 Responses to “WPML Notice key Corruption may cause a Fatal error: Uncaught TypeError: array_key_exists()...”

  1. We recently encountered this issue and its become recurrent. We are unable to figure out how these notices are being corrupted. The issue is that one or more notice groups are assigned `null` instead of an array or instead of being removed as the `WPML_Notices` seemingly does.

    We’ve noticed a number of forum support tickets reporting similar issues, most resolved via the the proposed workaround. Unfortunately, it is inconvenient in automated deployment environments and migration.

    The following solution that we’ve implemented as a patch (for WPML Multilingual CMS v4.6.4 but should work in earlier versions) involves filtering out any groups that are not an array (we’ve also replaced one `if` statement’s conditions with a method call used elsewhere):


    --- classes/notices/class-wpml-notices.php
    +++ classes/notices/class-wpml-notices.php
    @@ -189,7 +189,7 @@
    if ( $this->notices_to_remove ) {
    foreach ( $this->notices_to_remove as $group => &$group_notices ) {
    foreach ( $group_notices as $id ) {
    - if ( array_key_exists( $group, $this->notices ) && array_key_exists( $id, $this->notices[ $group ] ) ) {
    + if ( $this->group_and_id_exist( $group, $id ) ) {
    unset( $this->notices[ $group ][ $id ] );
    $group_notices = array_diff( $this->notices_to_remove[ $group ], array( $id ) );
    }
    @@ -484,10 +484,14 @@

    private function filter_invalid_notices( $notices ) {
    foreach ( $notices as $group => $notices_in_group ) {
    - foreach ( $notices_in_group as $index => $notice ) {
    - if ( ! $notice instanceof WPML_Notice ) {
    - unset( $notices[ $group ][ $index ] );
    + if ( is_array( $notices_in_group ) ) {
    + foreach ( $notices_in_group as $index => $notice ) {
    + if ( ! $notice instanceof WPML_Notice ) {
    + unset( $notices[ $group ][ $index ] );
    + }
    }
    + } else {
    + unset( $notices[ $group ] );
    }
    }
    return $notices;

    I hope this helps.

    • Thank you very much for your feedback, Chauncey. I’ve passed this information to the development team in charge of this issue.
      I’m pretty sure it would be really helpful.
      Regards,
      Andrés