Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Can you please let me know how I can set a function to update change the style like any CSS class from the setting option page? For example I have some <P> elements with a class name .impo. Now, I would like to change the color of the class to red when the checkbox has been checked and to default color when un-checked.

What I have is:

<?php
 add_action('admin_menu', 'fwds_plugin_settings');
 function fwds_plugin_settings() {
 add_menu_page('Price Display', 'Price Display', 'administrator', 'fwds_settings', 'fwds_display_settings');
 }
function fwds_display_settings() {
$html = '<div class="wrap"><form action="options.php" method="post" name="options">
    <h2>Change The .impo Colors</h2>
    ' . wp_nonce_field('update-options') . '
  <p>
<table>
 <tr>
 <td>Change Color To Red </td>
 <td><input type="checkbox" name="fwds_autoplay" value="enabled" /></td>
 </tr>
</table>
<br />
<input type="submit" name="Submit" value="Update" /></form></div>';
echo $html;
}
share|improve this question

1 Answer 1

I think you have to solve this with jQuery. If checked -> addClass, if not -> removeClass.

Here's how to enqueue your JS file:

add_action('admin_menu', 'fwds_plugin_settings');

function fwds_plugin_settings() {
    $hook = add_menu_page(
        'Price Display', 
        'Price Display', 
        'add_users', 
        'fwds_settings', 
        'fwds_display_settings'
    );
    add_action( "admin_print_scripts-$hook", 'fwds_print_scripts' );
}
function fwds_print_scripts()
{
    wp_register_script( 
         'my-fx' 
        , plugin_dir_url( __FILE__ ) . '/my-fx.js'
        , array( 'jquery' ) // Dependencies
    );

    wp_enqueue_script( 'my-fx' );
}

And my-fx.js:

jQuery(document).ready(function($) 
{   
    alert('my page');
});             
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.