WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 days ago

#18979 closed enhancement (duplicate)

Add $post_type parameter and a filter to meta_form()

Reported by: takayukister Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Administration Keywords:
Focuses: performance Cc:

Description

In the current version, meta_form(), the function which outputs Custom Fields form used in Edit Post pages, shows all meta keys you have used regardless of post type. Sometimes this gives users unwanted options.

I'd like to suggest adding $post_type parameter to meta_form() to show only meta keys you have used in the same post type. In addition, it would be better if there were a filter for the meta keys.

Attachments (1)

meta_form.diff (1.7 KB) - added by takayukister 4 years ago.
a patch for meta_form()

Download all attachments as: .zip

Change History (5)

@takayukister4 years ago

a patch for meta_form()

comment:1 @nacin4 years ago

I would rather the solution just be that a developer disables the Custom Fields box and creates their own meta box. Any improvements here seem like they're a waste of energy (and CPU).

comment:2 @michelwppi3 years ago

  • Cc contact@… added

Just a short contribution to improve - old - meta_form() function according filtering and protecting rules of meta_key and custom post type:

In current post_custom_meta_box (displaying custom form fields), list_meta is filtered via is_protected_meta function (and his own available filter 'is_protected_meta'). But it is impossible to filter the content of the popup list populated by $key built by meta_form().

With 'is_protected_meta' filter it is possible to subselect metas according context. To subselect popup menu , I suggest a very simple filter just before

<td id="newmetaleft" class="left">
<?php if ($keys){
 <td id="newmetaleft" class="left">
<?php 
$keys = apply_filters( 'post_meta_key_subselect', $keys, $limit);
if ($keys){

Inside the filter, it will be easy to re-query keys (like described above by takayukister) or to subselect and sort the popup list according context an rules (post_type, and more...) without rebuilding a whole custom field metabox UI. It is also a simple way to fixe contamination of keys used buy one post type in another.

This very simple improvement is in concordance with the available filter 'is_protected_meta' where it is possible to not only subselect key with prefix '_' but with another rules.

note: don't need to add post_type parameter. the filter can use global $post and

$post_type = get_post_type ( $post->ID  );

Hope that help to review.

Last edited 3 years ago by michelwppi (previous) (diff)

comment:3 @chriscct79 months ago

  • Keywords needs-refresh added

comment:4 @chriscct74 days ago

  • Component changed from Editor to Administration
  • Focuses performance added
  • Keywords needs-refresh removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #24498.

Note: See TracTickets for help on using tickets.