主题中的add_filter函数(wordpress)

时间:2012-10-25 11:51:26

标签: wordpress themes rewrite add-filter

我有一个加密内容的功能:

function rewrite_text( $article, $case_sensitive=false ) {

    $workwith=$article;
    *(hide line code for copyright)....(hide line code for copyright)*
    $codul='<script type="text/javascript">
document.write(String.fromCharCode('.$numbers.'));
</script>';
        $workwith=$codul;
        }
    return $workwith;
}
add_filter('the_content', 'rewrite_text', 100);

在我的wordpress主题(deTube wordpress主题)中有一个show youtube播放器的功能(在theme_name / functions.php中):

function dp_video($post_id, $autoplay = false) {    
    $file = get_post_meta($post_id, 'dp_video_file', true);
    $file = !empty($file) ? explode("\n", $file) : array();
    $url = trim(get_post_meta($post_id, 'dp_video_url', true));
    $code = trim(get_post_meta($post_id, 'dp_video_code', true));
    if(!empty($code)) {
        $code = do_shortcode($code);
        if(function_exists('jwplayer_tag_callback'))
            $code = jwplayer_tag_callback($code);
        $code = extend_video_html($code, $autoplay);        
        echo '<div class="video-wrap">'.$code.'</div>';
    } elseif(!empty($url)) {
        $youtube_id = getYouTubeIdFromURL($url);
        $video = "<div class=\"video-wrap\"><embed src=\"http://www.youtube.com/v/".$youtube_id."?modestbranding=1&version=3&hl=vi_VN&rel=0&autoplay=1&showsearch=0&iv_load_policy=3&theme=light\" type=\"application/x-shockwave-flash\" allowFullScreen=\"true\" allowScriptAccess=\"always\" width=\"100%\" height=\"100%\"/></div>";
        echo $video;

我想通过add_filter函数dp_video加密youtube链接(youtube播放器代码),使用:

add_filter('dp_video', 'rewrite_text', 100);

但它不起作用! 你能帮我添加dp_video功能的过滤器吗? 非常感谢你!

1 个答案:

答案 0 :(得分:0)

如果您add_filter('dp_video'),某处必须有apply_filters('dp_video')。例如,如果您想过滤$ video,可以将最后一行更改为

echo apply_filters('dp_video', $video);