Piklist入门教程十:不同的Post Status锁定Meta Fields

Piklist 允许我们可以锁定field的编辑(就是指只读),打个比方,我们可以在Product自定义Post Type的estimate状态下不锁定可以编辑,而在complete状态时锁定编辑。so easy!
1.在meta-boxes目录新建一个lock_metabox.php
lock
2.写上常规的text控件,照样用教程九中的on_post_status,这里的参数就是用’value’=> ‘complete’,应用到多个不连续状态就用逗号区分,连续多个就用–两个中划线。注意被锁定的field是看不到描述的,看下面代码,切换你不同的post的状态理解一下它吧
lock-metabox.php全部代码:

<?php
/*
Title: My Lock Meta Box
Post Type: product
*/

piklist('field', array(
    'type' => 'text'
    ,'scope' => 'post_meta'
    ,'field' => 'lock_text'
    ,'label' => 'Text box'
    ,'description' => 'lock by complete'
    ,'value' => 'lock by complete'
    ,'on_post_status' => array(
        'value' => 'complete'       //单个状态锁定
    )
));

piklist('field', array(
    'type' => 'text'
    ,'scope' => 'post_meta'
    ,'field' => 'lock2_text'
    ,'label' => 'Text box'
    ,'description' => 'locks estimate and repair'
    ,'value' => 'estimate and repair'
    ,'on_post_status' => array(
        'value' => array('estimate','repair')       //多个不连续状态锁定
    )
));

piklist('field', array(
    'type' => 'text'
    ,'scope' => 'post_meta'
    ,'field' => 'lock3_text'
    ,'label' => 'Text box'
    ,'description' => 'locks by estimate--repair'
    ,'value' => 'estimate--repair'
    ,'on_post_status' => array(
        'value' => 'estimate--repair'       //多个连续状态锁定
    )
));

效果预览:

unlock_status1

unlock_status2

文章分类 Piklist, 经验分享 标签: ,

发表评论


Warning: Use of undefined constant XML - assumed 'XML' (this will throw an Error in a future version of PHP) in /var/www/wp/code/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1048