Thanks yo Howdy_McGee, Here is working code.
// Remove favorite authors from current users DB
function fav_author_remove_user(){
check_ajax_referer( 'fav_authors_obj_ajax', 'security' );
$remove_this_author = $_POST['clicked_author_id'];
if ( current_user_can( 'edit_posts' ) ){
$user_id = fav_authors_get_user_id();
$author_list = get_user_meta( $user_id, FAV_AUTHORS_META_KEY, true );
//print_r($author_list);
$author_saved = array_search($remove_this_author, $author_list);
if( FALSE !== $author_saved ){
// Remove $author_saved
unset($author_list[$author_saved]);
$author_arr = ( is_array( $author_list ) ) ? $author_list : array( $author_list );
update_user_meta( $user_id, FAV_AUTHORS_META_KEY, $author_arr );
}
}
}
add_action( 'wp_ajax_remove_fav_author_id', 'fav_author_remove_user' );
Related Posts:
- Where the Nickname is being used in WordPress
- Upload files programmatically to users
- update_user_meta add value on the top on existing value
- Average Account Age
- How to keep users unique id stored in session in addition to IP in WordPress plugin?
- Shortcode to update user meta
- Search users with custom meta data
- WordPress /users/me endpoint request forbidden
- Auto populate a user custom field from another user custom field
- User updating their profile wipes my custom fields
- How To Export User’s Custom Fields in CSV or XLSX
- Get all user meta_keys and then group users by matching values
- Update User Meta Via Ajax
- User Following System
- Confusing problem with displaying message recipient metadata
- How to delete only user meta value (not key) from usermeta table in wordpress?
- wp_set_auth_cookie causes 403 error in the wooCommerce checkout
- Ajax contact form widget plugin data not insert in database
- woocommerce_package_rates not fired when wordpress woocommerce accessed as non ajax
- Theme is Causing Ajax Conflicts for a plugin I cant identify it
- Why WordPress plugin url ajax doesn’t work?
- wordpress, search form using ajax
- jquery not calling php function
- Search for categories
- AJAX in plugin wp_send_json() sending html
- Modifying Author Link to add Author Meta in URL
- How can I copy all users to newly created site on a multisite network in WordPress?
- Best place for if/else piece of code related to custom plugin?
- Making sure that a plugin’s scripts and stylesheets are included for dynamicaly loaded content
- Ajax call returning 0
- How to create restrict content to users (by user, not by role)
- Ajax with plugins returns 0
- WordPress + JavaScipt + AJAX + MySQL: insert query for form
- Ajax fail and get 504 error
- Ajax Search Lite: Customize Autoscroll
- Enable users to change change and add taxonomies of posts
- admin-ajax.php warning max input vars exceeded on layered pop plugins [closed]
- How can I change the meta_key for a particular piece of information?
- update_user_meta() misfires sometimes
- WordPress Integration with Google Groups
- Best place to load wp_ajax_the_ajax_hook action in plugin
- jQuery.post not working within shortcode – WordPress Ajax
- Create tabs in admin options page from custom post type loop
- How to load wp_editor via AJAX
- How can I inject options into an select tag inside the widget form?
- Init plugin again after ajax call finish
- Custom User meta field display
- Display wordpress post’s in popup?
- Using AJAX to generate front end / viewer end pages
- Using color picker in plugin, does input attribute order matter?
- How to handle cookies from a WordPress plugin on a cached page?
- Cannot update user display_name field
- Ajax : Call undefined function plugin_function() … can’t call any plugin function
- wordpress file upload with ajax when site is ajaxyfi
- Post Comments with Ajax in WordPress
- AJAX search as you type? [duplicate]
- WordPress api call using wp-ajax returns error 400
- AJAX call – failling to call do_action
- how to insert data in wordpress table usnig jquery ajax
- Using wpdb without loading all plug-ins via wp-load.php
- What are the Best Practises When Using AJAX in Plugin Development?
- edit_user_profile and show_user_profile are not firing inside a class
- Admin AJAX doesn’t work in plugin admin page – Even though code is copied verbatim from WordPress Codex
- AJAX fileupload – TypeError: not a function ajaxSubmit()
- Call plugin with php function
- How to pull all the contributer users records and order by Designation (which is users meta data)?
- How to create multiple users at once?
- Render Modula Plugin Shortcode On Ajax Request
- Multisite – maximum number of users with specific role
- AJAX on Front-End Button Click not working – Custom Plugin
- How do I get the user ID of the user that was updated in WordPress?
- How to handle WordPress Plugin Front-end AJAX Call [duplicate]
- Does having more than 30 Admin Ajax affects site performance (plugin)?
- Understanding State in WordPress Multisites
- How to have sample page for each new register users in a membership website
- Submit Form data to another page via Ajax (WordPress Way)
- AJAX Load more start with x posts
- Is it safe to use admin-ajax.php in the frontend?
- How to get all posts belongs to a user between a certain date
- plugin shortcode not working on ajax request call
- wordpress add_action() issue in ajax call
- How to display checked posts on another page over AJAX? (like comparasion style)
- Meta query for comparing two dates
- Specific way to allow WordPress users to view their current password? And edit it?
- Create WordPress posts from JSON array using plugin in admin
- PHP script from functions php is loaded via admin-ajax to div…and the result is 0, not the desired content
- Ajax Plugin Not Echoing Response
- Adding inside wp-plugin jQuery script that receives JSON-formatted data, generated by php-function inside this plugin
- how can I query all wordpress users of a blog
- where do I send my ajax calls
- Ajax save data to database on document ready, no data being saved
- Add Content to Content()
- WordPress front end AJAX. Return 0 :?
- ACF: How to get users with a ACF flexible content subfield with a specific value AND layout?
- WordPress Ajax code is not Working
- Using WordPress to build membership Page
- Is there a plugin for WordPress for creating ‘Accounts’ where all users who belong to that Account can only see Account data? [closed]
- don’t call ajax if not plugin page
- How to get specific string/value from an array? php [closed]
- coding a WordPress AJAX Form using PHP to check if User is Logged Out and Show error