C:\xampp\htdocs\landing\wp-content\plugins\wpforms-lite\includes\admin\importers\class-base.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
/**
 * Base Importer class.
 *
 * @since 1.4.2
 */
abstract class WPForms_Importer implements WPForms_Importer_Interface {

    
/**
     * Importer name.
     *
     * @since 1.4.2
     *
     * @var string
     */
    
public $name;

    
/**
     * Importer name in slug format.
     *
     * @since 1.4.2
     *
     * @var string
     */
    
public $slug;

    
/**
     * Importer plugin path.
     *
     * @since 1.4.2
     *
     * @var string
     */
    
public $path;

    
/**
     * Primary class constructor.
     *
     * @since 1.4.2
     */
    
public function __construct() {

        
$this->init();

        
// Add to list of available importers.
        
add_filter'wpforms_importers', array( $this'register' ), 10);

        
// Return array of all available forms.
        
add_filter"wpforms_importer_forms_{$this->slug}", array( $this'get_forms' ), 10);

        
// Import a specific form with AJAX.
        
add_action"wp_ajax_wpforms_import_form_{$this->slug}", array( $this'import_form' ) );
    }

    
/**
     * Add to list of registered importers.
     *
     * @since 1.4.2
     *
     * @param array $importers List of supported importers.
     *
     * @return array
     */
    
public function register$importers = array() ) {

        
$importers$this->slug ] = array(
            
'name'      => $this->name,
            
'slug'      => $this->slug,
            
'path'      => $this->path,
            
'installed' => file_existstrailingslashitWP_PLUGIN_DIR ) . $this->path ),
            
'active'    => $this->is_active(),
        );

        return 
$importers;
    }

    
/**
     * If the importer source is available.
     *
     * @since 1.4.2
     *
     * @return bool
     */
    
protected function is_active() {
        return 
is_plugin_active$this->path );
    }

    
/**
     * Add the new form to the database and return AJAX data.
     *
     * @since 1.4.2
     *
     * @param array $form Form to import.
     * @param array $unsupported List of unsupported fields.
     * @param array $upgrade_plain List of fields, that are supported inside the paid WPForms, but not in Lite.
     * @param array $upgrade_omit No field alternative in WPForms.
     */
    
public function add_form$form$unsupported = array(), $upgrade_plain = array(), $upgrade_omit = array() ) {

        
// Create empty form so we have an ID to work with.
        
$form_id wp_insert_post( array(
            
'post_status' => 'publish',
            
'post_type'   => 'wpforms',
        ) );

        if ( empty( 
$form_id ) || is_wp_error$form_id ) ) {
            
wp_send_json_success( array(
                
'error' => true,
                
'name'  => sanitize_text_field$form['settings']['form_title'] ),
                
'msg'   => esc_html__'There was an error while creating a new form.''wpforms-lite' ),
            ) );
        }

        
$form['id']       = $form_id;
        
$form['field_id'] = count$form['fields'] ) + 1;

        
// Update the form with all our compiled data.
        
wpforms()->form->update$form_id$form );

        
// Make note that this form has been imported.
        
$this->track_import$form['settings']['import_form_id'], $form_id );

        
// Build and send final AJAX response!
        
wp_send_json_success( array(
            
'name'          => $form['settings']['form_title'],
            
'edit'          => esc_url_rawadmin_url'admin.php?page=wpforms-builder&view=fields&form_id=' $form_id ) ),
            
'preview'       => wpforms_get_form_preview_url$form_id ),
            
'unsupported'   => $unsupported,
            
'upgrade_plain' => $upgrade_plain,
            
'upgrade_omit'  => $upgrade_omit,
        ) );
    }

    
/**
     * After a form has been successfully imported we track it, so that in the
     * future we can alert users if they try to import a form that has already
     * been imported.
     *
     * @since 1.4.2
     *
     * @param int $source_id Imported plugin form ID.
     * @param int $wpforms_id WPForms form ID.
     */
    
public function track_import$source_id$wpforms_id ) {

        
$imported get_option'wpforms_imported', array() );

        
$imported$this->slug ][ $wpforms_id ] = $source_id;

        
update_option'wpforms_imported'$importedfalse );
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586