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/wp-conte.../plugins/wpforms-.../src/Admin/Tools/Importer...
File: Base.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace WPForms\Admin\Tools\Importers;
[2] Fix | Delete
[3] Fix | Delete
/**
[4] Fix | Delete
* Base Importer class.
[5] Fix | Delete
*
[6] Fix | Delete
* @since 1.6.6
[7] Fix | Delete
*/
[8] Fix | Delete
abstract class Base implements ImporterInterface {
[9] Fix | Delete
[10] Fix | Delete
/**
[11] Fix | Delete
* Importer name.
[12] Fix | Delete
*
[13] Fix | Delete
* @since 1.6.6
[14] Fix | Delete
*
[15] Fix | Delete
* @var string
[16] Fix | Delete
*/
[17] Fix | Delete
public $name;
[18] Fix | Delete
[19] Fix | Delete
/**
[20] Fix | Delete
* Importer name in slug format.
[21] Fix | Delete
*
[22] Fix | Delete
* @since 1.6.6
[23] Fix | Delete
*
[24] Fix | Delete
* @var string
[25] Fix | Delete
*/
[26] Fix | Delete
public $slug;
[27] Fix | Delete
[28] Fix | Delete
/**
[29] Fix | Delete
* Importer plugin path.
[30] Fix | Delete
*
[31] Fix | Delete
* @since 1.6.6
[32] Fix | Delete
*
[33] Fix | Delete
* @var string
[34] Fix | Delete
*/
[35] Fix | Delete
public $path;
[36] Fix | Delete
[37] Fix | Delete
/**
[38] Fix | Delete
* Primary class constructor.
[39] Fix | Delete
*
[40] Fix | Delete
* @since 1.6.6
[41] Fix | Delete
*/
[42] Fix | Delete
public function __construct() {
[43] Fix | Delete
[44] Fix | Delete
$this->init();
[45] Fix | Delete
[46] Fix | Delete
// Import a specific form with AJAX.
[47] Fix | Delete
add_action( "wp_ajax_wpforms_import_form_{$this->slug}", [ $this, 'import_form' ] );
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
/**
[51] Fix | Delete
* Add to list of registered importers.
[52] Fix | Delete
*
[53] Fix | Delete
* @since 1.6.6
[54] Fix | Delete
*
[55] Fix | Delete
* @param array $importers List of supported importers.
[56] Fix | Delete
*
[57] Fix | Delete
* @return array
[58] Fix | Delete
*/
[59] Fix | Delete
public function register( $importers = [] ) {
[60] Fix | Delete
[61] Fix | Delete
$importers[ $this->slug ] = [
[62] Fix | Delete
'name' => $this->name,
[63] Fix | Delete
'slug' => $this->slug,
[64] Fix | Delete
'path' => $this->path,
[65] Fix | Delete
'installed' => file_exists( trailingslashit( WP_PLUGIN_DIR ) . $this->path ),
[66] Fix | Delete
'active' => $this->is_active(),
[67] Fix | Delete
];
[68] Fix | Delete
[69] Fix | Delete
return $importers;
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
/**
[73] Fix | Delete
* If the importer source is available.
[74] Fix | Delete
*
[75] Fix | Delete
* @since 1.6.6
[76] Fix | Delete
*
[77] Fix | Delete
* @return bool
[78] Fix | Delete
*/
[79] Fix | Delete
protected function is_active() {
[80] Fix | Delete
[81] Fix | Delete
return is_plugin_active( $this->path );
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
/**
[85] Fix | Delete
* Add the new form to the database and return AJAX data.
[86] Fix | Delete
*
[87] Fix | Delete
* @since 1.6.6
[88] Fix | Delete
*
[89] Fix | Delete
* @param array $form Form to import.
[90] Fix | Delete
* @param array $unsupported List of unsupported fields.
[91] Fix | Delete
* @param array $upgrade_plain List of fields, that are supported inside the paid WPForms, but not in Lite.
[92] Fix | Delete
* @param array $upgrade_omit No field alternative in WPForms.
[93] Fix | Delete
*/
[94] Fix | Delete
public function add_form( $form, $unsupported = [], $upgrade_plain = [], $upgrade_omit = [] ) {
[95] Fix | Delete
[96] Fix | Delete
// Create empty form so we have an ID to work with.
[97] Fix | Delete
$form_id = wp_insert_post(
[98] Fix | Delete
[
[99] Fix | Delete
'post_status' => 'publish',
[100] Fix | Delete
'post_type' => 'wpforms',
[101] Fix | Delete
]
[102] Fix | Delete
);
[103] Fix | Delete
[104] Fix | Delete
if ( empty( $form_id ) || is_wp_error( $form_id ) ) {
[105] Fix | Delete
wp_send_json_success(
[106] Fix | Delete
[
[107] Fix | Delete
'error' => true,
[108] Fix | Delete
'name' => sanitize_text_field( $form['settings']['form_title'] ),
[109] Fix | Delete
'msg' => esc_html__( 'There was an error while creating a new form.', 'wpforms-lite' ),
[110] Fix | Delete
]
[111] Fix | Delete
);
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
$form['id'] = $form_id;
[115] Fix | Delete
$form['field_id'] = count( $form['fields'] ) + 1;
[116] Fix | Delete
[117] Fix | Delete
// Update the form with all our compiled data.
[118] Fix | Delete
wpforms()->get( 'form' )->update( $form_id, $form );
[119] Fix | Delete
[120] Fix | Delete
// Make note that this form has been imported.
[121] Fix | Delete
$this->track_import( $form['settings']['import_form_id'], $form_id );
[122] Fix | Delete
[123] Fix | Delete
// Build and send final AJAX response!
[124] Fix | Delete
wp_send_json_success(
[125] Fix | Delete
[
[126] Fix | Delete
'name' => $form['settings']['form_title'],
[127] Fix | Delete
'edit' => esc_url_raw( admin_url( 'admin.php?page=wpforms-builder&view=fields&form_id=' . $form_id ) ),
[128] Fix | Delete
'preview' => wpforms_get_form_preview_url( $form_id ),
[129] Fix | Delete
'unsupported' => $unsupported,
[130] Fix | Delete
'upgrade_plain' => $upgrade_plain,
[131] Fix | Delete
'upgrade_omit' => $upgrade_omit,
[132] Fix | Delete
]
[133] Fix | Delete
);
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
/**
[137] Fix | Delete
* After a form has been successfully imported we track it, so that in the
[138] Fix | Delete
* future we can alert users if they try to import a form that has already
[139] Fix | Delete
* been imported.
[140] Fix | Delete
*
[141] Fix | Delete
* @since 1.6.6
[142] Fix | Delete
*
[143] Fix | Delete
* @param int $source_id Imported plugin form ID.
[144] Fix | Delete
* @param int $wpforms_id WPForms form ID.
[145] Fix | Delete
*/
[146] Fix | Delete
public function track_import( $source_id, $wpforms_id ) {
[147] Fix | Delete
[148] Fix | Delete
$imported = get_option( 'wpforms_imported', [] );
[149] Fix | Delete
[150] Fix | Delete
$imported[ $this->slug ][ $wpforms_id ] = $source_id;
[151] Fix | Delete
[152] Fix | Delete
update_option( 'wpforms_imported', $imported, false );
[153] Fix | Delete
}
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function