0

i am currently setting up an options page in wordpress for my plugin. Why is it not possible to implement the functions as protected or private? The class is directly instantiated. As far as is know, it is possible with java as object oriented language to make them protected in this scenario, isn´t it?

Do i have to implement the $this variable generally with array or is this wordpress specific? It works right now and i have found some comments in the doc claiming that it has to me made this way, but i don´t understand why it´s necessary.

I know this is mostly basic php knowledge, but that´s why i am asking - to learn. Thanks for any help

<?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();
  • What functions do you need to make protected or private – omukiguy Mar 23 '18 at 17:40
  • I dont really need to have them protected or private. It´s more that i want to understand why i cant have them right now. As far as i knew, all functions could be protected, but somehow the code can not be processed in protected or private status – JUVO_Webdes Mar 23 '18 at 17:45
  • maybe, it'll be better to look here : https://stackoverflow.com/a/21902271/8053001 – Samvel Aleqsanyan Mar 23 '18 at 21:31

0 Answers0