Skip to content

Commit

Permalink
v070
Browse files Browse the repository at this point in the history
RC1
- remove debug code
- ToDo: add DocComment
- ToDo: validate capability in class Easy_Settings_Api
  • Loading branch information
RalfAlbert committed Nov 6, 2011
1 parent 0ade282 commit 3e86891
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 111 deletions.
72 changes: 13 additions & 59 deletions class-easy_settings_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,9 @@ public function __construct( $outputclass = '' ) {
self::$config->scripts = new stdClass();
self::$config->styles = new stdClass();
self::$config->sections = new stdClass();

// check if $settings was set. if not, just create an object of this class
// if( null !== $settings ) {
// $this->_setup( $settings );
// $this->init();
// }

}

public function create_optionspage(){
$this->init();
// $this->show_errors();
// die( var_dump( self::$config->sections ) );
}

/* -------------------------------------------------------------------------- */
/* class configuration ------------------------------------------------------ */
Expand Down Expand Up @@ -369,14 +358,14 @@ public function show_errors(){

/**
*
* Adding the page to the menu and register the settings
* Adding the page to the menu and register the settings. Displays errors if any are encountered
* @param none
* @return none
* @uses add_action()
* @since 0.1
* @access public
*/
public function init(){
public function create_optionspage(){
// show errors
add_action( 'admin_notices', array( &$this, 'show_errors' ) );

Expand Down Expand Up @@ -494,19 +483,17 @@ public function add_page() {

$where = 'add_' . $c->menu_position . '_page';
$c->admin_page = $where( $c->page_title, $c->menu_title, $c->capability, $c->page_slug, array( &$this, 'display_page' ) );


// register javascript(s) if set
if( ! empty( self::$config->scripts ) ){
add_action( 'load-' . $c->admin_page, array( __CLASS__, 'enqueue_scripts' ) );

}
if( ! empty( self::$config->scripts ) )
add_action( 'load-' . $c->admin_page, array( __CLASS__, 'enqueue_scripts' ) );

// hook up custom stylesheets
if( ! empty( self::$config->styles ) )
add_action( 'admin_print_styles-' . $c->admin_page, array( &$this, 'enqueue_styles' ) );

// copy back modified config
// copy back modified config (copy admin_page to config->basic)
self::$config->basic = $c;
}

Expand All @@ -532,8 +519,7 @@ public function register_settings() {

foreach ( $data->fields as $field ) {
$this->create_setting( $field );
}

}
}

}
Expand All @@ -559,7 +545,7 @@ public function create_setting( $args = null ) {
if( ! empty( $this->fields_defaults ) )
$args = self::parse_args( $args, $this->fields_defaults );
else
$this->add_error( 'Can\t get field defaults from output class.');
$this->add_error( sprintf( "Can't get field defaults from output class. (%s)", __METHOD__ ) );

// copy the 'id' to 'label_for'
$args->label_for = $args->id;
Expand Down Expand Up @@ -641,17 +627,6 @@ public function display_settings_field( $args = null ) {
$$cv = $args->$cv;
}

// set standard for multi-checkbox
if( ( isset( $std ) && is_array( $std ) ) &&
( isset( $type) && $type == 'mcheckbox' ) &&
! isset( $this->options[$id] ) ) {

foreach( $std as $key ) {
if( ! isset( $this->options[$id . '-' . $key] ) )
$this->options[$id . '-' . $key] = 'on';
}
}

// set standard for multi-checkbox
if( ( isset( $std ) && is_array( $std ) ) &&
( isset( $type) && $type == 'mcheckbox' ) &&
Expand All @@ -669,10 +644,6 @@ public function display_settings_field( $args = null ) {
! isset( $this->options[$id] ) ) {

$this->options[$id] = $std;
// foreach( $std as $key ) {
// if( ! isset( $this->options[$id . '-' . $key] ) )
// $this->options[$id . '-' . $key] = 'on';
// }
}

// set standard for all other
Expand All @@ -681,7 +652,7 @@ public function display_settings_field( $args = null ) {

// set css class
if( ! empty( $class ) )
$args->class = ' class="' . $class . '"';
$args->class = 'class="' . $class . '"';

// options_name is needed for ceckboxes, radio & select
$args->options_name = self::$config->basic->options_name;
Expand Down Expand Up @@ -715,28 +686,12 @@ public static function enqueue_scripts(){
$slug = self::$config->basic->page_slug;

foreach( self::$config->scripts as $tag => $values ){
// no tag was set
// no tag was set (tag == integer)
if( ! is_string( $tag ) )
$tag = $slug.'_'.$tag;

// the simplest way, $values is just a string. make $values an array
// if( ! is_array( $values ) ){
// $values = array( 'src' => $values );
//
// }
//
// $defaults = array( 'src' => false,
// 'dependencies' => array(),
// 'version' => false,
// 'in_footer' => true
// );
// $values = wp_parse_args( $values, $defaults );
//
// if( ! is_array( $values['dependencies'] ) )
// $values['dependencies'] = (array) $values['dependencies'];

// maybe no source was set. but don't care about if $src exists or is readable!!!
if( ! $values['src'] )
if( empty( $values['src'] ) )
continue;

wp_enqueue_script( $tag, $values['src'], $values['dependencies'], $values['version'], $values['in_footer'] );
Expand Down Expand Up @@ -838,8 +793,7 @@ protected function get_file_headers( $file ){
$defaults->menu_title = $name;
$defaults->description = $desc;

return $defaults;

return $defaults;
}


Expand Down
39 changes: 15 additions & 24 deletions class-easy_settings_api_html_output.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.5.2
* @version 0.7.0
* @license GPL
*/

Expand Down Expand Up @@ -161,9 +161,11 @@ public static function checkbox( $args = null ){
( isset( self::$options[$args->id] ) && 'on' === self::$options[$args->id] ) ?
$checked = 'checked="checked"' : $checked = '';

//echo '<input' . $args->class . ' type="checkbox" id="' . $args->id . '" name="' . $args->options_name . '[' . $args->id . ']" value="on"' . $checked . ' /> <label for="' . $args->id . '">' . $args->text_after . '</label>';
$format = '<input id="%1$s" name="%3$s[%1$s]" %2$s type="checkbox" value="on" %5$s /> <label for="%1$s">%4$s</label>';
printf($format, $args->id, $args->class, $args->options_name, $args->text_after, $checked );
printf(
'<input id="%1$s" name="%2$s[%1$s]" %3$s type="checkbox" value="on" %5$s />&nbsp;
<label for="%1$s">%4$s</label>',
$args->id, $args->options_name,$args->class, $args->text_after, $checked
);

self::display_field_description( $args->description );
}
Expand All @@ -184,9 +186,8 @@ public static function radio( $args = null ){
( isset( self::$options[$args->id] ) && self::$options[$args->id] == $key ) ?
$selected = 'checked="checked"' : $selected = '';

//echo '<input' . $args->class . ' type="radio" name="' . $args->options_name . '[' . $args->id . ']" id="' . $args->id . $i . '" value="' . $value . '"' . $selected . '> <label for="' . $args->id . $i . '">' . $label . '</label>';
printf(
'<input id="%1$s4$s" name="%2$s[%1$s]" %3$s type="radio" value="%5$s" %6$s />
'<input id="%1$s4$s" name="%2$s[%1$s]" %3$s type="radio" value="%5$s" %6$s />&nbsp;
<label for="%1$s%4$s">%7$s</label>',
$args->id, $args->options_name, $args->class, $i, $key, $selected, $label
);
Expand Down Expand Up @@ -216,9 +217,8 @@ public static function mcheckbox( $args = null ){
( isset( self::$options[$args->id . '-' . $key]) && 'on' === self::$options[$args->id . '-' . $key]) ?
$checked = 'checked="checked"' : $checked = '';

//echo '<input' . $args->class . ' type="checkbox" id="' . $args->id . '-' . $key . '" name="' . $args->options_name . '[' . $args->id . '-' . $key . ']" value="on"' . $checked . ' /> <label for="' . $args->id . '">' . $label . '</label>';
printf(
'<input id="%1$s-%4$s" name="%2$s[%1$s-%4$s]" type="checkbox" value="on" %5$s />
'<input id="%1$s-%4$s" name="%2$s[%1$s-%4$s]" type="checkbox" value="on" %5$s />&nbsp;
<label for="' . $args->id . '">' . $label . '</label>',
$args->id, $args->options_name, $args->class, $key, $checked

Expand Down Expand Up @@ -250,21 +250,19 @@ public static function select( $args = null ){

$args = self::parse_args( $args, self::$fields_defaults );

$size = '';
if( isset( $args->size ) && 1 < $args->size )
$size = 'size="' . $args->size . '"';
( isset( $args->size ) && 1 < $args->size ) ?
$size = 'size="' . $args->size . '"' : $size = '';

//echo '<select' . $args->class . ' name="' . $args->options_name . '[' . $args->id . ']"' . $lines . ' style="height:100%">';
printf(
'<select id="%1$s" name="%3$s[%1$s]" %2$s %4$s style="height:100%%">',
$args->id, $args->class, $args->options_name, $size
);

foreach( $args->choices as $key => $label ) {
$selected = '';
if( isset( self::$options[$args->id] ) && self::$options[$args->id] == $key )
$selected = 'selected="selected"';
//echo '<option value="' . $value . '"' . $selected . '>' . $label . '</option>';

( isset( self::$options[$args->id] ) && self::$options[$args->id] == $key ) ?
$selected = 'selected="selected"' : $selected = '';

printf(
'<option value="%1$s" %2$s>%3$s</option>',
$key, $selected, $label
Expand All @@ -288,9 +286,6 @@ public static function mselect( $args = null ){
( isset( $args->size ) && 1 < $args->size ) ?
$size = 'size="' . $args->size . '"' : $size = '';

//var_dump(self::$options[$args->id]);
//var_dump(self::$options);

printf( '<select id="%1$s" %2$s name="%3$s[%1$s][]" %4$s multiple="multiple" style="height:100%%">',
$args->id, $args->class, $args->options_name, $size
);
Expand All @@ -299,7 +294,7 @@ public static function mselect( $args = null ){

( in_array( $key, self::$options[$args->id] ) ) ?
$selected = 'selected="selected"' : $selected = '';
//echo '<option value="' . $key . '"' . $selected . '>' . $label . '</option>';

printf(
'<option value="%1$s" %2$s>%3$s</option>',
$key, $selected, $label
Expand All @@ -323,7 +318,6 @@ public static function textarea( $args = null ){

$value = isset( self::$options[$args->id] ) ? self::$options[$args->id] : $args->std;

//echo '<textarea' . $args->class . ' id="' . $args->id . '" name="' . $args->options_name . '[' . $args->id . ']" rows="' . $args->rows . '" cols="' . $args->cols . '" placeholder="' . $args->std . '">' . esc_textarea( $value ) . '</textarea>';
printf(
'<textarea id="%1$s" name="%2$s[%1$s]" %3$s rows="%4$s" cols="%5$s" placeholder="%6$s">%7$s</textarea>%8$s',
$args->id, $args->options_name, $args->class, $args->rows, $args->cols, $args->std, esc_textarea( $value ), $args->text_after
Expand All @@ -343,7 +337,6 @@ public static function password( $args = null ){

$value = isset( self::$options[$args->id] ) ? self::$options[$args->id] : $args->std;

//echo '<input' . $args->class . ' type="password" id="' . $args->id . '" name="' . $args->options_name . '[' . $args->id . ']" value="' . $value . '" />' . $args->text_after;
printf(
'<input id="%1$s" name="%2$s[%1$s]" %3$s type="password" value="%4$s" />%5$s',
$args->id, $args->options_name, $args->class, $value, $args->text_after
Expand All @@ -363,8 +356,6 @@ public static function text( $args = null ){

$value = isset( self::$options[$args->id] ) ? self::$options[$args->id] : $args->std;

// echo '<input' . $args->class . ' type="text" size="' . $args->size . ' id="' . $args->id . '" name="' . $args->options_name . '[' . $args->id . ']"
// placeholder="' . $args->std . '" value="' . esc_html( $value ) . '" />' . $args->text_after;
printf(
'<input id="%1$s" name="%2$s[%1$s]" %3$s type="text" value="%4$s" size="%6$s" placeholder="%7$s" />%5$s',
$args->id, $args->options_name, $args->class, esc_html( $value ), $args->text_after, $args->size, $args->std
Expand Down
Loading

0 comments on commit 3e86891

Please sign in to comment.