WordPress选项页面功能可见性

时间:2018-03-23 17:18:50

标签: php wordpress application-settings

我目前正在wordpress中为我的插件设置一个选项页面。为什么不能将这些功能实现为受保护或私有?该类直接实例化。据我们所知,在这种情况下,使用java作为面向对象的语言可以使它们受到保护,不是吗?

我是否必须通常使用数组实现$ this变量,或者这个wordpress是否具体?它现在正常工作,我在文档中发现了一些评论,声称我必须这样做,但我不明白为什么这是必要的。

我知道这主要是基本的PHP知识,但这就是为什么我要求 - 学习。谢谢你的帮助

<?php
class SettingsPage {

    static $optionGroup = 'juvo_option_group';
    static $optionTitle = 'JUVO Anpassungen';

    public function __construct() {
        // create custom plugin settings menu
        add_action('admin_menu', array( $this, 'my_cool_plugin_create_menu'));

        //call register settings function
        add_action( 'admin_init', array( $this, 'register_juvo_plugin_settings' ));
     }

    public function my_cool_plugin_create_menu() {

        //create new top-level menu
        add_options_page(
            self::$optionTitle,  //Page Title
            self::$optionTitle,  //Menu Title
            'manage_options',       //required Capabilities
            'juvo-setting',            //Slug
            array( $this, 'juvo_settings_page')
        );

    }

    public function register_juvo_plugin_settings() {
        //register our settings
        register_setting( self::$optionGroup, 'privacy_policy_comments' );
    }

    public function juvo_settings_page() {
    ?>
    <div class="wrap">
    <h1><?php echo self::$optionTitle ?></h1>

    <form method="post" action="options.php">

        <?php settings_fields( self::$optionGroup );
        $options = get_option( 'privacy_policy_comments' );
        do_settings_sections( self::$optionGroup ); ?>

        <table class="form-table">

            <tr valign="top">
            <th scope="row">Seitentitel Datenschutzerklärung</th>
            <td><input type="text" name="privacy_policy_comments[title]" value="<?php echo esc_attr( $options['title']); ?>" /></td>
            </tr>

        </table>

        <?php submit_button(); ?>

    </form>
    </div>
    <?php }
}

if( is_admin() )
    $my_settings_page = new SettingsPage();

0 个答案:

没有答案