WordPress Plugin Activate / Deactive Failing

So the ‘activate_plugin’ was a typo in the question. But even so, as a friendly reminder (for all of us), activate_plugin() is an existing function in WordPress. And you should use unique prefix in your custom functions (that are defined in the global scope): function my_plugin_activate_plugin() { … } register_activation_hook( __FILE__, ‘my_plugin_activate_plugin’ ); The Problem … Read more

How do I have now a duplicated user entry if this is not allowed (and I cannot replicate it)?

Yes, WordPress checks for duplicate emails internally, but not duplicate usernames To test this I ran this several times via wp shell: wp_create_user( ‘test’, ‘password’, ‘[email protected]’ ); The result on the second attempt was: => class WP_Error#1962 (2) { public $errors => array(1) { ‘existing_user_email’ => array(1) { [0] => string(42) “Sorry, that email address … Read more

400 Bad Request, in wordpress theme development, wp_ajax

The problem is that, you have added extra white space before wp_ajax action. remove space from actions ‘ wp_ajax_my_action’ and ‘ wp_ajax_nopriv_my_action’. because of extra space before ajax request, showing the 400 bad request error. You should use : add_action(‘wp_ajax_my_action’, ‘my_action’); add_action(‘wp_ajax_nopriv_my_action’, ‘my_action’);

Remove entire [$key] from array stored in custom field using Ajax – unset($array[$key]); not working

Currently you can not unset key because you can not find proper key from array. The issue is that you did $stamp = array($_POST[‘stamp’]); as array which is wrong. you have to remove array() from $stamp, so which look like $stamp = $_POST[‘stamp’];. then you can search value in column from array and unset it. … Read more

Is it possible to abort post update if specific conditions on metadata are met?

There’s an action hook, pre_post_update that gets executed just before updating a post. add_action(‘pre_post_update’, function($post_id, $data)){ if(!isset($_POST[‘date_start’]){ wp_safe_redirect(“post.php?post={$post_id}”); die(); } } I didn’t find any action that gets executed right before creating a post, however, I did find a filter that does and will work to validate data / abort with a redirect just like … Read more

Bad Request in AJAX

The problem is that it’s sending JSON request headers, the old legacy Admin AJAX API doesn’t understand this. As a result these are the cause of the bad request: dataType: “json”, contentType: “application/json” Your endpoint might be able to handle that input, but WP’s admin AJAX handler can’t, so it never knows which action to … Read more