Advertisement
sciking

Migrazione Blogger- Wordpress 1

Mar 5th, 2015
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  1.   <?php
  2.      
  3.     function labnol_blogger_query_vars_filter( $vars ) {
  4.     $vars[] = "blogger";
  5.     return $vars;
  6.     }
  7.      
  8.     add_filter('query_vars', 'labnol_blogger_query_vars_filter');
  9.      
  10.     function labnol_blogger_template_redirect() {
  11.     global $wp_query;
  12.     $blogger = $wp_query->query_vars['blogger'];
  13.     if ( isset ( $blogger ) ) {
  14.     wp_redirect( labnol_get_wordpress_url ( $blogger ) , 301 );
  15.     exit;
  16.     }
  17.     }
  18.      
  19.     add_action( 'template_redirect', 'labnol_blogger_template_redirect' );
  20.      
  21.     function labnol_get_wordpress_url($blogger) {
  22.     if ( preg_match('@^(?:https?://)?([^/]+)(.*)@i', $blogger, $url_parts) ) {
  23.     $query = new WP_Query (
  24.     array ( "meta_key" => "blogger_permalink", "meta_value" => $url_parts[2] ) );
  25.     if ($query->have_posts()) {
  26.     $query->the_post();
  27.     $url = get_permalink();
  28.     }
  29.     wp_reset_postdata();
  30.     }
  31.     return $url ? $url : home_url();
  32.     }
  33.      
  34.     ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement