function __construct($plugin_file_path)
 {
     $this->is_pro = true;
     $this->unhook_templates = array('exclude_post_revisions', 'wordpress_org_support', 'progress_upgrade', 'sidebar');
     parent::__construct($plugin_file_path);
     // templating actions
     add_action('wpmdb_notices', array($this, 'template_outdated_addons_warning'));
     add_action('wpmdb_notices', array($this, 'template_secret_key_warning'));
     add_action('wpmdb_notices', array($this, 'template_block_external_warning'));
     // Internal AJAX handlers
     add_action('wp_ajax_wpmdb_verify_connection_to_remote_site', array($this, 'ajax_verify_connection_to_remote_site'));
     add_action('wp_ajax_wpmdb_finalize_migration', array($this, 'ajax_finalize_migration'));
     add_action('wp_ajax_wpmdb_fire_migration_complete', array($this, 'fire_migration_complete'));
     add_action('wp_ajax_wpmdb_flush', array($this, 'ajax_flush'));
     // Required for Pull if user tables being updated.
     add_action('wp_ajax_nopriv_wpmdb_flush', array($this, 'ajax_nopriv_flush'));
     add_action('wp_ajax_wpmdb_reset_api_key', array($this, 'ajax_reset_api_key'));
     add_action('wp_ajax_wpmdb_save_setting', array($this, 'ajax_save_setting'));
     add_action('wp_ajax_wpmdb_activate_licence', array($this, 'ajax_activate_licence'));
     add_action('wp_ajax_wpmdb_check_licence', array($this, 'ajax_check_licence'));
     add_action('wp_ajax_wpmdb_copy_licence_to_remote_site', array($this, 'ajax_copy_licence_to_remote_site'));
     add_action('wp_ajax_wpmdb_reactivate_licence', array($this, 'ajax_reactivate_licence'));
     add_action('wp_ajax_wpmdb_process_notice_link', array($this, 'ajax_process_notice_link'));
     // external AJAX handlers
     add_action('wp_ajax_nopriv_wpmdb_verify_connection_to_remote_site', array($this, 'respond_to_verify_connection_to_remote_site'));
     add_action('wp_ajax_nopriv_wpmdb_remote_initiate_migration', array($this, 'respond_to_remote_initiate_migration'));
     add_action('wp_ajax_nopriv_wpmdb_process_chunk', array($this, 'respond_to_process_chunk'));
     add_action('wp_ajax_nopriv_wpmdb_process_pull_request', array($this, 'respond_to_process_pull_request'));
     add_action('wp_ajax_nopriv_wpmdb_fire_migration_complete', array($this, 'fire_migration_complete'));
     add_action('wp_ajax_nopriv_wpmdb_backup_remote_table', array($this, 'respond_to_backup_remote_table'));
     add_action('wp_ajax_nopriv_wpmdb_remote_finalize_migration', array($this, 'respond_to_remote_finalize_migration'));
     add_action('wp_ajax_nopriv_wpmdb_remote_flush', array($this, 'respond_to_remote_flush'));
     add_action('wp_ajax_nopriv_wpmdb_process_push_migration_cancellation', array($this, 'respond_to_process_push_migration_cancellation'));
     add_action('wp_ajax_nopriv_wpmdb_copy_licence_to_remote_site', array($this, 'respond_to_copy_licence_to_remote_site'));
     // Take over the update check
     add_filter('site_transient_update_plugins', array($this, 'site_transient_update_plugins'));
     // Add some custom JS into the WP admin pages
     add_action('admin_enqueue_scripts', array($this, 'enqueue_plugin_update_script'));
     // Add some custom CSS into the WP admin pages
     add_action('admin_head-plugins.php', array($this, 'add_plugin_update_styles'));
     // Hook into the plugin install process, inject addon download url
     add_filter('plugins_api', array($this, 'inject_addon_install_resource'), 10, 3);
     // Short circuit the HTTP request to WordPress.org for plugin information
     add_filter('plugins_api', array($this, 'short_circuit_wordpress_org_plugin_info_request'), 10, 3);
     // Clear update transients when the user clicks the "Check Again" button from the update screen
     add_action('current_screen', array($this, 'check_again_clear_transients'));
     // Add after_plugin_row... action for pro plugin and all addons
     add_action('after_plugin_row_wp-migrate-db-pro/wp-migrate-db-pro.php', array($this, 'plugin_row'), 11, 2);
     add_action('after_plugin_row_wp-migrate-db-pro-cli/wp-migrate-db-pro-cli.php', array($this, 'plugin_row'), 11, 2);
     add_action('after_plugin_row_wp-migrate-db-pro-media-files/wp-migrate-db-pro-media-files.php', array($this, 'plugin_row'), 11, 2);
     add_action('after_plugin_row_wp-migrate-db-pro-multisite-tools/wp-migrate-db-pro-multisite-tools.php', array($this, 'plugin_row'), 11, 2);
     // Seen when the user clicks "view details" on the plugin listing page
     add_action('install_plugins_pre_plugin-information', array($this, 'plugin_update_popup'));
     // Removes the exclude post revision functionality (as seen in the free version of the plugin)
     $this->remove_exclude_post_revision_functionality();
     // Check if WP Engine is filtering the buffer and prevent it. Added here for ajax pull requests
     $this->maybe_disable_wp_engine_filtering();
     $this->add_tabs();
 }
 /**
  * Stub for ajax_finalize_migration()
  * hooks on: wpmdb_cli_finalize_migration_response
  *
  * @param string $response
  *
  * @return string
  */
 function finalize_ajax($response)
 {
     // don't send redundant POST variables
     $args = $this->filter_post_elements($this->post_data, array('action', 'migration_state_id', 'prefix', 'tables'));
     $_POST = $args;
     $response = $this->wpmdb->ajax_finalize_migration();
     return trim($response);
 }
