• This plugin is using echo within the wp_enqueue_scripts function in the code below found in the modules/enqueue/plus-generator.php file:

    public function load_inline_script(){
        $js_inline1 = 'var theplus_ajax_url = "'.admin_url("admin-ajax.php").'";
        var theplus_ajax_post_url = "'.admin_url("admin-post.php").'";
        var theplus_nonce = "'.wp_create_nonce("theplus-addons").'";';
        echo wp_print_inline_script_tag($js_inline1);  
    }

    This is creating an issue with the default wp-sitemap.xml (as it’s being outputted there). The wp_enqueue_script function isn’t actually designed for echoing output to and should be for enqueuing scripts and styles.

    In the code above the wp_print_inline_script_tag function is actually a filter, and likely added mistakenly instead of wp_add_inline_script.

    Can this please be changed to follow the intended use of wp_enqueue_scripts to enqueue that inline script to help prevent issues with the echoing of that code prematurely?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Divyang Chaudhary

    (@divyangposimyth)

    Hello @antonynz
    This is Divyang from The Plus Addons team.

    Thank you for bringing this to our attention.
    I would like to inform you that our team is working on new dashboard and will address all such issues in that.

    This update will be included in the upcoming release of The Plus Addons. I kindly ask for your patience.

    In the meantime, please let us know if you have any concerns.

    Best Regards.

    Plugin Support Divyang Chaudhary

    (@divyangposimyth)

    Hello @antonynz
    Thank you for your patience.

    Our team has fixed the issues and released a new version 6.0.8. Can you please check and confirm the same?

    Looking forward to your response.

    Best Regards.

    Thread Starter Antony Booker

    (@antonynz)

    I wasn’t able to replicate the sitemap issue. However the function and that file is the same from what I can see? As it’s called within wp_enqueue_scripts it might have unexpected problems and conflicts.

    The two issues are:
    1. content echo’d in wp_enqueue_scripts
    2. wp_print_inline_script_tag used incorrectly with an “echo” in front

    Something like this would be more suitable if you are wanting to output javascript variables to the page when loading a javascript file:

    public function load_inline_script() {
    $script_handle = 'your-main-script-handle'; // Replace with the handle of your enqueued script

    $js_inline = '
    var theplus_ajax_url = "' . admin_url("admin-ajax.php") . '";
    var theplus_ajax_post_url = "' . admin_url("admin-post.php") . '";
    var theplus_nonce = "' . wp_create_nonce("theplus-addons") . '";
    ';

    wp_add_inline_script($script_handle, $js_inline);
    }

    Or if only the inline script is needed the script could be loaded using the wp_head action:

    public function load_inline_script() {
    add_action('wp_head', function() {
    ?>
    <script type="text/javascript">
    var theplus_ajax_url = "<?php echo esc_url(admin_url('admin-ajax.php')); ?>";
    var theplus_ajax_post_url = "<?php echo esc_url(admin_url('admin-post.php')); ?>";
    var theplus_nonce = "<?php echo esc_js(wp_create_nonce('theplus-addons')); ?>";
    </script>
    <?php
    });
    }

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘echo used in wp_enqueue_scripts’ is closed to new replies.