Hallo Zusammen.
Ich habe das Problem das bei diesem Script nicht alle URL geändert werden. Einiges Funktioniert.. aber nicht alles?
Alles anzeigen
Was könnte das Problem sein?
Ich habe das Problem das bei diesem Script nicht alle URL geändert werden. Einiges Funktioniert.. aber nicht alles?
PHP-Quellcode
- function mfn_migrate_cb(){
- global $wpdb;
- $safety_limit = 6;
- if( key_exists( 'mfn_migrate_nonce',$_POST ) ) {
- if ( wp_verify_nonce( $_POST['mfn_migrate_nonce'], basename(__FILE__) ) ) {
- $old_url = stripslashes(htmlspecialchars($_POST['old']));
- $new_url = stripslashes(htmlspecialchars($_POST['new']));
- if( strlen($old_url) < $safety_limit || strlen($new_url) < $safety_limit ){
- echo '<p><strong>For your own safety please use URLs longer than '. $safety_limit .' characters !</strong></p>';
- } elseif( strpos( $old_url, 'http' ) !== 0 || strpos( $new_url, 'http' !== 0 ) ){
- echo '<p><strong>URLs must begin with http:// or https:// !</strong></p>';
- } else {
- $results = $wpdb->get_results( "SELECT * FROM $wpdb->postmeta
- WHERE `meta_key` = 'mfn-page-items'
- " );
- if( is_array( $results ) ){
- // print_r($results);
- // posts loop -----------------
- foreach( $results as $result_key=>$result ){
- $meta_id = $result->meta_id;
- $meta_value = unserialize(base64_decode($result->meta_value));
- // print_r($meta_value);
- // sections loop ----------------
- foreach( $meta_value as $sec_key=>$sec ){
- // section attr loop ----------------
- foreach( $sec['attr'] as $attr_key=>$attr ){
- $attr = str_replace($old_url, $new_url, $attr);
- $meta_value[$sec_key]['attr'][$attr_key] = $attr;
- }
- // items loop ----------------
- foreach( $sec['items'] as $item_key=>$item ){
- // meta fields loop ----------------
- foreach( (array)$item['fields'] as $field_key=>$field ){
- $field = str_replace($old_url, $new_url, $field);
- $meta_value[$sec_key]['items'][$item_key]['fields'][$field_key] = $field;
- }
- }
- }
- // print_r($meta_value);
- $meta_value = base64_encode(serialize($meta_value));
- $wpdb->query( "UPDATE $wpdb->postmeta
- SET `meta_value` = '". addslashes($meta_value) ."'
- WHERE `meta_key` = 'mfn-page-items'
- AND `meta_id`= ". $meta_id ."
- ");
- }
- }
- echo '<p><strong>All done. Have fun!</strong></p>';
- }
- } else {
- echo '<p><strong>Invalid Nonce !</strong></p>';
- }
- }
- ?>
- <div class="wrap">
- <div id="icon-tools" class="icon32"></div>
- <h2><?php echo esc_html( get_admin_page_title() ); ?></h2>
- <br />
- <form action="" method="post">
- <input type="hidden" name="mfn_migrate_nonce" value="<?php echo wp_create_nonce(basename(__FILE__)); ?>" />
- <label style="width:50px; display:inline-block;">Find</label>
- <input type="text" name="old" value="" placeholder="Old URL" style="width:300px;" />
- <br />
- <label style="width:50px; display:inline-block;">Replace</label>
- <input type="text" name="new" value="<?php echo home_url(); ?>" style="width:300px;" />
- <input type="submit" name="submit" class="button button-primary" value="Replace" />
- </form>
- </div>
Was könnte das Problem sein?