Save Theme Options (options.php) From The Frontend

You Do Not want to post /wp-admin/options.php from the front end , thats a bad idea and can cause problems. To updated Options from the frontend simply use update_option() and make sure you verify correctly. here is an example using your code with minor fixes: <?php if (isset($_POST[‘stylesheet’]) && isset($_POST[‘action’]) && $_POST[‘action’] == “update_theme”){ if … Read more

Serialized settings in rest api

JSON Schema It’s supported if you explicitly register the object JSON schema as: $args = array( ‘show_in_rest’ => array( ‘schema’ => array( ‘type’ => ‘object’, ‘properties’ => array( ‘post’ => array( ‘type’ => ‘string’, ), ‘blog’ => array( ‘type’ => ‘string’, ), ) ), ), ); register_setting( ‘default_sidebars’, ‘default_sidebars’, $args ); Resulting in the following … Read more

Define WordPress image size in img tag

How about PHP Function getimagesize() <? $sImageurl = of_get_option(‘slideshow_1’); list($iWidthinpx, $iHeightinpx) = getimagesize($sImageurl); echo ‘<img src=”‘ . $sImageurl . ‘” width=”‘ . $iWidthinpx. ‘” height=”‘ . $iHeightinpx. ‘” alt=”#”/>’; ?> or if you know the attachment id instead of the attachment url you could use <? $aImagedata = wp_get_attachment_image_src($iAttachmentid, ‘my-image-size’, false); list($sImageurl, $iWidthinpx, $iHeightinpx) = … Read more

How to Save Different Settings Options Using Settings API and/or the Theme Optimizer

I did something similar as an import/export facility. Essentially I created a Theme Options Import/Export page in the dashboard, then just export the theme options (using get_option()) to a file as a JSON encoded string and post it for the user to download. Then give them an upload facility the imports said file (using update_option()). … Read more

Why isn’t get_option array contents displaying?

Let’s look at your code. Your first code block is treating an array like an object so your second attempt is closer to accurate: $the_contents=get_option(‘slider_contents’); // var_dump($the_content); foreach ($the_contents as $content) { $content1=stripslashes($content[‘content’]); $content2=stripslashes($content[‘content2’]); Assuming you did what I suggested and placed the var_dump where I have in that code block, then what is happening … Read more

Setting ‘autoload’ to ‘no’ with Settings API

The only way to accomplish this is to add the option to the database yourself before the Settings API does so. To do this, add a ‘sanitize_callback’ to the register_settings function: register_setting (‘my_options’, ‘my_option_name’, array (‘type’ => ‘string’, ‘sanitize_callback’ => ‘my_function_name’)); Then, in your function, update the option yourself: function my_function_name ($value) { update_option (‘my_option_name’, … Read more

Set a Default Value for an Option?

There isn’t anything clever that I can see. I’ve used two approaches in the past: 1 – Your plugin’s activation code could save all your default options, so that you never need to use the second parameter to get_option Really, this equates to your… default value for setting that have not yet been saved. 2 … Read more

How much string content can I store in an option?

Look at the table schema in wp-admin/includes/schema.php: // regular blog tables CREATE TABLE $wpdb->options ( option_id bigint(20) unsigned NOT NULL auto_increment, option_name varchar(64) NOT NULL default ”, option_value longtext NOT NULL, autoload varchar(20) NOT NULL default ‘yes’, PRIMARY KEY (option_id), UNIQUE KEY option_name (option_name) ) $charset_collate; // Multisite options CREATE TABLE $wpdb->sitemeta ( meta_id bigint(20) … Read more

Add_settings_field() parameterizing callback?

The last optional $args argument the you can pass to add_settings_fields() is passed to callback. So it seems you can use same callback just fine. Hope I am right because I just stumbled onto this two minutes ago because of discussion in chat. 🙂 PS looked through code and it’s indeed relatively recent, before ~2.9 … Read more

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