Custom fields: Allow for short-circuiting the meta key dropdown.

Adds the `postmeta_form_keys` filter which allows for a potentially expensive query against postmeta to be avoided.

props ericmann, tollmanz, nacin.
see #33885.


git-svn-id: https://develop.svn.wordpress.org/trunk@35717 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Helen Hou-Sandi 2015-11-20 06:15:34 +00:00
parent 583a84b1db
commit 03bd31aedd

View File

@ -576,6 +576,19 @@ function meta_form( $post = null ) {
global $wpdb; global $wpdb;
$post = get_post( $post ); $post = get_post( $post );
/**
* Filter values for the meta key dropdown in the Custom Fields meta box.
*
* Returning a non-null value will effectively short-circuit and avoid a
* potentially expensive query against postmeta.
*
* @since 4.4.0
*
* @param array|null $keys Pre-defined meta keys to be used in place of a postmeta query. Default null.
*/
$keys = apply_filters( 'postmeta_form_keys', null );
if ( null === $keys ) {
/** /**
* Filter the number of custom fields to retrieve for the drop-down * Filter the number of custom fields to retrieve for the drop-down
* in the Custom Fields meta box. * in the Custom Fields meta box.
@ -592,6 +605,8 @@ function meta_form( $post = null ) {
ORDER BY meta_key ORDER BY meta_key
LIMIT %d"; LIMIT %d";
$keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) ); $keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) );
}
if ( $keys ) { if ( $keys ) {
natcasesort( $keys ); natcasesort( $keys );
$meta_key_input_id = 'metakeyselect'; $meta_key_input_id = 'metakeyselect';