false, 'error' => esc_html__( 'Not allowed', 'epsilon-framework' ), ) ) ); } $args_action = array_map( 'sanitize_text_field', wp_unslash( $_POST['args']['action'] ) ); if ( count( $args_action ) !== 2 ) { wp_die( wp_json_encode( array( 'status' => false, 'error' => esc_html__( 'Not allowed', 'epsilon-framework' ), ) ) ); } if ( ! class_exists( $args_action[0] ) ) { wp_die( wp_json_encode( array( 'status' => false, 'error' => esc_html__( 'Class does not exist', 'epsilon-framework' ), ) ) ); } $class = $args_action[0]; $method = $args_action[1]; if ( 'generate_partial_section' === $method ) { $args = array_map( 'Epsilon_Ajax_Controller::sanitize_arguments_for_output', wp_unslash( $_POST['args']['args'] ) ); } else { $args = isset( $_POST['args']['args'] ) ? $_POST['args']['args'] : $_POST['args']; $args = array_map( 'Epsilon_Ajax_Controller::sanitize_arguments', wp_unslash( $args ) ); } $response = $class::$method( $args ); if ( is_array( $response ) ) { wp_die( wp_json_encode( $response ) ); } if ( 'ok' === $response ) { wp_die( wp_json_encode( array( 'status' => true, 'message' => 'ok', ) ) ); } wp_die( wp_json_encode( array( 'status' => false, 'message' => 'nok', ) ) ); } /** * Sanitize arguments * * @param $args */ public static function sanitize_arguments( $args ) { if ( is_array( $args ) ) { return array_map( 'sanitize_text_field', $args ); } else { return sanitize_text_field( $args ); } } /** * Sanitize arguments for output * * @param $args */ public static function sanitize_arguments_for_output( $args ) { if ( is_array( $args ) ) { return array_map( 'Epsilon_Ajax_Controller::sanitize_arguments_for_output', $args ); } else { return wp_kses_post( $args ); } } }