Advertisement
SasheVuchkov

Untitled

Jan 24th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. <?php
  2.  
  3. add_action('wp_ajax_some_ajax_generate_preview', 'some_ajax_generate_preview');
  4. function some_ajax_generate_preview() {
  5.  
  6. $shortcode = $_REQUEST['shortcode'];
  7. $clean_shortcode = some_ajax_clean_shortcode($_REQUEST['shortcode']);
  8. $type = $_REQUEST['type'];
  9. $post_types = get_option('some_ajax_types');
  10.  
  11. $response = function ($status, $message) {
  12.  
  13. return json_encode(['status' => $status,
  14. 'message' => $message]);
  15.  
  16. }
  17.  
  18. if(!current_user_can('administrator')) {
  19.  
  20. echo $response(false, _('Some message!', 'text-domain'));
  21. die();
  22.  
  23. }
  24.  
  25. if(!in_array($type, $post_types)) {
  26.  
  27. echo $response(false, _('Some message!', 'text-domain'));
  28. die();
  29.  
  30. }
  31.  
  32. if(!shortcode_exists($clean_shortcode)) {
  33.  
  34. echo $response(false, _('Some message!', 'text-domain'));
  35. die();
  36.  
  37. }
  38.  
  39. echo $response(true, _('Some message!', 'text-domain'));
  40. die();
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement