????
| Current Path : /home2/morganrand/www/wp-content-bkp/themes/wanderfuls/framework/shortcodes/ |
| Current File : /home2/morganrand/www/wp-content-bkp/themes/wanderfuls/framework/shortcodes/shortcodes.php |
<?php
/**
* Shortcodes in the TinyMCE
*
* @package Wanderfuls WordPress Theme
* @subpackage Framework
*/
// Adds button to mce
if ( tb_get_mod( 'editor_shortcodes_enable', true ) && is_admin() ) {
if ( ! function_exists( 'wanderfuls_shortcodes_add_mce_button' ) ) {
function wanderfuls_shortcodes_add_mce_button() {
// check user permissions
if ( ! current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) {
return;
}
// check if WYSIWYG is enabled
if ( 'true' == get_user_option( 'rich_editing' ) ) {
add_filter( 'mce_external_plugins', 'wanderfuls_shortcodes_add_tinymce_plugin' );
add_filter( 'mce_buttons', 'wanderfuls_shortcodes_register_mce_button' );
}
}
}
add_action( 'admin_head', 'wanderfuls_shortcodes_add_mce_button' );
}
// Loads js for the Button
if ( ! function_exists( 'wanderfuls_shortcodes_add_tinymce_plugin' ) ) {
function wanderfuls_shortcodes_add_tinymce_plugin( $plugin_array ) {
$plugin_array['wanderfuls_shortcodes_mce_button'] = TB_FRAMEWORK_DIR_URI .'shortcodes/tinymce.js';
return $plugin_array;
}
}
// Registers new button
if ( ! function_exists( 'wanderfuls_shortcodes_register_mce_button' ) ) {
function wanderfuls_shortcodes_register_mce_button( $buttons ) {
array_push( $buttons, 'wanderfuls_shortcodes_mce_button' );
return $buttons;
}
}
/**
* Allow shortcodes in widgets
*
* @since Wanderfuls 1.3.3
*/
add_filter( 'widget_text', 'do_shortcode' );
/**
* Fixes spacing issues with shortcodes
*
* @since Wanderfuls 1.0.0
*/
if ( ! function_exists( 'tb_fix_shortcodes' ) ) {
function tb_fix_shortcodes( $content ){
$array = array (
'<p>[' => '[',
']</p>' => ']',
']<br />' => ']'
);
$content = strtr( $content, $array) ;
return $content;
}
}
add_filter( 'the_content', 'tb_fix_shortcodes' );
/**
* Year shortcode
*
* @since Wanderfuls 1.0.0
*/
if ( ! function_exists( 'tb_year_shortcode' ) ) {
function tb_year_shortcode() {
return date('Y');
}
}
add_shortcode( 'current_year', 'tb_year_shortcode' );
/**
* Font Awesome Shortcode
*
* @since Wanderfuls 1.3.2
*/
if ( ! function_exists( 'tb_font_awesome_shortcode' ) ) {
function tb_font_awesome_shortcode( $atts ) {
extract( shortcode_atts( array (
'icon' => '',
'link' => '',
'link_title' => '',
'margin_right' => '',
'margin_left' => '',
'margin_top' => '',
'margin_bottom' => '',
'color' => '',
'size' => '',
'link' => '',
), $atts ) );
// Sanitize vars
$link = $link ? esc_url( $link ) : '';
$link_title = $link_title ? esc_attr( $link_title ) : '';
// Generate inline styles
$style = array();
if ( $color ) {
$style[] = 'color: #'. str_replace( '#', '', $color ) .';';
}
if ( $margin_left ) {
$style[] = 'margin-left: '. intval( $margin_left ) .'px;';
}
if ( $margin_right ) {
$style[] = 'margin-right: '. intval( $margin_right ) .'px;';
}
if ( $margin_top ) {
$style[] = 'margin-top: '. intval( $margin_top ) .'px;';
}
if ( $margin_bottom ) {
$style[] = 'margin-bottom: '. intval( $margin_bottom ) .'px;';
}
if ( $size ) {
$style[] = 'font-size: '. intval( $size ) .'px;';
}
$style = implode( '', $style );
if ( $style ) {
$style = wp_kses( $style, array() );
$style = ' style="' . esc_attr( $style) . '"';
}
// Display icon with link
if ( $link ) {
$output = '<a href="'. $link .'" title="'. $link_title .'"><i class="fa fa-'. $icon .'" '. $style .'></i></a>';
}
// Display icon without link
else {
$output = '<i class="fa fa-'. $icon .'" '. $style .'></i>';
}
// Return shortcode output
return $output;
}
}
add_shortcode( 'font_awesome', 'tb_font_awesome_shortcode' );
/**
* Login Link
*
* @since Wanderfuls 1.3.2
*/
if ( ! function_exists( 'tb_wp_login_url_shortcode' ) ) {
function tb_wp_login_url_shortcode( $atts ) {
extract( shortcode_atts( array(
'login_url' => '',
'url' => '',
'text' => __( 'Login', 'tb' ),
'logout_text' => __( 'Log Out', 'tb' ),
'target' => 'blank',
'logout_redirect' => '',
), $atts ) );
// Target
if ( 'blank' == $target ) {
$target = 'target="_blank"';
} else {
$target = '';
}
// Define login url
if ( $url ) {
$login_url = $url;
} elseif ( $login_url ) {
$login_url = $login_url;
} else {
$login_url = wp_login_url();
}
// Logout redirect
if ( ! $logout_redirect ) {
$permalink = get_permalink();
if ( $permalink ) {
$logout_redirect = $permalink;
} else {
$logout_redirect = home_url();
}
}
// Logged in link
if ( is_user_logged_in() ) {
return '<a href="'. wp_logout_url( $logout_redirect ) .'" title="'. $logout_text .'" class="tb-logout" rel="nofollow">'. $logout_text .'</a>';
}
// Non-logged in link
else {
return '<a href="'. $login_url .'" title="'. $text .'" class="tb-login" rel="nofollow" '. $target .'>'. $text .'</a>';
}
}
}
add_shortcode( 'wp_login_url', 'tb_wp_login_url_shortcode' );