I've created a plugin.
In this plugin I have a function that will display some data.
In this function I use is_admin() to determine if the function is being called from the backend, because then I can add some additional information.

In an admin page, the function is loaded normaly. After an update using jQuery, the function is called to display new data.

The problem is that when the function is called through jQuery, the is_admin() is false, even if I am backend in admin mode.

Why isn't is_admin working whne called through jQuery?


The code for is_admin() is called when I click the save button for a new event (or updating existing event).

After clicking save / update, the calendar list is updated through jQuery.

Here are parts of the plugin code.

// create custom plugin settings menu
if ( function_exists('add_action') ) {
  add_shortcode('eventcal', 'shortcode_display_event');

function shortcode_display_event($attr) {
  $ec = new EventCalendar();

        'type' => 'simple',
        'parent_id' => '',
        'category' => '',
        'count' => '10',
        'link' => ''
    ), $attr));

  $data['events'] = $ec->getMultipleEvents($cal_type, $count, $parent_id, $category);
  $data['link'] = $link;
  $data['type'] = $type;   

This is the bit that is added if I'm in admin mode:

function extendedList( $data ) {
    $eventList .= '<th class="eventActions"></th>';
  $eventList .= '</tr></thead><tbody>';

And here is the code for updating calendar list after update.

// New event - Form Submit
jQuery('#formNewEvent').live('submit' ,function() {

    var formData = jQuery('#formNewEvent').serializeArray();

    //Event ID is only given a value when an event has been clicked.
    if(jQuery('#event_id').val() != '')

      jQuery.post("/wp-content/plugins/wp-eventcal/eventcal_jquery.php", { instance: 'updateEvent', formData : formData, eventID : jQuery('#event_id').val() },
      function(data) {
        if(data.status == 'success') {
          // Here we update calendar list after data has been updated
          jQuery.post("/wp-content/plugins/wp-eventcal/eventcal_jquery.php", { instance: 'getEventList' },
          function(list) {
      }, "json");
    else {
      // ADD NEW EVENT
      jQuery.post("/wp-content/plugins/wp-eventcal/eventcal_jquery.php", { instance: 'addNewEvent', formData : formData },
      function(data) {
        // Here we update calendar list after new event have been added         
        if(data.status) {
          jQuery.post("/wp-content/plugins/wp-eventcal/eventcal_jquery.php", { instance: 'getEventList' },
          function(list) {
      }, "json");        
  return false;

2 Answers 2


Is it possible that you are not adding the jQuery() within an 'init' or 'admin_init'; my guess is 'yes'. Further, if you use an 'admin_init' hook you won't need to call is_admin().

Better yet, here's an answer about best practices when using jQuery within WordPress:

  • hmm... I think you might be right... but the code should be available even if I'm not backend (shortcode). I tested using init on add_shortcode, but hen the calendar was not rendered backend.
    – Steven
    Jan 30, 2011 at 13:29
  • @Steve - You've got a lot going on here so it's hard for me to isolate the problem without spending tons of time on this. Simple question for now: did you get something that works for you? If yes, maybe learn the nuances later. If not, please elaborate. Jan 31, 2011 at 2:45

Check the class attribute for body: If the theme is using body_class() the body has a class named logged-in for users that are logged in. Be aware the function can be used on the element html too.


    alert("Logged In");

    alert("Logged Out");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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