PluginProbe
Database Addon For WPForms ( wpforms entries ) – WPFormsDB / 1.0.4
Database Addon For WPForms ( wpforms entries ) – WPFormsDB v1.0.4
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.4, at database-for-wp-forms.php

194 lines 5.8 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: contact-form-WPFormsDB
7 Domain Path: /languages/
8 Version: 1.0.4
9 */
10
11 add_action('init', 'wpforms_db_init');
12
13 function wpforms_db_init(){
14 if( is_admin() ){
15 require_once 'inc/class-main-page.php';
16 require_once 'inc/class-sub-page.php';
17 require_once 'inc/class-form-details.php';
18 require_once 'inc/class-export-csv.php';
19
20 if( isset($_REQUEST['wpforms-csv']) && ( $_REQUEST['wpforms-csv'] == true ) && isset( $_REQUEST['nonce'] ) ) {
21
22 $nonce = filter_input( INPUT_GET, 'nonce', FILTER_SANITIZE_STRING );
23
24 if ( ! wp_verify_nonce( $nonce, 'dnonce' ) ) wp_die('Invalid nonce..!!');
25 $csv = new WPForms_Export_CSV();
26 $csv->download_csv_file();
27 }
28 new WPFormsDB_Wp_Main_Page;
29 }
30 }
31
32
33 function WPFormsDB_create_table(){
34
35 global $wpdb;
36 $wpform = apply_filters( 'WPFormsDB_database', $wpdb );
37 $table_name = $wpform->prefix.'wpforms_db';
38
39 if( $wpform->get_var("SHOW TABLES LIKE '$table_name'") != $table_name ) {
40
41 $charset_collate = $wpform->get_charset_collate();
42
43 $sql = "CREATE TABLE $table_name (
44 form_id bigint(20) NOT NULL AUTO_INCREMENT,
45 form_post_id bigint(20) NOT NULL,
46 form_value longtext NOT NULL,
47 form_date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
48 PRIMARY KEY (form_id)
49 ) $charset_collate;";
50
51 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
52 dbDelta( $sql );
53 }
54
55 add_option( 'WPFormsDB_view_install_date', date('Y-m-d G:i:s'), '', 'yes');
56
57 }
58
59 function WPFormsDB_on_activate( $network_wide ){
60
61 global $wpdb;
62 if ( is_multisite() && $network_wide ) {
63 // Get all blogs in the network and activate plugin on each one
64 $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
65 foreach ( $blog_ids as $blog_id ) {
66 switch_to_blog( $blog_id );
67 WPFormsDB_create_table();
68 restore_current_blog();
69 }
70 } else {
71 WPFormsDB_create_table();
72 }
73
74 // Add custom capability
75 $role = get_role( 'administrator' );
76 $role->add_cap( 'WPFormsDB_access' );
77 }
78
79 register_activation_hook( __FILE__, 'WPFormsDB_on_activate' );
80
81
82 function WPFormsDB_on_deactivate() {
83
84 // Remove custom capability from all roles
85 global $wp_roles;
86
87 foreach( array_keys( $wp_roles->roles ) as $role ) {
88 $wp_roles->remove_cap( $role, 'WPFormsDB_access' );
89 }
90 }
91
92 register_deactivation_hook( __FILE__, 'WPFormsDB_on_deactivate' );
93
94
95 function WPFormsDB_save( $fields, $entry, $form_id ) {
96
97 global $wpdb;
98 $wpform = apply_filters( 'WPFormsDB_database', $wpdb );
99 $table_name = $wpform->prefix.'wpforms_db';
100 $upload_dir = wp_upload_dir();
101
102
103 if ( $fields ) {
104
105 $data = $fields;
106 $uploaded_files = array();
107
108 $form_data = array();
109
110 $form_data['WPFormsDB_status'] = 'unread';
111 foreach ($data as $key => $d) {
112
113 $d['value'] = is_array( $d['value'] ) ? implode(',', $d['value']) : $d['value'];
114
115 $bl = array('\"',"\'",'/','\\','"',"'");
116 $wl = array('&quot;','&#039;','&#047;', '&#092;','&quot;','&#039;');
117 $d['value'] = str_replace($bl, $wl, $d['value'] );
118
119 $form_data[ $d['name'] ] = $d['value'];
120
121 }
122
123 /* WPFormsDB before save data. */
124 $form_data = apply_filters('WPFormsDB_before_save_data', $form_data);
125
126 do_action( 'WPFormsDB_before_save_data', $form_data );
127
128 $form_post_id = $form_id;
129 $form_value = serialize( $form_data );
130 $form_date = current_time('Y-m-d H:i:s');
131
132 $wpform->insert( $table_name, array(
133 'form_post_id' => $form_post_id,
134 'form_value' => $form_value,
135 'form_date' => $form_date
136 ) );
137
138 /* WPFormsDB after save data */
139 $insert_id = $wpform->insert_id;
140 do_action( 'WPFormsDB_after_save_data', $insert_id );
141 }
142
143 }
144
145 add_action( 'wpforms_process_entry_save', 'WPFormsDB_save', 10, 3 );
146
147 /**
148 * Plugin settings link
149 * @param array $links list of links
150 * @return array of links
151 */
152 function wpformsdb_settings_link( $links ) {
153 $forms_link = '<a href="admin.php?page=wp-forms-db-list.php">WPForms DB</a>';
154 array_unshift($links, $forms_link);
155 return $links;
156 }
157
158 $plugin = plugin_basename(__FILE__);
159 add_filter("plugin_action_links_$plugin", 'wpformsdb_settings_link' );
160
161 add_action( 'admin_notices', 'wpformsdb_admin_notice' );
162 add_action('admin_init', 'wpformsdb_view_ignore_notice' );
163
164 function wpformsdb_admin_notice() {
165
166 $install_date = get_option( 'WPFormsDB_view_install_date', '');
167 $install_date = date_create( $install_date );
168 $date_now = date_create( date('Y-m-d G:i:s') );
169 $date_diff = date_diff( $install_date, $date_now );
170
171 if ( $date_diff->format("%d") < 7 ) {
172
173 return false;
174 }
175
176 if ( ! get_option( 'wpformsdb_view_ignore_notice' ) ) {
177
178 echo '<div class="updated"><p>';
179
180 printf(__( '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>', 'wpformsdb' ), '?page=wp-forms-db-list.php&wpformsdb-ignore-notice=0',
181 'https://wordpress.org/plugins/database-for-wpforms/');
182 echo "</p></div>";
183 }
184 }
185
186 function wpformsdb_view_ignore_notice() {
187
188 if ( isset($_GET['wpformsdb-ignore-notice']) && '0' == $_GET['wpformsdb-ignore-notice'] ) {
189
190 update_option( 'wpformsdb_view_ignore_notice', 'true' );
191 }
192 }
193
194