0

I have a correctly formatted php functions file in my mu-plugins/ directory. When trying to use wp_is_mobile() or current_user_can(), I get an undefined function error.

Fatal error: Call to undefined function wp_is_mobile() in /var/www/dev.example.com/public/wp-content/mu-plugins/multisite-functions.php on line 147

Are certain core functions defined after the mu-plugins? How do I fix or avoid this? Can I simply not use certain functions in mu plugins?

Thank you!

  • 2
    How are you calling wp_is_mobile(), current_user_can(), etc? In a filter? – Pat J Dec 9 '14 at 20:02
  • I was foolishly doing it outside of the filter, it is now fixed and working though. Thank you for the help! – hawkeye126 Dec 9 '14 at 20:19
3

Thanks to diggy from StackOverflow I've foudn that in the WordPress cycle, the file vars.php (containing my needed functions) is included after muplugins_loaded executes.

Including wp_is_mobile() and current_user_can() in wrapper functions fixed my problem.

CORRECT

function my_epic_function() {
    if(current_user_can( 'edit_posts' )) {
      if(!wp_is_mobile()) {
        //code to be executed
      }
    }
}
add_action('init', 'my_epic_function');

INCORRECT

function my_epic_function() {
    //code to be executed
}
if(current_user_can( 'edit_posts' )) {
  if(!wp_is_mobile()) {
    add_action('init', 'my_epic_function');
  }
}
  • 1
    Could you add some example code to your answer to help any future visitors? – Andrew Bartel Dec 9 '14 at 21:29
  • 1
    Make sure you mark your answer Accepted so that others can benefit from your learning, too. (I think there's a 48-hour wait before you can accept your own answer.) – Pat J Dec 10 '14 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.