PluginProbe
Database Addon For WPForms ( wpforms entries ) – WPFormsDB / 1.0.5
Database Addon For WPForms ( wpforms entries ) – WPFormsDB v1.0.5
trunk 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.8.1 1.0.9 1.1.0
database-for-wpforms / database-for-wp-forms.php

database-for-wp-forms.php in Database Addon For WPForms ( wpforms entries ) – WPFormsDB 1.0.5, at database-for-wp-forms.php

211 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name:Database for WPforms
4 Description: Save and manage WPForms submissions. Never lose important data. Database add-on for WPForms.
5 Author: wpdebuglog
6 Text Domain: database-for-wpforms
7 Version: 1.0.5
8 License: GPL v2 or later
9 License URI: https://www.gnu.org/licenses/gpl-2.0.html
10 */
11
12 if ( ! defined( 'ABSPATH' ) ) exit;
13
14 function wpforms_db_plugin_load(){
15
16 load_plugin_textdomain( 'database-for-wpforms', false, plugin_basename( dirname( __FILE__ ) ) . '/lang' );
17 }
18
19 add_action('plugins_loaded', 'wpforms_db_plugin_load');
20
21
22 add_action('init', 'wpforms_db_init');
23
24 function wpforms_db_init(){
25 if( is_admin() ){
26 require_once 'inc/class-main-page.php';
27 require_once 'inc/class-sub-page.php';
28 require_once 'inc/class-form-details.php';
29 require_once 'inc/class-export-csv.php';
30
31 if( isset($_REQUEST['wpforms-csv']) && ( $_REQUEST['wpforms-csv'] == true ) && isset( $_REQUEST['nonce'] ) ) {
32
33 $nonce = sanitize_text_field( $_REQUEST['nonce'] );
34
35 if ( ! wp_verify_nonce( $nonce, 'dnonce' ) )
36 wp_die( esc_html__( 'Invalid nonce..!!', 'database-for-wpforms' ) );
37 $csv = new WPForms_Export_CSV();
38 $csv->download_csv_file();
39 }
40 new WPFormsDB_Wp_Main_Page;
41 }
42 }
43
44
45 function WPFormsDB_create_table(){
46
47 global $wpdb;
48 $wpform = apply_filters( 'WPFormsDB_database', $wpdb );
49 $table_name = $wpform->prefix.'wpforms_db';
50
51 if( $wpform->get_var("SHOW TABLES LIKE '$table_name'") != $table_name ) {
52
53 $charset_collate = $wpform->get_charset_collate();
54
55 $sql = "CREATE TABLE $table_name (
56 form_id bigint(20) NOT NULL AUTO_INCREMENT,
57 form_post_id bigint(20) NOT NULL,
58 form_value longtext NOT NULL,
59 form_date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
60 PRIMARY KEY (form_id)
61 ) $charset_collate;";
62
63 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
64 dbDelta( $sql );
65 }
66
67 add_option( 'WPFormsDB_view_install_date', gmdate('Y-m-d G:i:s'), '', 'yes');
68
69 }
70
71 function WPFormsDB_on_activate( $network_wide ){
72
73 global $wpdb;
74 if ( is_multisite() && $network_wide ) {
75 // Get all blogs in the network and activate plugin on each one
76 $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
77 foreach ( $blog_ids as $blog_id ) {
78 switch_to_blog( $blog_id );
79 WPFormsDB_create_table();
80 restore_current_blog();
81 }
82 } else {
83 WPFormsDB_create_table();
84 }
85
86 // Add custom capability
87 $role = get_role( 'administrator' );
88 $role->add_cap( 'WPFormsDB_access' );
89 }
90
91 register_activation_hook( __FILE__, 'WPFormsDB_on_activate' );
92
93
94 function WPFormsDB_on_deactivate() {
95
96 // Remove custom capability from all roles
97 global $wp_roles;
98
99 foreach( array_keys( $wp_roles->roles ) as $role ) {
100 $wp_roles->remove_cap( $role, 'WPFormsDB_access' );
101 }
102 }
103
104 register_deactivation_hook( __FILE__, 'WPFormsDB_on_deactivate' );
105
106
107 function WPFormsDB_save( $fields, $entry, $form_id ) {
108
109 global $wpdb;
110 $wpform = apply_filters( 'WPFormsDB_database', $wpdb );
111 $table_name = $wpform->prefix.'wpforms_db';
112 $upload_dir = wp_upload_dir();
113
114
115 if ( $fields ) {
116
117 $data = $fields;
118 $uploaded_files = array();
119
120 $form_data = array();
121
122 $form_data['WPFormsDB_status'] = 'unread';
123 foreach ($data as $key => $d) {
124
125 $d['value'] = is_array( $d['value'] ) ? implode(',', $d['value']) : $d['value'];
126
127 $bl = array('\"',"\'",'/','\\','"',"'");
128 $wl = array('&quot;','&#039;','&#047;', '&#092;','&quot;','&#039;');
129 $d['value'] = str_replace($bl, $wl, $d['value'] );
130
131 $form_data[ $d['name'] ] = $d['value'];
132
133 }
134
135 /* WPFormsDB before save data. */
136 $form_data = apply_filters('WPFormsDB_before_save_data', $form_data);
137
138 do_action( 'WPFormsDB_before_save_data', $form_data );
139
140 $form_post_id = $form_id;
141 $form_value = serialize( $form_data );
142 $form_date = current_time('Y-m-d H:i:s');
143
144 $wpform->insert( $table_name, array(
145 'form_post_id' => $form_post_id,
146 'form_value' => $form_value,
147 'form_date' => $form_date
148 ) );
149
150 /* WPFormsDB after save data */
151 $insert_id = $wpform->insert_id;
152 do_action( 'WPFormsDB_after_save_data', $insert_id );
153 }
154
155 }
156
157 add_action( 'wpforms_process_entry_save', 'WPFormsDB_save', 10, 3 );
158
159 /**
160 * Plugin settings link
161 * @param array $links list of links
162 * @return array of links
163 */
164 function wpformsdb_settings_link( $links ) {
165 $forms_link = '<a href="admin.php?page=wp-forms-db-list.php">WPForms DB</a>';
166 array_unshift($links, $forms_link);
167 return $links;
168 }
169
170 $plugin = plugin_basename(__FILE__);
171 add_filter("plugin_action_links_$plugin", 'wpformsdb_settings_link' );
172
173 add_action( 'admin_notices', 'wpformsdb_admin_notice' );
174 add_action('admin_init', 'wpformsdb_view_ignore_notice' );
175
176 function wpformsdb_admin_notice() {
177
178 $install_date = get_option( 'WPFormsDB_view_install_date', '');
179 $install_date = date_create( $install_date );
180 $date_now = date_create( gmdate('Y-m-d G:i:s') );
181 $date_diff = date_diff( $install_date, $date_now );
182
183 if ( $date_diff->format("%d") < 7 ) {
184
185 return false;
186 }
187
188 if ( ! get_option( 'wpformsdb_view_ignore_notice' ) ) {
189
190 echo '<div class="updated"><p>';
191
192 printf(
193 /* translators: 1: Settings URL, 2: Repository url */
194 esc_html__(
195 'Awesome, you\'ve been using <a href="admin.php?page=wp-forms-db-list.php">WPForms DB</a> for more than 1 week. May we ask you to give it a 5-star rating on WordPress? | <a href="%2$s" target="_blank">Ok, you deserved it</a> | <a href="%1$s">I already did</a> | <a href="%1$s">No, not good enough</a>', 'database-for-wpforms' ),
196 '?page=wp-forms-db-list.php&wpformsdb-ignore-notice=0',
197 'https://wordpress.org/plugins/database-for-wpforms/'
198 );
199 echo "</p></div>";
200 }
201 }
202
203 function wpformsdb_view_ignore_notice() {
204
205 if ( isset($_GET['wpformsdb-ignore-notice']) && '0' == $_GET['wpformsdb-ignore-notice'] ) {
206
207 update_option( 'wpformsdb_view_ignore_notice', 'true' );
208 }
209 }
210
211