t( 'General Setting' ), $this->t( 'General Setting' ), 'manage_options', 'ad5-loyalty-option', array( $this, 'display_option_page' ) ); add_submenu_page( 'ad5-loyalty-option', $this->t( 'Documentation' ), $this->t( 'Documentation' ), 'manage_options', 'ad5-loyalty-docs', array( $this, 'display_docs_page' ) ); do_action('ad5-loyalty-add-page'); } public function display_option_page() { include( dirname(__FILE__) . '/../template/admin-option.php' ); } public function display_docs_page() { include( dirname(__FILE__) . '/../template/admin-docs.php' ); } public function register_setting() { $options = array('ad5_loyalty_setting', 'ad5_loyalty_default_content_guest', 'ad5_loyalty_default_content_user'); foreach( $options as $option ) { register_setting( 'ad5-loyalty-option-group', $option ); } do_action( 'ad5-loyalty-register-setting' ); } /** * get option for this plugin */ public function get_setting( $key = null ) { if ( ! $this->setting ) { $this->setting = get_option( 'ad5_loyalty_setting' ); } if ( $key ) { if ( ! empty( $this->setting[$key] ) ) { return $this->setting[$key]; } else { if ( $key == 'color_button_primary' ) { return '#333333'; } elseif ( $key == 'color_button_secondary' ) { return '#666666'; } else { return null; } } } else { return $this->setting; } } /** * add metabox on edit-post page */ public function add_meta_box() { add_meta_box( 'ad5-loyalty-content', $this->t( 'Loyalty Contents' ), array( $this, 'display_meta_box' ), null, 'normal', 'high' ); } public function display_meta_box() { wp_nonce_field( 'ad5_loyalty_nonce', 'ad5_loyalty_nonce' ); global $post; $ad5_loyalty_content_guest = get_post_meta( $post->ID, 'ad5_loyalty_content_guest', true ); $ad5_loyalty_content_user = get_post_meta( $post->ID, 'ad5_loyalty_content_user', true ); echo '
' . $this->t( 'Contents below will be outputted after main content.' ) . '
'; echo '' . $this->t( 'To display totally different contents for guests and members, leave main content blank.' ) . '
'; echo '