Giter VIP home page Giter VIP logo

rationaloptionpages's Introduction

RationalOptionPages

A PHP class for building WordPress Option Pages. Uses multi-dimensional associative arrays to try and make the process of adding option pages a little easier to map out and use.

Table of Contents

  1. Installation
  2. Usage
    1. Pages
    2. Subpages
    3. Fields
  3. Retrieving Data
  4. To Do

Installation

  • Download or clone the repo
  • Include RationalOptionPages.php in your file
  • Instantiate the class with your array of pages
if ( !class_exists( 'RationalOptionPages' ) ) {
	require_once('RationalOptionPages.php');
}
$pages = array(
	'sample-page'	=> array(
		'page_title'	=> __( 'Sample Page', 'sample-domain' ),
	),
);
$option_page = new RationalOptionPages( $pages );

Note:

If you installed this previously and the class is already being instantiated somewhere else you will get fatal errors. You can avoid this by either renaming the class or by wrapping the require_once() in a if ( !class_exists() ) conditional.

Usage

Pages

Pages are added in a key/value syntax where the value is an array of parameters for the page itself.

Parameters

Based on WordPress' add_menu_page() function.

  • page_title - The text string for the title of the page Required.
  • menu_title - The text string for the menu item itself. Defaults to page_title.
  • capability - The permissions required to access this page. Defaults to manage_options.
  • menu_slug - The "slug" of the menu item. Defaults to a "slugified" version of the page_title.
  • icon_url - The URL of the menu icon. WordPress' Dashicons are available. Defaults to false, renders "dashicons-admin-generic".
  • position - The position where the menu item appears, from 1 to 99. Defaults to null, last.

If your page title is more than 2 words I recommend using the menu_title parameter to avoid wrapping. The default capability should work for most plugins and themes as only the admin would typically make higher level changes like these.

Subpages

Subpages are differentiated by the parent_slug parameter. They can be added either at the top level of the pages array submitted to the class or under a subpages key within another, top-level page parameter array.

Parameters

Based on WordPress' add_submenu_page() function.

  • parent_slug - The menu_slug of the parent page. WordPress has several top-level menu items. Required (unless added via the subpages key method).
  • page_title - The text string for the title of the page. Required.
  • menu_title - The text string for the menu item itself. Defaults to page_title.
  • capability - The permissions required to access this page. Defaults to manage_options.
  • menu_slug - The "slug" of the menu item. Defaults to a "slugified" version of the page_title.

Example

require_once('RationalOptionPages.php');
$pages = array(
	'sample-page'	=> array(
		'page_title'	=> __( 'Sample Page', 'sample-domain' ),
		// via the subpages key
		'subpages'		=> array(
			'sub-page-one'	=> array(
				'page_title'	=> __( 'Sub Page One', 'sample-domain' ),
			),
		),
	),
	// via the pages array itself
	'sub-page-two'	=> array(
		'parent_slug'	=> 'sample_page',
		'page_title'	=> __( 'Sub Page Two', 'sample-domain' ),
	),
	// sub page of the "Appearance" menu item
	'sub-theme'	=> array(
		'parent_slug'	=> 'themes.php',
		'page_title'	=> __( 'Sub Theme', 'sample-domain' ),
	),
);
$option_page = new RationalOptionPages( $pages );

Sections

Sections are added via a sections key in the page parameter arrays.

Parameters

Based on WordPress' add_settings_section() function.

  • title - The title of the section. Required.
  • id - The ID of the section.
  • callback - An optional parameter for generating custom, section content. Requires custom parameter be set to true.
  • custom - A boolean option that indicates you want to use a custom callback. Defaults to false.
  • text - An option parameter for adding HTML text under the section title.
  • include - An option parameter that calls PHP's include() under the section title. Use absolute path.

Example

