Thread Rating:
  • 2 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Theme Settings
#1
I created a generic theme settings plugin which makes it very easy to provide configurable themes.

Theme Settings version 0.1:
  • Just provide a short PHP settings.php with the configuration input fields, and
  • Replace references to these settings in your template file(s) with get_theme_setting('nameOfSetting', 'defaultValue').
  • The schema support allows you to easily define multiple settings in *.properties files and enables the user to switch multiple settings at once.
  • Using the LESS plugin it is also easy to make your CSS files configurable.

Version 0.4:

  • It now supports the I18N plugin for multilanguage sites: just add class "i18n" to input fields in settings.php to mark fields that might have different values in different languages.

An example theme can be found here.

For more information and usage instructions see http://mvlcek.bplaced.net/get-simple/theme-settings.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#2
That was fast
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#3
Impressive.

Just a couple issues with the demo theme:
- it requires the I18N plugin (directly calls get_i18n_component in <title>)
- if you leave the Tag Line field empty or enter something like "..." (without quotes) the site is broken (Less fatal error)
Reply
#4
(2014-07-12, 17:32:34)Carlos Wrote: Impressive.

Just a couple issues with the demo theme:
- it requires the I18N plugin (directly calls get_i18n_component in <title>)
- if you leave the Tag Line field empty or enter something like "..." (without quotes) the site is broken (Less fatal error)

Thank you for testing. I updated the theme and both the Theme Settings and the LESS plugin to avoid these errors.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#5
thanks for plugin and theme with tips
Reply
#6
Very useful !!
can give a lot of power to the theme now, getting closer to the way it's done in Wordpress

A few feature requests if I may ...

