为投稿人锁定帖子编辑屏幕上的元框位置

时间:2012-09-07 作者:Nate

我们的网站有一个开放系统,供投稿者(WP用户角色)向网站添加新闻和日历内容。

我想在后期编辑屏幕上设置并锁定内容和元框的位置。是否有一个过滤器或函数来设置我之前的方框顺序disable the option of changing the sort order?

例如,我希望我的帖子编辑屏幕显示在一列中-标题>分类法>正文>元框>元框>发布。

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

在上网时发现的。。。工作完美

add_action(\'admin_init\', \'set_user_metaboxes\'); //I want it to fire every time edit post screen comes up
//add_action(\'user_register\', \'set_user_metaboxes\');  //You can also have it only set when a new user is created

function set_user_metaboxes($user_id=NULL) {

  //These are the metakeys we will need to update  
  $meta_key[\'order\'] = \'meta-box-order_events\';
  $meta_key[\'hidden\'] = \'metaboxhidden_events\';

  //So this can be used without hooking into user_register
  if ( ! $user_id)
    $user_id = get_current_user_id(); 

  //Set the default order if it has not been set yet by the user. These are WP handles
  if ( ! get_user_meta( $user_id, $meta_key[\'order\'], true) ) {
    $meta_value = array(
        \'side\' => \'\',
        \'normal\' => \'events_metabox,submitdiv, commentsdiv\',
        \'advanced\' => \'\',
    );
    update_user_meta( $user_id, $meta_key[\'order\'], $meta_value );
  }

  // Set the default hidden boxes if it has not been set yet by the user
  if ( ! get_user_meta( $user_id, $meta_key[\'hidden\'], true) ) {
    $meta_value = array(\'postcustom\',\'trackbacksdiv\',\'commentstatusdiv\',\'commentsdiv\',\'slugdiv\',\'authordiv\',\'revisionsdiv\',\'postexcerpt\',\'postimagediv\',\'tagsdiv-post_tag\');
    update_user_meta( $user_id, $meta_key[\'hidden\'], $meta_value );
  }

 }//#end

SO网友:Praveen Tripathi

对于自定义帖子类型,它非常有效。。。

add_action(\'admin_init\', \'set_user_metaboxes\');
function set_user_metaboxes($user_id=NULL) {

    // These are the metakeys we will need to update
    $meta_key[\'order\'] = \'meta-box-order_event\';
    $meta_key[\'hidden\'] = \'metaboxhidden_event\';
    $brand_meta_key[\'order\']=\'meta-box-order_brand\';
    $venue_meta_key[\'order\']=\'meta-box-order_venue\';
    // So this can be used without hooking into user_register
    if ( ! $user_id)
        $user_id = get_current_user_id();

    // Set the default order if it has not been set yet

        $meta_value = array(
            \'side\' => \'submitdiv,formatdiv,categorydiv\',
            \'normal\' => \'postimagediv,event_type,eventfeaturedbrand,event_details,description_sectionid\',
            \'advanced\' => \'\',
        );
        $brand_meta_value = array(
            \'side\' => \'submitdiv,categorydiv\',
            \'normal\' => \'postimagediv,product_type\',
            \'advanced\' => \'\',
        );
        $venue_meta_value = array(
            \'side\' => \'submitdiv,categorydiv\',
            \'normal\' => \'venue_post_details,postimagediv\',
            \'advanced\' => \'\',
        );
        update_user_meta( $user_id, $meta_key[\'order\'], $meta_value );
        update_user_meta( $user_id, $brand_meta_key[\'order\'], $brand_meta_value );
        update_user_meta( $user_id, $venue_meta_key[\'order\'], $venue_meta_value );

    // Set the default hiddens if it has not been set yet
    if ( get_user_meta( $user_id, $meta_key[\'hidden\'], true) ) {
        $meta_value = array(\'postcustom\',\'trackbacksdiv\',\'commentstatusdiv\',\'commentsdiv\',\'slugdiv\',\'authordiv\',\'revisionsdiv\');
        update_user_meta( $user_id, $meta_key[\'hidden\'], $meta_value );
    }
}

结束

相关推荐

当出现错误时,防止wp_login_form()重定向到wp-admin

我已经在我的网站前端使用wp_login_form(). 但是,当用户键入错误的用户名/密码时,他们会被重定向到wp admin登录表单。如何在登录表单上方显示任何错误消息?理想情况下,我不希望用户看到Wordpress管理部分。我试过使用redirect_invalid_login() 胡克,但这似乎不起作用?