• Scott Paterson

    (@scottpaterson)


    Here is my code. Works fine on non-mulitsite, but on multisite, the globals $pagenow and $typenow are empty.

    Any ideas why or how to fix this?

    global $pagenow, $typenow;
    
    if ( in_array( $pagenow, array( 'post.php', 'page.php', 'post-new.php', 'post-edit.php' ) ) && $typenow != 'download' ) {
    ...

    Thanks,
    Scott

Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter Scott Paterson

    (@scottpaterson)

    Hi all,

    I thought I would updated this thread and mention I am still looking for a solution – so any help would be greatly appreciated.

    Could this be a bug in WordPress?

    Thanks,
    Scott

    Hmmm, I think I just ran into the same issue with one of my plugins… Will test further and share any findings here 🙂

    Or on http://stackoverflow.com/questions/29638998/wordpress-global-pagenow-not-available-in-multisite 😉

    No, turns out there is something else going wrong in my case. I used

    error_log('Pagenow: '.$pagenow);

    to see what the value would return when reloading my admin page and it does contain the correct admin page file name. My code runs on the plugins_loaded action where get_current_screen() apparently is not available yet (got error message about unknown function) so must use $pagenow here.

    At what point are you trying to get the $pagenow global?

    Thread Starter Scott Paterson

    (@scottpaterson)

    Hi RavanH,

    I am using it at the top of my main plugin file to add a media button to the editor.

    Thanks,
    Scott

    You should show your code, especially the hook/filter. My guess is that you are calling a hook where pagenow has not yet been defined/populated.

    Thread Starter Scott Paterson

    (@scottpaterson)

    Here is my code, but it works fine when not in mulitsite. When it mutliside $pagenow and $typenow are empty.

    global $pagenow, $typenow;
    
    // add media button for editor page
    if ( in_array( $pagenow, array( 'post.php', 'page.php', 'post-new.php', 'post-edit.php' ) ) && $typenow != 'download' ) {
    
    add_action('media_buttons', 'wpecpp_add_my_media_button', 20);
    function wpecpp_add_my_media_button() {
        echo '<a href="#TB_inline?width=600&height=400&inlineId=wpecpp_popup_container" title="Easy PayPal Button" id="insert-my-media" class="button thickbox">Easy PayPal Button</a>';
    }
    
    add_action( 'admin_footer',  'wpecpp_add_inline_popup_content' );
    function wpecpp_add_inline_popup_content() {

    Where is that snippet of code located? In a plugin or functions.php.

    Thread Starter Scott Paterson

    (@scottpaterson)

    Plugin

    Full code – http://plugins.svn.wordpress.org/wp-ecommerce-paypal/tags/1.6.7/wp-ecommerce-paypal.php

    You will see the code at the top of that file.

    Yes, that is exactly your problem. When WP multisite loads your plugin, pagenow and typenow are not defined/set. You need a wrapper for your plugin and call it at the appropriate time.

    Here is an example:

    add_action('init', 'my_wpecpp_wrapper_init');
    
    function my_wpecpp_wrapper_init() {
    global $pagenow, $typenow;
    
    // add media button for editor page
    if ( in_array( $pagenow, array( 'post.php', 'page.php', 'post-new.php', 'post-edit.php' ) ) && $typenow != 'download' ) {
    
    [rest of your code in here]

    Sorry looking at your code, I dont think this will work. You need to figure out when to call your add_action hooks.

    Thread Starter Scott Paterson

    (@scottpaterson)

    Hi jkhongusc,

    I see your point, and ill try that this afternoon. I am still curious as it why multisite handles it differently. But thanks for your help so far.

    Scott

    Scott –
    Give my little addition a try (with some tweaks). It would be relatively quick. My concern is that if there are any hooks in your code that are called before the ‘init’ hook… that would cause problems as it wouldnt be called. For example I believe activation hooks are called before init, therefore those hooks have to be outside the init wrapper.

    You could use plugins_loaded (even with an early execution of 0) instead of init. This is fired before init and $pagenow is available then. Don’t know about $typenow though…

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Global $pagenow not available in multisite’ is closed to new replies.