WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;
share|improve this question

Hi @Steven:

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:

share|improve this answer
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 '11 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. – MikeSchinkel Jan 31 '11 at 2:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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