快速编辑屏幕定制

时间:2011-01-19 作者:Zack

Possible Duplicate: How to show custom meta box on "Quick Edit" screen?

我正在尝试编辑自定义帖子类型“visitor”上的快速编辑屏幕,以便为最终用户添加一些选项。我的自定义帖子类型不需要/不需要发布日期、查看、发布状态的密码,也不需要用于自定义访客类别的大型分类框。

我已经为实际的编辑页面添加了一个自定义元框,但是would like to enable quick-edit support of those post meta fields while disabling the current quick-edit options.

我还发现了一个post (链接在我可能的副本中)在wordpress上。org的论坛,但不确定它到底做什么。

3 个回复
最合适的回答,由SO网友:jaredwilli 整理而成

我使用它将表单字段添加到快速编辑中。在WP中实现这一点并不完全容易,而且很难找到如何实现这一点的信息。你必须真正地挖掘源头才能找到它。

将表单字段添加到快速编辑

<?php
add_action(\'quick_edit_custom_box\', \'quickedit_posts_custom_box\', 10, 2);
add_action(\'admin_head-edit.php\', \'quick_add_script\');

function quickedit_posts_custom_box( $col, $type ) {
    if( $col != \'COLUMN_NAME\' || $type != \'post\' ) {
        return;
    } ?>
    <fieldset class="inline-edit-col-right"><div class="inline-edit-col">
        <div class="inline-edit-group">
            <label class="alignleft">
                <input type="checkbox" name="yourformfield" id="yourformfield_check">
                <span class="checkbox-title">This Post Has Cake</span>
            </label>
        </div>
    </fieldset>
    <?php
}

function quick_add_script() { ?>
    <script type="text/javascript">
    jQuery(document).ready(function() {
        jQuery(\'a.editinline\').live(\'click\', function() {
            var id = inlineEditPost.getId(this);
            var val = parseInt(jQuery(\'#inline_\' + id + \'_yourformfield\').text());
            jQuery(\'#yourformfield_check\').attr(\'checked\', !!val);
        });
    });
    </script>
    <?php
}

SO网友:Michael Cannon

我在这里有点自吹自擂,但为了让在WordPress中编辑自定义元字段更容易,我编写了一个名为Custom Bulk/Quick Edit.

该插件不仅将自定义元添加到批量和快速编辑屏幕以进行实际编辑,还将其作为列添加到帖子类型列表中。

然后,如果使用中的主题或插件尚未启用帖子类型列的自定义元,您可以使用过滤器添加列。

在您的主题中functions.php 文件添加类似于以下内容的代码。

add_filter( \'manage_post_posts_columns\', \'my_manage_post_posts_columns\' );
function my_manage_post_posts_columns( $columns ) {
$columns[\'custom_stuff\'] = esc_html__( \'Custom Stuff Here\' );

return $columns;
}
作为使用名为news-room, 请尝试以下操作。

add_filter( \'manage_news-room_posts_columns\', \'my_manage_newsroom_posts_columns\' );
function my_manage_newsroom_posts_columns( $columns ) {
$columns[\'wpcf-publication-author\'] = esc_html__( \'Publication Author\');
$columns[\'wpcf-newsroom-type\']      = esc_html__( \'News Room Type\');
$columns[\'_views_template\']         = esc_html__( \'Content Template\');

return $columns;
}
这是基于post 岗位类型。

请注意,为了帮助进一步开发和支持,免费插件仅限于WordPress自己的内置帖子类型。如果您使用的是自定义帖子类型,则可以购买自定义批量/快速编辑高级版。

或者,欢迎您通过以下方式从插件中提取代码https://github.com/michael-cannon/custom-bulkquick-edit.

SO网友:Piyush Dhanotiya

将此代码添加到functions.php 文件此代码用于自定义post类型明细表。根据需要更改帖子类型。

// Add to our admin_init function

add_filter(\'manage_schedule_posts_columns\', \'myown_add_post_columns\');

function myown_add_post_columns($columns) {
    $columns[\'stime\'] = \'Start Time\';
   $columns[\'etime\'] = \'End Time\';
    return $columns;
}

// Add to our admin_init function

add_action(\'manage_schedule_posts_custom_column\', \'myown_render_post_columns\', 10, 2);

function myown_render_post_columns($column_name, $id) {
    switch ($column_name) {
    case \'stime\':
        // show my_field
        echo get_post_meta( $id, \'stime\', TRUE);

case \'etime\':
        // show my_field
        $my_fieldvalue1 = get_post_meta( $id, \'etime\', TRUE);
        echo $my_fieldvalue1;
    }
}

// Add to our admin_init function

add_action(\'quick_edit_custom_box\',  \'myown_add_quick_edit\', 10, 2);

function myown_add_quick_edit($column_name, $post_type) {
    if ($column_name != \'stime\') return;
    ?>
    <fieldset class="inline-edit-col-left">
        <div class="inline-edit-col">
            <span class="title">start time</span>
            <input id="myfield_noncename" type="hidden" name="myfield_noncename" value="" />
            <input id="myfield" type="text" name="stime" value=""/></br>
         <span class="title">End time</span>
       <input id="myfield1" type="text" name="etime" value=""/></br>
        <div id="main">
         <span class="title">Add New Session date</span></br>
       <a href="#" class="aclick">Add new</a></br></div>
        </div>
    </fieldset>
     <?php
}

// Add to our admin_init function 

add_action(\'save_post\', \'myown_save_quick_edit_data\');   

function myown_save_quick_edit_data($post_id) {     
  // verify if this is an auto save routine.         
  if ( defined(\'DOING_AUTOSAVE\') && DOING_AUTOSAVE )          
      return $post_id;         
  // Check permissions     
  if ( \'stime\' == $_POST[\'post_type\'] ) {         
    if ( !current_user_can( \'edit_page\', $post_id ) )             
      return $post_id;     
  } 
if ( \'etime\' == $_POST[\'post_type\'] ) {         
    if ( !current_user_can( \'edit_page\', $post_id ) )             
      return $post_id;     
  } 
else {         
    if ( !current_user_can( \'edit_post\', $post_id ) )         
    return $post_id;     
  }        
if(isset($_POST[\'tag-name\']))
{
 if ( defined(\'DOING_AUTOSAVE\') && DOING_AUTOSAVE ) return;
  $post = get_post($post_id);
  if ( $post->post_type == \'schedule\') { // change \'post\' to any cpt you want to target
    $term = get_term_by(\'slug\', $post->post_name, \'schedule_category\');
    if ( empty($term) ) {
      $add = wp_insert_term( $_POST[\'tag-name\'], \'schedule_category\', array(\'slug\'=> $_POST[\'tag-name\']) );
      if ( is_array($add) && isset($add[\'term_id\']) ) {
        wp_set_object_terms($post_id, $add[\'term_id\'], \'schedule_category\', true );
      }
    }
  }
}

 // Authentication passed now we save the data   

  if (isset($_POST[\'stime\']) && ($post->post_type != \'revision\')) {
        $my_fieldvalue = esc_attr($_POST[\'stime\']);
        if ($my_fieldvalue)
            update_post_meta( $post_id, \'stime\', $my_fieldvalue);
        else
            delete_post_meta( $post_id, \'stime\');
    }
    return $my_fieldvalue;
 if (isset($_POST[\'etime\']) && ($post->post_type != \'revision\')) {
        $my_fieldvalue1 = esc_attr($_POST[\'etime\']);
        if ($my_fieldvalue1)
            update_post_meta( $post_id, \'etime\', $my_fieldvalue1);
        else
            delete_post_meta( $post_id, \'etime\');
    }
    return $my_fieldvalue1;
}

// Add to our admin_init function

add_action(\'admin_footer\', \'myown_quick_edit_javascript\');

function myown_quick_edit_javascript() {
    global $current_screen;
    if (($current_screen->post_type != \'schedule\')) return;

    ?>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery(".aclick").one("click", function(){  
   jQuery("#main").append(\'<input type="text" name="tag-name" />\');
});
});
function set_myfield_value(fieldValue,fieldValue1, nonce) {
        // refresh the quick menu properly
        inlineEditPost.revert();
        console.log(fieldValue);
        console.log(fieldValue1);
        jQuery(\'#myfield\').val(fieldValue);
         jQuery(\'#myfield1\').val(fieldValue1);
}
</script>
 <?php 
}

// Add to our admin_init function 

add_filter(\'post_row_actions\', \'myown_expand_quick_edit_link\', 10, 2);   
function myown_expand_quick_edit_link($actions, $post) {     
    global $current_screen;     
    if (($current_screen->post_type != \'schedule\')) 
        return $actions;
    $nonce = wp_create_nonce( \'myfield_\'.$post->ID);
    $myfielvalue = get_post_meta( $post->ID, \'stime\', TRUE);
    $myfielvalue1 = get_post_meta( $post->ID, \'etime\', TRUE);
    $actions[\'inline hide-if-no-js\'] = \'<a href="#" class="editinline" title="\';     
    $actions[\'inline hide-if-no-js\'] .= esc_attr( __( \'Edit this item inline\' ) ) . \'"\';
    $actions[\'inline hide-if-no-js\'] .= " onclick=\\"set_myfield_value(\'{$myfielvalue}\',\'{$myfielvalue1}\')\\" >";
    $actions[\'inline hide-if-no-js\'] .= __( \'Quick Edit\' );
    $actions[\'inline hide-if-no-js\'] .= \'</a>\';
    return $actions;
}

结束

相关推荐