/ 设置 10 秒超时 // 每日统计清 0 runtime_set('todaycomments', 0); runtime_set('todayarticles', 0); runtime_set('todayusers', 0); if ($forumlist) { $fidarr = array(); foreach ($forumlist as $fid => $forum) { $fidarr[] = $forum['fid']; } forum_update($fidarr, array('todayposts' => 0, 'todaythreads' => 0)); } // 清理临时附件 attach_gc(); // 当天24点 $today = strtotime(date('Ymd')) + 86400; runtime_set('cron_2_last_date', $today, TRUE); // 往前推8个小时,尽量保证在前一天 升级过来和采集的数据会很卡 // table_day_cron($time - 8 * 3600); cache_delete('cron_lock_2'); } } } ?>plugin development - Custom Meta Box returns no HTML|Concepts Of Algorithm

plugin development - Custom Meta Box returns no HTML

admin2025-04-20  2

I'm trying to write my first plugin and running into an issue with the callback in add_meta_box(). The meta box appears on the custom post type page however there is no content inside.

Here is the relevant code:

class MySkills
{
    function __construct()
    {
        add_action('init', array('MySkills', 'ip_myskills_register_post_type'));
        add_action('load-post.php', array($this, 'init_metabox'));
        add_action('load-post-new.php', array($this, 'init_metabox'));
    }

    public function init_metabox() {
        add_action('add_meta_boxes', array('MySkills', 'skillsmetabox_init'));
        add_action('save_post', array($this, 'save_metabox_details'));
    }

    public function skillsmetabox_init() {
        add_meta_box('myskills_meta', 'Proficiency', 'myskills_html');
    }

    public function myskills_html($post) {
        ?>
        <?php wp_nonce_field( basename(__FILE__ ), 'ipmyskills_nonce' ) ?>
        <label for="ipmyskills_input"><?php _e('Enter the proficiency level for this skill (1 to 100)', 'myskill') ?></label>
        <input type="text" class="widefat" name="ipmysills_input" id="ipmyskills_input" value="<?php echo esc_attr( get_post_meta($post->ID, 'ip_myskills_input', true) ) ?>" />
        <?php
    }


}

I'm trying to write my first plugin and running into an issue with the callback in add_meta_box(). The meta box appears on the custom post type page however there is no content inside.

Here is the relevant code:

class MySkills
{
    function __construct()
    {
        add_action('init', array('MySkills', 'ip_myskills_register_post_type'));
        add_action('load-post.php', array($this, 'init_metabox'));
        add_action('load-post-new.php', array($this, 'init_metabox'));
    }

    public function init_metabox() {
        add_action('add_meta_boxes', array('MySkills', 'skillsmetabox_init'));
        add_action('save_post', array($this, 'save_metabox_details'));
    }

    public function skillsmetabox_init() {
        add_meta_box('myskills_meta', 'Proficiency', 'myskills_html');
    }

    public function myskills_html($post) {
        ?>
        <?php wp_nonce_field( basename(__FILE__ ), 'ipmyskills_nonce' ) ?>
        <label for="ipmyskills_input"><?php _e('Enter the proficiency level for this skill (1 to 100)', 'myskill') ?></label>
        <input type="text" class="widefat" name="ipmysills_input" id="ipmyskills_input" value="<?php echo esc_attr( get_post_meta($post->ID, 'ip_myskills_input', true) ) ?>" />
        <?php
    }


}
Share Improve this question asked Sep 27, 2019 at 19:33 IsaacIsaac 432 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Try adding array( $this, 'myskills_html' ) to the third argument.

    public function skillsmetabox_init() {
        add_meta_box( 'myskills_meta', 'Proficiency', array( $this, 'myskills_html' ) );
    }

Since this is class method, it should have the $this as well.

The same way you did with

add_action( 'save_post', array( $this, 'save_metabox_details' ) );
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745123449a286285.html

最新回复(0)