Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Evan Fraser
Evan Fraser
6,789 Points

Auto wordpress core and plugin updates function not working

I have 3 checkboxes here that when checked are disabling XMLRPC, WP core auto updates and WP plugin auto updates. im not even sure if they are working based on what I wrote and have been trying to figure it out too long and am now confused lol. Just wondering if you can help me determine if this is properly activating the filters:

Here is a screenshot of the theme options: https://i.stack.imgur.com/rWIfo.png

<?php if(!defined('ABSPATH')){ exit(); }
/**
 * Hawp theme security tab
 *
 * @package hawptheme
 */

/**
 * Security checkbox options.
 */
function disable_wordpress_data_options(){

    // Assign settings to variable
    $hawp_disable_xmlrpc      = get_option('hawp_disable_xmlrpc');
    $hawp_auto_update_core    = get_option('hawp_auto_update_core');
    $hawp_auto_update_plugins = get_option('hawp_auto_update_plugins');

    // The box checked (red) equals 'disabled', unchecked (green) equals enabled
    if( $hawp_disable_xmlrpc     === 'disabled' ) { add_filter( 'xmlrpc_enabled', '__return_false' ); }
    if( $hawp_auto_update_core    != 'disabled' ) { add_filter( 'auto_update_core', '__return_true' ); }
    if( $hawp_auto_update_plugins != 'disabled' ) { add_filter( 'auto_update_plugin', '__return_true' ); }
}
add_action('admin_init', 'disable_wordpress_data_options', 999);
?>
<form action="options.php" name="MyForm" id="getProduct" method="post">
    <?php settings_fields('hawp_security'); ?>

    <div class="hawp-container dark-container">
        <h3><span class="dashicons dashicons-lock"></span> Core Options</h3>
        <table>
            <tbody>
                <tr>
                    <td>
                        <?php $hawp_disable_xmlrpc = get_option('hawp_disable_xmlrpc'); ?>
                        <p>XML-RPC <label class="switch"><input type="checkbox" id="hawp_disable_xmlrpc" name="hawp_disable_xmlrpc" <?php checked( $hawp_disable_xmlrpc, 'disabled' ); ?> value="disabled"><span class="slider round"><?php $toggle_msg ?></span></label></p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <?php $hawp_auto_update_core = get_option('hawp_auto_update_core'); ?>
                        <p>Auto Update Core <label class="switch"><input type="checkbox" id="hawp_auto_update_core" name="hawp_auto_update_core" <?php checked( $hawp_auto_update_core, 'disabled' ); ?> value="disabled"><span class="slider round"><?php $toggle_msg ?></span></label></p>
                    </td>
                </tr>
                <tr>
                    <td>
                        <?php $hawp_auto_update_plugins = get_option('hawp_auto_update_plugins'); ?>
                        <p>Auto Update Plugins <label class="switch"><input type="checkbox" id="hawp_auto_update_plugins" name="hawp_auto_update_plugins" <?php checked( $hawp_auto_update_plugins, 'disabled' ); ?> value="disabled"><span class="slider round"><?php $toggle_msg ?></span></label></p>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>

    <input type="submit" class="button-primary" value="Save Security Settings" />
</form>