require_once('RationalOptionPages.php');
$pages = array(
	'sample-page'	=> array(
		'page_title'	=> __( 'Sample Page', 'sample-domain' ),
		'sections'		=> array(
			'section-one'	=> array(
				'title'			=> __( 'Section One', 'sample-domain' ),
				'text'			=> '<p>' . __( 'Some HTML text to describe the section', 'sample-domain' ) . '</p>',
				'include'		=> plugin_dir_path( __FILE__ ) . '/your-include.php',
			),
			'section-two'	=> array(
				'title'			=> __( 'Section Two', 'sample-domain' ),
				'custom'		=> true,
				'callback'		=> 'custom_section_callback_function',
			),
		),
	),
);
$option_page = new RationalOptionPages( $pages );

Fields

Fields are added via a fields key in the section parameter array.

Parameters

Based on WordPress' add_settings_field() function.

  • title - The title/label of the field. Required.
  • id - The ID of the field.
  • callback - An optional parameter for generating custom, field content. Requires custom parameter be set to true.
  • custom - A boolean option that indicates you want to use a custom callback. Defaults to false.
  • type - The type of field to use. Most input types are available as well as select, textarea, wp_editor and media (instead of file input type).
  • text - Help text for most input types. Label for checkbox.
  • title_attr - The "title" attribute of the input (if available).
  • choices - Associative array of options for radio groups and select elements. Required for radio and select types.
  • placeholder - The placeholder attribute of the input (if available).
  • value - The default value of the input.
  • checked - A boolean for the default state of the checkbox type. Defaults to false.
  • attributes - Associative array of additional attributes for the input element.
    • Input - autocomplete, autofocus, disabled, list, max, maxlength, min, pattern, readonly, required, size and step
    • Select - multiple, size
    • Textarea - cols, rows and wrap
  • sanitize - A boolean that indicates whether or not the field's value should be sanitized. Defaults to false, and doesn't apply to checkboxes.

Examples

The most basic of inputs.

require_once('RationalOptionPages.php');
$pages = array(
	'sample-page'	=> array(
		'page_title'	=> __( 'Sample Page', 'sample-domain' ),
		'sections'		=> array(
			'section-one'	=> array(
				'title'			=> __( 'Section One', 'sample-domain' ),
				'fields'		=> array(
					'default'		=> array(
						'title'			=> __( 'Default', 'sample-domain' ),
					),
				),
			),
		),
	),
);
$option_page = new RationalOptionPages( $pages );

Almost everything.

require_once('RationalOptionPages.php');
$pages = array(
	'sample-page'	=> array(
		'page_title'	=> __( 'Sample Page', 'sample-domain' ),
		'sections'		=> array(
			'section-one'	=> array(
				'title'			=> __( 'Standard Inputs', 'sample-domain' ),
				'fields'		=> array(
					'default'		=> array(
						'title'			=> __( 'Default (text)', 'sample-domain' ),
						'text'			=> __( 'Text attributes are used as help text for most input types.' ),
					),
					'date'			=> array(
						'title'			=> __( 'Date', 'sample-domain' ),
						'type'			=> 'date',
						'value'			=> 'now',
					),
					'datetime'		=> array(
						'title'			=> __( 'Datetime-Local', 'sample-domain' ),
						'type'			=> 'datetime-local',
						'value'			=> 'now',
					),
					'datetime-local' => array(
						'title'			=> __( 'Datetime-Local', 'sample-domain' ),
						'type'			=> 'datetime-local',
						'value'			=> 'now',
					),
					'email'			=> array(
						'title'			=> __( 'Email', 'sample-domain' ),
						'type'			=> 'email',
						'placeholder'	=> '[email protected]',
					),
					'month'			=> array(
						'title'			=> __( 'Month', 'sample-domain' ),
						'type'			=> 'month',
						'value'			=> 'now',
					),
					'number'		=> array(
						'title'			=> __( 'Number', 'sample-domain' ),
						'type'			=> 'number',
						'value'			=> 42,
					),
					'password'		=> array(
						'title'			=> __( 'Password', 'sample-domain' ),
						'type'			=> 'password',
					),
					'search'		=> array(
						'title'			=> __( 'Search', 'sample-domain' ),
						'type'			=> 'search',
						'placeholder'	=> __( 'Keywords or terms&hellip;', 'sample-domain' ),
					),
					'tel'			=> array(
						'title'			=> __( 'Telephone', 'sample-domain' ),
						'type'			=> 'tel',
						'placeholder'	=> '(555) 555-5555',
					),
					'time'			=> array(
						'title'			=> __( 'Time', 'sample-domain' ),
						'type'			=> 'time',
						'value'			=> 'now',
					),
					'url'			=> array(
						'title'			=> __( 'URL', 'sample-domain' ),
						'type'			=> 'url',
						'placeholder'	=> 'http://jeremyhixon.com',
					),
					'week'			=> array(
						'title'			=> __( 'Week', 'sample-domain' ),
						'type'			=> 'week',
						'value'			=> 'now',
					),
				),
			),
			'section-two'	=> array(
				'title'			=> __( 'Non-standard Input', 'sample-domain' ),
				'fields'		=> array(
					'checkbox'		=> array(
						'title'			=> __( 'Checkbox', 'sample-domain' ),
						'type'			=> 'checkbox',
						'text'			=> __( 'Text attributes are used as labels for checkboxes' ),
					),
					'color'			=> array(
						'title'			=> __( 'Color', 'sample-domain' ),
						'type'			=> 'color',
						'value'			=> '#cc0000',
					),
					'media'			=> array(
						'title'			=> __( 'Media', 'sample-domain' ),
						'type'			=> 'media',
						'value'			=> 'http://your-domain.com/wp-content/uploads/2016/01/sample.jpg',
					),
					'radio'			=> array(
						'title'			=> __( 'Radio', 'sample-domain' ),
						'type'			=> 'radio',
						'value'			=> 'option-two',
						'choices'		=> array(
							'option-one'	=> __( 'Option One', 'sample-domain' ),
							'option-two'	=> __( 'Option Two', 'sample-domain' ),
						),
					),
					'range'			=> array(
						'title'			=> __( 'Range', 'sample-domain' ),
						'type'			=> 'range',
						'value'			=> 75,
					),
					'select'		=> array(
						'title'			=> __( 'Select', 'sample-domain' ),
						'type'			=> 'select',
						'value'			=> 'option-two',
						'choices'		=> array(
							'option-one'	=> __( 'Option One', 'sample-domain' ),
							'option-two'	=> __( 'Option Two', 'sample-domain' ),
						),
					),
					'select-multiple'		=> array(
						'title'			=> __( 'Select multiple', 'sample-domain' ),
						'type'			=> 'select',
						'value' => array(
							'option-two'
						),
						'choices' => array(
							'option-one' => __( 'Option One', 'sample-domain' ),
							'option-two' => __( 'Option Two', 'sample-domain' ),
							'option-three' => __( 'Option Three', 'sample-domain' ),
						),
						'attributes' => array(
							'multiple' => 'multiple'
						),
						'sanitize' => true
					),
					'textarea'		=> array(
						'title'			=> __( 'Textarea', 'sample-domain' ),
						'type'			=> 'textarea',
						'value'			=> 'Pellentesque consectetur volutpat lectus, ac molestie lorem molestie nec. Vestibulum in auctor massa. Vivamus convallis nunc quis lacus maximus, non ultricies risus gravida. Praesent ac diam imperdiet, volutpat nisi sed, semper eros. In nec orci hendrerit, laoreet nunc eu, semper magna. Curabitur eu lorem a enim sodales consequat. Vestibulum eros nunc, congue sed blandit in, maximus eu tellus.',
					),
					'wp_editor'		=> array(
						'title'			=> __( 'WP Editor', 'sample-domain' ),
						'type'			=> 'wp_editor',
						'value'			=> 'Pellentesque consectetur volutpat lectus, ac molestie lorem molestie nec. Vestibulum in auctor massa. Vivamus convallis nunc quis lacus maximus, non ultricies risus gravida. Praesent ac diam imperdiet, volutpat nisi sed, semper eros. In nec orci hendrerit, laoreet nunc eu, semper magna. Curabitur eu lorem a enim sodales consequat. Vestibulum eros nunc, congue sed blandit in, maximus eu tellus.',
					),
				),
			),
		),
	),
);
$option_page = new RationalOptionPages( $pages );

