WordPress custom post type capabilities issue

You definitely need to set map_meta_cap to true instead of false to create custom capabilities. I haven’t seen the ‘capability_type’ => [‘note’,’notes’] way of creating capabilities before – maybe it’s shorthand, but if just changing map_meta_cap doesn’t work, you might want to spell everything out the long way: <?php $args = array( ‘labels’ => $labels, … 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

How to add apply_filter for a class property in plugin

Your problem has nothing to do with apply_filters, it’s a basic PHP mistake: public function init (){ $filter_fields = apply_filters(‘tbg_reg_fields’, $this->fields); } Here, you create a brand new variable in the init method scope named $filter_fields, then never use it. $this->filter_fields and $filter_fields are not the same. Additionally, because you used a filter and stored … Read more

Custom array from a query only write the last row of the query

This is because you’re not adding elements to the array. You’re overwriting them: $modified_result = array(); foreach($queryresult as $result){ $modified_result[‘name’] = $result->name; $modified_result[‘address’] = $result->address; } Your loop is setting the name and address property of the $modified_result array directly, and then replacing them for each item in the loop. You want $modified_result to be … 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