updates all urls in your website by replacing old urls with new urls. To get started: 1) Click the "Activate" link to the left of this description, and 2) Go to your Update URLs page to use it. Author: VelvetBlues.com Author URI: http://www.velvetblues.com/ Author Email: info@velvetblues.com Version: 3.2.10 License: GPLv2 or later Text Domain: velvet-blues-update-urls */ /* Copyright 2020 Velvet Blues Web Design (email : info@velvetblues.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ if ( !function_exists( 'add_action' ) ) { exit; } function VelvetBluesUU_add_management_page(){ add_management_page("Velvet Blues Update URLs", "Update URLs", "manage_options", basename(__FILE__), "VelvetBluesUU_management_page"); } function VelvetBluesUU_load_textdomain(){ load_plugin_textdomain( 'velvet-blues-update-urls', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); } function VelvetBluesUU_management_page(){ if ( !function_exists( 'VB_update_urls' ) ) { function VB_update_urls($options,$oldurl,$newurl){ global $wpdb; $results = array(); $queries = array( 'content' => array("UPDATE $wpdb->posts SET post_content = replace(post_content, %s, %s)", __('Content Items (Posts, Pages, Custom Post Types, Revisions)','velvet-blues-update-urls') ), 'excerpts' => array("UPDATE $wpdb->posts SET post_excerpt = replace(post_excerpt, %s, %s)", __('Excerpts','velvet-blues-update-urls') ), 'attachments' => array("UPDATE $wpdb->posts SET guid = replace(guid, %s, %s) WHERE post_type = 'attachment'", __('Attachments','velvet-blues-update-urls') ), 'links' => array("UPDATE $wpdb->links SET link_url = replace(link_url, %s, %s)", __('Links','velvet-blues-update-urls') ), 'custom' => array("UPDATE $wpdb->postmeta SET meta_value = replace(meta_value, %s, %s)", __('Custom Fields','velvet-blues-update-urls') ), 'guids' => array("UPDATE $wpdb->posts SET guid = replace(guid, %s, %s)", __('GUIDs','velvet-blues-update-urls') ) ); foreach($options as $option){ if( $option == 'custom' ){ $n = 0; $row_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->postmeta" ); $page_size = 10000; $pages = ceil( $row_count / $page_size ); for( $page = 0; $page < $pages; $page++ ) { $current_row = 0; $start = $page * $page_size; $end = $start + $page_size; $pmquery = "SELECT * FROM $wpdb->postmeta WHERE meta_value <> ''"; $items = $wpdb->get_results( $pmquery ); foreach( $items as $item ){ $value = $item->meta_value; if( trim($value) == '' ) continue; $edited = VB_unserialize_replace( $oldurl, $newurl, $value ); if( $edited != $value ){ $fix = $wpdb->query("UPDATE $wpdb->postmeta SET meta_value = '".$edited."' WHERE meta_id = ".$item->meta_id ); if( $fix ) $n++; } } } $results[$option] = array($n, $queries[$option][1]); } else{ $result = $wpdb->query( $wpdb->prepare( $queries[$option][0], $oldurl, $newurl) ); $results[$option] = array($result, $queries[$option][1]); } } return $results; } } if ( !function_exists( 'VB_unserialize_replace' ) ) { function VB_unserialize_replace( $from = '', $to = '', $data = '', $serialised = false ) { try { if ( false !== is_serialized( $data ) ) { $unserialized = unserialize( $data ); $data = VB_unserialize_replace( $from, $to, $unserialized, true ); } elseif ( is_array( $data ) ) { $_tmp = array( ); foreach ( $data as $key => $value ) { $_tmp[ $key ] = VB_unserialize_replace( $from, $to, $value, false ); } $data = $_tmp; unset( $_tmp ); } else { if ( is_string( $data ) ) $data = str_replace( $from, $to, $data ); } if ( $serialised ) return serialize( $data ); } catch( Exception $error ) { } return $data; } } if ( isset( $_POST['VBUU_settings_submit'] ) && !check_admin_referer('VBUU_submit','VBUU_nonce')){ if(isset($_POST['VBUU_oldurl']) && isset($_POST['VBUU_newurl'])){ if(function_exists('esc_attr')){ $vbuu_oldurl = esc_attr(trim($_POST['VBUU_oldurl'])); $vbuu_newurl = esc_attr(trim($_POST['VBUU_newurl'])); }else{ $vbuu_oldurl = attribute_escape(trim($_POST['VBUU_oldurl'])); $vbuu_newurl = attribute_escape(trim($_POST['VBUU_newurl'])); } } echo '
'.__('ERROR','velvet-blues-update-urls').' - '.__('Please try again.','velvet-blues-update-urls').'
'.__('ERROR','velvet-blues-update-urls').' - '.__('Your URLs have not been updated.','velvet-blues-update-urls').'
'.__('Please select at least one checkbox.','velvet-blues-update-urls').'
'.__('ERROR','velvet-blues-update-urls').' - '.__('Your URLs have not been updated.','velvet-blues-update-urls').' '.__('Please enter values for both the old url and the new url.','velvet-blues-update-urls').' '; } } ?>Velvet Blues Update URLs |