PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.9
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.9
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 / inc / class-wpseo-custom-fields.php

class-wpseo-custom-fields.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.9, at inc/class-wpseo-custom-fields.php

68 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPSEO plugin file.
4 *
5 * @package WPSEO
6 */
7
8 /**
9 * WPSEO_Custom_Fields.
10 */
11 class WPSEO_Custom_Fields {
12
13 /**
14 * Custom fields cache.
15 *
16 * @var array
17 */
18 protected static $custom_fields = null;
19
20 /**
21 * Retrieves the custom field names as an array.
22 *
23 * @link WordPress core: wp-admin/includes/template.php. Reused query from it.
24 *
25 * @return array The custom fields.
26 */
27 public static function get_custom_fields() {
28 global $wpdb;
29
30 // Use cached value if available.
31 if ( ! is_null( self::$custom_fields ) ) {
32 return self::$custom_fields;
33 }
34
35 self::$custom_fields = [];
36
37 /**
38 * Filters the number of custom fields to retrieve for the drop-down
39 * in the Custom Fields meta box.
40 *
41 * @param int $limit Number of custom fields to retrieve. Default 30.
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 ) );
49
50 if ( is_array( $fields ) ) {
51 self::$custom_fields = array_map( [ 'WPSEO_Custom_Fields', 'add_custom_field_prefix' ], $fields );
52 }
53
54 return self::$custom_fields;
55 }
56
57 /**
58 * Adds the cf_ prefix to a field.
59 *
60 * @param string $field The field to prefix.
61 *
62 * @return string The prefixed field.
63 */
64 private static function add_custom_field_prefix( $field ) {
65 return 'cf_' . $field;
66 }
67 }
68