Make WordPress Core

Ticket #33885: 33885.2.diff

File 33885.2.diff, 1.8 KB (added by ericmann, 9 years ago)

Add a filter to set predefined keys (or override with a different query) if necessary.

  • src/wp-admin/includes/template-functions.php

     
    577577        $post = get_post( $post );
    578578
    579579        /**
    580          * Filter the number of custom fields to retrieve for the drop-down
    581          * in the Custom Fields meta box.
     580         * Filter any pre-defined post meta keys for the Custom Fields meta box
     581         * to short circuit a range query agaisnt postmeta.
    582582         *
    583          * @since 2.1.0
     583     * @since 4.4.0
    584584         *
    585          * @param int $limit Number of custom fields to retrieve. Default 30.
    586          */
    587         $limit = apply_filters( 'postmeta_form_limit', 30 );
    588         $sql = "SELECT DISTINCT meta_key
    589                 FROM $wpdb->postmeta
    590                 WHERE meta_key NOT BETWEEN '_' AND '_z'
    591                 HAVING meta_key NOT LIKE %s
    592                 ORDER BY meta_key
    593                 LIMIT %d";
    594         $keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) );
     585         * @param array $keys Pre-defined meta keys to be used in place of a postmeta query. Default array().
     586     */
     587        $keys = apply_filters( 'postmeta_form_keys', array() );
     588
     589        if ( empty( $keys ) ) {
     590                /**
     591                 * Filter the number of custom fields to retrieve for the drop-down
     592                 * in the Custom Fields meta box.
     593                 *
     594                 * @since 2.1.0
     595                 *
     596                 * @param int $limit Number of custom fields to retrieve. Default 30.
     597                 */
     598                $limit = apply_filters( 'postmeta_form_limit', 30 );
     599                $sql = "SELECT DISTINCT meta_key
     600                        FROM $wpdb->postmeta
     601                        WHERE meta_key NOT BETWEEN '_' AND '_z'
     602                        HAVING meta_key NOT LIKE %s
     603                        ORDER BY meta_key
     604                        LIMIT %d";
     605                $keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) );
     606        }
     607
    595608        if ( $keys ) {
    596609                natcasesort( $keys );
    597610                $meta_key_input_id = 'metakeyselect';