| @@ -138,17 +138,32 @@ | ||
| 138 | 138 | $cat_slug = sanitize_title( $cat_name . '-' . $lang->slug ); |
| 139 | 139 | $cat = wp_insert_term( $cat_name, $taxonomy, array( 'slug' => $cat_slug ) ); |
| 140 | 140 | |
| 141 | 141 | // Check that the term was not previously created (in case the language was deleted and recreated). |
| 142 | - $cat = $cat->error_data['term_exists'] ?? $cat['term_id']; | |
| 142 | + if ( is_array( $cat ) ) { | |
| 143 | + $cat = $cat['term_id']; | |
| 144 | + } elseif ( ! empty( $cat->get_error_data( 'term_exists' ) ) ) { | |
| 145 | + $cat = $cat->get_error_data( 'term_exists' ); | |
| 146 | + } else { | |
| 147 | + return; | |
| 148 | + } | |
| 143 | 149 | |
| 150 | + if ( ! is_numeric( $cat ) ) { | |
| 151 | + return; | |
| 152 | + } | |
| 153 | + | |
| 144 | 154 | // Set language. |
| 145 | 155 | $this->model->term->set_language( (int) $cat, $lang ); |
| 146 | 156 | |
| 147 | 157 | // This is a translation of the default term. |
| 148 | - $default = (int) get_option( 'default_' . $taxonomy ); | |
| 149 | - $translations = $this->model->term->get_translations( $default ); | |
| 158 | + $default = get_option( 'default_' . $taxonomy ); | |
| 150 | 159 | |
| 160 | + if ( ! is_numeric( $default ) ) { | |
| 161 | + return; | |
| 162 | + } | |
| 163 | + | |
| 164 | + $translations = $this->model->term->get_translations( (int) $default ); | |
| 165 | + | |
| 151 | 166 | $this->model->term->save_translations( (int) $cat, $translations ); |
| 152 | 167 | } |
| 153 | 168 | |
| 154 | 169 | /** |
| @@ -161,9 +176,10 @@ | ||
| 161 | 176 | */ |
| 162 | 177 | public function handle_default_term_on_create_language( $args ) { |
| 163 | 178 | foreach ( $this->taxonomies as $taxonomy ) { |
| 164 | 179 | if ( 'category' === $taxonomy ) { |
| 165 | - $default = (int) get_option( 'default_' . $taxonomy ); | |
| 180 | + $default = get_option( 'default_' . $taxonomy ); | |
| 181 | + $default = is_numeric( $default ) ? (int) $default : 0; | |
| 166 | 182 | |
| 167 | 183 | // Assign default language to default term. |
| 168 | 184 | if ( ! $this->model->term->get_language( $default ) ) { |
| 169 | 185 | $this->model->term->set_language( $default, $args['slug'] ); |