Code Monkey home page Code Monkey logo

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

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

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

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.

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

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

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...

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.

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?."

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?

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),
					),
				),
			),
		),
	),
);

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?

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.

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;```

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?

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

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!

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 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.

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;

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

'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',
                         )
                    )
               )
          )
     )
);

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?

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.

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

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.

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

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.