PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / trunk
Yoast SEO – Advanced SEO with real-time guidance and built-in AI vtrunk
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / src / user-meta / infrastructure / cleanup-repository.php

cleanup-repository.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI trunk, at src/user-meta/infrastructure/cleanup-repository.php

39 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Yoast\WP\SEO\User_Meta\Infrastructure;
4
5 /**
6 * Repository going into the database to clean up.
7 */
8 class Cleanup_Repository {
9
10 /**
11 * Deletes empty usermeta based on their meta_keys and returns the number of the deleted meta.
12 *
13 * @param array<string> $meta_keys The meta to be potentially deleted.
14 * @param int $limit The number of maximum deletions.
15 *
16 * @return int|false The number of rows that was deleted or false if the query failed.
17 */
18 public function delete_empty_usermeta_query( $meta_keys, $limit ) {
19 global $wpdb;
20
21 // phpcs:disable WordPress.DB.PreparedSQLPlaceholders.ReplacementsWrongNumber -- Reason: we're passing an array instead.
22 $delete_query = $wpdb->prepare(
23 'DELETE FROM %i
24 WHERE meta_key IN ( ' . \implode( ', ', \array_fill( 0, \count( $meta_keys ), '%s' ) ) . ' )
25 AND meta_value = ""
26 ORDER BY user_id
27 LIMIT %d',
28 \array_merge( [ $wpdb->usermeta ], $meta_keys, [ $limit ] ),
29 );
30 // phpcs:enable
31
32 // phpcs:disable WordPress.DB.DirectDatabaseQuery.NoCaching -- Reason: No relevant caches.
33 // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery -- Reason: Most performant way.
34 // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared -- Reason: Is it prepared already.
35 return $wpdb->query( $delete_query );
36 // phpcs:enable
37 }
38 }
39