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?
1 Answer
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:
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: