It’s failing because WordPress isn’t loaded. Instead of making AJAX requests directly to PHP files in your theme, make them to a REST API endpoint.
For example:
add_action( 'rest_api_init', function () {
register_rest_route( 'petebolduc/v1', '/test/', array(
'callback' => 'petebolduc_ajax'
) );
} );
function petebolduc( $parameters ) {
$foo = $parameters['foo'];
return "foo is " . $foo;
}
With that code, visiting: example.com/wp-json/petebolduc/v1/test?foo=bar
gives:
"foo is bar"
Related Posts:
- List users by last name in WP_User_Query
- Wp_User_Query not sorting by meta key
- WP_User_Query with combined meta query – not working?
- pre_user_query meta_query admin user list
- How to use search_columns in WP_User_Query?
- How to query users who have empty first_name?
- WordPress User getting added with id of 0
- WP User Query fails when searching meta queries and search columns
- Getting users by specific capability, not role
- how to know when the user is in specific part of the website and when he leaves that part and display the data in the admin dashboard
- WP_User_Query – searching multiple fields
- Accessing current users data within a plugin
- How to activate the user search
- List Users alphabetically with heading
- How to get the count
- How can I prevent certain custom roles from seeing other custom roles on the user list page?
- Display the line breaks in user bio without using html
- User with same Mail but a different additional info(like domain)
- SQL to set Display Name to First Name + Last Name
- Cannot update newly added User field using wp_update_user
- Getting user data via ajax
- Find count of WordPress users by role and search string for user name
- Sort users by custom user meta value
- Show only users with the same role in Dashboard user list
- How to limit users to one comment per post
- Is there an upper limit for users in WP?
- How to let user set password on registration
- Extending WP_User class and using this sub-class during the whole lifecycle
- Why does is_user_logged_in() return false after redirect from another site?
- How can I add a user through SQL?
- Copy a user from one WordPress site to another
- How to use tinyMCE for user “biographical info” without messing with any core file?
- How to change the order in which users are displayed in admin?
- WordPress has a trash for users? (Wrong result for count_user, greater than expected)
- How Do I Prevent Junk Account Creation?
- Hide a user from WordPress
- Redirect after users complete profile form
- Cannot set user passwords
- Memory usage for scalable usermeta queries
- How to get current user’s phone number
- How can I retrieve current user id within wordpress plugin?
- How can I verify users facebook ID that he provides during signup process
- Generate unique number when registering a new user
- WordPress User Meta & ChromePHP or other way to debug/view php variables
- How to disable a specific page for a specific user
- How to change textarea rows height for user’s biographical Info?
- New users not showing up in Post -> Edit
- How can i change the name order in the admin?
- Getting author page slug from get_users() or get_userdata() functions
- How to add user from front end
- Rewrite Rules and Login Issue
- I am getting mysql_real_escape_string() function error while adding user?
- User profile updates password even if not filled (Theme my login) in Firefox? [closed]
- users and usermeta table
- Getting the age of a users account
- New user form rejected because “passwords don’t match”—but there’s only one password field
- Unable to change email address of admin on localhost
- WordPress Password security related questions
- How to make Users sort in reverse order by default?
- Assign random (and unique) user meta upon registration
- How to get ID of Edit User page during wp_handle_upload_prefilter, whilst in Media picker?
- What is correct way to change user’s email?
- Get registered user’s country or IP
- Custom capability for a single user
- wp_dropdown_users() to include null value
- Adding more fields to the add user page on dashboard
- Pagination on WP_User_Query not updating current page
- Change User Role based on Point System Issue
- WP_User_Query not searching
- Remove users access to dashboard
- Allow users to upload flash videos?
- delete_user_meta from a foreach results page
- How to display all user profile info in myaccount page wordpress
- Need to use WordPress page as authentication for different service
- How can I clone a suscriber profile in wordpress
- Reading additional fields in PMPro
- How to put the ‘assign to new user’ select when you delete a user that has custom post type posts, but no normal posts
- How can I show a button in WordPress but make it unclickable unless logged in?
- How to display extra fields for user
- How to make WordPress ‘editor’ role to list/view/add/edit users only with the role ‘author’?
- How to grab data after wp user search is complete
- How to make custom user profile page public?
- User Role not showing in Users Screen
- Change user URL
- User email verification without a plugin, is it possible?
- Deleting anonymous wp_users function not working?
- List all users based on array of domains
- Add method for tracking who referred new users
- Cloning admin pages like users.php
- User count only for role frontend vendor
- Does WordPress Need BuddyPress to Handle Large Amounts of Users?
- Giving users an editable homepage/business directory
- Buddypress – New user type with no profile and can’t interact but can be admin of a group
- Store subscription details for users in WordPress
- Disable editing profile for second time
- No one can edit post/pages by Administrator
- How to add custom detail page for a Subscriber at Admin Panel
- How to allow users to make quizzes or tests in WordPress?
- Sorting Users page admin column with ACF field
- Can we get user profile page using user_id in the URL?