php – Custom Plugin scripts from admin working in frontend

Question

I am developing a custom plugin and I am pretty much done with it, my only problem right now is taking data from a script that is enqueued both in the Admin and frontend but it does not work as I thought it would.
So, I have created a couple of checkboxes in the admin panel of the plugin and I want when someone clicks one of the checkboxes to change CSS from a div to make it look like the example image above the checkbox.

my code:

function vsuc_page_html() { ?>
<div class="wrap vsuc-wrapper">
    <form method="post" action="options.php">
        <?php settings_errors() ?>
        <?php settings_fields('vsuc_option_group'); ?>
  <?php echo '<h3 class="header_admin">Viorel Stanciu User Counter Plugin</h3>'; ?>
        <label class="label_text" for="vsuc_field_eat">Text Label:</label>
        <input name="vsuc_text_field" id="vsuc_field_eat" type="text" value=" <?php echo get_option('vsuc_text_field'); ?> "><br>
    <input type="checkbox" id="vsuc_checkbox1" name="vsuc_checkbox1" value="style1">
    <label for="checkbox1"><img src="<?php echo plugin_dir_url( __FILE__ ); ?>/img/style1.PNG" class="style1"></label>
    <input type="checkbox" id="checkbox2" name="vsuc_checkbox2" value="style2">
    <label for="checkbox2"><img src="<?php echo plugin_dir_url( __FILE__ ); ?>/img/style2.png" class="style1"></label>
        <?php echo '<p class="shortcode"> Insert this shortcode where you want to display the plugin: [pagehits]';
     submit_button(); ?>
    </form>
</div>

function vsuc_register_settings() {
    register_setting('vsuc_option_group', 'vsuc_text_field');
    register_setting('vsuc_option_group', 'vsuc_checkbox1');
}

The checkboxes appear correctly, but they are not doing anything.

Test script:

$(document).ready(function () {
    $('#checkbox1').change(function () {
        var x = document.getElementsByClassName("visitor_count");
        if (this.checked) {
            x.style.display = "none !important";
        } else {
            x.style.display = "block !important";
        }
    })
});

Any help or hint would be much appreciated.

0
Urus221 10 months 2022-08-23T05:19:10-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse