Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/ninja-fo.../includes/AJAX/REST
File: Controller.php
<?php if ( ! defined( 'ABSPATH' ) ) exit;
[0] Fix | Delete
use NinjaForms\Includes\Admin\RestControllerSafeList;
[1] Fix | Delete
[2] Fix | Delete
/**
[3] Fix | Delete
* A controller extensions for mapping REST requests to an admin-ajax action.
[4] Fix | Delete
*/
[5] Fix | Delete
abstract class NF_AJAX_REST_Controller extends NF_Abstracts_Controller
[6] Fix | Delete
{
[7] Fix | Delete
/**
[8] Fix | Delete
* The name of the admin-ajax action.
[9] Fix | Delete
* @var string
[10] Fix | Delete
*/
[11] Fix | Delete
protected $action;
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* Setup admin-ajax to access the endpoint router.
[15] Fix | Delete
*/
[16] Fix | Delete
public function __construct()
[17] Fix | Delete
{
[18] Fix | Delete
if( $this->action ) {
[19] Fix | Delete
/**
[20] Fix | Delete
* The function that handles these actions are located in the
[21] Fix | Delete
* classes that extend this class. The action is usually of the type 'get', 'post', or 'delete'
[22] Fix | Delete
* These files inlcude:
[23] Fix | Delete
* NF_AJAX_REST_BatchProcess
[24] Fix | Delete
* NF_AJAX_REST_Forms
[25] Fix | Delete
* NF_AJAX_REST_NewFormTemplates
[26] Fix | Delete
* NF_AJAX_REST_RequiredUpdate
[27] Fix | Delete
*
[28] Fix | Delete
* And any other class that extends this class(NF_AJAX_REST_Controller)
[29] Fix | Delete
*/
[30] Fix | Delete
add_action('wp_ajax_' . $this->action, array($this, 'route'));
[31] Fix | Delete
}
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Map admin-ajax requests to the corresponding method callback.
[36] Fix | Delete
*/
[37] Fix | Delete
public function route()
[38] Fix | Delete
{
[39] Fix | Delete
register_shutdown_function( array( $this, 'shutdown' ) );
[40] Fix | Delete
[41] Fix | Delete
$method = strtolower( $_SERVER['REQUEST_METHOD'] );
[42] Fix | Delete
[43] Fix | Delete
/*
[44] Fix | Delete
* Request Method Override
[45] Fix | Delete
* Allows for a POST request to function as another Request Method
[46] Fix | Delete
* by passing a `method_override` value as a request parameter.
[47] Fix | Delete
* For example, some servers do not support the DELETE request method.
[48] Fix | Delete
*/
[49] Fix | Delete
if( 'post' == $method and isset( $_REQUEST[ 'method_override' ] ) ){
[50] Fix | Delete
$method = sanitize_text_field( $_REQUEST[ 'method_override' ] );
[51] Fix | Delete
[52] Fix | Delete
if(!RestControllerSafeList::isClassMethodAllowed(static::class,$method)){
[53] Fix | Delete
[54] Fix | Delete
$this->_errors[] = esc_html__( 'Requested method override is not allowed', 'ninja-forms' );
[55] Fix | Delete
$this->_respond();
[56] Fix | Delete
}
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
if( ! method_exists( $this, $method ) ){
[60] Fix | Delete
$this->_errors[] = esc_html__( 'Endpoint does not exist.', 'ninja-forms' );
[61] Fix | Delete
$this->_respond();
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
[65] Fix | Delete
/**
[66] Fix | Delete
* This call get the $_REQUEST info for the call(post, get, etc.)
[67] Fix | Delete
* being called.
[68] Fix | Delete
*/
[69] Fix | Delete
$request_data = $this->get_request_data();
[70] Fix | Delete
[71] Fix | Delete
try {
[72] Fix | Delete
$data = $this->$method($request_data);
[73] Fix | Delete
$this->_respond( $data );
[74] Fix | Delete
} catch( Exception $e ) {
[75] Fix | Delete
$this->_errors[] = $e->getMessage();
[76] Fix | Delete
}
[77] Fix | Delete
$this->_respond();
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
/**
[81] Fix | Delete
* [OVERRIDE THIS] Get sanitized request data for use in method callbacks.
[82] Fix | Delete
* @return array
[83] Fix | Delete
*/
[84] Fix | Delete
protected function get_request_data()
[85] Fix | Delete
{
[86] Fix | Delete
// This section intentionally left blank.
[87] Fix | Delete
[88] Fix | Delete
/*
[89] Fix | Delete
* [Example] FORM ID
[90] Fix | Delete
*/
[91] Fix | Delete
// if( isset( $_REQUEST[ 'form_id' ] ) && $_REQUEST[ 'form_id' ] ){
[92] Fix | Delete
// $request_data[ 'form_id' ] = absint( $_REQUEST[ 'form_id' ] );
[93] Fix | Delete
// }
[94] Fix | Delete
[95] Fix | Delete
return array();
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
/**
[99] Fix | Delete
* Returns debugging data when a fatal error is triggered.
[100] Fix | Delete
*/
[101] Fix | Delete
public function shutdown()
[102] Fix | Delete
{
[103] Fix | Delete
$error = error_get_last();
[104] Fix | Delete
if( $error !== NULL && in_array( $error[ 'type' ], array( E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_USER_ERROR ) ) ) {
[105] Fix | Delete
[106] Fix | Delete
$this->_errors[ 'form' ][ 'last' ] = esc_html__( 'The server encountered an error during processing.', 'ninja-forms' );
[107] Fix | Delete
[108] Fix | Delete
if( current_user_can( 'manage_options' ) && isset( $error[ 'message' ] ) ){
[109] Fix | Delete
$this->_errors[ 'form' ][ 'last_admin' ] = '<pre>' . $error[ 'message' ] . '</pre>';
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
$this->_errors[ 'last' ] = $error;
[113] Fix | Delete
$this->_respond();
[114] Fix | Delete
}
[115] Fix | Delete
}
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function