Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. function update_date_job() {
  2.  
  3. if( ! isset( $_POST ) || empty( $_POST ) || !current_user_can('administrator') ) {
  4.  
  5. // If we don't - return custom error message and exit
  6. header( 'HTTP/1.1 400 Empty POST Values' );
  7. echo 'Could Not Verify POST Values.';
  8. exit;
  9. }
  10.  
  11. $post_id = sanitize_text_field($_POST['post_id']);
  12. $date = sanitize_text_field($_POST['new_date']);
  13. $gmtdate = sanitize_text_field($_POST['gmt_date']);
  14. $my_args = array(
  15. 'ID' => $post_id,
  16. 'post_date' => $date,
  17. 'post_date_gmt' => $gmtdate
  18. );
  19.  
  20. $lan = ICL_LANGUAGE_CODE=='pl'? 'en':'pl';
  21. $id = icl_object_id($post_id, 'job_listing', false,$lan);
  22.  
  23. if(current_user_can('administrator')){
  24. wp_update_post( $my_args );
  25. wp_publish_post( $post_id );
  26. $GLOBALS['wp_fastest_cache']->singleDeleteCache(false, $post_id);
  27. if(!empty($id)){
  28. $GLOBALS['wp_fastest_cache']->singleDeleteCache(false, $id);
  29. // wp_update_post(array(
  30. // 'ID' => $id,
  31. // 'post_date' => $date,
  32. // 'post_date_gmt' => $gmtdate
  33. // ));
  34. }
  35. }
  36. wp_die();
  37. }
  38.  
  39. add_action( 'wp_ajax_update_date_job', 'update_date_job' );
  40.  
  41. $my_args = array(
  42. 'ID' => $post_id,
  43. 'post_date' => $date,
  44. 'post_date_gmt' => $gmtdate,
  45. 'post_status' => 'publish'
  46. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement