Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

set_theme_mod() outside of the Customizer WordPress

  • SOLVED

Please can someone re-write the below function so a new theme_mod value is set when my form is submitted. A 'Success' confirmation message should be displayed when the form/values have been updated. Data should be sanitized before being saved to the database.

function create_custom_css_page() {
$content = get_theme_mod('custom_theme_css', '');
?>
<div class="wrap">
<h2><?php _e('Custom CSS', 'mytheme'); ?></h2>
<form name="custom-css-form" action="?????" method="post" enctype="multipart/form-data">
<textarea name="new_css_content" id="new_css_content" ><?php echo esc_html( $content ); ?></textarea>
<?php submit_button( __('Update CSS', 'mytheme'), 'primary', 'submit', true ); ?>
</form>
</div>
<?php
$new_content = set_theme_mod('custom_theme_css', $new_css_content);
}


Basically I'm attempting to re-work the [[LINK href="https://wordpress.org/plugins/simple-custom-css/"]]Simple Custom CSS plugin[[/LINK]] so CSS changes are saved against a theme rather than as a single option.

Thank you

Answers (3)

2014-12-23

Dbranes answers:

Hi @designbuildtest

Here's one idea how you could modify your own copy of the SCCSS plugin:

In the <em>admin.php</em> file:

<strong>1)</strong> Replace

register_setting( 'sccss_settings_group', 'sccss_settings' );


with:

register_setting( 'sccss_settings_group', 'sccss_settings', 'sccss_settings_sanitize' );

<strong>2)</strong> Replace:

$options = get_option( 'sccss_settings' );


with

$options = get_theme_mod('wpq_css', '');


in the <em>sccss_render_submenu_page()</em> function.

<strong>3)</strong> Add this function:

function sccss_settings_sanitize( $input ) {
set_theme_mod( 'wpq_css', $input );
return $input;
}



I hope you can modify this further to your needs.


designbuildtest comments:

Perfect, many thanks Dbranes.
I made some minor tweaks to your suggestions, merged with my existing plugin code and everything is now working as planned.
Much appreciated.

2014-12-22

Arnav Joy answers:

can you describe more about what you want ?


designbuildtest comments:

Hi Arnav, rather than using the Settings API to store a single block of custom CSS (via get_option) , I want to store and retrieve a block of custom CSS against each theme (via get/set_theme_mod).

2014-12-22

Firoja_Imtosupport answers:

Hi,

You can refer to http://oik-plugins.eu/buddypress-a2z/oik_api/set_theme_mod/, If you still dont have solution let me know and i can write for you.

Thanks