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/Controll...
File: Preview.php
<?php if ( ! defined( 'ABSPATH' ) ) exit;
[0] Fix | Delete
[1] Fix | Delete
class NF_AJAX_Controllers_Preview extends NF_Abstracts_Controller
[2] Fix | Delete
{
[3] Fix | Delete
private static $transient_prefix = 'nf_form_preview_';
[4] Fix | Delete
[5] Fix | Delete
public function __construct()
[6] Fix | Delete
{
[7] Fix | Delete
// Ajax call handled in 'update' in this file
[8] Fix | Delete
add_action( 'wp_ajax_nf_preview_update', array( $this, 'update' ) );
[9] Fix | Delete
[10] Fix | Delete
add_filter( 'ninja_forms_run_action_settings', array( $this, 'filter_action_settings' ), 10, 4 );
[11] Fix | Delete
}
[12] Fix | Delete
[13] Fix | Delete
public function update()
[14] Fix | Delete
{
[15] Fix | Delete
// Does the current user have admin privileges
[16] Fix | Delete
if (!current_user_can(apply_filters('ninja_forms_admin_all_forms_capabilities', 'manage_options'))) {
[17] Fix | Delete
$this->_data['errors'] = esc_html__('Access denied. You must have admin privileges to perform this action.', 'ninja-forms');
[18] Fix | Delete
$this->_respond();
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
check_ajax_referer( 'ninja_forms_builder_nonce', 'security' );
[22] Fix | Delete
[23] Fix | Delete
$form = json_decode( stripslashes( $_POST['form'] ), ARRAY_A );
[24] Fix | Delete
[25] Fix | Delete
$form_id = $form[ 'id' ];
[26] Fix | Delete
[27] Fix | Delete
$form_data = $this->get_form_data( $form_id );
[28] Fix | Delete
[29] Fix | Delete
/*
[30] Fix | Delete
* Form Settings
[31] Fix | Delete
*/
[32] Fix | Delete
[33] Fix | Delete
if( isset( $form[ 'settings' ] ) && is_array( $form[ 'settings' ] ) ) {
[34] Fix | Delete
[35] Fix | Delete
$old_settings = $form_data[ 'settings' ];
[36] Fix | Delete
[37] Fix | Delete
$form_data[ 'settings' ] = array_merge( $old_settings, $form[ 'settings' ] );
[38] Fix | Delete
}
[39] Fix | Delete
[40] Fix | Delete
/*
[41] Fix | Delete
* Fields and Field Settings
[42] Fix | Delete
*/
[43] Fix | Delete
[44] Fix | Delete
if( isset( $form[ 'fields' ] ) && is_array( $form[ 'fields' ] ) ) {
[45] Fix | Delete
[46] Fix | Delete
foreach( $form[ 'fields' ] as $field ){
[47] Fix | Delete
[48] Fix | Delete
$id = $field[ 'id' ];
[49] Fix | Delete
[50] Fix | Delete
$old_settings = ( isset( $form_data[ 'fields' ][ $id ][ 'settings' ] ) ) ? $form_data[ 'fields' ][ $id ][ 'settings' ] : array();
[51] Fix | Delete
[52] Fix | Delete
$new_settings = array_merge( $old_settings, $field[ 'settings' ] );
[53] Fix | Delete
[54] Fix | Delete
$form_data[ 'fields' ][ $id ][ 'settings' ] = $new_settings;
[55] Fix | Delete
}
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
if( isset( $form[ 'deleted_fields' ] ) ) {
[59] Fix | Delete
[60] Fix | Delete
foreach( $form[ 'deleted_fields' ] as $deleted_field ){
[61] Fix | Delete
[62] Fix | Delete
unset( $form_data[ 'fields' ][ $deleted_field ] );
[63] Fix | Delete
}
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
/*
[67] Fix | Delete
* Actions and Action Settings
[68] Fix | Delete
*/
[69] Fix | Delete
[70] Fix | Delete
if( isset( $form[ 'actions' ] ) && is_array( $form[ 'actions' ] ) ) {
[71] Fix | Delete
[72] Fix | Delete
foreach( $form[ 'actions' ] as $action ){
[73] Fix | Delete
[74] Fix | Delete
$id = $action[ 'id' ];
[75] Fix | Delete
[76] Fix | Delete
if( isset( $form[ 'deleted_actions' ][ $id ] ) ) {
[77] Fix | Delete
[78] Fix | Delete
unset( $form_data[ 'actions' ][ $id ] );
[79] Fix | Delete
continue;
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
$old_settings = ( isset ( $form_data[ 'actions' ][ $id ][ 'settings' ] ) ) ? $form_data[ 'actions' ][ $id ][ 'settings' ]: array();
[83] Fix | Delete
[84] Fix | Delete
$new_settings = array_merge( $old_settings, $action[ 'settings' ] );
[85] Fix | Delete
[86] Fix | Delete
$form_data[ 'actions' ][ $id ][ 'settings' ] = $new_settings;
[87] Fix | Delete
}
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
if( isset( $form[ 'deleted_actions' ] ) ) {
[91] Fix | Delete
[92] Fix | Delete
foreach( $form[ 'deleted_actions' ] as $deleted_action ){
[93] Fix | Delete
[94] Fix | Delete
unset( $form_data[ 'actions' ][ $deleted_action ] );
[95] Fix | Delete
}
[96] Fix | Delete
}
[97] Fix | Delete
[98] Fix | Delete
[99] Fix | Delete
[100] Fix | Delete
$this->update_form_data( $form_data );
[101] Fix | Delete
[102] Fix | Delete
$this->_data['form'] = $form_data;
[103] Fix | Delete
[104] Fix | Delete
do_action( 'ninja_forms_save_form_preview', $form_id );
[105] Fix | Delete
[106] Fix | Delete
$this->_respond();
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
public function filter_action_settings( $action_settings, $form_id, $action_id, $form_settings )
[110] Fix | Delete
{
[111] Fix | Delete
if( ! isset( $form_settings[ 'is_preview' ] ) ) return $action_settings;
[112] Fix | Delete
[113] Fix | Delete
$form_data = $this->get_form_data( $form_id );
[114] Fix | Delete
[115] Fix | Delete
if( isset( $form_data[ 'actions' ][ $action_id ] ) ){
[116] Fix | Delete
[117] Fix | Delete
$settings = $form_data['actions'][$action_id]['settings'];
[118] Fix | Delete
$action_settings = array_merge( $action_settings, $settings );
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
return $action_settings;
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
private function get_form_data( $form_id )
[125] Fix | Delete
{
[126] Fix | Delete
$form_data = get_user_option( self::$transient_prefix . $form_id, FALSE );
[127] Fix | Delete
[128] Fix | Delete
if( ! $form_data ){
[129] Fix | Delete
$form_data = array(); // Initialize $form_data as an empty array. Resolves a PHP deprecated notice
[130] Fix | Delete
[131] Fix | Delete
if( is_string( $form_id ) ){
[132] Fix | Delete
$form = Ninja_Forms()->form()->get();
[133] Fix | Delete
$form_data['id'] = $form_id;
[134] Fix | Delete
$form_data[ 'settings' ] = array();
[135] Fix | Delete
$form_data[ 'fields' ] = array();
[136] Fix | Delete
$form_data[ 'actions' ] = array();
[137] Fix | Delete
} else {
[138] Fix | Delete
/*
[139] Fix | Delete
* Form data is not string and evals to false, so initialize as empty array
[140] Fix | Delete
* Resolves a PHP deprecated notice
[141] Fix | Delete
*/
[142] Fix | Delete
$form_data =[];
[143] Fix | Delete
[144] Fix | Delete
$form = Ninja_Forms()->form($form_id)->get();
[145] Fix | Delete
$form_data['id'] = $form_id;
[146] Fix | Delete
[147] Fix | Delete
$form_data[ 'settings' ] = $form->get_settings();
[148] Fix | Delete
[149] Fix | Delete
$fields = Ninja_Forms()->form( $form_id )->get_fields();
[150] Fix | Delete
foreach( $fields as $field ){
[151] Fix | Delete
[152] Fix | Delete
$field_id = $field->get_id();
[153] Fix | Delete
$form_data[ 'fields' ][ $field_id ][ 'settings' ] = $field->get_settings();
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
$actions = Ninja_Forms()->form( $form_id )->get_actions();
[157] Fix | Delete
foreach( $actions as $action ){
[158] Fix | Delete
[159] Fix | Delete
$action_id = $action->get_id();
[160] Fix | Delete
$form_data[ 'actions' ][ $action_id ][ 'settings' ] = $action->get_settings();
[161] Fix | Delete
}
[162] Fix | Delete
}
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
return $form_data;
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
private function update_form_data( $form_data )
[169] Fix | Delete
{
[170] Fix | Delete
$update = update_user_option( get_current_user_id(), self::$transient_prefix . $form_data['id'], $form_data );
[171] Fix | Delete
[172] Fix | Delete
$this->_data[ 'updated' ] = $update;
[173] Fix | Delete
[174] Fix | Delete
if( ! $update ){
[175] Fix | Delete
$this->_errors[ 'Form Preview Not Updated' ] = $form_data;
[176] Fix | Delete
$this->_errors[ 'Current User' ] = get_current_user_id();
[177] Fix | Delete
$this->_errors[ 'Option' ] = self::$transient_prefix . $form_data['id'];
[178] Fix | Delete
}
[179] Fix | Delete
}
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function