| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Plugin Name: WP Data Access |
| 5 |
* Plugin URI: https://wpdataaccess.com/ |
| 6 |
* Description: The best WordPress table plugin with an intuitive table builder and a highly customizable form builder to support data entry |
| 7 |
* Version: 5.5.14 |
| 8 |
* Author: Passionate Programmers B.V. |
| 9 |
* Author URI: https://wpdataaccess.com/ |
| 10 |
* Text Domain: wp-data-access |
| 11 |
* License: GPL-2.0+ |
| 12 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt |
| 13 |
* Domain Path: /languages |
| 14 |
* |
| 15 |
* |
| 16 |
* @package plugin |
| 17 |
* @author Peter Schulz |
| 18 |
* @since 1.0.0 |
| 19 |
*/ |
| 20 |
use WPDataAccess\WPDA; |
| 21 |
if ( !defined( 'WPINC' ) ) { |
| 22 |
die; |
| 23 |
} |
| 24 |
if ( !defined( 'ABSPATH' ) ) { |
| 25 |
exit; |
| 26 |
} |
| 27 |
// Add freemius to WP Data Access. |
| 28 |
if ( function_exists( 'wpda_freemius' ) ) { |
| 29 |
wpda_freemius()->set_basename( false, __FILE__ ); |
| 30 |
} else { |
| 31 |
// Load WPDataAccess namespace. |
| 32 |
require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; |
| 33 |
/** |
| 34 |
* Create a helper function for easy SDK access |
| 35 |
* |
| 36 |
* @return Freemius |
| 37 |
*/ |
| 38 |
function wpda_freemius() { |
| 39 |
global $wpda_freemius; |
| 40 |
if ( !isset( $wpda_freemius ) ) { |
| 41 |
// Include Freemius SDK. |
| 42 |
require_once dirname( __FILE__ ) . '/freemius/start.php'; |
| 43 |
$wpda_freemius = fs_dynamic_init( array( |
| 44 |
'id' => '6189', |
| 45 |
'slug' => 'wp-data-access', |
| 46 |
'type' => 'plugin', |
| 47 |
'public_key' => 'pk_fc2d1714ca61c930152f6e326b575', |
| 48 |
'is_premium' => false, |
| 49 |
'premium_suffix' => 'Premium', |
| 50 |
'has_addons' => false, |
| 51 |
'has_paid_plans' => true, |
| 52 |
'trial' => array( |
| 53 |
'days' => 14, |
| 54 |
'is_require_payment' => false, |
| 55 |
), |
| 56 |
'menu' => array( |
| 57 |
'slug' => 'wpda_navi', |
| 58 |
'contact' => false, |
| 59 |
'network' => true, |
| 60 |
), |
| 61 |
'is_live' => true, |
| 62 |
) ); |
| 63 |
} |
| 64 |
return $wpda_freemius; |
| 65 |
} |
| 66 |
|
| 67 |
// Init Freemius. |
| 68 |
wpda_freemius(); |
| 69 |
// Signal that SDK was initiated. |
| 70 |
do_action( 'wpda_freemius_loaded' ); |
| 71 |
/** |
| 72 |
* Change plugin settings info |
| 73 |
* |
| 74 |
* @param mixed $links Links. |
| 75 |
* @param mixed $file File. |
| 76 |
* @return mixed |
| 77 |
*/ |
| 78 |
function wpda_row_meta( $links, $file ) { |
| 79 |
if ( strpos( $file, plugin_basename( __FILE__ ) ) !== false ) { |
| 80 |
// Add settings link. |
| 81 |
$settings_url = admin_url( 'options-general.php' ) . '?page=wpdataaccess'; |
| 82 |
$settings_link = "<a href='{$settings_url}'>Settings</a>"; |
| 83 |
array_push( $links, $settings_link ); |
| 84 |
//phpcs:ignore - 8.1 proof |
| 85 |
} |
| 86 |
return $links; |
| 87 |
} |
| 88 |
|
| 89 |
add_filter( |
| 90 |
'plugin_row_meta', |
| 91 |
'wpda_row_meta', |
| 92 |
10, |
| 93 |
2 |
| 94 |
); |
| 95 |
/** |
| 96 |
* Activate plugin |
| 97 |
* |
| 98 |
* @author Peter Schulz |
| 99 |
* @since 1.0.0 |
| 100 |
*/ |
| 101 |
function activate_wp_data_access() { |
| 102 |
require_once plugin_dir_path( __FILE__ ) . 'includes/class-wp-data-access-switch.php'; |
| 103 |
WP_Data_Access_Switch::activate(); |
| 104 |
} |
| 105 |
|
| 106 |
register_activation_hook( __FILE__, 'activate_wp_data_access' ); |
| 107 |
/** |
| 108 |
* Deactivate plugin |
| 109 |
* |
| 110 |
* @author Peter Schulz |
| 111 |
* @since 1.0.0 |
| 112 |
*/ |
| 113 |
function deactivate_wp_data_access() { |
| 114 |
require_once plugin_dir_path( __FILE__ ) . 'includes/class-wp-data-access-switch.php'; |
| 115 |
WP_Data_Access_Switch::deactivate(); |
| 116 |
} |
| 117 |
|
| 118 |
register_deactivation_hook( __FILE__, 'deactivate_wp_data_access' ); |
| 119 |
/** |
| 120 |
* Check if database needs to be updated |
| 121 |
* |
| 122 |
* @author Peter Schulz |
| 123 |
* @since 1.5.2 |
| 124 |
*/ |
| 125 |
function wpda_update_db_check() { |
| 126 |
if ( get_option( WPDataAccess\WPDA::OPTION_WPDA_VERSION[0] ) !== WPDataAccess\WPDA::OPTION_WPDA_VERSION[1] ) { |
| 127 |
activate_wp_data_access(); |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
add_action( 'plugins_loaded', 'wpda_update_db_check' ); |
| 132 |
/** |
| 133 |
* Uninstall blog |
| 134 |
* |
| 135 |
* This functions is called when the plugin is uninstalled. The following actions are performed: |
| 136 |
* + Drop plugin tables (unless settings indicate not to) |
| 137 |
* + Delete plugin options from $wpdb->options (unless settings indicate not to) |
| 138 |
* |
| 139 |
* Actions are processed on the current blog and are repeated for every blog on a multisite installation. Must be |
| 140 |
* called from the dashboard (WP_UNINSTALL_PLUGIN defined). User must have the proper privileges (activate_plugins). |
| 141 |
* |
| 142 |
* @author Peter Schulz |
| 143 |
* @since 1.0.0 |
| 144 |
*/ |
| 145 |
function wpda_uninstall_blog() { |
| 146 |
global $wpdb; |
| 147 |
$drop_tables = get_option( 'wpda_uninstall_tables' ); |
| 148 |
if ( 'on' === $drop_tables ) { |
| 149 |
// Get all plugin table names (without WP prefix). |
| 150 |
$plugin_tables = WPDataAccess\WPDA::get_wpda_tables(); |
| 151 |
foreach ( $plugin_tables as $plugin_table ) { |
| 152 |
// Loop through plugin tables. |
| 153 |
// Drop plugin table. |
| 154 |
$wpdb->query( $wpdb->prepare( |
| 155 |
'DROP TABLE IF EXISTS `%1s`', |
| 156 |
// phpcs:ignore WordPress.DB.PreparedSQLPlaceholders, WordPress.DB.DirectDatabaseQuery.SchemaChange |
| 157 |
WPDataAccess\WPDA::remove_backticks( $plugin_table ) |
| 158 |
) ); |
| 159 |
// db call ok; no-cache ok. |
| 160 |
// Get plugin backup tables (if applicable). |
| 161 |
$backup_tables = $wpdb->get_results( $wpdb->prepare( ' |
| 162 |
select table_name as table_name from information_schema.tables |
| 163 |
where table_schema = %s |
| 164 |
and table_name like %s |
| 165 |
', array($wpdb->dbname, "{$plugin_table}_BACKUP_%") ), 'ARRAY_A' ); |
| 166 |
// db call ok; no-cache ok. |
| 167 |
foreach ( $backup_tables as $backup_table ) { |
| 168 |
// Drop plugin backup table. |
| 169 |
$wpdb->query( $wpdb->prepare( |
| 170 |
'DROP TABLE IF EXISTS `%1s`', |
| 171 |
// phpcs:ignore WordPress.DB.PreparedSQLPlaceholders, WordPress.DB.DirectDatabaseQuery.SchemaChange |
| 172 |
WPDataAccess\WPDA::remove_backticks( $backup_table['table_name'] ) |
| 173 |
) ); |
| 174 |
// db call ok; no-cache ok. |
| 175 |
} |
| 176 |
} |
| 177 |
} |
| 178 |
$delete_options = get_option( 'wpda_uninstall_options' ); |
| 179 |
if ( 'on' === $delete_options ) { |
| 180 |
// Delete all options from wp_options. |
| 181 |
$wpdb->query( "\n\t\t\t\t\tDELETE FROM {$wpdb->options}\n\t\t\t\t\tWHERE option_name LIKE 'wpda%'\n\t\t\t\t" ); |
| 182 |
// db call ok; no-cache ok. |
| 183 |
$wpdb->query( "\n\t\t\t\t\tDELETE FROM {$wpdb->usermeta}\n\t\t\t\t\tWHERE meta_key LIKE 'wpda%'\n\t\t\t\t\t OR meta_key LIKE '%wp-data-access%'\n\t\t\t\t" ); |
| 184 |
// db call ok; no-cache ok. |
| 185 |
} |
| 186 |
} |
| 187 |
|
| 188 |
/** |
| 189 |
* Uninstall WP Data Access tables, options and meta keys |
| 190 |
* |
| 191 |
* @return void |
| 192 |
*/ |
| 193 |
function wpda_uninstall() { |
| 194 |
if ( is_multisite() ) { |
| 195 |
global $wpdb; |
| 196 |
// Uninstall plugin for all blogs one by one (will fail silently for blogs having no plugin tables/options). |
| 197 |
$blogids = $wpdb->get_col( "select blog_id from {$wpdb->blogs}" ); |
| 198 |
// db call ok; no-cache ok. |
| 199 |
foreach ( $blogids as $blog_id ) { |
| 200 |
// Uninstall blog. |
| 201 |
switch_to_blog( $blog_id ); |
| 202 |
wpda_uninstall_blog(); |
| 203 |
restore_current_blog(); |
| 204 |
} |
| 205 |
} else { |
| 206 |
// Uninstall on single site installation. |
| 207 |
wpda_uninstall_blog(); |
| 208 |
} |
| 209 |
WPDA::wpda_delete_content_folder(); |
| 210 |
} |
| 211 |
|
| 212 |
wpda_freemius()->add_action( 'after_uninstall', 'wpda_uninstall' ); |
| 213 |
/** |
| 214 |
* Add WP Data Access icon to freemius |
| 215 |
* |
| 216 |
* @return string |
| 217 |
*/ |
| 218 |
function wpda_freemius_icon() { |
| 219 |
return dirname( __FILE__ ) . '/freemius/assets/img/wpda.png'; |
| 220 |
} |
| 221 |
|
| 222 |
wpda_freemius()->add_filter( 'plugin_icon', 'wpda_freemius_icon' ); |
| 223 |
/** |
| 224 |
* Start plugin |
| 225 |
* |
| 226 |
* @author Peter Schulz |
| 227 |
* @since 1.0.0 |
| 228 |
*/ |
| 229 |
function run_wp_data_access() { |
| 230 |
require_once plugin_dir_path( __FILE__ ) . 'includes/class-wp-data-access.php'; |
| 231 |
$wpdataaccess = new WP_Data_Access(); |
| 232 |
$wpdataaccess->run(); |
| 233 |
} |
| 234 |
|
| 235 |
run_wp_data_access(); |
| 236 |
} |