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
← All changes | inc/class-wpseo-custom-fields.php +21 -6 27.6 → trunk View file →
@@ -39,14 +39,29 @@
39 39 * in the Custom Fields meta box.
40 40 *
41 41 * @param int $limit Number of custom fields to retrieve. Default 30.
42 42 */
43 - $limit = apply_filters( 'postmeta_form_limit', 30 );
44 - $sql = "SELECT DISTINCT meta_key
45 - FROM $wpdb->postmeta
46 - WHERE meta_key NOT BETWEEN '_' AND '_z' AND SUBSTRING(meta_key, 1, 1) != '_'
47 - LIMIT %d";
48 - $fields = $wpdb->get_col( $wpdb->prepare( $sql, $limit ) );
43 + $limit = apply_filters( 'postmeta_form_limit', 30 );
44 +
45 + /**
46 + * Filter: 'wpseo_custom_fields_pre_query' - Filters the custom-fields lookup before the database query runs.
47 + *
48 + * Returning a non-null array short-circuits the default `SELECT DISTINCT meta_key`
49 + * query against `wp_postmeta`. On very large postmeta tables this can be a way
50 + * to supply a pre-cached list or an alternative query to improve loading times.
51 + *
52 + * @param string[]|null $custom_fields Pre-computed list of meta_key names, or null to run the default query.
53 + * @param int $limit The configured result limit; honor it if running a custom query.
54 + */
55 + $fields = apply_filters( 'wpseo_custom_fields_pre_query', null, $limit );
56 +
57 + if ( ! is_array( $fields ) ) {
58 + $sql = "SELECT DISTINCT meta_key
59 + FROM $wpdb->postmeta
60 + WHERE meta_key NOT BETWEEN '_' AND '_z' AND SUBSTRING(meta_key, 1, 1) != '_'
61 + LIMIT %d";
62 + $fields = $wpdb->get_col( $wpdb->prepare( $sql, $limit ) );
63 + }
49 64
50 65 /**
51 66 * Filters the custom fields that are auto-completed and replaced as replacement variables
52 67 * in the meta box and sidebar.