Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7550393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:12:03+00:00 2026-05-30T10:12:03+00:00

I have customized a plugin to make some ajax calls to admin-ajax.php and it

  • 0

I have customized a plugin to make some ajax calls to admin-ajax.php and it works great. I copied the code over to another site and it no longer works for users who are not logged in.

From firebug:

POST http://<subdomain>.<server>/wp-admin/admin-ajax.php 302 Moved Temporarily 1.08s    

GET http://<subdomain>.<server>/ 200 OK

edit: The question is what could a theme possibly do to redirect ajax requests. The plugin has two hooks:

add_action( 'wp_ajax_em_ajax_getEvents', 'em_ajax_getEvents' ); // ajax for logged in users
add_action( 'wp_ajax_nopriv_em_ajax_getEvents', 'em_ajax_getEvents' ); // ajax for not logged in users

They both work fine on most sites, but one theme redirects requests from non logged in users somehow. Since these actions are specific to the plugin I am at a loss as to where to start looking.

SOLUTION: Big thanks to Ronald Huereca for the add_action( 'init' solution, that”s exactly where the offending redirect was hooking in, in an attempt to protect the admin area. Now I just need to find a safe fix here that doesn’t compromise the theme’s admin area, but also doesn’t hamstring other plugins from allowing users to make anonymous ajax requests.

// stop users accessing the admin
add_action('init', array( $this, 'prevent_admin_access' ), 0);

function prevent_admin_access() {       

    if (strpos(strtolower($_SERVER['REQUEST_URI']), '/wp-admin') !== false) {
        $current_user = wp_get_current_user(); 

        if(!user_can($current_user->ID, 'administrator') && ( !user_can($current_user->ID, 'contributor') ) ){
            wp_redirect(get_option('siteurl'));
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T10:12:04+00:00Added an answer on May 30, 2026 at 10:12 am

    I had something similar occur in a theme. The original coder was trying to prevent a non-admin user from being able to see the /wp-admin/ area.

    Here’s an example:

    // Block Access to /wp-admin for non admins.
    function custom_blockusers_init() {
      if ( is_user_logged_in() && is_admin() && !current_user_can( 'administrator' ) ) {
        wp_redirect( home_url() );
        exit;
      }
    }
    add_action( 'init', 'custom_blockusers_init' ); // Hook into 'init'
    

    I would check your theme for source code similar to what I have.

    When you find the code, just add an extra conditional to make sure that a user isn’t redirected if the DOING_AJAX constant is defined.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are developing a customized installer using Wix and Wpf. We have developed some
I am using cakePHP rating plugin with Flowplayer. I have customized the Flowplayer using
I am new to Eclipse Plugin development. I have already customized my main menu
I try to have customized number format for US country. It works fine so
I have been using wordpress plugins and I have customized one of my plugin
In my magento project the search result not displays. I have customized my magento.
We have a lot of customized spreadsheet solutions that are being used and we
I have a lot of customized javascript and layout design, and I want to
I have to develop a customized tab control and decided to create it with
i have taken the default asp.net mvc template and customized to work for me.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.