get_options();
/** Add plugin settings page. */
$this->add_settings_page();
}
/**
* Render Tabs Headers.
*
* @since 1.0.0
* @access private
*
* @return void
**/
private function render_tabs() {
/** Selected tab key. */
$current = $this->get_current_tab();
/** Tabs array. */
$tabs = Plugin::get_tabs();
/** Render Tabs. */
?>
mail
thumb_up
$tab ) {
/** Skip tabs without handlers. */
if ( empty( $tab['class'] ) ) { continue; }
/** Call add_settings from appropriate class for each tab. */
call_user_func( [ $tab['class'], 'get_instance' ] )->add_settings( $tab_slug );
}
}
/**
* Add admin menu for plugin settings.
*
* @since 1.0.0
* @access public
*
* @return void
**/
public function add_admin_menu() {
/** Submenu for Elementor plugins. */
if ( 'elementor' === Plugin::get_type() ) {
$this->add_submenu_elementor();
/** Root level menu for WordPress plugins. */
} else {
$this->add_menu_wordpress();
}
}
/**
* Add admin menu for Elementor plugins.
*
* @since 1.0.0
* @access private
*
* @return void
**/
private function add_submenu_elementor() {
/** Check if Elementor installed and activated. */
$parent = 'options-general.php';
if ( did_action( 'elementor/loaded' ) ) {
$parent = 'elementor';
//$parent = 'edit-comments.php';
}
add_submenu_page(
$parent,
esc_html__( 'AdUnlocker Settings', 'AdUnlocker' ),
esc_html__( 'AdUnlocker for ', 'AdUnlocker' ),
'manage_options',
'pp_AdUnlocker_settings',
[ $this, 'options_page' ]
);
}
/**
* Add admin menu for WordPress plugins.
*
* @since 1.0.0
* @access private
*
* @return void
**/
private function add_menu_wordpress() {
add_menu_page(
esc_html__( 'AdUnlocker Settings', 'AdUnlocker' ),
esc_html__( 'AdUnlocker', 'AdUnlocker' ),
'manage_options',
'pp_AdUnlocker_settings',
[ $this, 'options_page' ],
$this->get_admin_menu_icon(),
$this->get_admin_menu_position()
);
}
/**
* Return path to admin menu icon or base64 encoded image.
*
* @since 1.0.0
* @access public
*
* @return string
**/
private function get_admin_menu_icon() {
return 'data:image/svg+xml;base64,' . base64_encode( file_get_contents( Plugin::get_path() . 'images/logo-menu.svg' ) );
}
/**
* Calculate admin menu position based on plugin slug value.
*
* @since 1.0.0
* @access public
*
* @return string
**/
private function get_admin_menu_position() {
$hash = md5( Plugin::get_slug() );
$int = (int) filter_var( $hash, FILTER_SANITIZE_NUMBER_INT );
$int = (int) ( $int / 1000000000000 );
return '58.' . $int;
}
/**
* Plugin Settings Page.
*
* @since 1.0.0
* @access public
*
* @return void
**/
public function options_page() {
/** User rights check. */
if ( ! current_user_can( 'manage_options' ) ) { return; } ?>
get_current_tab();
return ( $tab === $current_tab ) && Tab::is_tab_enabled( $current_tab );
}
/**
* Render nags on after settings save.
*
* @since 1.0.0
* @access private
*
* @return void
**/
private function render_nags() {
/** Exit if this is not settings update. */
if ( ! isset( $_GET['settings-updated'] ) ) { return; }
/** Render "Settings Saved" message. */
$this->render_nag_saved();
}
/**
* Render "Settings Saved" message.
*
* @since 1.0.0
* @access private
*
* @return void
**/
private function render_nag_saved() {
/** Exit if settings saving was not successful. */
if ( 'true' !== $_GET['settings-updated'] ) { return; }
/** Render "Settings Saved" message. */
UI::get_instance()->render_snackbar( esc_html__( 'Settings saved!', 'AdUnlocker' ) );
}
/**
* Render logo and Save changes button in plugin settings.
*
* @since 1.0.0
* @access private
*
* @return void
**/
private function render_logo() {
?>
$tab ) {
/** If current tab haven't fields. */
if ( empty( $tab['fields'] ) ) { continue; }
/** Collect default values from each field. */
foreach ( $tab['fields'] as $field_slug => $field ) {
$default[$field_slug] = $field['default'];
}
}
return $default;
}
/**
* Get plugin settings with default values.
*
* @since 1.0.0
* @access public
*
* @return void
**/
public function get_options() {
/** Default values. */
$defaults = $this->get_default_settings();
$results = [];
/** Get all plugin tabs with settings fields. */
$tabs = Plugin::get_tabs();
/** Collect settings from each tab. */
foreach ( $tabs as $tab_slug => $tab ) {
$opt_name = "pp_AdUnlocker_{$tab_slug}_settings";
$options = get_option( $opt_name );
$results = wp_parse_args( $options, $defaults );
$defaults = $results;
}
$this->options = $results;
}
/**
* Main Settings Instance.
* Insures that only one instance of Settings exists in memory at any one time.
*
* @static
* @since 1.0.0
* @access public
*
* @return Settings
**/
public static function get_instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof self ) ) {
self::$instance = new self;
}
return self::$instance;
}
}