Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Under the discussion tab on the post page, there's 'allow comments' and 'allow trackbacks and pingbacks', how would I hide the option to allow pingbacks from users but still have it be on by default?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Method 1 (CSS)

You can hide it for all non-admins via CSS:

function hide_ping_track_wpse_103502() {
    if( get_post_type() === "post" ){
        if( ! current_user_can( 'manage_options' ) ){
            // only for non-admins
            echo "<style>.meta-options label[for=ping_status], #ping_status{display:none !important;} </style>";
        }
    }
}
add_action( 'admin_head-post.php', 'hide_ping_track_wpse_103502' );

Before:

Before

After:

After

Method 2 (PHP)

You can also remove the native discussion metabox and replace it with your own:

add_action( 'admin_menu', 'remove_discussion_meta_box' );
add_action( 'add_meta_boxes', 'add_custom_discussion_meta_box' );

function remove_discussion_meta_box() {
    remove_meta_box('commentstatusdiv', 'post', 'normal');
}

function add_custom_discussion_meta_box() {
        add_meta_box(
            'custom_discussion',
            __( 'Custom Discussion' ),
            'custom_discussion_meta_box',
            'post'
        );
}

function custom_discussion_meta_box($post) {
?>
<input name="advanced_view" type="hidden" value="1" />
<p class="meta-options">
        <label for="comment_status" class="selectit">
            <input name="comment_status" type="checkbox" id="comment_status" 
                   value="open" <?php checked($post->comment_status, 'open'); ?> /> 
            <?php _e( 'Allow comments.' ) ?>
        </label>

         <input name="ping_status" type="hidden" id="ping_status" 
                    value="<?php echo $post->ping_status;?>" />

        <?php do_action('post_comment_status_meta_box-options', $post); ?>
</p>
<?php
}

where the ping_status form input field is hidden with the current value.

After:

After

share|improve this answer
    
I'm not sure a CSS solution is the best way to go. –  andy Jun 19 '13 at 15:16
    
You could of course remove the whole discussion metabox and add your own custom metabox with the modified content. –  birgire Jun 19 '13 at 15:20
    
I updated the answer with that kind of solution. –  birgire Jun 19 '13 at 17:11
    
Thanks, birgire. Which method do you think is better? –  andy Jun 19 '13 at 17:25
    
good question, I might go with the second method, since the CSS I provided for the attribute target on the label might not be supported by all browsers ;-) –  birgire Jun 19 '13 at 17:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.