PluginProbe
Polylang / trunk
Polylang vtrunk
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
← All changes | src/default-term.php +20 -4 3.8.9 → trunk View file →
@@ -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'] );