• Resolved Josh

    (@josh401)


    Hey there,

    I was developing a new plugin for a client; when I noticed my admin styles were not appearing properly on the admin page I created.

    Upon further investigation… I found your jQuery styles are being enqueued on all admin pages.

    Specifically, it originates from this block:

    function addHeaderCode() {
                wp_enqueue_script('jquery-ui-core');
                wp_enqueue_script('jquery-ui-tabs');
                if (@!class_exists('AGCA')) {
                    wp_enqueue_script('wpscstniceditor', plugins_url('/js/nicedit/nicEdit.js', __FILE__), array('jquery'), '1.3.2');
                }
                wp_enqueue_style('plugin_name-admin-ui-css', plugins_url('/css/custom-theme/jquery-ui-1.10.3.custom.css', __FILE__), false, 2, false);
            }

    Which references back to this block of code:

    add_action("admin_print_scripts-$newTicketPage", array(&$wpscSupportTickets, 'addHeaderCode'));
    add_action("admin_print_scripts-$editPage", array(&$wpscSupportTickets, 'addHeaderCode'));
    if(@function_exists('wpscSupportTicketDepartments')) { // For wpsc Support Tickets v5.0+
        add_action("admin_print_scripts-$departmentsPage", array(&$wpscSupportTickets, 'addHeaderCode'));
    }
    add_action("admin_print_scripts-$statsPage", array(&$wpscSupportTickets, $statsHeaderCode));
                add_action("admin_print_scripts-$settingsPage", array(&$wpscSupportTickets, 'addHeaderCode'));
                add_action("admin_print_scripts-$fieldsPage", array(&$wpscSupportTickets, 'addFieldsHeaderCode'));

    I do see where you are attempting to run the scripts only on the needed pages… but your approach is apparently not working properly.

    I think instead of doing it like this:

    add_action("admin_print_scripts-$newTicketPage", array(&$wpscSupportTickets, 'addHeaderCode'));

    … it would work if you did it like this:

    add_action("admin_print_scripts-".$newTicketPage, array(&$wpscSupportTickets, 'addHeaderCode'));

    You’ve done everything perfectly when adding the menu and submenu pages (by setting them to a variable). I think if you changed the code as mentioned above; it would make everything work exactly as you intended.

    Thanks for looking into this.

    https://wordpress.org/plugins/wpsc-support-tickets/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author jquindlen

    (@jquindlen)

    Thanks for pointing this bug out. You are correct that the admin styles appear to be loading on all admin pages. I also appreciate your suggestion for a solution, however functionally these two lines of code do the exact same thing:

    add_action("admin_print_scripts-$newTicketPage", array(&$wpscSupportTickets, 'addHeaderCode'));

    add_action("admin_print_scripts-".$newTicketPage, array(&$wpscSupportTickets, 'addHeaderCode'));

    That is because when you use double quotes you can directly use variables inside of strings. Just to be on the safe side, I tried your code suggestion anyway, with no luck. However, I did find a solution which works, and the patch is in 4.8.8 which will be out very soon.

    Thanks again!

    Thread Starter Josh

    (@josh401)

    Excellent. Thanks for the quick response. I’ll let them know.

    Yeah, I didn’t test the code first.. sorry. But, I didn’t know the double quote thing. Thanks for the lesson.

    However… I use the exact same method for some of my plugins… and it does work. At least, I think it does. Perhaps I need to go back and check again…

    I may have to test your plugin; out of curiosity 😉
    Did you empty the cache after making the change?
    Screw it… I’m going to go test it 🙂

    Regardless, thanks for the prompt attention.

    EDIT:
    Yeah.. that didn’t make a change.
    But, I checked my plugins, and it does work properly.

    Yours seems to be stemming from line #2133. Commenting that line out restored the styles to my other admin page.
    I can’t quite figure out what you are doing there… but… You know your plugin much better than I… so I trust you 🙂

    Thanks again.

    Plugin Author jquindlen

    (@jquindlen)

    Hmm, line 2133 is a comment in 4.8.8, so I’m wondering if the plugin is up to date. The changes in 4.8.8 hardcoded the admin pages specifically it would work on, like such:

    function addHeaderCode() {
                    if(@$_GET['page']=='wpscSupportTickets-admin' || @$_GET['page']=='wpscSupportTickets-newticket' || @$_GET['page']=='wpscSupportTickets-settings' || @$_GET['page']=='wpscSupportTickets-edit' || @$_GET['page']=='wpscSupportTickets-departments' || @$_GET['page']=='wpscSupportTickets-stats') {
                    wp_enqueue_script('jquery-ui-core');
                    wp_enqueue_script('jquery-ui-tabs');
                    if (@!class_exists('AGCA')) {
                        wp_enqueue_script('wpscstniceditor', plugins_url('/js/nicedit/nicEdit.js', __FILE__), array('jquery'), '1.3.2');
                    }
                    wp_enqueue_style('plugin_name-admin-ui-css', plugins_url('/css/custom-theme/jquery-ui-1.10.3.custom.css', __FILE__), false, 2, false);
                }
            }

    Since I verified your initial problem and was able to see that my admin CSS was loading on every admin page, once I implemented the fixes in 4.8.8 I was also to verify that the admin CSS only loaded on the correct pages now with the patch.

    Please double check you’ve got 4.8.8 and that your addHeaderCode() function is wrapped in the if statement, like above. If you’re still experiencing problems after that then I’m at a loss as I now cannot recreate issue. Let me know please! Thanks again.

    Thread Starter Josh

    (@josh401)

    Please double check you’ve got 4.8.8

    I must have missed that (smacks forehead).
    I updated her earlier today when I started working in her admin panel. She was still using a version 3 or 4 times outdated. I didn’t see the most recent release.

    It works great now; using 4.8.8.

    Thanks for the most awesome responses. You certainly are a worthy plugin developer. I’ll definitely urge her to upgrade to your pro version.

    Working great.
    Issue resolved.
    Thank you very much!

    Plugin Author jquindlen

    (@jquindlen)

    You’re fine, I’m just glad to have helped and to hear that the problem is resolved 😉 The WordPress admin panel only checks for updates once a day or something like that, so it’s not always evident when there’s a new plugin/theme update. While a PRO purchase is always nice, at this point an honest good review is worth more to me. Have a great one, and let me know if there’s anything else I can do for you.

    Thread Starter Josh

    (@josh401)

    Done.
    Thanks again!

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

The topic ‘jQuery on all admin pages’ is closed to new replies.