Yoast\WP\SEO\Repositories
Indexable_Cleanup_Repository::clean_indexables_for_orphaned_users()
Deletes rows from the indexable table where the source is no longer there.
Метод класса: Indexable_Cleanup_Repository{}
Хуков нет.
Возвращает
int|true|false
. The number of rows that was deleted or false if the query failed.
Использование
$Indexable_Cleanup_Repository = new Indexable_Cleanup_Repository(); $Indexable_Cleanup_Repository->clean_indexables_for_orphaned_users( $limit );
- $limit(int) (обязательный)
- The limit we'll apply to the delete query.
Код Indexable_Cleanup_Repository::clean_indexables_for_orphaned_users() Indexable Cleanup Repository::clean indexables for orphaned users Yoast 23.5
public function clean_indexables_for_orphaned_users( $limit ) { global $wpdb; $indexable_table = Model::get_table_name( 'Indexable' ); $source_table = $wpdb->users; // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Reason: There is no unescaped user input. $query = $wpdb->prepare( " SELECT indexable_table.object_id FROM {$indexable_table} indexable_table LEFT JOIN {$source_table} AS source_table ON indexable_table.object_id = source_table.ID WHERE source_table.ID IS NULL AND indexable_table.object_id IS NOT NULL AND indexable_table.object_type = 'user' LIMIT %d", $limit ); // phpcs:enable // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: Already prepared. $orphans = $wpdb->get_col( $query ); if ( empty( $orphans ) ) { return 0; } // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: Already prepared. return $wpdb->query( "DELETE FROM $indexable_table WHERE object_type = 'user' AND object_id IN( " . \implode( ',', $orphans ) . ' )' ); }