WPSEO_Upgrade::remove_indexable_rows_for_non_public_post_types()
Removes all indexables for posts that are not publicly viewable. This method should be called after init, because post_types can still be registered.
Метод класса: WPSEO_Upgrade{}
Хуков нет.
Возвращает
null
. Ничего.
Использование
$WPSEO_Upgrade = new WPSEO_Upgrade(); $WPSEO_Upgrade->remove_indexable_rows_for_non_public_post_types();
Код WPSEO_Upgrade::remove_indexable_rows_for_non_public_post_types() WPSEO Upgrade::remove indexable rows for non public post types Yoast 20.0
public function remove_indexable_rows_for_non_public_post_types() { global $wpdb; // If migrations haven't been completed successfully the following may give false errors. So suppress them. $show_errors = $wpdb->show_errors; $wpdb->show_errors = false; $indexable_table = Model::get_table_name( 'Indexable' ); $included_post_types = \YoastSEO()->helpers->post_type->get_indexable_post_types(); // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Reason: Too hard to fix. if ( empty( $included_post_types ) ) { $delete_query = "DELETE FROM $indexable_table WHERE object_type = 'post' AND object_sub_type IS NOT NULL"; } else { $delete_query = $wpdb->prepare( "DELETE FROM $indexable_table WHERE object_type = 'post' AND object_sub_type IS NOT NULL AND object_sub_type NOT IN ( " . \implode( ', ', \array_fill( 0, \count( $included_post_types ), '%s' ) ) . ' )', $included_post_types ); } // phpcs:enable // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way. // phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches. // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared -- Reason: Is it prepared already. $wpdb->query( $delete_query ); // phpcs:enable $wpdb->show_errors = $show_errors; }