Exemple #3
0
 function __construct($plugin_file_path)
 {
     $this->is_pro = true;
     $this->unhook_templates = array('exclude_post_revisions', 'wordpress_org_support', 'progress_upgrade', 'sidebar');
     parent::__construct($plugin_file_path);
     // templating actions
     add_action('wpmdb_notices', array($this, 'template_outdated_addons_warning'));
     // Internal AJAX handlers
     add_action('wp_ajax_wpmdb_verify_connection_to_remote_site', array($this, 'ajax_verify_connection_to_remote_site'));
     add_action('wp_ajax_wpmdb_reset_api_key', array($this, 'ajax_reset_api_key'));
     add_action('wp_ajax_wpmdb_save_setting', array($this, 'ajax_save_setting'));
     add_action('wp_ajax_wpmdb_activate_licence', array($this, 'ajax_activate_licence'));
     add_action('wp_ajax_wpmdb_check_licence', array($this, 'ajax_check_licence'));
     // external AJAX handlers
     add_action('wp_ajax_nopriv_wpmdb_verify_connection_to_remote_site', array($this, 'respond_to_verify_connection_to_remote_site'));
     add_action('wp_ajax_nopriv_wpmdb_remote_initiate_migration', array($this, 'respond_to_remote_initiate_migration'));
     add_action('wp_ajax_nopriv_wpmdb_process_chunk', array($this, 'ajax_process_chunk'));
     add_action('wp_ajax_nopriv_wpmdb_process_pull_request', array($this, 'respond_to_process_pull_request'));
     add_action('wp_ajax_nopriv_wpmdb_fire_migration_complete', array($this, 'fire_migration_complete'));
     add_action('wp_ajax_nopriv_wpmdb_backup_remote_table', array($this, 'respond_to_backup_remote_table'));
     add_action('wp_ajax_nopriv_wpmdb_remote_finalize_migration', array($this, 'respond_to_remote_finalize_migration'));
     add_action('wp_ajax_nopriv_wpmdb_process_push_migration_cancellation', array($this, 'respond_to_process_push_migration_cancellation'));
     // Take over the update check
     add_filter('site_transient_update_plugins', array($this, 'site_transient_update_plugins'));
     // Add some custom JS into the WP admin pages
     add_action('admin_enqueue_scripts', array($this, 'enqueue_plugin_update_script'));
     // Add some custom CSS into the WP admin pages
     add_action('admin_head-plugins.php', array($this, 'add_plugin_update_styles'));
     // Hook into the plugin install process, inject addon download url
     add_action('plugins_api', array($this, 'inject_addon_install_resource'), 10, 3);
     // Clear update transients when the user clicks the "Check Again" button from the update screen
     add_action('current_screen', array($this, 'check_again_clear_transients'));
     // Removes the exclude post revision functionality (as seen in the free version of the plugin)
     $this->remove_exclude_post_revision_functionality();
     $this->add_tabs();
     // Stores a list of MySQL tables for use within the various plugin page templates
     $this->tables = $this->get_table_sizes();
 }
