function wp_migrate_db_loaded() { // exit quickly unless: standalone admin; multisite network admin; one of our AJAX calls if (!is_admin() || is_multisite() && !is_network_admin() && !WPMDB_Utils::is_ajax()) { return; } wp_migrate_db(); }
function wp_migrate_db_loaded() { // exit quickly unless: standalone admin; one of our AJAX calls if (!is_admin() || is_multisite() && !current_user_can('manage_network_options') && !WPMDB_Utils::is_ajax()) { return false; } wp_migrate_db(); }
/** * once all plugins are loaded, load up the rest of this plugin * * @return boolean */ function wp_migrate_db_pro_loaded() { // load if it is wp-cli, so that version update will show in wp-cli if (defined('WP_CLI') && WP_CLI) { wp_migrate_db_pro(); return true; } // exit quickly unless: standalone admin; one of our AJAX calls if (!is_admin() || is_multisite() && !current_user_can('manage_network_options') && !WPMDB_Utils::is_ajax()) { return false; } wp_migrate_db_pro(); return true; }
/** * When the "Use SSL for WP-admin and WP-login" option is checked in the * WP Engine settings, the WP Engine must-use plugin buffers the output and * does a find & replace for URLs. When we return PHP serialized data, it * replaces http:// with https:// and corrupts the serialization. * So here, we disable this filtering for our requests. */ function maybe_disable_wp_engine_filtering() { // Detect if the must-use WP Engine plugin is running if (!defined('WPE_PLUGIN_BASE')) { return; } // Make sure this is a WP Migrate DB Ajax request if (!class_exists('WPMDB_Utils') || !WPMDB_Utils::is_ajax()) { return; } // Turn off WP Engine's output filtering if (!defined('WPE_NO_HTML_FILTER')) { define('WPE_NO_HTML_FILTER', true); } }
/** * Returns validated and sanitized form data. * * @param array|string $data * * @return array|string * * This is a base implementation that should be overridden and included with a call to parent before validating form_data contents. */ function parse_migration_form_data($data) { parse_str($data, $form_data); // As the magic_quotes_gpc setting affects the output of parse_str() we may need to remove any quote escaping. // (it uses the same mechanism that PHP > uses to populate the $_GET, $_POST, etc. variables) if (get_magic_quotes_gpc()) { $form_data = WPMDB_Utils::safe_wp_unslash($form_data); } return $form_data; }
/** * Sends the local WP Migrate DB Pro licence to the remote machine and activates it, returns errors if applicable. * * @return array Empty array or an array containing an error message. */ function ajax_copy_licence_to_remote_site() { $this->check_ajax_referer('copy-licence-to-remote-site'); $key_rules = array('action' => 'key', 'url' => 'url', 'key' => 'string', 'nonce' => 'key'); $this->set_post_data($key_rules); $return = array(); $data = array('action' => 'wpmdb_copy_licence_to_remote_site', 'licence' => $this->get_licence_key()); $data['sig'] = $this->create_signature($data, $this->state_data['key']); $ajax_url = $this->ajax_url(); $serialized_response = $this->remote_post($ajax_url, $data, __FUNCTION__, array(), true); if (false === $serialized_response) { $return = array('wpmdb_error' => 1, 'body' => $this->error); $result = $this->end_ajax(json_encode($return)); return $result; } $response = WPMDB_Utils::unserialize($serialized_response, __METHOD__); if (false === $response) { $error_msg = __('Failed attempting to unserialize the response from the remote server. Please contact support.', 'wp-migrate-db'); $return = array('wpmdb_error' => 1, 'body' => $error_msg); $this->log_error($error_msg, $serialized_response); $result = $this->end_ajax(json_encode($return)); return $result; } if (isset($response['error']) && $response['error'] == 1) { $return = array('wpmdb_error' => 1, 'body' => $response['message']); $this->log_error($response['message'], $response); $result = $this->end_ajax(json_encode($return)); return $result; } $result = $this->end_ajax(json_encode($return)); return $result; }
/** * Take a serialized array and unserialize it replacing elements as needed and * unserialising any subordinate arrays and performing the replace on those too. * * Mostly from https://github.com/interconnectit/Search-Replace-DB * * @param mixed $data Used to pass any subordinate arrays back to in. * @param bool $serialized Does the array passed via $data need serialising. * @param bool $parent_serialized Passes whether the original data passed in was serialized * @param bool $filtered Should we apply before and after filters successively * * @return mixed The original array with all elements replaced as needed. */ function recursive_unserialize_replace($data, $serialized = false, $parent_serialized = false, $filtered = true) { $pre = apply_filters('wpmdb_pre_recursive_unserialize_replace', false, $data, $this); if (false !== $pre) { return $pre; } $is_json = false; $before_fired = false; $successive_filter = $filtered; if (true === $filtered) { list($data, $before_fired, $successive_filter) = apply_filters('wpmdb_before_replace_custom_data', array($data, $before_fired, $successive_filter), $this); } // some unserialized data cannot be re-serialized eg. SimpleXMLElements try { if (is_string($data) && ($unserialized = WPMDB_Utils::unserialize($data, __METHOD__)) !== false) { // PHP currently has a bug that doesn't allow you to clone the DateInterval / DatePeriod classes. // We skip them here as they probably won't need data to be replaced anyway if (is_object($unserialized)) { if ($unserialized instanceof DateInterval || $unserialized instanceof DatePeriod) { return $data; } } $data = $this->recursive_unserialize_replace($unserialized, true, true, $successive_filter); } elseif (is_array($data)) { $_tmp = array(); foreach ($data as $key => $value) { $_tmp[$key] = $this->recursive_unserialize_replace($value, false, $parent_serialized, $successive_filter); } $data = $_tmp; unset($_tmp); } elseif (is_object($data)) { // Submitted by Tina Matter $_tmp = clone $data; foreach ($data as $key => $value) { // Integer properties are crazy and the best thing we can do is to just ignore them. // see http://stackoverflow.com/a/10333200 and https://github.com/deliciousbrains/wp-migrate-db-pro/issues/853 if (is_int($key)) { continue; } $_tmp->{$key} = $this->recursive_unserialize_replace($value, false, $parent_serialized, $successive_filter); } $data = $_tmp; unset($_tmp); } elseif ($this->wpmdb->is_json($data, true)) { $_tmp = array(); $data = json_decode($data, true); foreach ($data as $key => $value) { $_tmp[$key] = $this->recursive_unserialize_replace($value, false, $parent_serialized, $successive_filter); } $data = $_tmp; unset($_tmp); $is_json = true; } elseif (is_string($data)) { list($data, $do_replace) = apply_filters('wpmdb_replace_custom_data', array($data, true), $this); if ($do_replace) { $data = $this->apply_replaces($data); } } if ($is_json) { $data = json_encode($data); } if ($serialized) { $data = serialize($data); } } catch (Exception $error) { $error_msg = __('Failed attempting to do the recursive unserialize replace. Please contact support.', 'wp-migrate-db'); $error_details = $error->getMessage() . "\n\n"; $error_details .= var_export($data, true); $this->wpmdb->log_error($error_msg, $error_details); } if (true === $filtered) { $data = apply_filters('wpmdb_after_replace_custom_data', $data, $before_fired, $this); } return $data; }