WordPress.org

Make WordPress Core

Ticket #24498: 24498-alternative.patch

File 24498-alternative.patch, 2.5 KB (added by swissspidy, 6 years ago)

This alternative patch removes the query entirely and only allows entering meta keys through the text input

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

    diff --git src/wp-admin/includes/template.php src/wp-admin/includes/template.php
    index 302e9b4..3f8dcd7 100644
    function _list_meta_row( $entry, &$count ) { 
    665665 * @param WP_Post $post Optional. The post being edited.
    666666 */
    667667function meta_form( $post = null ) {
    668         global $wpdb;
    669         $post = get_post( $post );
    670 
    671         /**
    672          * Filter the number of custom fields to retrieve for the drop-down
    673          * in the Custom Fields meta box.
    674          *
    675          * @since 2.1.0
    676          *
    677          * @param int $limit Number of custom fields to retrieve. Default 30.
    678          */
    679         $limit = apply_filters( 'postmeta_form_limit', 30 );
    680         $sql = "SELECT meta_key
    681                 FROM $wpdb->postmeta
    682                 GROUP BY meta_key
    683                 HAVING meta_key NOT LIKE %s
    684                 ORDER BY meta_key
    685                 LIMIT %d";
    686         $keys = $wpdb->get_col( $wpdb->prepare( $sql, $wpdb->esc_like( '_' ) . '%', $limit ) );
    687         if ( $keys ) {
    688                 natcasesort( $keys );
    689                 $meta_key_input_id = 'metakeyselect';
    690         } else {
    691                 $meta_key_input_id = 'metakeyinput';
    692         }
    693668?>
    694669<p><strong><?php _e( 'Add New Custom Field:' ) ?></strong></p>
    695670<table id="newmeta">
    696671<thead>
    697672<tr>
    698 <th class="left"><label for="<?php echo $meta_key_input_id; ?>"><?php _ex( 'Name', 'meta name' ) ?></label></th>
     673<th class="left"><label for="metakeyinput"><?php _ex( 'Name', 'meta name' ) ?></label></th>
    699674<th><label for="metavalue"><?php _e( 'Value' ) ?></label></th>
    700675</tr>
    701676</thead>
    function meta_form( $post = null ) { 
    703678<tbody>
    704679<tr>
    705680<td id="newmetaleft" class="left">
    706 <?php if ( $keys ) { ?>
    707 <select id="metakeyselect" name="metakeyselect">
    708 <option value="#NONE#"><?php _e( '&mdash; Select &mdash;' ); ?></option>
    709 <?php
    710 
    711         foreach ( $keys as $key ) {
    712                 if ( is_protected_meta( $key, 'post' ) || ! current_user_can( 'add_post_meta', $post->ID, $key ) )
    713                         continue;
    714                 echo "\n<option value='" . esc_attr($key) . "'>" . esc_html($key) . "</option>";
    715         }
    716 ?>
    717 </select>
    718 <input class="hide-if-js" type="text" id="metakeyinput" name="metakeyinput" value="" />
    719 <a href="#postcustomstuff" class="hide-if-no-js" onclick="jQuery('#metakeyinput, #metakeyselect, #enternew, #cancelnew').toggle();return false;">
    720 <span id="enternew"><?php _e('Enter new'); ?></span>
    721 <span id="cancelnew" class="hidden"><?php _e('Cancel'); ?></span></a>
    722 <?php } else { ?>
    723681<input type="text" id="metakeyinput" name="metakeyinput" value="" />
    724 <?php } ?>
    725682</td>
    726683<td><textarea id="metavalue" name="metavalue" rows="2" cols="25"></textarea></td>
    727684</tr>