Exemple #4
0
 /**
  * Sanitize and validate data.
  *
  * @param string|array $data            The data to the sanitized.
  * @param string|array $key_rules       The keys in the data (if data is an array) and the sanitization rule(s) to apply for each key.
  * @param string       $context         Additional context data for messages etc.
  * @param int          $recursion_level How deep in the recursion are we? Optional, defaults to 0.
  *
  * @return mixed The sanitized data, the data if no key rules supplied or `false` if an unrecognized rule supplied.
  */
 private static function _sanitize_data($data, $key_rules, $context, $recursion_level = 0)
 {
     if (empty($data) || empty($key_rules)) {
         return $data;
     }
     if (0 === $recursion_level && is_array($data)) {
         // We always expect associative arrays.
         if (!is_array($key_rules)) {
             wp_die(sprintf(__('%1$s was not expecting data to be an array.', 'wp-db-migrate-pro'), $context));
             return false;
         }
         foreach ($data as $key => $value) {
             // If a key does not have a rule it's not ours and can be removed.
             // We should not fail if there is extra data as plugins like Polylang add their own data to each ajax request.
             if (!array_key_exists($key, $key_rules)) {
                 unset($data[$key]);
                 continue;
             }
             $data[$key] = WPMDB_Sanitize::_sanitize_data($value, $key_rules[$key], $context, $recursion_level + 1);
         }
     } elseif (is_array($key_rules)) {
         foreach ($key_rules as $rule) {
             $data = WPMDB_Sanitize::_sanitize_data($data, $rule, $context, $recursion_level + 1);
         }
     } else {
         // Neither $data or $key_rules are a first level array so can be analysed.
         if ('array' == $key_rules) {
             if (!is_array($data)) {
                 wp_die(sprintf(__('%1$s was expecting an array but got something else: "%2$s"', 'wp-db-migrate-pro'), $context, $data));
                 return false;
             }
         } elseif ('string' == $key_rules) {
             if (!is_string($data)) {
                 wp_die(sprintf(__('%1$s was expecting a string but got something else: "%2$s"', 'wp-db-migrate-pro'), $context, $data));
                 return false;
             }
         } elseif ('key' == $key_rules) {
             $key_name = sanitize_key($data);
             if ($key_name !== $data) {
                 wp_die(sprintf(__('%1$s was expecting a valid key but got something else: "%2$s"', 'wp-db-migrate-pro'), $context, $data));
                 return false;
             }
             $data = $key_name;
         } elseif ('text' == $key_rules) {
             $text = sanitize_text_field($data);
             if ($text !== $data) {
                 wp_die(sprintf(__('%1$s was expecting text but got something else: "%2$s"', 'wp-db-migrate-pro'), $context, $data));
                 return false;
             }
             $data = $text;
         } elseif ('serialized' == $key_rules) {
             if (!is_string($data) || !is_serialized($data)) {
                 wp_die(sprintf(__('%1$s was expecting serialized data but got something else: "%2$s"', 'wp-db-migrate-pro'), $context, $data));
                 return false;
             }
         } elseif ('json_array' == $key_rules) {
             if (!is_string($data) || !WPMDB::is_json($data)) {
                 wp_die(sprintf(__('%1$s was expecting JSON data but got something else: "%2$s"', 'wp-db-migrate-pro'), $context, $data));
                 return false;
             }
             $data = json_decode($data, true);
         } elseif ('json' == $key_rules) {
             if (!is_string($data) || !WPMDB::is_json($data)) {
                 wp_die(sprintf(__('%1$s was expecting JSON data but got something else: "%2$s"', 'wp-db-migrate-pro'), $context, $data));
                 return false;
             }
         } elseif ('numeric' == $key_rules) {
             if (!is_numeric($data)) {
                 wp_die(sprintf(__('%1$s was expecting a valid numeric but got something else: "%2$s"', 'wp-db-migrate-pro'), $context, $data));
                 return false;
             }
         } elseif ('int' == $key_rules) {
             // As we are sanitizing form data, even integers are within a string.
             if (!is_numeric($data) || (int) $data != $data) {
                 wp_die(sprintf(__('%1$s was expecting an integer but got something else: "%2$s"', 'wp-db-migrate-pro'), $context, $data));
                 return false;
             }
             $data = (int) $data;
         } elseif ('positive_int' == $key_rules) {
             if (!is_numeric($data) || (int) $data != $data || 0 > $data) {
                 wp_die(sprintf(__('%1$s was expecting a positive number (int) but got something else: "%2$s"', 'wp-db-migrate-pro'), $context, $data));
                 return false;
             }
             $data = floor($data);
         } elseif ('negative_int' == $key_rules) {
             if (!is_numeric($data) || (int) $data != $data || 0 < $data) {
                 wp_die(sprintf(__('%1$s was expecting a negative number (int) but got something else: "%2$s"', 'wp-db-migrate-pro'), $context, $data));
                 return false;
             }
             $data = ceil($data);
         } elseif ('zero_int' == $key_rules) {
             if (!is_numeric($data) || (int) $data != $data || 0 !== $data) {
                 wp_die(sprintf(__('%1$s was expecting 0 (int) but got something else: "%2$s"', 'wp-db-migrate-pro'), $context, $data));
                 return false;
             }
             $data = 0;
         } elseif ('empty' == $key_rules) {
             if (!empty($data)) {
                 wp_die(sprintf(__('%1$s was expecting an empty value but got something else: "%2$s"', 'wp-db-migrate-pro'), $context, $data));
                 return false;
             }
         } elseif ('url' == $key_rules) {
             $url = esc_url_raw($data);
             if (empty($url)) {
                 wp_die(sprintf(__('%1$s was expecting a URL but got something else: "%2$s"', 'wp-db-migrate-pro'), $context, $data));
                 return false;
             }
             $data = $url;
         } elseif ('bool' == $key_rules) {
             $bool = sanitize_key($data);
             if (empty($bool) || !in_array($bool, array('true', 'false'))) {
                 wp_die(sprintf(__('%1$s was expecting a bool but got something else: "%2$s"', 'wp-db-migrate-pro'), $context, $data));
                 return false;
             }
             $data = $bool;
         } else {
             wp_die(sprintf(__('Unknown sanitization rule "%1$s" supplied by %2$s', 'wp-db-migrate-pro'), $key_rules, $context));
             return false;
         }
     }
     return $data;
 }
Exemple #5
0
 /**
  * stub for ajax_migrate_table()
  *
  * @param array|bool $args
  *
  * @return string
  */
 function migrate_table($args = false)
 {
     $_POST = $args;
     $response = $this->wpmdb->ajax_migrate_table();
     return $response;
 }