Retrieving Data

Each page stores it's fields in an entry in the database. The key is the array key for your page.

Using the example above as a reference:

// Get all options for the page
$options = get_option( 'sample-page', array() );

// Each field id is a key in the options array
$date = $options['date'];
$tel = $options['telephone'];

If you let the class generate the field IDs then they will be "slugified" versions of the title parameter. For example; a field with the title of "Website Address" will have an ID of "website_address". You can also see this key by inspecting the input and looking at the input's name attribute. Within the square ([]) brackets.

To Do

  • Add text and include parameters to pages.

rationaloptionpages's People

Contributors

jeremyhixon avatar jeremyhixonfw avatar logicalor avatar markhealy88 avatar ricotheque avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rationaloptionpages's Issues

Settings saved notice is not getting displayed

Hi,
I am trying to reproduce your demo code in the readme. I put it in the functions.php as it is without any modifications. It created the page with all fields. It can also save and put the values in the database. But it does not show a "settings saved notice". What could be the reason? Am I missing anything?

Thanks.

Disabling media buttons on wp_editor

Is there a way to pass parameters to wp_editor in the $pages array, for instance, to remove media buttons? I tried a few different things, but haven't had much luck. I also tried changing line 94 to:

'media_buttons' => false,

but the button is still there.

Creating Subpage called "Settings"

I really like this! I'm getting started with WordPress plugin development, and this has been really helpful. My issue may be unique and not a typical use case, but here is what I'm trying to accomplish:

  • Plugin Menu Name
    -- Settings
    -- Another Option

You can see that above I'm trying to create the initial page for my plugin. That page has all of my sections, fields, etc., set on it. I added a sub-page to the plugin, and it automatically made a sub-page above it that has the same name as the menu:

  • Plugin Menu Name
    -- Plugin Menu Name
    -- Another Option

What I would like to do is rename the first sub-page to be called "Settings." I've seen a lot of plugins do it this way, and I wanted to mimic that. The slug between "Settings" and "Plugin Menu Name" should be the same.

Is this possible?."

Translation ready

Hi,
I just had a nightmare dealing with localization, it turns out that even with :
php 'title' => __( 'Activate E-mail modification', 'text-domain' ),
the title is not translated.

Is that normal or i am doing something wrong ?

Thank you

Illegal characters

Hi!
Thank you for this useful tool.

Just wondering about an issue with non-latin characters using in page_title or field title.
Something connected to

iconv(): Detected an illegal character in input string in RationalOptionPages.php on line 621

How can i fix it or bypass if i want to use non-latin, cyrillic for example?

Thanks!

Textarea missing cols and wrap

That should be the fix for it.

Line 491