1. wysiwyg support for textareas fields
2. photo/files fields support , for easily attaching images to theme (logos, backgrounds, sliders, etc').
3. dedicated data dir ( other/ThemeSettings/.... ) for keeping data tidy in case of multiple themes.
Reply
#7
Actually, here is the code for an image picker field (should be in settings.php) :

PHP Code:
<p><label for="sitelogo" >Logo</label>
<
input id="sitelogo" name="sitelogo" class="text" value="<?php get_theme_setting('sitelogo'); ?>" type="url" onClick='window.open("../admin/filebrowser.php?CKEditorFuncNum=1&returnid=sitelogo&type=images","mywindow","width=600,height=500")' /></p

Clicking inside the field opens a new win to choose an image ...
Reply
#8
O.k. ...
Here is an easy solution for wysiwyg powered fields :

1. Add the attached ckeditor.php file to the plugin directory ( IE: plugins/theme_settings/ckeditor.php )

2. Add the code below into the settings.php of your theme for your wysiwyg powered textarea (for a field I called "democontent"):

Code:
<div>
  <p>
    <label for="democontent">תוכן נסיוני:</label>
    <textarea class="wysiwygedit" name="democontent" id="democontent" style="width:90%; height?:50px;"><?php get_theme_setting('democontent', $default='', $isHtml=true); ?></textarea>
  </p>
</div>

3. Add this line to the end of your setting.php :

Code:
<?php include(GSPLUGINPATH . 'theme_settings/ckeditor.php'); ?>


Attached Files
.php   ckeditor.php (Size: 3.06 KB / Downloads: 16)
Reply
#9
image editor does not add
[code]<img alt=\"\" src=\"http://mydomen/data/thumbs/thumbnail.a75800734.jpg\" style=\"width: 200px; height: 143px;\" />[code]
Reply
#10
(2014-07-15, 23:13:45)Oleg06 Wrote: image editor does not add ...

@Oleg06
If you asked me about the image field - it only return the url of the image
in the template.php you should simply call it :

Code:
<img src="<?php get_theme_setting('sitelogo', '', true); ?>" alt="">
Reply
#11
that is, you need to remove the unnecessary buttons from the editor Smile
Reply
#12
(2014-07-15, 23:34:09)Oleg06 Wrote: that is, you need to remove the unnecessary buttons from the editor Smile

I was referring to the "image picker field" , not to the wysiwyg textarea.

My wysiwyg is not acting as you described, it embed photos just fine .... weird ...
It's embedded @ my template.php like this:
Code:
<?php get_theme_setting('democontent', '', true); ?>

But - if mvlcek will include it in the plugin, he'll probably take a look
I don't like to add things to someone else new plugins :-) ... those are just a quick suggestions ....
Reply
#13
this happens when the site is installed in the folder
Reply
#14
HTML data is not saved as HTML (CData) in the data file.
which makes a lot of problems.
Reply
#15
Theme Settings version 0.3:
  • correctly saves HTML to the settings file (@Tzvook thanks for testing)
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#16
(2014-07-30, 02:49:59)mvlcek Wrote: Theme Settings version 0.3:
  • correctly saves HTML to the settings file (@Tzvook thanks for testing)

Why not changing line 45 to
PHP Code:
$data->addChild($key)->addCData($value); 

Seems it's working fine, though you probably know better :-) ????
Reply
#17
(2014-07-30, 02:49:59)mvlcek Wrote: Theme Settings version 0.3:
  • correctly saves HTML to the settings file (@Tzvook thanks for testing)

mvlcek ???
is my fix ok ?
Reply
#18
(2014-07-30, 03:04:02)Tzvook Wrote:
(2014-07-30, 02:49:59)mvlcek Wrote: Theme Settings version 0.3:
  • correctly saves HTML to the settings file (@Tzvook thanks for testing)

Why not changing line 45 to
PHP Code:
$data->addChild($key)->addCData($value); 

Seems it's working fine, though you probably know better :-) ????

Of course this works, too. I just don't like to use CData for everything ;-)
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#19
is it possible to add checkboxes and radio buttons in the settings
Reply
#20
(2015-04-08, 19:58:34)Oleg06 Wrote: is it possible to add checkboxes and radio buttons in the settings

Should be possible. But if a checkbox is not checked no value will be saved, so you should make sure to use a default value in get/return_theme_setting.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#21
Great idea for a plugin! But question/suggestion:
Is it possible to skip the schema? I'd like to offer the user to choose ANY color they want, rather than my small list of color combinations. Example: I'd use @backgroundColor in LESS, and then have a text input field in settings.php that allows user to enter in any 6-digit hex number for it that they wish. They could get that hex number from one of many online color choosing tools. (Although, even better, a color chooser could be incorporated into the settings.php??).

But what function/code would I need to create that text input field in settings.php to allow user to enter a color hex number?

Thanks.
Reply
#22
(2015-12-31, 16:31:18)Arugula Wrote: Great idea for a plugin!  But question/suggestion:
     Is it possible to skip the schema? I'd like to offer the user to choose ANY color they want, rather than my small list of color combinations.   Example:  I'd use @backgroundColor in LESS, and then have a text input field in settings.php that allows user to enter in any 6-digit hex number for it that they wish.  They could get that hex number from one of many online color choosing tools.   (Although, even better, a color chooser could be incorporated into the settings.php??).

But what function/code would I need to create that text input field in settings.php to allow user to enter a color hex number?

You can specify any fields in the settings.php.
To combine extra fields specified in settings.php, but not in the *.properties (e.g. provide a template, but let the user specify the link color), use something like this:

Code:
<?php
$additional = array('f1' => return_theme_setting('f1'), 'f2' => return_theme_setting('f2'));
get_less_css('default.less', return_theme_settings($additional));
?>

If you don't have schemas, remove the schema select from settings.php and make sure you have a empty default.properties.

You could then also create the css like this (but the above code would still work):

Code:
<?php
$additional = array('f1' => return_theme_setting('f1'), 'f2' => return_theme_setting('f2'));
get_less_css('default.less', $additional);
?>
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#23
Thank you! that was quick. I didn't fully understand your directions at first, but I played around with your code and got it working!

One problem though: on the settings page, when user presses the 'Save Settings' button, the data he'd put in the entry fields disappears. It IS sent to LESS/css, because the edit changes show correctly on the pages. But I'd really like the 'current value' for each of those fields to show in the boxes, even when the user logs back in weeks later, so he or I can see the current value, before attempting to change it.

Is there a change in the code, or new functions that could be made, that would allow us to get/see the 'current existing value' for each of these fields? (So when logging in you'd see: 'Background Color: #D3BD29' or some such. )
Thanks so much for your time!
Reply
#24
(2016-01-01, 10:23:45)Arugula Wrote: One problem though:   on the settings page, when user presses the 'Save Settings' button, the data he'd put in the entry fields disappears.   It IS sent to LESS/css, because the edit changes show correctly on the pages.   But I'd really like the 'current value' for each of those fields to show in the boxes, even when the user logs back in weeks later, so he or I can see the current value, before attempting to change it. 

Did you include the value="<?php get_theme_setting('fieldname'); ?>" in your input tag (as shown in the example on http://mvlcek.bplaced.net/get-simple/theme-settings)?
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply
#25
OK, that worked! I was using the return_theme_setting before. But the change worked. Thanks again so much!
Reply




Users browsing this thread: 1 Guest(s)