ajax-actions.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * Author: ExactMetrics team
  4. * Author URI: https://exactmetrics.com
  5. * Copyright 2018 ExactMetrics team
  6. * License: GPLv2 or later
  7. * License URI: http://www.gnu.org/licenses/gpl-2.0.html
  8. */
  9. // Exit if accessed directly
  10. if ( ! defined( 'ABSPATH' ) )
  11. exit();
  12. if ( ! class_exists( 'GADWP_Common_Ajax' ) ) {
  13. final class GADWP_Common_Ajax {
  14. private $gadwp;
  15. public function __construct() {
  16. $this->gadwp = GADWP();
  17. if ( GADWP_Tools::check_roles( $this->gadwp->config->options['access_back'] ) || GADWP_Tools::check_roles( $this->gadwp->config->options['access_front'] ) ) {
  18. add_action( 'wp_ajax_gadwp_set_error', array( $this, 'ajax_set_error' ) );
  19. }
  20. }
  21. /**
  22. * Ajax handler for storing JavaScript Errors
  23. *
  24. * @return json|int
  25. */
  26. public function ajax_set_error() {
  27. if ( ! isset( $_POST['gadwp_security_set_error'] ) || ! ( wp_verify_nonce( $_POST['gadwp_security_set_error'], 'gadwp_backend_item_reports' ) || wp_verify_nonce( $_POST['gadwp_security_set_error'], 'gadwp_frontend_item_reports' ) ) ) {
  28. wp_die( - 40 );
  29. }
  30. $timeout = 24 * 60 * 60;
  31. GADWP_Tools::set_error( $_POST['response'], $timeout );
  32. wp_die();
  33. }
  34. }
  35. }