Using WordPress ‘post_comment_status_meta_box-options’ PHP action

The post_comment_status_meta_box-options WordPress PHP action fires at the end of the Discussion meta box on the post editing screen, allowing you to add custom content or options.

Usage

add_action('post_comment_status_meta_box-options', 'my_custom_function', 10, 1);

function my_custom_function($post) {
  // your custom code here
}

Parameters

  • $post (WP_Post): The WP_Post object for the current post.

More information

See WordPress Developer Resources: post_comment_status_meta_box-options

Examples

Adding a custom checkbox to the Discussion meta box

This example adds a custom checkbox to the Discussion meta box:

add_action('post_comment_status_meta_box-options', 'add_custom_checkbox', 10, 1);

function add_custom_checkbox($post) {
  $custom_value = get_post_meta($post->ID, '_custom_meta_key', true);
  ?>
  <br>
  <input type="checkbox" id="custom-meta-key" name="custom_meta_key" value="1" <?php checked($custom_value, '1'); ?>>
  <label for="custom-meta-key">Enable Custom Feature</label>
  <?php
}

Displaying a custom message

This example displays a custom message in the Discussion meta box:

add_action('post_comment_status_meta_box-options', 'display_custom_message', 10, 1);

function display_custom_message($post) {
  echo '<p>This is a custom message displayed in the Discussion meta box.</p>';
}

Adding custom input field

This example adds a custom input field to the Discussion meta box:

add_action('post_comment_status_meta_box-options', 'add_custom_input_field', 10, 1);

function add_custom_input_field($post) {
$custom_value = get_post_meta($post->ID, '_custom_input_key', true);
?>
<br>
<label for="custom-input-key">Custom Input:</label>
<input type="text" id="custom-input-key" name="custom_input_key" value="<?php echo esc_attr($custom_value); ?>">
<?php
}

Displaying custom information based on post status

This example displays custom information based on the post's status:

add_action('post_comment_status_meta_box-options', 'display_status_based_message', 10, 1);

function display_status_based_message($post) {
  if ($post->post_status == 'publish') {
    echo '<p>This post is published.</p>';
  } else {
    echo '<p>This post is not published yet.</p>';
  }
}