| @@ -1,33 +1,20 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 3 | 2 | /** |
| 4 | 3 | * Suppress "error - 0 - No summary was found for this file" on phpdoc generation |
| 5 | 4 | * |
| 6 | 5 | * @package plugin\includes |
| 7 | 6 | */ |
| 8 | -use WPDataAccess\Connection\WPDADB; | |
| 9 | -use WPDataAccess\Cookies\WPDA_Cookies; | |
| 7 | + | |
| 10 | 8 | use WPDataAccess\Data_Dictionary\WPDA_Dictionary_Lists; |
| 11 | 9 | use WPDataAccess\Data_Tables\WPDA_Data_Tables; |
| 12 | 10 | use WPDataAccess\Utilities\WPDA_Table_Actions; |
| 11 | +use WPDataAccess\Utilities\WPDA_Example; | |
| 13 | 12 | use WPDataAccess\Utilities\WPDA_Export; |
| 14 | 13 | use WPDataAccess\Utilities\WPDA_Favourites; |
| 15 | -use WPDataAccess\WPDA; | |
| 16 | 14 | use WPDataProjects\Utilities\WPDP_Export_Project; |
| 17 | 15 | use WPDataAccess\Backup\WPDA_Data_Export; |
| 18 | -use WPDataAccess\Plugin_Table_Models\WPDA_CSV_Uploads_Model; | |
| 19 | -use WPDataRoles\WPDA_Roles; | |
| 20 | -use WPDataAccess\Utilities\WPDA_Autocomplete; | |
| 21 | -use WPDataAccess\Premium\WPDAPRO_Geo_Location\WPDAPRO_Geo_Location_WS; | |
| 22 | -use WPDataAccess\Premium\WPDAPRO_Geo_Location\WPDAPRO_Geo_Location; | |
| 23 | -use WPDataAccess\Query_Builder\WPDA_Query_Builder; | |
| 24 | -use WPDataAccess\Dashboard\WPDA_Dashboard; | |
| 25 | -use WPDataAccess\Dashboard\WPDA_Widget_Code; | |
| 26 | -use WPDataAccess\Dashboard\WPDA_Widget_Publication; | |
| 27 | -use WPDataAccess\Dashboard\WPDA_Widget_Dbms; | |
| 28 | -use WPDataAccess\Dashboard\WPDA_Widget_Google_Chart; | |
| 29 | -use WPDataAccess\Premium\WPDAPRO_Dashboard\WPDAPRO_Widget_Project; | |
| 16 | + | |
| 30 | 17 | /** |
| 31 | 18 | * Class WP_Data_Access |
| 32 | 19 | * |
| 33 | 20 | * Core plugin class used to define: |
| @@ -35,8 +22,9 @@ | ||
| 35 | 22 | * + public specific functionality {@see WP_Data_Access_Public} |
| 36 | 23 | * + internationalization {@see WP_Data_Access_I18n} |
| 37 | 24 | * + plugin activation and deactivation {@see WP_Data_Access_Loader} |
| 38 | 25 | * |
| 26 | + * @package plugin\includes | |
| 39 | 27 | * @author Peter Schulz |
| 40 | 28 | * @since 1.0.0 |
| 41 | 29 | * |
| 42 | 30 | * @see WP_Data_Access_Admin |
| @@ -44,439 +32,189 @@ | ||
| 44 | 32 | * @see WP_Data_Access_I18n |
| 45 | 33 | * @see WP_Data_Access_Loader |
| 46 | 34 | */ |
| 47 | 35 | class WP_Data_Access { |
| 48 | - /** | |
| 49 | - * Reference to plugin loader | |
| 50 | - * | |
| 51 | - * @var WP_Data_Access_Loader | |
| 52 | - * | |
| 53 | - * @since 1.0.0 | |
| 54 | - * | |
| 55 | - * @see WP_Data_Access_Loader | |
| 56 | - */ | |
| 57 | - protected $loader; | |
| 58 | 36 | |
| 59 | - /** | |
| 60 | - * Menu slug or null | |
| 61 | - * | |
| 62 | - * @var null | |
| 63 | - */ | |
| 64 | - protected $page = null; | |
| 37 | + /** | |
| 38 | + * Reference to plugin loader | |
| 39 | + * | |
| 40 | + * @var WP_Data_Access_Loader | |
| 41 | + * | |
| 42 | + * @since 1.0.0 | |
| 43 | + * | |
| 44 | + * @see WP_Data_Access_Loader | |
| 45 | + */ | |
| 46 | + protected $loader; | |
| 65 | 47 | |
| 66 | - /** | |
| 67 | - * WP_Data_Access constructor | |
| 68 | - * | |
| 69 | - * Calls method the following methods to setup plugin: | |
| 70 | - * + {@see WP_Data_Access::load_dependencies()} | |
| 71 | - * + {@see WP_Data_Access::set_locale()} | |
| 72 | - * + {@see WP_Data_Access::define_admin_hooks()} | |
| 73 | - * + {@see WP_Data_Access::define_public_hooks()} | |
| 74 | - * | |
| 75 | - * @since 1.0.0 | |
| 76 | - * | |
| 77 | - * @see WP_Data_Access::load_dependencies() | |
| 78 | - * @see WP_Data_Access::set_locale() | |
| 79 | - * @see WP_Data_Access::define_admin_hooks() | |
| 80 | - * @see WP_Data_Access::define_public_hooks() | |
| 81 | - */ | |
| 82 | - public function __construct() { | |
| 83 | - if ( isset( $_REQUEST['page'] ) ) { | |
| 84 | - // phpcs:ignore WordPress.Security.NonceVerification | |
| 85 | - $this->page = sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ); | |
| 86 | - // phpcs:ignore WordPress.Security.NonceVerification | |
| 87 | - } | |
| 88 | - $this->load_dependencies(); | |
| 89 | - $this->set_locale(); | |
| 90 | - $this->define_admin_hooks(); | |
| 91 | - $this->define_public_hooks(); | |
| 92 | - // WP Data Access REST API. | |
| 93 | - $this->api(); | |
| 94 | - } | |
| 48 | + /** | |
| 49 | + * WP_Data_Access constructor | |
| 50 | + * | |
| 51 | + * Calls method the following methods to setup plugin: | |
| 52 | + * + {@see WP_Data_Access::load_dependencies()} | |
| 53 | + * + {@see WP_Data_Access::set_locale()} | |
| 54 | + * + {@see WP_Data_Access::define_admin_hooks()} | |
| 55 | + * + {@see WP_Data_Access::define_public_hooks()} | |
| 56 | + * | |
| 57 | + * @since 1.0.0 | |
| 58 | + * | |
| 59 | + * @see WP_Data_Access::load_dependencies() | |
| 60 | + * @see WP_Data_Access::set_locale() | |
| 61 | + * @see WP_Data_Access::define_admin_hooks() | |
| 62 | + * @see WP_Data_Access::define_public_hooks() | |
| 63 | + */ | |
| 64 | + public function __construct() { | |
| 95 | 65 | |
| 96 | - /** | |
| 97 | - * Add WP Data Access JSON REST API | |
| 98 | - * | |
| 99 | - * @return void | |
| 100 | - */ | |
| 101 | - private function api() { | |
| 102 | - $api = new \WPDataAccess\API\WPDA_API(); | |
| 103 | - $this->loader->add_action( 'init', $api, 'hide' ); | |
| 104 | - $this->loader->add_action( 'rest_api_init', $api, 'init' ); | |
| 105 | - } | |
| 66 | + $this->load_dependencies(); | |
| 67 | + $this->set_locale(); | |
| 68 | + $this->define_admin_hooks(); | |
| 69 | + $this->define_public_hooks(); | |
| 106 | 70 | |
| 107 | - /** | |
| 108 | - * Load required dependencies | |
| 109 | - * | |
| 110 | - * Loads required plugin files and initiates the plugin loader. | |
| 111 | - * | |
| 112 | - * @since 1.0.0 | |
| 113 | - * | |
| 114 | - * @see WP_Data_Access_Loader | |
| 115 | - */ | |
| 116 | - private function load_dependencies() { | |
| 117 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-data-access-loader.php'; | |
| 118 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-data-access-i18n.php'; | |
| 119 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wp-data-access-admin.php'; | |
| 120 | - require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wp-data-access-public.php'; | |
| 121 | - $this->loader = new WP_Data_Access_Loader(); | |
| 122 | - } | |
| 71 | + } | |
| 123 | 72 | |
| 124 | - /** | |
| 125 | - * Set locale for internationalization | |
| 126 | - * | |
| 127 | - * @since 1.0.0 | |
| 128 | - * | |
| 129 | - * @see WP_Data_Access_I18n | |
| 130 | - */ | |
| 131 | - private function set_locale() { | |
| 132 | - $wpda_i18n = new WP_Data_Access_I18n(); | |
| 133 | - $this->loader->add_action( 'init', $wpda_i18n, 'load_plugin_textdomain' ); | |
| 134 | - } | |
| 73 | + /** | |
| 74 | + * Load required dependencies | |
| 75 | + * | |
| 76 | + * Loads required plugin files and initiates the plugin loader. | |
| 77 | + * | |
| 78 | + * @since 1.0.0 | |
| 79 | + * | |
| 80 | + * @see WP_Data_Access_Loader | |
| 81 | + */ | |
| 82 | + private function load_dependencies() { | |
| 135 | 83 | |
| 136 | - /** | |
| 137 | - * Add admin hooks | |
| 138 | - * | |
| 139 | - * Initiates {@see WP_Data_Access_Admin} (admin functionality) and {@see WPDA_Export} (export functionality). | |
| 140 | - * Adds the appropriate actions to the loader. | |
| 141 | - * | |
| 142 | - * @since 1.0.0 | |
| 143 | - * | |
| 144 | - * @see WP_Data_Access_Admin | |
| 145 | - * @see WPDA_Export | |
| 146 | - */ | |
| 147 | - private function define_admin_hooks() { | |
| 148 | - $plugin_admin = new WP_Data_Access_Admin(); | |
| 149 | - if ( WPDA::is_plugin_page( $this->page ) ) { | |
| 150 | - // Handle plugin cookies. | |
| 151 | - $wpda_cookies = new WPDA_Cookies(); | |
| 152 | - $this->loader->add_action( 'admin_init', $wpda_cookies, 'handle_plugin_cookies' ); | |
| 153 | - } | |
| 154 | - // Admin menu. | |
| 155 | - $this->loader->add_action( 'admin_menu', $plugin_admin, 'add_menu_items' ); | |
| 156 | - $this->loader->add_action( | |
| 157 | - 'admin_menu', | |
| 158 | - $plugin_admin, | |
| 159 | - 'add_menu_my_tables', | |
| 160 | - 11 | |
| 161 | - ); | |
| 162 | - $this->loader->add_filter( 'submenu_file', $plugin_admin, 'wpda_submenu_filter' ); | |
| 163 | - // Admin scripts. | |
| 164 | - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); | |
| 165 | - $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); | |
| 166 | - $this->loader->add_action( 'in_admin_header', $plugin_admin, 'user_admin_notices' ); | |
| 167 | - $this->loader->add_action( 'admin_head', $plugin_admin, 'remove_icons' ); | |
| 168 | - // Add settings page. | |
| 169 | - $this->loader->add_action( 'admin_menu', $this, 'wpdataaccess_register_settings_page' ); | |
| 170 | - // Query Builder. | |
| 171 | - $query_builder = new WPDA_Query_Builder(); | |
| 172 | - $this->loader->add_action( 'admin_action_wpda_query_builder_execute_sql', $query_builder, 'execute' ); | |
| 173 | - $this->loader->add_action( 'admin_action_wpda_query_builder_save_sql', $query_builder, 'save' ); | |
| 174 | - $this->loader->add_action( 'admin_action_wpda_query_builder_open_sql', $query_builder, 'open' ); | |
| 175 | - $this->loader->add_action( 'admin_action_wpda_query_builder_delete_sql', $query_builder, 'delete' ); | |
| 176 | - $this->loader->add_action( 'admin_action_wpda_query_builder_get_db_hints', $query_builder, 'get_db_hints' ); | |
| 177 | - $this->loader->add_action( 'admin_action_wpda_query_builder_set_db_hints', $query_builder, 'set_db_hints' ); | |
| 178 | - $this->loader->add_action( 'admin_action_wpda_query_builder_get_vqb', $query_builder, 'get_visual_query' ); | |
| 179 | - // Export action. | |
| 180 | - $this->loader->add_action( 'admin_action_wpda_export', WPDA_Export::class, 'export' ); | |
| 181 | - // Dashboard and widgets. | |
| 182 | - $this->loader->add_action( 'wp_ajax_wpda_save_dashboard', WPDA_Dashboard::class, 'save' ); | |
| 183 | - $this->loader->add_action( 'wp_ajax_wpda_dashboard_list', WPDA_Dashboard::class, 'get_list' ); | |
| 184 | - $this->loader->add_action( 'wp_ajax_wpda_widget_load_panel', WPDA_Dashboard::class, 'load_widget' ); | |
| 185 | - $this->loader->add_action( 'wp_ajax_wpda_widget_delete', WPDA_Dashboard::class, 'delete_widget' ); | |
| 186 | - $this->loader->add_action( 'wp_ajax_wpda_widget_code_add', WPDA_Widget_Code::class, 'ajax_widget' ); | |
| 187 | - $this->loader->add_action( 'wp_ajax_wpda_widget_dbms_add', WPDA_Widget_Dbms::class, 'ajax_widget' ); | |
| 188 | - $this->loader->add_action( 'wp_ajax_wpda_widget_dbms_refresh', WPDA_Widget_Dbms::class, 'ajax_refresh' ); | |
| 189 | - $this->loader->add_action( 'wp_ajax_wpda_remove_new_dashboard_message', WPDA_Dashboard::class, 'remove_new_dashboard_message' ); | |
| 190 | - $this->loader->add_action( 'wp_ajax_wpda_widget_pub_add', WPDA_Widget_Publication::class, 'ajax_widget' ); | |
| 191 | - $this->loader->add_action( 'wp_ajax_wpda_widget_chart_add', WPDA_Widget_Google_Chart::class, 'ajax_widget' ); | |
| 192 | - $this->loader->add_action( 'wp_ajax_wpda_widget_chart_refresh', WPDA_Widget_Google_Chart::class, 'ajax_refresh' ); | |
| 193 | - // Add/remove favourites. | |
| 194 | - $plugin_favourites = new WPDA_Favourites(); | |
| 195 | - $this->loader->add_action( 'admin_action_wpda_add_favourite', $plugin_favourites, 'add' ); | |
| 196 | - $this->loader->add_action( 'admin_action_wpda_rem_favourite', $plugin_favourites, 'rem' ); | |
| 84 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-data-access-loader.php'; | |
| 85 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wp-data-access-i18n.php'; | |
| 86 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wp-data-access-admin.php'; | |
| 87 | + require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wp-data-access-public.php'; | |
| 88 | + | |
| 89 | + $this->loader = new WP_Data_Access_Loader(); | |
| 90 | + | |
| 91 | + } | |
| 92 | + | |
| 93 | + /** | |
| 94 | + * Set locale for internationalization | |
| 95 | + * | |
| 96 | + * @since 1.0.0 | |
| 97 | + * | |
| 98 | + * @see WP_Data_Access_I18n | |
| 99 | + */ | |
| 100 | + private function set_locale() { | |
| 101 | + | |
| 102 | + $wpda_i18n = new WP_Data_Access_I18n(); | |
| 103 | + $this->loader->add_action( 'init', $wpda_i18n, 'load_plugin_textdomain' ); | |
| 104 | + | |
| 105 | + } | |
| 106 | + | |
| 107 | + /** | |
| 108 | + * Add admin hooks | |
| 109 | + * | |
| 110 | + * Initiates {@see WP_Data_Access_Admin} (admin functionality), {@see WPDA_Export} (export functionality) and | |
| 111 | + * {@see WPDA_Example} (example plugin that demostrates the use of WP Data Access by code from another plugin). | |
| 112 | + * Adds the appropriate actions to the loader. | |
| 113 | + * | |
| 114 | + * @since 1.0.0 | |
| 115 | + * | |
| 116 | + * @see WP_Data_Access_Admin | |
| 117 | + * @see WPDA_Export | |
| 118 | + * @see WPDA_Example | |
| 119 | + */ | |
| 120 | + private function define_admin_hooks() { | |
| 121 | + | |
| 122 | + $plugin_admin = new WP_Data_Access_Admin(); | |
| 123 | + | |
| 124 | + // Handle plugin cookies. | |
| 125 | + $this->loader->add_action( 'admin_init' , $plugin_admin, 'handle_plugin_cookies' ); | |
| 126 | + | |
| 127 | + // Admin menu. | |
| 128 | + $this->loader->add_action( 'admin_menu', $plugin_admin, 'add_menu_items' ); | |
| 129 | + $this->loader->add_action( 'admin_menu', $plugin_admin, 'add_menu_my_tables', 11 ); | |
| 130 | + | |
| 131 | + // Admin scripts. | |
| 132 | + $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_styles' ); | |
| 133 | + $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); | |
| 134 | + | |
| 135 | + // TinyMCE listboxes (get table list). | |
| 136 | + $this->loader->add_action( 'admin_footer', $plugin_admin, 'tinymce_listboxes_get_tables' ); | |
| 137 | + | |
| 138 | + // Export action. | |
| 139 | + $plugin_export = new WPDA_Export(); | |
| 140 | + $this->loader->add_action( 'admin_action_wpda_export', $plugin_export, 'export' ); | |
| 141 | + | |
| 142 | + // Example requested. | |
| 143 | + $plugin_example = new WPDA_Example(); | |
| 144 | + $this->loader->add_action( 'admin_action_wpda_example', $plugin_example, 'get_example' ); | |
| 145 | + | |
| 146 | + // Add/remove favourites. | |
| 147 | + $plugin_favourites = new WPDA_Favourites(); | |
| 148 | + $this->loader->add_action( 'admin_action_add_favourite', $plugin_favourites, 'add' ); | |
| 149 | + $this->loader->add_action( 'admin_action_rem_favourite', $plugin_favourites, 'rem' ); | |
| 150 | + | |
| 197 | 151 | // Show tables actions. |
| 198 | 152 | $plugin_table_actions = new WPDA_Table_Actions(); |
| 199 | - $this->loader->add_action( 'admin_action_wpda_show_table_actions', $plugin_table_actions, 'show' ); | |
| 200 | - $plugin_dictionary_list = new WPDA_Dictionary_Lists(); | |
| 201 | - // Get tables for a specific database. | |
| 202 | - $this->loader->add_action( 'admin_action_wpda_get_tables', $plugin_dictionary_list, 'get_tables_ajax' ); | |
| 153 | + $this->loader->add_action( 'admin_action_show_table_actions', $plugin_table_actions, 'show' ); | |
| 154 | + | |
| 203 | 155 | // Get columns for a specific table. |
| 204 | - $this->loader->add_action( 'admin_action_wpda_get_columns', $plugin_dictionary_list, 'get_columns' ); | |
| 205 | - // Get row count for a specific table. | |
| 206 | - $this->loader->add_action( 'admin_action_wpda_get_table_row_count', $plugin_dictionary_list, 'get_table_row_count_ajax' ); | |
| 207 | - // Get table widget info. | |
| 208 | - $this->loader->add_action( 'admin_action_wpda_get_table_widget_info', $plugin_dictionary_list, 'get_table_widget_info' ); | |
| 209 | - // Global database search and replace. | |
| 210 | - $this->loader->add_action( 'wp_ajax_wpda_global_search', \WPDataAccess\Global_Search\WPDA_Global_Search::class, 'search' ); | |
| 211 | - $this->loader->add_action( 'wp_ajax_wpda_global_replace', \WPDataAccess\Global_Search\WPDA_Global_Search::class, 'replace' ); | |
| 156 | + $plugin_column_list = new WPDA_Dictionary_Lists(); | |
| 157 | + $this->loader->add_action( 'admin_action_get_columns', $plugin_column_list, 'get_columns' ); | |
| 158 | + | |
| 212 | 159 | // Export project. |
| 213 | - $plugin_export_project = new WPDP_Export_Project(); | |
| 214 | - $this->loader->add_action( 'admin_action_wpda_export_project', $plugin_export_project, 'export' ); | |
| 215 | - // Data backup. | |
| 216 | - $wpda_data_backup = new WPDA_Data_Export(); | |
| 217 | - $this->loader->add_action( 'wpda_data_backup', $wpda_data_backup, 'wpda_data_backup' ); | |
| 218 | - // Allow to add multiple user roles. | |
| 219 | - $wpda_roles = new WPDA_Roles(); | |
| 220 | - $this->loader->add_action( 'user_new_form', $wpda_roles, 'multiple_roles_selection' ); | |
| 221 | - $this->loader->add_action( 'edit_user_profile', $wpda_roles, 'multiple_roles_selection' ); | |
| 222 | - $this->loader->add_action( 'profile_update', $wpda_roles, 'multiple_roles_update' ); | |
| 223 | - $this->loader->add_filter( 'manage_users_columns', $wpda_roles, 'multiple_roles_label' ); | |
| 224 | - // Check if a remote db connection can be established via ajax. | |
| 225 | - $wpdadb = new WPDADB(); | |
| 226 | - $this->loader->add_action( 'admin_action_wpda_check_remote_database_connection', $wpdadb, 'check_remote_database_connection' ); | |
| 227 | - // Make WordPress user ID available to database connections. | |
| 228 | - add_action( | |
| 229 | - 'wpda_dbinit', | |
| 230 | - function ( $wpdadb ) { | |
| 231 | - if ( null !== $wpdadb ) { | |
| 232 | - $suppress_errors = $wpdadb->suppress_errors( true ); | |
| 233 | - $wpdadb->query( 'set @wpda_wp_user_id = ' . get_current_user_id() ); | |
| 234 | - $wpdadb->suppress_errors( $suppress_errors ); | |
| 235 | - } | |
| 236 | - }, | |
| 237 | - 10, | |
| 238 | - 1 | |
| 239 | - ); | |
| 240 | - add_action( | |
| 241 | - 'wp_ajax_wpda_dbinit_admin', | |
| 242 | - function () { | |
| 243 | - if ( !isset( $_POST['wpnonce'], $_POST['wpdaschema_name'] ) ) { | |
| 244 | - WPDA::sent_header( 'application/json' ); | |
| 245 | - echo WPDA::sent_msg( 'ERROR', 'Invalid arguments' ); | |
| 246 | - // phpcs:ignore WordPress.Security.EscapeOutput | |
| 247 | - wp_die(); | |
| 248 | - } | |
| 249 | - $wpnonce = sanitize_text_field( wp_unslash( $_REQUEST['wpnonce'] ) ); | |
| 250 | - // input var okay. | |
| 251 | - if ( !current_user_can( 'manage_options' ) || !wp_verify_nonce( $wpnonce, 'wpda_dbinit_admin_' . WPDA::get_current_user_login() ) ) { | |
| 252 | - WPDA::sent_header( 'application/json' ); | |
| 253 | - echo WPDA::sent_msg( 'ERROR', 'Not authorized' ); | |
| 254 | - // phpcs:ignore WordPress.Security.EscapeOutput | |
| 255 | - wp_die(); | |
| 256 | - } | |
| 257 | - $wpdaschema_name = sanitize_text_field( wp_unslash( $_REQUEST['wpdaschema_name'] ) ); | |
| 258 | - // input var okay. | |
| 259 | - $wpdadb = WPDADB::get_db_connection( $wpdaschema_name ); | |
| 260 | - if ( null === $wpdadb ) { | |
| 261 | - WPDA::sent_header( 'application/json' ); | |
| 262 | - echo WPDA::sent_msg( 'ERROR', 'Cannot connect to database' ); | |
| 263 | - // phpcs:ignore WordPress.Security.EscapeOutput | |
| 264 | - wp_die(); | |
| 265 | - } | |
| 266 | - $suppress_errors = $wpdadb->suppress_errors( true ); | |
| 267 | - $wpdadb->query( 'create function wpda_get_wp_user_id() returns integer deterministic no sql return @wpda_wp_user_id' ); | |
| 268 | - $error = $wpdadb->last_error; | |
| 269 | - $fnc = $wpdadb->dbh->query( "show function status like 'wpda_get_wp_user_id'" ); | |
| 270 | - $wpdadb->suppress_errors( $suppress_errors ); | |
| 271 | - if ( 1 === count( (array) $fnc ) ) { | |
| 272 | - //phpcs:ignore - 8.1 proof | |
| 273 | - echo WPDA::sent_msg( 'OK', '' ); | |
| 274 | - // phpcs:ignore WordPress.Security.EscapeOutput | |
| 275 | - } else { | |
| 276 | - echo WPDA::sent_msg( 'ERROR', "Function not created [{$error}]" ); | |
| 277 | - // phpcs:ignore WordPress.Security.EscapeOutput | |
| 278 | - } | |
| 279 | - wp_die(); | |
| 280 | - }, | |
| 281 | - 10, | |
| 282 | - 1 | |
| 283 | - ); | |
| 284 | - // Add id to wpda_datatables.js (for IE). | |
| 285 | - $this->loader->add_filter( | |
| 286 | - 'script_loader_tag', | |
| 287 | - $this, | |
| 288 | - 'add_id_to_script', | |
| 289 | - 10, | |
| 290 | - 3 | |
| 291 | - ); | |
| 292 | - // Add CSV mapping calls. | |
| 293 | - $wpda_csv_uploads_model = new WPDA_CSV_Uploads_Model(); | |
| 294 | - $this->loader->add_action( 'admin_action_wpda_save_csv_mapping', $wpda_csv_uploads_model, 'save_mapping' ); | |
| 295 | - $this->loader->add_action( 'admin_action_wpda_csv_preview_mapping', $wpda_csv_uploads_model, 'preview_mapping' ); | |
| 296 | - // Data Tables services. | |
| 297 | - $this->loader->add_action( 'wp_ajax_wpda_test_publication', \WPDataAccess\Data_Publisher\WPDA_Publisher_Form::class, 'test_publication' ); | |
| 298 | - // Add custom CSS to freemius pages. | |
| 299 | - add_action( | |
| 300 | - 'admin_footer', | |
| 301 | - function () { | |
| 302 | - if ( 'wpda-account' === $this->page || 'wpda-pricing' === $this->page ) { | |
| 303 | - ?> | |
| 304 | - <script type="application/javascript"> | |
| 305 | - jQuery(function() { | |
| 306 | - jQuery.each(document.styleSheets, function (index, cssFile) { | |
| 307 | - if (cssFile.href!==null && cssFile.href.toString().includes("load-styles.php")) { | |
| 308 | - var classes = cssFile.rules || cssFile.cssRules; | |
| 309 | - for (var x=0; x<classes.length; x++) { | |
| 310 | - if ( | |
| 311 | - classes[x].selectorText!==undefined && | |
| 312 | - classes[x].selectorText!==null && | |
| 313 | - classes[x].selectorText.includes("#adminmenu li.current a.menu-top") | |
| 314 | - ) { | |
| 315 | - jQuery("#adminmenu #toplevel_page_wpda a.menu-top").attr("style", classes[x].style.cssText); | |
| 316 | - } | |
| 317 | - } | |
| 318 | - } | |
| 319 | - }); | |
| 320 | - }); | |
| 321 | - </script> | |
| 322 | - <?php | |
| 323 | - } | |
| 324 | - }, | |
| 325 | - 10, | |
| 326 | - 1 | |
| 327 | - ); | |
| 328 | - } | |
| 160 | + $plugin_export_project = new WPDP_Export_Project(); | |
| 161 | + $this->loader->add_action( 'admin_action_wpdp_export_project', $plugin_export_project, 'export' ); | |
| 329 | 162 | |
| 330 | - /** | |
| 331 | - * Needed for JDT to support IE | |
| 332 | - * | |
| 333 | - * @param string $tag Tag. | |
| 334 | - * @param string $handle Handle. | |
| 335 | - * @param string $src Source. | |
| 336 | - * @return mixed|string | |
| 337 | - */ | |
| 338 | - public function add_id_to_script( $tag, $handle, $src ) { | |
| 339 | - if ( 'wpda_datatables' === $handle ) { | |
| 340 | - $tag = '<script id="wpda_datatables" src="' . $src . '"></script>'; | |
| 341 | - // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript | |
| 342 | - } | |
| 343 | - return $tag; | |
| 344 | - } | |
| 163 | + // Data backup. | |
| 164 | + $wpda_data_backup = new WPDA_Data_Export(); | |
| 165 | + $this->loader->add_action( 'wpda_data_backup', $wpda_data_backup, 'wpda_data_backup' ); | |
| 345 | 166 | |
| 346 | - /** | |
| 347 | - * Add public hooks | |
| 348 | - * | |
| 349 | - * Initiates {@see WP_Data_Access_Public} (public functionality), {@see WPDA_Data_Tables} (ajax call to support | |
| 350 | - * server side jQuery DataTables functionality). Adds the appropriate actions to | |
| 351 | - * the loader. | |
| 352 | - * | |
| 353 | - * @since 1.0.0 | |
| 354 | - * | |
| 355 | - * @see WP_Data_Access_Public | |
| 356 | - * @see WPDA_Data_Tables | |
| 357 | - * @see WPDA_Dictionary_Lists | |
| 358 | - */ | |
| 359 | - private function define_public_hooks() { | |
| 360 | - $plugin_public = new WP_Data_Access_Public(); | |
| 361 | - // Shortcodes. | |
| 362 | - $this->loader->add_action( 'init', $plugin_public, 'register_shortcodes' ); | |
| 363 | - // Public scripts. | |
| 364 | - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); | |
| 365 | - $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); | |
| 366 | - $this->loader->add_action( | |
| 367 | - 'admin_bar_menu', | |
| 368 | - $plugin_public, | |
| 369 | - 'add_apps_to_admin_toolbar', | |
| 370 | - 9999 | |
| 371 | - ); | |
| 372 | - $this->loader->add_action( | |
| 373 | - 'admin_bar_menu', | |
| 374 | - $plugin_public, | |
| 375 | - 'add_data_projects_to_admin_toolbar', | |
| 376 | - 9999 | |
| 377 | - ); | |
| 378 | - // Ajax calls. | |
| 379 | - $plugin_datatables = new WPDA_Data_Tables(); | |
| 380 | - $this->loader->add_action( 'wp_ajax_wpda_datatables', $plugin_datatables, 'get_data' ); | |
| 381 | - $this->loader->add_action( 'wp_ajax_nopriv_wpda_datatables', $plugin_datatables, 'get_data' ); | |
| 382 | - // Export action. | |
| 383 | - $this->loader->add_action( 'wp_ajax_wpda_export', WPDA_Export::class, 'export_ajax' ); | |
| 384 | - $this->loader->add_action( 'wp_ajax_nopriv_wpda_export', WPDA_Export::class, 'export_ajax' ); | |
| 385 | - // Add id to wpda_datatables.js (for IE). | |
| 386 | - $this->loader->add_filter( | |
| 387 | - 'script_loader_tag', | |
| 388 | - $this, | |
| 389 | - 'add_id_to_script', | |
| 390 | - 10, | |
| 391 | - 3 | |
| 392 | - ); | |
| 393 | - // Autocomplete. | |
| 394 | - $autocomplete_service = new WPDA_Autocomplete(); | |
| 395 | - $this->loader->add_action( 'wp_ajax_wpda_autocomplete', $autocomplete_service, 'autocomplete' ); | |
| 396 | - $this->loader->add_action( 'wp_ajax_nopriv_wpda_autocomplete', $autocomplete_service, 'autocomplete_anonymous' ); | |
| 397 | - } | |
| 167 | + } | |
| 398 | 168 | |
| 399 | - /** | |
| 400 | - * Start plugin loader | |
| 401 | - * | |
| 402 | - * @since 1.0.0 | |
| 403 | - */ | |
| 404 | - public function run() { | |
| 405 | - $this->loader->run(); | |
| 406 | - } | |
| 169 | + /** | |
| 170 | + * Add public hooks | |
| 171 | + * | |
| 172 | + * Initiates {@see WP_Data_Access_Public} (public functionality), {@see WPDA_Data_Tables} (ajax call to support | |
| 173 | + * server side jQuery DataTables functionality) and {@see WPDA_Dictionary_Lists} (table and column list for tables | |
| 174 | + * to which access is granted to the front-end to support the shortcode wizard). Adds the appropriate actions to | |
| 175 | + * the loader. | |
| 176 | + * | |
| 177 | + * @since 1.0.0 | |
| 178 | + * | |
| 179 | + * @see WP_Data_Access_Public | |
| 180 | + * @see WPDA_Data_Tables | |
| 181 | + * @see WPDA_Dictionary_Lists | |
| 182 | + */ | |
| 183 | + private function define_public_hooks() { | |
| 407 | 184 | |
| 408 | - /** | |
| 409 | - * Add plugin settings page | |
| 410 | - */ | |
| 411 | - public function wpdataaccess_register_settings_page() { | |
| 412 | - add_options_page( | |
| 413 | - 'WP Data Access', | |
| 414 | - 'WP Data Access', | |
| 415 | - 'manage_options', | |
| 416 | - WP_Data_Access_Admin::PAGE_SETTINGS, | |
| 417 | - array($this, 'wpdataaccess_settings_page') | |
| 418 | - ); | |
| 419 | - } | |
| 185 | + $plugin_public = new WP_Data_Access_Public(); | |
| 420 | 186 | |
| 421 | - /** | |
| 422 | - * Show settings page | |
| 423 | - */ | |
| 424 | - public function wpdataaccess_settings_page() { | |
| 425 | - WPDA_Dashboard::add_dashboard(); | |
| 426 | - $current_tab = ( isset( $_REQUEST['tab'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['tab'] ) ) : 'plugin' ); | |
| 427 | - // phpcs:ignore WordPress.Security.NonceVerification | |
| 428 | - switch ( $current_tab ) { | |
| 429 | - case 'backend': | |
| 430 | - $wpda_settings_class_name = 'WPDA_Settings_BackEnd'; | |
| 431 | - $help_url = 'https://wpdataaccess.com/docs/plugin-settings/back-end/'; | |
| 432 | - break; | |
| 433 | - case 'frontend': | |
| 434 | - $wpda_settings_class_name = 'WPDA_Settings_FrontEnd'; | |
| 435 | - $help_url = 'https://wpdataaccess.com/docs/plugin-settings/front-end/'; | |
| 436 | - break; | |
| 437 | - case 'pds': | |
| 438 | - $wpda_settings_class_name = 'WPDA_Settings_PDS'; | |
| 439 | - $help_url = 'https://wpdataaccess.com/docs/plugin-settings/premium-data-services/'; | |
| 440 | - break; | |
| 441 | - case 'dashboard': | |
| 442 | - $wpda_settings_class_name = 'WPDA_Settings_Dashboard'; | |
| 443 | - $help_url = 'https://wpdataaccess.com/docs/plugin-settings/dashboard/'; | |
| 444 | - break; | |
| 445 | - case 'datatables': | |
| 446 | - $wpda_settings_class_name = 'WPDA_Settings_DataTables'; | |
| 447 | - $help_url = 'https://wpdataaccess.com/docs/plugin-settings/data-tables/'; | |
| 448 | - break; | |
| 449 | - case 'dataforms': | |
| 450 | - $wpda_settings_class_name = 'WPDA_Settings_DataForms'; | |
| 451 | - $help_url = 'https://wpdataaccess.com/docs/plugin-settings/data-forms/'; | |
| 452 | - break; | |
| 453 | - case 'databackup': | |
| 454 | - $wpda_settings_class_name = 'WPDA_Settings_DataBackup'; | |
| 455 | - $help_url = 'https://wpdataaccess.com/docs/plugin-settings/data-backup/'; | |
| 456 | - break; | |
| 457 | - case 'uninstall': | |
| 458 | - $wpda_settings_class_name = 'WPDA_Settings_Uninstall'; | |
| 459 | - $help_url = 'https://wpdataaccess.com/docs/plugin-settings/uninstall/'; | |
| 460 | - break; | |
| 461 | - case 'repository': | |
| 462 | - $wpda_settings_class_name = 'WPDA_Settings_ManageRepository'; | |
| 463 | - $help_url = 'https://wpdataaccess.com/docs/plugin-settings/manage-repository/'; | |
| 464 | - break; | |
| 465 | - case 'roles': | |
| 466 | - $wpda_settings_class_name = 'WPDA_Settings_ManageRoles'; | |
| 467 | - $help_url = 'https://wpdataaccess.com/docs/plugin-settings/manage-roles/'; | |
| 468 | - break; | |
| 469 | - case 'system': | |
| 470 | - $wpda_settings_class_name = 'WPDA_Settings_SystemInfo'; | |
| 471 | - $help_url = 'https://wpdataaccess.com/docs/plugin-settings/system-info/'; | |
| 472 | - break; | |
| 473 | - default: | |
| 474 | - $wpda_settings_class_name = 'WPDA_Settings_Plugin'; | |
| 475 | - $help_url = 'https://wpdataaccess.com/docs/plugin-settings/plugin/'; | |
| 476 | - } | |
| 477 | - $wpda_settings_class_name = '\\WPDataAccess\\Settings\\' . $wpda_settings_class_name; | |
| 478 | - $wpda_settings = new $wpda_settings_class_name($current_tab, $help_url); | |
| 479 | - $wpda_settings->show(); | |
| 480 | - } | |
| 187 | + // Shortcodes. | |
| 188 | + $this->loader->add_action( 'init', $plugin_public, 'register_shortcodes' ); | |
| 189 | + $this->loader->add_action( 'init', $plugin_public, 'wpdataaccess_shortcode_button_init' ); | |
| 190 | + | |
| 191 | + // Public scripts. | |
| 192 | + $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); | |
| 193 | + $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); | |
| 194 | + | |
| 195 | + // Ajax calls. | |
| 196 | + $plugin_datatables = new WPDA_Data_Tables(); | |
| 197 | + $this->loader->add_action( 'wp_ajax_wpda_datatables', $plugin_datatables, 'get_data' ); | |
| 198 | + $this->loader->add_action( 'wp_ajax_nopriv_wpda_datatables', $plugin_datatables, 'get_data' ); | |
| 199 | + | |
| 200 | + // Ajax calls to dynamically load listbox content (tables and columns). | |
| 201 | + $plugin_tinymce_listboxes = new WPDA_Dictionary_Lists(); | |
| 202 | + $this->loader->add_action( 'wp_ajax_wpda_tinymce_listbox_tables', $plugin_tinymce_listboxes, 'get_tables_tinymce_listbox' ); | |
| 203 | + $this->loader->add_action( 'wp_ajax_nopriv_wpda_tinymce_listbox_tables', $plugin_tinymce_listboxes, 'get_tables_tinymce_listbox' ); | |
| 204 | + $this->loader->add_action( 'wp_ajax_wpda_tinymce_listbox_columns', $plugin_tinymce_listboxes, 'get_columns_tinymce_listbox' ); | |
| 205 | + $this->loader->add_action( 'wp_ajax_nopriv_wpda_tinymce_listbox_columns', $plugin_tinymce_listboxes, 'get_columns_tinymce_listbox' ); | |
| 206 | + | |
| 207 | + } | |
| 208 | + | |
| 209 | + /** | |
| 210 | + * Start plugin loader | |
| 211 | + * | |
| 212 | + * @since 1.0.0 | |
| 213 | + */ | |
| 214 | + public function run() { | |
| 215 | + | |
| 216 | + $this->loader->run(); | |
| 217 | + | |
| 218 | + } | |
| 481 | 219 | |
| 482 | 220 | } |