Does jQuery/Ajax send cookies when using the rest API or do I need to somehow add them?

No, you are not passing cookies with jQuery AJAX calls .. certainly not via Cross-domain access. If you’re going to use jQuery to pass data, you need to pass the current user ID and use get_userdata($userid) to determine whether the user has the correct capabilities. Server side: $jQuery_user = get_userdata($_POST[‘user_id’]); if(!user_can($jQuery_user,’publish_posts’)){ return array(‘reply’=>0,’error’=>’Forbidden’,’code’=>’403′); } Client … Read more

Developing Themes with React/Angular

First of all like Fayaz had said questions with multiple questions are not the best way to ask something on this platform. Ok, let me try to answer your questions. (Disclaimer: I’m not an react expert. So please don`t hang me if i tell something stupid.) Question 1: No you need not Node.js but npm … Read more

Add Products to user’s ID Woocommerce

/* Add to cart product api */ add_action( ‘rest_api_init’, function () { register_rest_route( ‘wp/v2’, ‘add_to_cart_product’, array( ‘methods’ => array(‘GET’,’POST’), ‘callback’ => ‘add_to_cart_product’, ) ); } ); function add_to_cart_product(){ //wp_set_current_user($_POST[‘user_id’]); /*wp_set_auth_cookie($_POST[‘user_id’]);*/ /* Required Parameters $_POST[‘user_id’] $_POST[‘product_id’] */ global $woocommerce,$wpdb; $array = $wpdb->get_results(“select meta_value from “.$wpdb->prefix.”usermeta where meta_key=’_woocommerce_persistent_cart_1′ and user_id = “.$_POST[‘user_id’]); $data =$array[0]->meta_value; $cart_data=unserialize($data); $flag = … Read more

WordPress: How to create custom REST API route?

We can create route using rest_api_init action like : Simply add below code to your theme functions.php file. add_action( ‘rest_api_init’, function () { register_rest_route(‘wp/v2’, ‘forgot_password’, array( ‘methods’ => array(‘GET’, ‘POST’), ‘callback’ => ‘forgot_password’ )); } ); function forgot_password(){ // YOUR CALLBACK FUNCTION STUFF HERE } forgot_password will define route URL address. methods will define which … Read more