// 登录用户可见按钮与短代码
function ruike_shortcode( $atts, $content ){
if( !is_null( $content ) && !is_user_logged_in() ) $content = '<div class="browserBox">' . __('此处内容需要瑞课VIP用户才可见','ruike') . '</div>';
return $content;
}
add_shortcode( 'ruikelogged', 'ruike_shortcode' );
使用的话在编辑器代码模式下输入:[ruikelogged]隐藏的内容[ruikelogged]
//播放器代码
add_shortcode("player","ipc_ckplayer");
function ipc_ckplayer( $atts, $content=null ) {
if(wp_is_mobile()){
return '<video controls="controls" src="'.$content.'" id="Player" width="100%" height="100%" autoplay="autoplay"></video>';
}
else{
return '<embed name="Player" id="Player" src="'.get_stylesheet_directory_uri().'/player/player.swf" flashvars="a='.$content.'&p=0" quality="high" width="100%" height="500" align="middle" allowScriptAccess="always" allowFullscreen="true" type="application/x-shockwave-flash"></embed>';
}
}
使用的话在编辑器代码模式下输入:
[ruikelogged]隐藏的内容[ruikelogged]
[player]视频地址[/player]
要把这些短码添加wordpress编辑器,还需要添加以下代码,你可以把以下的代码丢到functions.php中或者单独的PHP文件中来引用它,但里面的必须让它用js格式运行,所以单独能个短代码按钮JS最好方便管理。
QTags.addButton( 'ruikelogged', '登录可见', '\n[ruikelogged]\n\n[/ruikelogged]', "" );//添加登录可见短代码
QTags.addButton( 'player', 'CK优酷', "[player][/player]" );
下面这个呢根据以上是第二种方式只需丢到functions.php中,创建个my_quicktags.js把上面代码加入即可。
add_action('admin_print_scripts', 'my_quicktags');
function my_quicktags() {
wp_enqueue_script(
'my_quicktags',
get_stylesheet_directory_uri().'/js/my_quicktags.js',
array('quicktags')
);
};

