$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>plugins - How to check if you are on widget.php page?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugins - How to check if you are on widget.php page?

matteradmin8PV0评论

I am trying to write a widget and I need to add the color picker to my widget form. I want to add the script only on widget.php page and not on all the admin pages.

Is there a way that I can detect the page inside the construct function of my widget? If not how I can include the script only when I'm on widget.php page?

I am trying to write a widget and I need to add the color picker to my widget form. I want to add the script only on widget.php page and not on all the admin pages.

Is there a way that I can detect the page inside the construct function of my widget? If not how I can include the script only when I'm on widget.php page?

Share Improve this question asked Nov 4, 2018 at 17:18 agahiagahi 1013 silver badges12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

You may use the global variable $pagenow to figure out if you are on a particular admin page, in your case this would be checking if you are on the widgets.php admin page:

<?php 

    global $pagenow;

    if( $pagenow === 'widgets.php' ) {
        ?>
        <script>

            // JavaScript goes here

        </script>
        <?php 
    }
 

Furthermore, it will be helpful for you to use the plugin Query Monitor so that you may easily find out what conditionals may be used on a particular instance.

Post a comment

comment list (0)

  1. No comments so far