2016-11-26 5 views
1

私はJWプレーヤーとのみすべてのプレビュービデオリンクを再生したいと思います。 私はwwのためにjwプレーヤー& jwプレーヤー7をインストールします。新しい投稿にのみ影響を与えることができます! どうすればデフォルトのワードプレスビデオプレイヤーに置き換えることができますか?デフォルトプレイヤーをJWプレーヤーに変更

+0

Jwプレーヤーはどのようなショートコードを投稿に追加しますか? – Benoti

+0

私はこのプラグインを使用しました。wordpress.org/plugins/simple-shortcode-for-jw-player-7/... [jw7-video] – Mohammad

答えて

1

ここで、オンデマンドで適用する小さなスクリプト(delete_option行のコメントを外して再度それを行う)をfunction.phpに配置します。

このスクリプトはすべての投稿を検索し、古いショートコードタグを新しいものに置き換えます。

get_shortcode_regex()has_shortcodeを使用すると、ショートコードを登録されたショートコードにする必要があります(add_shortcode()経由で追加します。最後にdummy_shortcode()を参照)。 has_shortcode()

add_action('init', 'se_40815010'); 

function se_40815010(){ 

    if(get_option('se_40815010') == true){ 
     return; 
    } 

    $old_tag = 'video'; 
    $new_tag = 'jw7-video'; 

    $args = array(
     'post_type' =>'post', 
     'posts_per_page'=> -1, 
     'post_status' => 'any' 
    ); 

    $posts = new WP_Query($args); 

    foreach($posts->posts as $post){ 
     if(has_shortcode($post->post_content, $old_tag)){ 

      $pattern = get_shortcode_regex(); 

      if ( preg_match_all('/'. $pattern .'/s', $post->post_content, $matches) 
       && array_key_exists(2, $matches) 
       && in_array($old_tag, $matches[2])) { 

        $new_content = str_replace($matches[2][0], $new_tag, $post->post_content); 

        $post_update = array(
         'ID'=> $post->ID, 
         'post_content'=> $new_content 
        ); 

        $update = wp_update_post($post_update, true); 

        if($update && !is_wp_error($update)){ 
         $result .= 'Post ID '.$post->ID.', gallery shortcode modified.</br>'; 
        } 
        else{ 
         $error_string = $update->get_error_message(); 
         $result .= '<div id="message" class="error"><p>' . $error_string .'</p></div>'; 
        } 
      } 
     } 
    } 

    wp_mail(get_option('admin_email'), 'Shortcode replace', $result); 

    update_option('se_40815010', true); 
} 
// delete_option('se_40815010'); 

、ショートが認識されるようにadd_shortcode()に登録する必要があります。偽のショートコードを作成し、探している古いタグが認識されます。

if(get_option('se_40815010')!= true){ 
    add_shortcode('fakegallery', 'dummy_shortcode'); 
} 
function dummy_shortcode($content){ 
    return 'hello world'; 
} 

希望します。

+1

どのような「ダウンしました」、エラーメッセージもタイムアウトもありませんでしたか?なぜか分かりませんが、function.phpの最後にphpタグを閉じる必要はありません。 – Benoti

+0

それを削除する、それは不可能だ、デバッグモードを有効にする必要があります。 – Benoti

+0

あなたのサイトのリンクを共有できますか? – Hitesh

関連する問題