Yoast\WP\SEO\Repositories
Indexable_Cleanup_Repository::update_indexable_authors
Updates the indexable's author_id referring to a deleted author with the id of the reassigned user.
Метод класса: Indexable_Cleanup_Repository{}
Хуков нет.
Возвращает
int|true|false. The associative array with shape [ old_id => [ old_id, new_author ] ] or false if query to get data fails.
Использование
// private - только в коде основоного (родительского) класса $result = $this->update_indexable_authors( $reassigned_authors_objs, $limit );
- $reassigned_authors_objs(массив) (обязательный)
- The array of objects with shape [ old_id => [ old_id, new_id ] ].
- $limit(int) (обязательный)
- The limit we'll apply to the queries.
Код Indexable_Cleanup_Repository::update_indexable_authors() Indexable Cleanup Repository::update indexable authors Yoast 28.1
private function update_indexable_authors( $reassigned_authors_objs, $limit ) {
global $wpdb;
$indexable_table = Model::get_table_name( 'Indexable' );
// This is a workaround for the fact that the array_column function does not work on objects in PHP 5.6.
$reassigned_authors_array = \array_map(
static function ( $obj ) {
return (array) $obj;
},
$reassigned_authors_objs,
);
$reassigned_authors = \array_combine( \array_column( $reassigned_authors_array, 'author_id' ), \array_column( $reassigned_authors_array, 'post_author' ) );
foreach ( $reassigned_authors as $old_author_id => $new_author_id ) {
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Reason: There is no unescaped user input.
$query = $wpdb->prepare(
"
UPDATE {$indexable_table}
SET {$indexable_table}.author_id = {$new_author_id}
WHERE {$indexable_table}.author_id = {$old_author_id}
AND object_type='post'
LIMIT %d",
$limit,
);
// phpcs:enable
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared,WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: Already prepared.
$wpdb->query( $query );
}
return \count( $reassigned_authors );
}