-
-
-
-
- %2$s %3$s',
- esc_url( $update_php_url ),
- __( 'Learn more about updating PHP' ),
- /* translators: accessibility text */
- __( '(opens in a new tab)' )
- );
- ?>
-
-
- composer install.', 'vaultpress' ),
- array( 'code' => true )
- )
- );
- }
- /**
- * Outputs an admin notice for folks running VaultPress without having run `composer install`.
- */
- function vaultpress_admin_missing_autoloader() {
- ?>
-
-
-
- here.', 'vaultpress' ),
- array(
- 'a' => array(
- 'href' => array(),
- 'target' => array(),
- 'rel' => array(),
- ),
- )
- ),
- 'https://dashboard.vaultpress.com/account/'
- );
- ?>
-
-
-
- output();
- }
-
- function get_config( $key ) {
- $val = get_option( $key );
- if ( $val )
- return $val;
- switch( $key ) {
- case '_vp_config_option_name_ignore':
- $val = $this->get_option_name_ignore( true );
- update_option( '_vp_config_option_name_ignore', $val );
- break;
- case '_vp_config_post_meta_name_ignore':
- $val = $this->get_post_meta_name_ignore( true );
- update_option( '_vp_config_post_meta_name_ignore', $val );
- break;
- case '_vp_config_should_ignore_files':
- $val = $this->get_should_ignore_files( true );
- update_option( '_vp_config_should_ignore_files', $val );
- break;
- }
- return $val;
- }
-
- // Option name patterns to ignore
- function get_option_name_ignore( $return_defaults = false ) {
- $defaults = array(
- 'vaultpress',
- 'cron',
- 'wpsupercache_gc_time',
- 'rewrite_rules',
- 'akismet_spam_count',
- '/_transient_/',
- '/^_vp_/',
- );
- if ( $return_defaults )
- return $defaults;
- $ignore_names = $this->get_config( '_vp_config_option_name_ignore' );
- return array_unique( array_merge( $defaults, $ignore_names ) );
- }
-
- // post meta name patterns to ignore
- function get_post_meta_name_ignore( $return_defaults = false ) {
- $defaults = array(
- 'pvc_views'
- );
- if ( $return_defaults )
- return $defaults;
- $ignore_names = $this->get_config( '_vp_config_post_meta_name_ignore' );
- return array_unique( array_merge( $defaults, $ignore_names ) );
- }
-
- // file name patterns to ignore
- function get_should_ignore_files( $return_defaults = false ) {
- $defaults = array();
- if ( $return_defaults )
- return $defaults;
- $ignore_names = (array) $this->get_config( '_vp_config_should_ignore_files' );
- return array_unique( array_merge( $defaults, $ignore_names ) );
- }
-
- ###
- ### Section: Backup Notification Hooks
- ###
-
- // Handle Handle Notifying VaultPress of Options Activity At this point the options table has already been modified
- //
- // Note: we handle deleted, instead of delete because VaultPress backs up options by name (which are unique,) that
- // means that we do not need to resolve an id like we would for, say, a post.
- function option_handler( $option_name ) {
- global $wpdb;
- // Step 1 -- exclusionary rules, don't send these options to vaultpress, because they
- // either change constantly and/or are inconsequential to the blog itself and/or they
- // are specific to the VaultPress plugin process and we want to avoid recursion
- $should_ping = true;
- $ignore_names = $this->get_option_name_ignore();
- foreach( (array)$ignore_names as $val ) {
- if ( $val[0] == '/' ) {
- if ( preg_match( $val, $option_name ) )
- $should_ping = false;
- } else {
- if ( $val == $option_name )
- $should_ping = false;
- }
- if ( !$should_ping )
- break;
- }
- if ( $should_ping )
- $this->add_ping( 'db', array( 'option' => $option_name ) );
-
- // Step 2 -- If WordPress is about to kick off a some "cron" action, we need to
- // flush vaultpress, because the "remote" cron threads done via http fetch will
- // be happening completely inside the window of this thread. That thread will
- // be expecting touched and accounted for tables
- if ( $option_name == '_transient_doing_cron' )
- $this->do_pings();
-
- return $option_name;
- }
-
- // Handle Notifying VaultPress of Comment Activity
- function comment_action_handler( $comment_id ) {
- if ( !is_array( $comment_id ) ) {
- if ( wp_get_comment_status( $comment_id ) != 'spam' )
- $this->add_ping( 'db', array( 'comment' => $comment_id ) );
- } else {
- foreach ( $comment_id as $id ) {
- if ( wp_get_comment_status( $comment_id ) != 'spam' )
- $this->add_ping( 'db', array( 'comment' => $id) );
- }
- }
- }
-
- // Handle Notifying VaultPress of Theme Switches
- function theme_action_handler( $theme ) {
- $this->add_ping( 'themes', array( 'theme' => get_option( 'stylesheet' ) ) );
- }
-
- // Handle Notifying VaultPress of Upload Activity
- function upload_handler( $file ) {
- $this->add_ping( 'uploads', array( 'upload' => str_replace( $this->resolve_upload_path(), '', $file['file'] ) ) );
- return $file;
- }
-
- // Handle Notifying VaultPress of Plugin Activation/Deactivation
- function plugin_action_handler( $plugin='' ) {
- $this->add_ping( 'plugins', array( 'name' => $plugin ) );
- }
-
- // Handle Notifying VaultPress of User Edits
- function userid_action_handler( $user_or_id ) {
- if ( is_object($user_or_id) )
- $userid = intval( $user_or_id->ID );
- else
- $userid = intval( $user_or_id );
- if ( !$userid )
- return;
- $this->add_ping( 'db', array( 'user' => $userid ) );
- }
-
- // Handle Notifying VaultPress of term changes
- function term_handler( $term_id, $tt_id=null ) {
- $this->add_ping( 'db', array( 'term' => $term_id ) );
- if ( $tt_id )
- $this->term_taxonomy_handler( $tt_id );
- }
-
- // Handle Notifying VaultPress of term_taxonomy changes
- function term_taxonomy_handler( $tt_id ) {
- $this->add_ping( 'db', array( 'term_taxonomy' => $tt_id ) );
- }
- // add(ed)_term_taxonomy handled via the created_term hook, the term_taxonomy_handler is called by the term_handler
-
- // Handle Notifying VaultPress of term_taxonomy changes
- function term_taxonomies_handler( $tt_ids ) {
- foreach( (array)$tt_ids as $tt_id ) {
- $this->term_taxonomy_handler( $tt_id );
- }
- }
-
- // Handle Notifying VaultPress of term_relationship changes
- function term_relationship_handler( $object_id, $term_id ) {
- $this->add_ping( 'db', array( 'term_relationship' => array( 'object_id' => $object_id, 'term_taxonomy_id' => $term_id ) ) );
- }
-
- // Handle Notifying VaultPress of term_relationship changes
- function term_relationships_handler( $object_id, $term_ids ) {
- foreach ( (array)$term_ids as $term_id ) {
- $this->term_relationship_handler( $object_id, $term_id );
- }
- }
-
- // Handle Notifying VaultPress of term_relationship changes
- function set_object_terms_handler( $object_id, $terms, $tt_ids ) {
- $this->term_relationships_handler( $object_id, $tt_ids );
- }
-
- // Handle Notifying VaultPress of UserMeta changes
- function usermeta_action_handler( $umeta_id, $user_id, $meta_key, $meta_value='' ) {
- $this->add_ping( 'db', array( 'usermeta' => $umeta_id ) );
- }
-
- // Handle Notifying VaultPress of Post Changes
- function post_action_handler($post_id) {
- if ( current_filter() == 'delete_post' )
- return $this->add_ping( 'db', array( 'post' => $post_id ), 'delete_post' );
- return $this->add_ping( 'db', array( 'post' => $post_id ), 'edit_post' );
- }
-
- // Handle Notifying VaultPress of Link Changes
- function link_action_handler( $link_id ) {
- $this->add_ping( 'db', array( 'link' => $link_id ) );
- }
-
- // Handle Notifying VaultPress of Commentmeta Changes
- function commentmeta_insert_handler( $meta_id, $comment_id=null ) {
- if ( empty( $comment_id ) || wp_get_comment_status( $comment_id ) != 'spam' )
- $this->add_ping( 'db', array( 'commentmeta' => $meta_id ) );
- }
-
- function commentmeta_modification_handler( $meta_id, $object_id, $meta_key, $meta_value ) {
- if ( !is_array( $meta_id ) )
- return $this->add_ping( 'db', array( 'commentmeta' => $meta_id ) );
- foreach ( $meta_id as $id ) {
- $this->add_ping( 'db', array( 'commentmeta' => $id ) );
- }
- }
-
- // Handle Notifying VaultPress of PostMeta changes via newfangled metadata functions
- function postmeta_insert_handler( $meta_id, $post_id, $meta_key, $meta_value='' ) {
- if ( in_array( $meta_key, $this->get_post_meta_name_ignore() ) )
- return;
-
- $this->add_ping( 'db', array( 'postmeta' => $meta_id ) );
- }
-
- function postmeta_modification_handler( $meta_id, $object_id, $meta_key, $meta_value ) {
- if ( in_array( $meta_key, $this->get_post_meta_name_ignore() ) )
- return;
-
- if ( !is_array( $meta_id ) )
- return $this->add_ping( 'db', array( 'postmeta' => $meta_id ) );
- foreach ( $meta_id as $id ) {
- $this->add_ping( 'db', array( 'postmeta' => $id ) );
- }
- }
-
- // Handle Notifying VaultPress of PostMeta changes via old school cherypicked hooks
- function postmeta_action_handler( $meta_id, $post_id = null, $meta_key = null ) {
- if ( in_array( $meta_key, $this->get_post_meta_name_ignore() ) )
- return;
-
- if ( !is_array($meta_id) )
- return $this->add_ping( 'db', array( 'postmeta' => $meta_id ) );
- foreach ( $meta_id as $id )
- $this->add_ping( 'db', array( 'postmeta' => $id ) );
- }
-
- // WooCommerce notifications
- function woocommerce_tax_rate_handler( $id ) {
- $this->generic_change_handler( 'woocommerce_tax_rates', array( 'tax_rate_id' => $id ) );
- $this->block_change_handler( 'woocommerce_tax_rate_locations', array( 'tax_rate_id' => $id ) );
- }
-
- /**
- * Monitor for changes to a Woo order (creation, update, or deletion).
- *
- * @param int $id Item ID.
- */
- public function woocommerce_order_item_handler( $id ) {
- $this->generic_change_handler( 'woocommerce_order_items', array( 'order_item_id' => $id ) );
- }
-
- /**
- * Monitor for changes to a Woo order meta (creation, update, or deletion).
- *
- * @param int $id Item ID.
- */
- public function woocommerce_order_item_meta_handler( $id ) {
- $this->generic_change_handler( 'woocommerce_order_itemmeta', array( 'meta_id' => $id ) );
- }
-
- /**
- * Monitor for changes to a Woo attribute (creation, update, or deletion).
- *
- * @param int $id Item ID.
- */
- public function woocommerce_attribute_handler( $id ) {
- $this->generic_change_handler( 'woocommerce_attribute_taxonomies', array( 'attribute_id' => $id ) );
- }
-
- function generic_change_handler( $table, $key ) {
- $this->add_ping( 'db', array( $table => $key ) );
- }
-
- function block_change_handler( $table, $query ) {
- $this->add_ping( 'db', array( "bulk~{$table}" => $query ) );
- }
-
- function verify_table( $table ) {
- global $wpdb;
- $status = $wpdb->get_row( $wpdb->prepare( "SHOW TABLE STATUS WHERE Name = %s", $table ) );
- if ( !$status || !$status->Update_time || !$status->Comment || $status->Engine != 'MyISAM' )
- return true;
- if ( preg_match( '/([0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2})/', $status->Comment, $m ) )
- return ( $m[1] == $status->Update_time );
- return false;
- }
-
- // Emulate $wpdb->last_table
- function record_table( $table ) {
- global $vaultpress_last_table;
- $vaultpress_last_table = $table;
- return $table;
- }
-
- // Emulate $wpdb->last_table
- function get_last_table() {
- global $wpdb, $vaultpress_last_table;
- if ( is_object( $wpdb ) && isset( $wpdb->last_table ) )
- return $wpdb->last_table;
- return $vaultpress_last_table;
- }
-
- // Emulate hyperdb::is_write_query()
- function is_write_query( $q ) {
- $word = strtoupper( substr( trim( $q ), 0, 20 ) );
- if ( 0 === strpos( $word, 'SELECT' ) )
- return false;
- if ( 0 === strpos( $word, 'SHOW' ) )
- return false;
- if ( 0 === strpos( $word, 'CHECKSUM' ) )
- return false;
- return true;
- }
-
- // Emulate hyperdb::get_table_from_query()
- function get_table_from_query( $q ) {
- global $wpdb, $vaultpress_last_table;
-
- if ( is_object( $wpdb ) && method_exists( $wpdb, "get_table_from_query" ) )
- return $wpdb->get_table_from_query( $q );
-
- // Remove characters that can legally trail the table name
- $q = rtrim( $q, ';/-#' );
- // allow ( select... ) union [...] style queries. Use the first queries table name.
- $q = ltrim( $q, "\t (" );
-
- // Quickly match most common queries
- if ( preg_match( '/^\s*(?:'
- . 'SELECT.*?\s+FROM'
- . '|INSERT(?:\s+IGNORE)?(?:\s+INTO)?'
- . '|REPLACE(?:\s+INTO)?'
- . '|UPDATE(?:\s+IGNORE)?'
- . '|DELETE(?:\s+IGNORE)?(?:\s+FROM)?'
- . ')\s+`?(\w+)`?/is', $q, $maybe) )
- return $this->record_table($maybe[1] );
-
- // Refer to the previous query
- if ( preg_match( '/^\s*SELECT.*?\s+FOUND_ROWS\(\)/is', $q ) )
- return $this->get_last_table();
-
- // Big pattern for the rest of the table-related queries in MySQL 5.0
- if ( preg_match( '/^\s*(?:'
- . '(?:EXPLAIN\s+(?:EXTENDED\s+)?)?SELECT.*?\s+FROM'
- . '|INSERT(?:\s+LOW_PRIORITY|\s+DELAYED|\s+HIGH_PRIORITY)?(?:\s+IGNORE)?(?:\s+INTO)?'
- . '|REPLACE(?:\s+LOW_PRIORITY|\s+DELAYED)?(?:\s+INTO)?'
- . '|UPDATE(?:\s+LOW_PRIORITY)?(?:\s+IGNORE)?'
- . '|DELETE(?:\s+LOW_PRIORITY|\s+QUICK|\s+IGNORE)*(?:\s+FROM)?'
- . '|DESCRIBE|DESC|EXPLAIN|HANDLER'
- . '|(?:LOCK|UNLOCK)\s+TABLE(?:S)?'
- . '|(?:RENAME|OPTIMIZE|BACKUP|RESTORE|CHECK|CHECKSUM|ANALYZE|OPTIMIZE|REPAIR).*\s+TABLE'
- . '|TRUNCATE(?:\s+TABLE)?'
- . '|CREATE(?:\s+TEMPORARY)?\s+TABLE(?:\s+IF\s+NOT\s+EXISTS)?'
- . '|ALTER(?:\s+IGNORE)?\s+TABLE'
- . '|DROP\s+TABLE(?:\s+IF\s+EXISTS)?'
- . '|CREATE(?:\s+\w+)?\s+INDEX.*\s+ON'
- . '|DROP\s+INDEX.*\s+ON'
- . '|LOAD\s+DATA.*INFILE.*INTO\s+TABLE'
- . '|(?:GRANT|REVOKE).*ON\s+TABLE'
- . '|SHOW\s+(?:.*FROM|.*TABLE)'
- . ')\s+`?(\w+)`?/is', $q, $maybe ) )
- return $this->record_table( $maybe[1] );
-
- // All unmatched queries automatically fall to the global master
- return $this->record_table( '' );
- }
-
- function table_notify_columns( $table ) {
- $want_cols = array(
- // data
- 'posts' => '`ID`',
- 'users' => '`ID`',
- 'links' => '`link_id`',
- 'options' => '`option_id`,`option_name`',
- 'comments' => '`comment_ID`',
- // metadata
- 'postmeta' => '`meta_id`',
- 'commentmeta' => '`meta_id`',
- 'usermeta' => '`umeta_id`',
- // taxonomy
- 'term_relationships' => '`object_id`,`term_taxonomy_id`',
- 'term_taxonomy' => '`term_taxonomy_id`',
- 'terms' => '`term_id`',
- // plugin special cases
- 'wpo_campaign' => '`id`', // WP-o-Matic
- 'wpo_campaign_category' => '`id`', // WP-o-Matic
- 'wpo_campaign_feed' => '`id`', // WP-o-Matic
- 'wpo_campaign_post' => '`id`', // WP-o-Matic
- 'wpo_campaign_word' => '`id`', // WP-o-Matic
- 'wpo_log' => '`id`', // WP-o-Matic
- );
- if ( isset( $want_cols[$table] ) )
- return $want_cols[$table];
- return '*';
- }
-
- /**
- * Use an option ID to ensure a unique ping ID for the site.
- *
- * @return int|false The new ping number. False, if there was an error.
- */
- function ai_ping_next() {
- global $wpdb;
-
- if ( ! $this->allow_ai_pings() ) {
- return false;
- }
-
- $name = "_vp_ai_ping";
- $wpdb->query( $wpdb->prepare( "DELETE FROM `$wpdb->options` WHERE `option_name` = %s;", $name ) );
- $success = $wpdb->query( $wpdb->prepare( "INSERT INTO `$wpdb->options` (`option_name`, `option_value`, `autoload`) VALUES (%s, '', 'no')", $name ) );
- if ( ! $success ) {
- return false;
- }
- return $wpdb->insert_id;
- }
-
- function ai_ping_insert( $value ) {
- if ( ! $this->allow_ai_pings() ) {
- return false;
- }
-
- $new_id = $this->ai_ping_next();
-
- if ( !$new_id )
- return false;
- add_option( '_vp_ai_ping_' . $new_id, $value, '', 'no' );
- }
-
- function allow_ai_pings() {
- static $allow_ai_pings = null;
-
- if ( null === $allow_ai_pings ) {
- $queue_size = $this->ai_ping_queue_size();
- $size_limit = 50 * 1024 * 1024;
- $allow_ai_pings = ( $queue_size->option_count < 100 && $queue_size->option_size < $size_limit );
- }
-
- return $allow_ai_pings;
- }
-
- function ai_ping_queue_size() {
- global $wpdb;
- return $wpdb->get_row( "SELECT COUNT(`option_id`) `option_count`, SUM(LENGTH(`option_value`)) `option_size` FROM $wpdb->options WHERE `option_name` LIKE '\_vp\_ai\_ping\_%'" );
- }
-
- function ai_ping_get( $num=1, $order='ASC' ) {
- global $wpdb;
- if ( strtolower($order) != 'desc' )
- $order = 'ASC';
- else
- $order = 'DESC';
- return $wpdb->get_results( $wpdb->prepare(
- "SELECT * FROM $wpdb->options WHERE `option_name` LIKE '\_vp\_ai\_ping\_%%' ORDER BY `option_id` $order LIMIT %d",
- min( 10, max( 1, (int)$num ) )
- ) );
- }
-
- function ai_ping_queue_delete() {
- global $wpdb;
-
- return $wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE '\_vp\_ai\_ping%'" );
- }
-
- function request_firewall_update( $external_services = false ) {
- $args = array( 'timeout' => $this->get_option( 'timeout' ), 'sslverify' => true );
- $hostname = $this->get_option( 'hostname' );
- $path = $external_services ? 'service-ips-external' : 'service-ips';
-
- $data = false;
- $https_error = null;
- $retry = 2;
- $protocol = 'https';
- do {
- $retry--;
- $args['sslverify'] = 'https' == $protocol ? true : false;
- $r = wp_remote_get( $url=sprintf( "%s://%s/%s?cidr_ranges=1", $protocol, $hostname, $path ), $args );
- if ( 200 == wp_remote_retrieve_response_code( $r ) ) {
- if ( 99 == $this->get_option( 'connection_error_code' ) )
- $this->clear_connection();
- $data = @unserialize( wp_remote_retrieve_body( $r ) );
- break;
- }
- if ( 'https' == $protocol ) {
- $https_error = $r;
- $protocol = 'http';
- }
- usleep( 100 );
- } while( $retry > 0 );
-
- if ( $https_error != null && ! empty( $data ) ) {
- $r_code = wp_remote_retrieve_response_code( $https_error );
- if ( 200 != $r_code ) {
- $error_message = sprintf( 'Unexpected HTTP response code %s', $r_code );
- if ( false === $r_code )
- $error_message = 'Unable to find an HTTP transport that supports SSL verification';
- elseif ( is_wp_error( $https_error ) )
- $error_message = $https_error->get_error_message();
-
- $this->update_option( 'connection', time() );
- $this->update_option( 'connection_error_code', 99 );
- $this->update_option( 'connection_error_message', sprintf( __('Warning: The VaultPress plugin is using an insecure protocol because it cannot verify the identity of the VaultPress server. Please contact your hosting provider, and ask them to check that SSL certificate verification is correctly configured on this server. The request failed with the following error: "%s". If you’re still having issues please