And finally, and maybe that's micro-optimization, it's said that ===
is faster than ==
===
is faster than ==
.
You'll note that there'll be an issue with the current admin menu indicator, it can be solved like this like this or this.
And finally, and maybe that's micro-optimization, it's said that ===
is faster than ==
.
You'll note that there'll be an issue with the current admin menu indicator, it can be solved like this or this.
And finally, and maybe that's micro-optimization, it's said that ===
is faster than ==
.
You'll note that there'll be an issue with the current admin menu indicator, it can be solved like this or this.
Given that all this ends in a jQuery fix. You, you can consider only add_theme_page()
and deal with the Tabs display doing a switch( $_GET['tab'] ) {}
.
##Scripts and styles
To target our own pages, the add_(sub)menu_*menu_page
functions return the hook name that we can use like:
$hook = add_menu_page( $args );
add_action( "admin_print_scripts-$hook", array( $this, 'print_scripts' );
public function print_scripts(){
?>
<style> /* declare styles */ </style>
<script>/* run scripts */ </style>
<?php
}
private $hooks = array();
public function add_options_pages() {
foreach ( $this->pages as $page ) {
if ($page['type']=='menu')
$this->hooks[] = add_theme_page( $args );
else if ($page['type'] == 'submenu')
$this->hooks[] = add_submenu_page( $args );
}
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
}
public function enqueue( $hook ){
if( !in_array( $hook, $this->hooks ) )
return;
wp_enqueue_script( 'my-scp', plugins_url( '/js/my-script.js', __FILE__) ); # Adjust to use with themes
wp_enqueue_style( 'my-stl', plugins_url( '/css/my-style.js', __FILE__) );
}
Those are only two items, but as good practice it's recommended that we store all our plugin/theme settings inside one option only. Truth be told, as you have it it's much better than what we see in the wild, one optiondb entry for each and every sub-option.
Given that all this ends in a jQuery fix. You can consider only add_theme_page()
and deal with the Tabs display doing a switch( $_GET['tab'] ) {}
.
##Scripts and styles
To target our own pages, the add_(sub)menu_*
functions return the hook name that we can use like:
$hook = add_menu_page( $args );
add_action( "admin_print_scripts-$hook", array( $this, 'print_scripts' );
public function print_scripts(){
?>
<style> /* declare styles */ </style>
<script>/* run scripts */ </style>
<?php
}
private $hooks = array();
public function add_options_pages() {
foreach ( $this->pages as $page ) {
if ($page['type']=='menu')
$this->hooks[] = add_theme_page( $args );
else if ($page['type'] == 'submenu')
$this->hooks[] = add_submenu_page( $args );
}
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
}
public function enqueue( $hook ){
if( !in_array( $hook, $this->hooks ) )
return;
wp_enqueue_script( 'my-scp', plugins_url( '/my-script.js', __FILE__) ); # Adjust to use with themes
}
Those are only two items, but as good practice it's recommended that we store all our plugin/theme settings inside one option only. Truth be told, as you have it it's much better than what we see in the wild, one option for each and every sub-option.
Given that all this ends in a jQuery fix, you can consider only add_theme_page()
and deal with the Tabs display doing a switch( $_GET['tab'] ) {}
.
##Scripts and styles
To target our own pages, the add_(sub)menu_page
functions return the hook name that we can use like:
$hook = add_menu_page( $args );
add_action( "admin_print_scripts-$hook", array( $this, 'print_scripts' );
public function print_scripts(){
?>
<style> /* declare styles */ </style>
<script>/* run scripts */ </style>
<?php
}
private $hooks = array();
public function add_options_pages() {
foreach ( $this->pages as $page ) {
if ($page['type']=='menu')
$this->hooks[] = add_theme_page( $args );
else if ($page['type'] == 'submenu')
$this->hooks[] = add_submenu_page( $args );
}
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
}
public function enqueue( $hook ){
if( !in_array( $hook, $this->hooks ) )
return;
wp_enqueue_script( 'my-scp', plugins_url( '/js/my-script.js', __FILE__) ); # Adjust to use with themes
wp_enqueue_style( 'my-stl', plugins_url( '/css/my-style.js', __FILE__) );
}
Those are only two items, but as good practice it's recommended that we store all our plugin/theme settings inside one option only. Truth be told, as you have it it's much better than what we see in the wild, one db entry for each and every sub-option.