printf(
	'<textarea %s id="%s" name="%s" %s %s %s %s title="%s">%s</textarea>%s', <-----------
	!empty( $field['class'] ) ? "class='{$field['class']}'" : '', 
	$field['id'],
	"{$page_key}[{$field['id']}]",
	!empty( $field['placeholder'] ) ? "placeholder='{$field['placeholder']}'" : '',
	!empty( $field['rows'] ) ? "rows='{$field['rows']}'" : '',
	!empty( $field['cols'] ) ? "cols='{$field['cols']}'" : '', // cols       <-----------
	!empty( $field['wrap'] ) ? "wrap='{$field['wrap']}'" : '', // wrap     <-----------
	$field['title_attr'],
	$field['value'],	
	!empty( $field['text'] ) ? "<p class='help'>{$field['text']}</p>" : ''
);
break;```

wp_editor

wp editor does not work if it is called twice in a different section

'wp_editor_footer' => array(
                            'title' => __('WP Editor', 'sample-domain'),
                            'type' => 'wp_editor',
                            'value' => 'Pellentesque consectetur volutpat lectus, ac molestie lorem molestie nec. ',
                        ),

How to use callback?

Hello,
I'm having trouble to figure out how to use the callback. I already created a function, set 'custom' to true and set the 'callback' to the functions name. But, instead of running the function, the function's name is displayed as a notice message (below the page title).

This is the part of the code:

function awpha_bookmarks_test() {
	echo 'It works!';
}


$awpha_bookmarks_settings_page = array(
	'awpha_bookmarks_settings'	=> array(
		'parent_slug'	=> 'edit.php?post_type=awpha_bookmarks',
		'page_title'	=> __( 'Settings', 'awpha_bookmarks' ),
		'menu_slug '	=> 'awpha_bookmarks_settings',
		'sections'		=> array(
			//Setup
			'section-2'	=> array(
				'title'			=> __( 'Submit bookmark URL', 'awpha_bookmarks' ),
				'fields'		=> array(
					'frontend_url'		=> array(
						'id'			=> 'frontend_url',
						'title'			=> __( 'Frontend URL', 'awpha_bookmarks' ),
						'custom'		=> true,
						'callback'		=> 'awpha_bookmarks_test',
					),
				),
			),
		...extra code...

Load setting from other plugin

Hi,

Is it possible to load a settings field from an other plugin.
I like to "copy" the Google Analytics Tracking ID from the Perfmatters plugin into a own options page.

Select media

Hi,
is there a way to add a "select media" button to select a media from wordpress library and store the media url in the $options array?
Thanks

Text attribute for select

Thanks for a brilliant library!

Is there a particular reason why the select type doesn't support the text attribute?

I quick and dirty hack to make it work (but will probably fail any html validation):

@@ -472,6 +472,7 @@ class RationalOptionPages {
                                        $field_tag_name,                                                                                                                // name
                                        __($field['title_attr'],'text-domain')                                                                                                                          // title
                                );
+                $myLab = "";
                                foreach ( $field['choices'] as $value => $text ) {
                                        $selected = $value === $field['value'] ? 'selected' : '';
                                        if ( isset( $this->options[ $field['id'] ] ) ) {
@@ -488,8 +489,10 @@ class RationalOptionPages {
                                                $value,                                                                                                                                                         // value
                                                __($text,'text-domain')                                                                                                                                                         // text
                                        );
+                    if (!empty( $field['text'] ) ) { $myLab='<p class="help">'.__($field['text'],'text-domain').'</p>'; }
                                }
                                echo '</select>';
+                if (!empty($myLab) ) {echo $myLab;}
                                break;
                        case 'textarea':
                                printf(

This can produces an output like this with the text attribute places underneath the select box:
select_with_text

Keep text format using wp_editor

Hi, if I use 'type' => 'wp_editor' it works correctly but when I save, it lose all text formats (bold, italic etc..) and the page reloads without keeping text format.
How can I solve it?
And then, when I use it, is it enough to echo it?
Thanks

How to delete the option when uninstalling a plugin

Hi,

Thanks for providing this PHP Class. I find this easier to work with for creating fields on a settings page in a plugin.

If we take this sample code,

require_once('RationalOptionPages.php');
$pages = array(
	'sample-page'	=> array(
		'page_title'	=> __( 'Sample Page', 'sample-domain' ),
	),
);
$option_page = new RationalOptionPages( $pages );

how can I delete the option named sample-page from the database when the plugin is uninstalled/deleted?

function your_prefix_activate() {
	register_uninstall_hook( __FILE__, 'your_prefix_uninstall' );
}

// And here goes the uninstallation function:
function your_prefix_uninstall() {
	delete_post_meta_by_key( 'sample-page' );
}

is my current attempt but it doesn't seem to be working.

Any help is appreciated.

Getting page to appear in the 'Tools' menu

I add the 'parent_slug' option to the page array with the value 'tools' in the hope that it'll appear in the tools menu, however my page doesn't appear in Tools, but also doesn't appear anywhere else. Not sure what I'm doing wrong.

$pages = array(
	'footer-text'	=> array(
		'page_title'	=> __( 'Footer Text', 'footer-domain' ),
		'parent_slug'	=> 'tools',
		'icon_url'		=>	'dashicons-feedback',
		'sections'		=> array(
			'section-one'	=> array(
				'title'			=> __( 'Edit Footer Content', 'footer-domain' ),
				'fields'		=> array(
					'footer-left'		=> array(
						'title'			=> __( 'Left Content', 'footer-domain' ),
						'type'			=> 'wp_editor',
						'attributes'	=> Array('rows'=>10),
					),
					'footer-right'		=> array(
						'title'			=> __( 'Right Content', 'footer-domain' ),
						'type'			=> 'wp_editor',
						'attributes'	=> Array('rows'=>10),
					),
				),
			),
		),
	),
);

Won't Display Value

I've tried everything to get the value of the settings to display. I want to display the value on the front end via a page template, but nothing I'm doing works. Maybe I'm doing something wrong, can someone show me how they got theirs to work?

Class to <tr>

Hi, is there a way to add class to <tr> element?
I added 'class' => 'my_custom_class' under a single field array but it assign the class to the input element.
Thanks
Fosco

output not working

Notice: Undefined variable: tel

// Get all options for the page
$options = get_option( 'sample-page', array() );

// Each field id is a key in the options array
$date = $options['date'];
$tel = $options['telephone'];

echo $tel;

Select with multiple attribute not working

I tried to create a select field that allows the user to choose multiple entries.
The Input will not be saved and no option will be selected by default.

//...
'fields' => array(
  'test_field'    => array(
    'id'         => 'test_field',
    'title'      => 'Test Field',
    'type'       => 'select',
    'choices'    => array( 'a', 'b', 'c' ),
    'attributes' => array(
      'multiple'   => true,
    ),
  ),
//...

Everything works fine without 'multiple' => true.
Am I missing something here or is it a bug?

Issue with setting page with appearance menu.

Hi @jeremyHixon

I am pretty new to wordpress plugins and this tool just amazes the way it can create menus.
I wanted to create a page that is right above 'Appearance Menu'. I was using the Page Generator tool and the result for 2 different setting are same. The settings are as following

Setting1
Menu Option: Position-> Separator (Below Comment)

Setting2
Menu Option: Position-> Appearance

My question is isn't the setting1 supposed to display the new menu above the appearance tab?

I compare the codes for both settings and the difference is shown the image below
https://i.imgur.com/U3N1vR4.png

How to display this page (noob question)

I love and prefer the layout of this code, I want to use the samples you have provided but I have no idea how to call it.

I have created a menu item, and I have created a page but I have no idea how to use your RationalOptionsPages.php to output my array that I have made to show my options in the admin.

HTML in TextArea

I am trying to have users enter some HTML in two textarea blocks and when saving the HTML is being stripped out. How can I keep it in there?
Also...I can't seem to figure out how to set the cols and rows for the textarea. Would you happen to have an example?

Selectbox: Numeric choice values are not working

Thanks for providing this library :)

There seams to be a type mismatch if you define numeric values for your choice values.
PHP transfers them into int but in the values from get_option are always strings.

Example Configuration:

        'sample-page' => array(
            'page_title' => __('Sample Page', 'sample-domain'),
            'sections' => array(
                'sample-section' => array(
                    'title' => __('Section One', 'sample-domain'),
                    'fields' => array(
                        'select' => array(
                            'title' => __('Select', 'sample-domain'),
                            'type' => 'select',
                            'value' => 'option-two',
                            'choices' => array(
                                '0' => __('Nothing selected', 'sample-domain'),
                                '1' => __('Not working', 'sample-domain'),
                                'x' => __('Working', 'sample-domain'),
                            ),
                        ),
                    )
                )
            ),
        ),
    );

Try to select the "Not working" choice.

PHP Array:

    var_dump(array(
        '0' => __('Nothing selected', 'sample-domain'),
        '1' => __('Not working', 'sample-domain'),
        'x' => __('Working', 'sample-domain'),
    ));
array(3) {
--
  | [0]=>
  | string(16) "Nothing selected"
  | [1]=>
  | string(11) "Not working"
  | ["x"]=>
  | string(7) "Working"
  | }

get_option

var_dump(get_option('sample-page', array() ));

array(1) {
--
  | ["select"]=>
  | string(1) "1"
  | }

My use case is to save have a dropdown for all categories, I would like to save just the id of the selected category, but at the moment I have to add a string prefix to make it work

Range

Is there a way to display the value of the range slider so the user knows what they have selected in the option panel

WP_Editor No Data

When using wp_editor field, no data is saved and empty wp_editor is returned on page refresh.

Well this happens if we omit value attribute in the wp_editor array.
The solution I found was to include array value data as 'value' => '',
Can you update the code so that even if we don't include the value attribute, it get's automatically adds an empty value?

Unable to set default selected options in multiple select - Fix Provided

First of all - amazing work! Thank you so much!

Just working through a situation where I have a multi-select and I am unable to set default selected options. I've used it in the same way as you would on a standard select box and the settings screen loads fine, but just doesn't select anything.

So, I've fixed the issue and it turns out the default wasn't being set for a standard selects either. Here's the fix I implemented and I hope it's something you can test and add to your codebase?

//RationalOptionPages.php Line 475
// we need to add an extra 'else' statement inside the foreach loop for when the select DOESN'T have any options set - i.e it's not been updated yet. Whole revised foreach loop code below. Also removed the unnecessary '$selected' variable on Line 476

foreach ( $field['choices'] as $value => $text ) {

  if ( isset( $this->options[ $field['id'] ] ) ) {
      if (!is_array($this->options[ $field['id'] ] ) ) {
	      $selected = $value === $this->options[ $field['id'] ] ? 'selected="selected"' : '';
      } else 
      {
	      $selected = in_array( $value, $this->options[ $field['id'] ] ) ? 'selected="selected"' : '';
      }
  } else
  {
      if(is_array($field['value']))
      {
         $selected = (in_array($value, $field['value'])) ? 'selected="selected"' : '';
      } else
      {
	      $selected = $value === $field['value'] ? 'selected="selected"' : '';
      }
}
    printf('<option %s value="%s">%s</option>',
        $selected,																			// selected
        $value,																				// value
        __($text,'text-domain')                                                                                                                                 // text
    );
}

// end

'capability' allows access but not permission to change options

I have an options subpage setup under a custom post type page.

Changing 'capability' to 'editor' allows access to the page for Editors, but it doesn't allow Editors to save changes. Editors get the "Cheatin' uh?" message when attempting to save.

I've also tried using a custom capability in place of the role name. Same deal.

Is this a limitation of WP?
Might I be missing a setting in the array?

Here's what I've got:

$signersOptions = array(
     'signers-page' => array(
          'parent_slug' => 'edit.php?post_type=cpt_signers',
          'menu_title' => 'Options',
          'page_title' => 'Signers',
          'capability' => 'editor',
          'sections' => array(
               'signers_section1' => array(
                    'title' => 'Options',
                    'fields' => array(
                         'schools' => array(
                              'title' => 'Schools to include',
                              'id' => 'included_schools',
                              'type' => 'textarea',
                         )
                    )
               )
          )
     )
);

Checkbox settings field renderer doesn't account for multiple choices

https://github.com/jeremyHixon/RationalOptionPages/blob/master/RationalOptionPages.php#L401-L417

As it stands, when I pass a field like this:

'post-types'    => array(
    'title'     => __( 'Post Types', 'plugin-name' ),
    'type'      => 'checkbox',
    'choices'   => $post_types_choices,
  ),
),

... the $post_type_choices don't get rendered. Instead, I just get a single checkbox that will resolve the field to "on" rather than giving each choice it's own toggle. I'd expect it to work like this instead.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.