Tag Info

Hot answers tagged

8

You are most likely to save the url of the image and not the whole image tag, and there is a great tutorial that explains just how to use the media uploader in your own theme or plugin: http://www.webmaster-source.com/2010/01/08/using-the-wordpress-uploader-in-your-plugin-or-theme/ update In case of using this in a meta box you will need the post id so ...


8

Why one should consider other ... options Frameworks like "Option Tree" (there're also several others) shouldn't be used anymore. The "Theme Customization API" is what you should use now, as it also adds the possibility of live editing a Theme in the Theme Customizer and binding the Theme options to the "Theme Modification API". The "Settings API", which ...


8

The answer that yes, the theme_mod functions will be slower, but not significantly, and the benefits outweigh the differences. Theme mods are stored as options. So, in essence, the theme_mod functions are wrappers around the options functions. First, understand that theme_mod settings are stored as an array in a single option, keyed to the specific theme ...


7

The page content for custom backgrounds is created in wp-admin/custom-background.php. There is no action available where the fields are printed. To add new fields we have to print JavaScript into the page footer. The action is 'admin_footer-appearance_page_custom-background'. To save those field values we have to hook into ...


6

Here is one way to do it by extending the control you want to use. Below is an example where we extend the text control and add an extra description like the one seen here on the screenshot: function mytheme_customizer( $wp_customize ) { class Custom_Text_Control extends WP_Customize_Control { public $type = 'customtext'; public ...


6

esc_html() and esc_textarea() are, appropriate to their names, escaping functions and really meant for display rather than sanitizing or validating. I would use wp_kses() or wp_kses_post() (which is just wp_kses() with the global $allowedposttags) to sanitize input from a wp_editor() field before saving.


5

You need to add a name attribute to your editors. The name attribute needs to be set to the value of of your option, so like this: function us_partners_cb() { $us_partners_desc = get_option( 'us_partners_desc' ); echo wp_editor( $us_partners_desc, 'uspartnersdesc', array('textarea_name' => 'us_partners_desc') ); }


5

I believe the underlying problem is that the option array keys don't exist yet. Let's start here, in your initialization function: if( false == get_option( 'thanathos_theme_display_options' ) ) { add_option( 'thanathos_theme_display_options' ); } First, this: false == get_option( 'thanathos_theme_display_options' ) ...should be this: false ...


5

Check if get_option returns a value and if it is not blank, then output the links. This should work for you: <?php if(get_option('to_facebook') && get_option('to_facebook') != '') { ?> <a href="<?php echo get_option('to_facebook'); ?>"></a> <?php } if(get_option('to_google_plus') && ...


5

stripslashes(wp_filter_post_kses(addslashes($_POST['sidebar_code']))); but you should know that the kses filter is not 100% safe.


5

see: http://clark-technet.com/2010/12/wordpress-self-hosted-plugin-update-api Basically the idea is to hook your update checking function to the pre_set_site_transient_update_themes filter. The version array key you return from this function will be compared by WP to the current theme version from style.css.... Use the admin_notices action to make your ...


5

Yep you are missing something, On your validate_options function you need to: get an array of all existing options. update only the options your Submenu page handles. return that array. So something like: function validate_options($input){ //do regular validation stuff //... //... //get all options $options = get_option(THEMENAME . ...


5

The problem is they are getting saved... it's just you're always saving the defaults! $ev_options = ev_theme_settings_defaults(); if ( false === $ev_options ) { $ev_options = ev_theme_settings_defaults(); } update_option( 'theme_evolutionary_options', $ev_options ); And that's running on every page load (it's hooked to the action after_theme_setup). ...


5

wp_add_inline_style() is intended to add additional CSS to an existing stylesheet. The idea is that you may need to dynamically alter the stylesheet - for instance, you have user-selected colours associated with categories and you would like to colour each category's title accordingly. You can't hardcode this since the colours in question are not known, but ...


5

First, change your code into the following: $value = get_option( 'mytheme_value' ); query_posts ( "meta_key=post_views_count&orderby=meta_value_num&order=DESC&meta_value={$value}"); When you use single quotation marks, php isn't parsed in the string, and functions (like get_option) will never be called from within a string. Therefore, call the ...


4

Regardless of the platform (WordPress, Joomla!, Drupal) or the language (PHP, C++, VB) it's pretty much accepted/standard practice to break out code in to functional units. This includes not only functions and classes, but files as well. As @Toscho points out: The code is used in multiple places. It improves readability. It also makes it easier to: ...


4

You need to use wp_localize_script to pass PHP variables to your javascript. In your javascript file you can reference the variable as such: myCustomVariable.fadeOption Then in your options panel you can assign $_POST['fade_option'] to myCustomVariable.fadeOption: function load_fade_option(){ wp_enqueue_script('slider', 'slider.js', array( 'jquery' ...


4

I think the problem is that you are using uppercase letters in the options id: footer-nav1_URL Try instead: footer-nav1_url In general you should avoid using uppercase letters in options names in WordPress.


4

If you look at Mystique theme (a great example of option panel with preview BTW) you can see that the main idea is to lavrage the form fields OnChange or change() events to load the theme's preview with Jquery and a bit of ajax. So you have one function to load by ajax the preview function mystique_get_site_preview() { check_ajax_referer("site_preview"); ...


4

Takea look at framework for plugin/theme options panel? and WordPress frameworks and parent themes which both together list a very large number of frameworks and themes to use with there pros and cons.


4

More importantly, you should not let *untrusted, unsanitized $_POST data* into WordPress. But I think the issue is that you're updating the option with the entire $_POST data, instead of the appropriate array key: update_option('eirepanel_inline_ads_options', $_POST); Should probably be something like: update_option('eirepanel_inline_ads_options', ...


4

It makes sense that if it's faster to use a new table for a thousand entries, it must also be faster for tens or hundreds of entries. Performance is not about the pure number rows – the real amount of data and their structure counts. Usually, you use just the theme mod API. Your theme data is on a predictable place and can easily exported or changed by ...


4

If you add tracking code to a theme file you will need to do this on every theme change. It is considered good practice to use plugin for this, like Google Analytics for WordPress. It will use common hooks (that every theme worth using has) to insert code and that way you don't need to think about that when changing.


4

The TinyMCE has an Filter for all allowed tags. You can change the tags, there are set in standard for your options and the editor fitler the tags. Its not necassary, that you filter after save. Example for enhanced tags: function fb_change_mce_options( $initArray ) { // Comma separated string od extendes tags // Command separated string of ...


3

As @Ashfame as already pointed out, you shouldn't store defaults in the database - that should be for user selected options (of course, if they select the defaults, then fine - store them :). However, you don't need to use wp_parse_args() either. get_option allows you to select a default value. For instance: //If nuod_logo is not found, uses 'newlogo.pnp' ...


3

Just wrap you code up in a conditional: if ( $GLOBALS['is_iphone'] ) { // do funky stuff for mini screens } global $is_iphone; will trigger TRUE for all mobile devices incl. tablets. Edit for WP 3.4+ Now there's wp_is_mobile() to make checks for User-Agent. It's basically a wrapper for $is_iphone and does the same.


3

Your error is not an error at all Warning: Illegal string offset 'show_header' in C:\xampp\htdocs\wordpress\wp-content\themes\01MyWork\includes\theme-options.php on line 62 A warning is not an error, an error would halt PHP execution, a warning does not ( though sometimes it can if its outputted before headers ). This error is caused by accessing ...


3

I had the same problem a few minutes ago. Here is what I used in the src tag: <?php if (get_theme_mod( 'custom_logo_image' )) : echo get_theme_mod( 'custom_logo_image'); else: echo get_template_directory_uri().'/inc/images/default_logo.png'; endif; ?> It seemed to solve my problem. Let me know if it works for you.


3

I would strongly recommend following the Theme Review guidelines for Theme Settings and Data Security. (If you intend for your Theme to be hosted in the WPORG repository, you will be required to follow these guidelines. Here's a brief summary: Themes are required to prefix all options, custom functions, custom variables, and custom constants with ...



Only top voted, non community-wiki answers of a minimum length are eligible