Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Creating meta box according to post format
- abstract class WPOrg_Meta_Box
- {
- public static function add()
- {
- $screens = ['post', 'wporg_cpt'];
- foreach ($screens as $screen) {
- if ( has_post_format('video') ) {
- add_meta_box(
- 'wporg_box_id', // Unique ID
- 'Meta box For Video',
- [self::class, 'html'], // Content callback, must be of type callable
- $screen // Post type
- );
- }
- if ( has_post_format('Audio') ) {
- add_meta_box(
- 'wporg_box_id', // Unique ID
- 'Meta box For Audio',
- [self::class, 'html'], // Content callback, must be of type callable
- $screen // Post type
- );
- }
- }
- }
- public static function save($post_id)
- {
- if (array_key_exists('wporg_field', $_POST)) {
- update_post_meta(
- $post_id,
- '_wporg_meta_key',
- $_POST['wporg_field']
- );
- }
- }
- public static function html($post)
- {
- $value = get_post_meta($post->ID, '_wporg_meta_key', true);
- if ( has_post_format('video') ) {
- ?>
- <label for="wporg_field">Meta Field For Video</label>
- <input class="text-regular" type="text" >
- <?php
- }
- if ( has_post_format('audio') ) {
- ?>
- <label for="wporg_field">Meta Field For Audio</label>
- <input class="text-regular" type="text" >
- <?php
- }
- }
- }
- add_action('add_meta_boxes', ['WPOrg_Meta_Box', 'add']);
- add_action('save_post', ['WPOrg_Meta_Box', 'save']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement