WordPress Settings API, Implementing Tabs On Custom Menu Page

Here is how I do it, beware, post is extensive. /* Add Menus —————————————————————–*/ add_action(‘admin_menu’, ‘ch_essentials_admin’); function ch_essentials_admin() { /* Base Menu */ add_menu_page( ‘Essentials Theme’, ‘Essentials Theme’, ‘manage_options’, ‘ch-essentials-options’, ‘ch_essentials_index’); } Now for my settings fields, extra fields removed, just as an example. This is for ‘Front Page Settings’ and ‘Front Page Tab’ add_action(‘admin_init’, … Read more

Add Option if Not Exists

The logic on the IF THEN ELSE does seem a bit wonky. If I’m reading it correctly… The call to get_option( $option_name ) will return FALSE if the option does not exist or if it has no value. So the IF would be executed: when the option doesn’t exist and $new_value != FALSE the option … Read more

Using get_option() in JavaScript

Define an array of parameters to be injected into the script: $script_params = array( ‘myWidth’ => get_option(‘my_width’) ); Localize the script via wp_localize_script: wp_localize_script( ‘your-script-handle’, ‘scriptParams’, $script_params ); scriptParams now is a js object you can access from within the script: alert( scriptParams.myWidth ); // the value from the PHP get_option call in the js

Options for CDN with WordPress Including Supporting Plugins?

Amazon CloudFront Amazon CloudFront is an CDN ‘wrapper’ around Amazon’s S3 service. Distributions can be created from existing S3 buckets, and when a file is requested from it’s CloudFront URL it is either served from the nearest edge locations’s cache or fetched from S3 and cached. Plugins My CDN – handles URL rewriting of JS, … Read more

Modifying a JS file with data from plugin settings

better is, you use the functions of WP for this, a example for multilanguage: add_action( ‘admin_enqueue_scripts’, ‘add_scripts’ ); function add_scripts($where) { wp_localize_script( ‘post2media’, ‘post2media_strings’, $this->localize_vars() ); } function localize_vars() { $strings = array( ‘btntext’ => __( ‘Link with post’, INPSYDE_P2M_TEXTDOMAIN ), ‘txtallnone’ => __( ‘Include in gallery:’, INPSYDE_P2M_TEXTDOMAIN ), ‘txtall’ => __( ‘All’, INPSYDE_P2M_TEXTDOMAIN ), … Read more

This CSS Stuffing Works, But Is This A Good Practice?

You can use wp_add_inline_style() to add to a stylesheet that you’ve already defined, such as in your plugin. This way an options screen or other user settings can affect the final style output. That could become very tedious, however, depending on how many changes you are giving the user the power over. However, it is … Read more

Limit the number of inactive widgets

Tested under v3.2.1: $sidebars = wp_get_sidebars_widgets(); if(count($sidebars[‘wp_inactive_widgets’]) > 10){ $new_inactive = array_slice($sidebars[‘wp_inactive_widgets’],-10,10); // remove the dead widget options $dead_inactive = array_slice($sidebars[‘wp_inactive_widgets’],0,count($sidebars[‘wp_inactive_widgets’])-10); foreach($dead_inactive as $dead){ $pos = strpos($dead,’-‘); $widget_name = substr($dead,0,$pos); $widget_number = substr($dead,$pos+1); $option = get_option(‘widget_’.$widget_name); unset($option[$widget_number]); update_option(‘widget_’.$widget_name,$option); } // save our new widget setup $sidebars[‘wp_inactive_widgets’] = $new_inactive; wp_set_sidebars_widgets($sidebars); } The above code limits the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)