WPSEO_Upgrade::remove_indexable_rows_for_non_public_taxonomies()publicYoast 1.0

Removes all indexables for terms that are not publicly viewable. This method should be called after init, because taxonomies can still be registered.

Метод класса: WPSEO_Upgrade{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$WPSEO_Upgrade = new WPSEO_Upgrade();
$WPSEO_Upgrade->remove_indexable_rows_for_non_public_taxonomies();

Код WPSEO_Upgrade::remove_indexable_rows_for_non_public_taxonomies() Yoast 22.4

public function remove_indexable_rows_for_non_public_taxonomies() {
	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_taxonomies = YoastSEO()->helpers->taxonomy->get_indexable_taxonomies();

	if ( empty( $included_taxonomies ) ) {
		// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
		// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
		$wpdb->query(
			$wpdb->prepare(
				"DELETE FROM %i
				WHERE %i = 'term'
				AND %i IS NOT NULL",
				[ $indexable_table,'object_type','object_sub_type' ]
			)
		);
	}
	else {
		// phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
		// phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
		$wpdb->query(
			$wpdb->prepare(
				"DELETE FROM %i
				WHERE %i = 'term'
				AND %i IS NOT NULL
				AND %i NOT IN ( " . implode( ', ', array_fill( 0, count( $included_taxonomies ), '%s' ) ) . ' )',
				array_merge( [ $indexable_table,'object_type','object_sub_type','object_sub_type' ], $included_taxonomies )
			)
		);
	}

	$wpdb->show_errors = $show_errors;
}