| Server IP : 192.241.186.36 / Your IP : 216.73.216.164 Web Server : Apache/2.4.29 (Ubuntu) System : Linux webserver7 4.15.0-194-generic #205-Ubuntu SMP Fri Sep 16 19:49:27 UTC 2022 x86_64 User : root ( 0) PHP Version : 7.4.32 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/adsonicdigital/wp-content/plugins/seo-by-rank-math/includes/traits/ |
Upload File : |
<?php
/**
* The AJAX.
*
* @since 0.9.0
* @package RankMath
* @subpackage RankMath\Traits
* @author Rank Math <support@rankmath.com>
*/
namespace RankMath\Traits;
use RankMath\Helper;
defined( 'ABSPATH' ) || exit;
/**
* Ajax class.
*/
trait Ajax {
/**
* Hooks a function on to a specific ajax action
*
* @param string $tag The name of the action to which the $function_to_add is hooked.
* @param callable $function_to_add The name of the function you wish to be called.
* @param int $priority Optional. Used to specify the order in which the functions
* associated with a particular action are executed. Default 10.
* Lower numbers correspond with earlier execution,
* and functions with the same priority are executed
* in the order in which they were added to the action.
*/
protected function ajax( $tag, $function_to_add, $priority = 10 ) {
\add_action( 'wp_ajax_rank_math_' . $tag, [ $this, $function_to_add ], $priority );
}
/**
* Verify request nonce
*
* @param string $action The nonce action name.
*/
public function verify_nonce( $action ) {
if ( ! isset( $_REQUEST['security'] ) || ! \wp_verify_nonce( $_REQUEST['security'], $action ) ) {
$this->error( __( 'Error: Nonce verification failed', 'rank-math' ) );
}
}
/**
* Whether the current user has a specific capability. If not die with error.
*
* @see has_cap()
*
* @param string $capability Capability name.
* @return boolean Whether the current user has the given capability.
*/
public function has_cap_ajax( $capability ) {
if ( ! Helper::has_cap( $capability ) ) {
$this->error( esc_html__( 'You are not authorized to perform this action.', 'rank-math' ) );
}
return true;
}
/**
* Wrapper function for sending success response
*
* @param mixed $data Data to send to response.
*/
public function success( $data = null ) {
$this->send( $data );
}
/**
* Wrapper function for sending error
*
* @param mixed $data Data to send to response.
*/
public function error( $data = null ) {
$this->send( $data, false );
}
/**
* Send AJAX response.
*
* @param array $data Data to send using ajax.
* @param boolean $success Optional. If this is an error. Defaults: true.
*/
private function send( $data, $success = true ) {
if ( is_string( $data ) ) {
$data = $success ? [ 'message' => $data ] : [ 'error' => $data ];
}
$data['success'] = isset( $data['success'] ) ? $data['success'] : $success;
\wp_send_json( $data );
}
}