如何使用另外2个字段扩展“快速编辑”选项

时间:2012-11-01 18:24:02

标签: php wordpress tags

我想知道WordPress是否能够在标签Quick Edits中添加2个字段(输入和文本区域)。

实际上我要在Quick Edit中添加这两个字段,这些字段位于修改标记页面中,但我想在Quick Edit中显示这两个字段,所以我会能够轻松访问它们。

CODES

// Add a dummy column for the `posts` post type    
add_filter('manage_edit-post_tag_columns', 'add_dummy_column', 10, 2);
function add_dummy_column($columns)
{
    $columns['headline'] = 'Headline';
    $columns['intro-text'] = 'Intro Text';
    return $columns;
}

// But remove it again on the edit screen (other screens to?)
add_filter('manage_edit-post_tag_columns', 'remove_dummy_column');
function remove_dummy_column($columns)
{
    unset($columns['description']);
    return $columns;
}

function my_column_value($empty = '', $custom_column, $term_id)  
{  
    include_once('taxonomy-metadata.php');
    return esc_html(get_term_meta($term_id, $custom_column, true));  
}  
add_filter('manage_post_tag_custom_column', 'my_column_value', 10, 3); 


function my_quick_edit_custom_box($column_name, $screen, $name)  
{  
    if($name != 'post_tag' && ($column_name != 'headline' || $column_name != 'intro-text')) return false; 

    if($name == 'post_tag' && $column_name == 'headline' ) {
?>  
    <fieldset>  
        <div id="my-custom-content" class="inline-edit-col">  
            <label>  
                <span class="title"><?php if($column_name == 'headline') _e('Headline', 'ie_tag_plugin'); else _e('Intro text', 'ie_tag_plugin'); ?></span>  
                <span class="input-text-wrap"><input name="<?php echo $column_name; ?>" class="ptitle" value="" type="text"></span>  
            </label>            
        </div>  
    </fieldset>  
<?php 
    }

    if($name == 'post_tag' && $column_name == 'intro-text' ) {
?>  
    <fieldset>  
        <div id="my-custom-content" class="inline-edit-col">  
            <label>  
                <span class="title"><?php if($column_name == 'headline') _e('Headline', 'ie_tag_plugin'); else _e('Intro text', 'ie_tag_plugin'); ?></span>  
                <span class="input-text-wrap"><textarea name="<?php echo $column_name; ?>" class="ptitle"><?php $data = esc_html( $data ); ?></textarea></span>  
            </label>            
        </div>  
    </fieldset>  
<?php 
    }   
}  
add_action('quick_edit_custom_box', 'my_quick_edit_custom_box', 10, 3);


function my_save_term_meta($term_id)  
{  
    $allowed_html = array(  
        'b' => array(),  
        'em' => array (),  
        'i' => array (),  
        'strike' => array(),  
        'strong' => array(),  
    );  
    if(isset($_POST['headline']))  
        update_term_meta($term_id, 'headline', wp_kses($_POST['headline'], $allowed_html));  
    if(isset($_POST['intro-text']))  
        update_term_meta($term_id, 'intro-text', wp_kses($_POST['intro-text'], $allowed_html));  
} 

add_action('edited_post_tag', 'my_save_term_meta', 10, 1);

我试图这样做,但是这些代码没有保存数据,而且在完成所有操作后似乎一团糟。

enter image description here

有没有办法完成这项任务,请告诉我。我将非常感激。

谢谢大家。

1 个答案:

答案 0 :(得分:0)

This Page提供了许多有用的代码供您连接到Wordpress快速编辑菜单进行自定义。

The Wordpress Codex also has quite a bit of information on this subject as well