Skip to content

Commit

Permalink
v0.6.2
Browse files Browse the repository at this point in the history
-add: load custom stylesheets
-add: folder css
-add: css/demostyle.css

-add: array with stylesheets to sac_demo.php
-change: deactivate javascripts and stylesheets in sac_demo.php
  • Loading branch information
RalfAlbert committed Oct 22, 2011
1 parent 8e54462 commit a2ae011
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 14 deletions.
62 changes: 52 additions & 10 deletions class-easy_settings_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @package WordPress
* @subpackage Settings-API class
* @author Ralf Albert
* @version 0.6.1
* @version 0.6.2
* @license GPL
*/

Expand Down Expand Up @@ -78,8 +78,6 @@ class Easy_Settings_API
*/
protected static $_settings = array();

protected static $static_settings = array();

/**
*
* Single settings
Expand Down Expand Up @@ -227,8 +225,6 @@ public function setup( array $settings = null) {
$this->$key = $value;
}

self::$static_settings = self::$_settings;

return true;
}

Expand All @@ -242,10 +238,12 @@ public function setup( array $settings = null) {
* @access public
*/
public function init(){
// show errors
add_action( 'admin_notices', array( &$this, 'show_errors' ) );

// add page to admin-menu and register settings
add_action( 'admin_menu', array( &$this, 'add_page' ) );
add_action( 'admin_init', array( &$this, 'register_settings' ) );
add_action( 'admin_init', array( &$this, 'register_settings' ) );
}

/**
Expand Down Expand Up @@ -337,6 +335,7 @@ protected function get_options( $options_name = '' ){
return $this->options;
}


/**
*
* Returns the html-output-object
Expand All @@ -352,6 +351,7 @@ protected function get_output(){

return $this->output;
}


/**
*
Expand Down Expand Up @@ -382,6 +382,7 @@ protected function set_output(){
return $this->output;
}


/**
*
* Getter for settings
Expand All @@ -393,6 +394,7 @@ protected function set_output(){
public function get_settings() {
return self::$_settings;
}


/**
*
Expand Down Expand Up @@ -444,6 +446,7 @@ public function set_settings( array $settings = null, $defaults = array() ){

}


/**
*
* Add the page to the admin menu. Store page-hook in $_settings.
Expand All @@ -461,8 +464,12 @@ public function add_page() {
if( ! empty( self::$_settings['js_scripts'] ) && is_array( self::$_settings['js_scripts'] ) ){
self::register_js( self::$_settings['js_scripts'] );
}


// hook up custom stylesheets
if( ! empty( self::$_settings['styles'] ) )
add_action( 'admin_print_styles-' . self::$_settings['admin_page'], array( &$this, 'enqueue_styles' ) );
}


/**
*
Expand All @@ -488,6 +495,7 @@ public function register_settings() {

unset( $slug, $title, $field );
}


/**
*
Expand All @@ -514,6 +522,7 @@ public function create_setting( array $args = array() ) {
unset( $args, $defaults );
}


/**
*
* Display the page
Expand All @@ -537,6 +546,7 @@ public function display_page() {

$this->output->display_page( $args );
}


/**
*
Expand All @@ -551,6 +561,7 @@ public function display_section( array $section ) {
echo $this->section_descs[$section['id']];
}


/**
*
* Outputs the HTML for every single setting field
Expand Down Expand Up @@ -617,6 +628,7 @@ public function display_settings_field( array $args = array() ) {
}

}


/**
*
Expand Down Expand Up @@ -645,7 +657,7 @@ public static function register_js( array $scripts = null ){

// optionspage was added, js_src was set, add actionhook
add_action( 'load-' . self::$_settings['admin_page'], array( __CLASS__, 'enqueue_scripts' ) );

return true;
}

Expand All @@ -664,12 +676,12 @@ public static function enqueue_scripts(){
return false;

// use the page_slug as part of the tag if no tag was set
$name = self::$_settings['page_slug'];
$slug = self::$_settings['page_slug'];

foreach( self::$_settings['js_scripts'] as $tag => $values ){
// no tag was set
if( ! is_string( $tag ) )
$tag = $name . '-' . $tag;
$tag = $slug.'_'.$tag;

// the simplest way, $values is just a string. make $values an array
if( ! is_array( $values ) ){
Expand All @@ -696,6 +708,36 @@ public static function enqueue_scripts(){

}

/**
*
* Enqueue stylesheets
* Enqueue stylesheets, hooked by admin_print_styles-
* @param none
* @return void
* @since 0.6.2
* @access public
*/
public function enqueue_styles(){
if( ! empty( self::$_settings['styles'] ) ){
$styles = self::$_settings['styles'];
$slug = self::$_settings['page_slug'];
$count = 0;

// first check if $styles is an array. if not, use the page_slug as tag
if( ! is_array( $styles ) )
$styles = array( $slug => $styles );

foreach( $styles as $tag => $source ){
// if no tag is set, use page_slug+index as tag
if( ! is_string( $tag ) )
$tag = $slug.'_'.$tag;

wp_enqueue_style( $tag, $source, false, false, 'all' );
}

}
}

/* --------------- sanitizing --------------- */
/**
*
Expand Down
2 changes: 2 additions & 0 deletions css/demostyle.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/* simple demo style */
.wrap{ background: yellow; }
21 changes: 17 additions & 4 deletions sac_demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @package WordPress
* @subpackage Easy Settings API Class
* @author Ralf Albert
* @version 0.3.1
* @version 0.6.2
*
*/

Expand All @@ -14,7 +14,7 @@
* Domain Path: /languages
* Description: Demo for the the Easy Settings-API Class (ESAC). This plugin create a simple option page to show all available setting fields
* Author: Ralf Albert
* Version: 0.6.1
* Version: 0.6.2
* Author URI: http://neun12.de/
* Licence: GPL
*/
Expand Down Expand Up @@ -128,7 +128,7 @@ public function __construct()
* - version: js version
* - in_footer: load script in footer (true) or head (false)
*/

/*
'js_scripts' => array(
'sac-demo2-js' => plugins_url( 'js/alert.js', __FILE__ ),
Expand All @@ -141,7 +141,20 @@ public function __construct()
// some other javascripts
),

*/
/*
* Enqueue stylesheets
*
* tag => source
* or simply the path to the stylesheet. than the page_slug will be use as tag
*
*/
/*
'styles' => array( 'first-demo-style' => plugins_url( 'css/demostyle.css', __FILE__ ),
'second-demo-style' => plugins_url( 'css/demostyle.css', __FILE__ ),
plugins_url( 'css/demostyle.css', __FILE__ ),
),
*/
/*
* Sections
*/
Expand Down

0 comments on commit a2ae011

Please sign in to comment.