Created
September 17, 2013 14:38
-
-
Save imath/6595222 to your computer and use it in GitHub Desktop.
Example of use of Bowe Codes to add your very own BuddyPress shortcodes. You can paste the above code in the functions.php of your active theme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Building a new BuddyPress shortcode | |
* using Bowe Codes built-in "API" | |
* | |
* You'll need Bowe Codes : http://wordpress.org/plugins/bowe-codes/ | |
* And BuddyPress 1.7+ | |
*/ | |
class Burnardo_Shortcode{ | |
/** | |
* Displays "profile card for the loggedin user" | |
*/ | |
function __construct() { | |
$this->setup_filters(); | |
} | |
function setup_filters() { | |
add_filter( 'bowe_codes_shortcodes', array( $this, 'register' ), 10, 1 ); | |
add_filter( 'bowe_codes_shortcodes_settings', array( $this, 'settings' ), 10, 1); | |
} | |
function register( $shortcodes = array() ) { | |
$shortcodes['bc_burnardo'] = array( $this, 'display_burnardo_sc' ); | |
return $shortcodes; | |
} | |
function display_burnardo_sc( $atts = '' ) { | |
$defaults = array( | |
'avatar' => 1, | |
'size' => 50, | |
'class' => 'my_member', | |
'fields' => '', | |
); | |
$r = wp_parse_args( $atts, $defaults ); | |
extract( $r, EXTR_SKIP ); | |
// no loggedin user no content ! | |
if( !is_user_logged_in() ) | |
return false; | |
$user_id = bp_loggedin_user_id(); | |
/* using bowe_codes_html_member() function to quicky displays but you can use your own function*/ | |
$html_member_box = '<div class="'.$class.'">'; | |
$html_member_box .= '<ul class="'.$class.'-ul">'.bowe_codes_html_member( $user_id, $avatar, $size, $fields ).'</ul>'; | |
$html_member_box .= '</div>'; | |
echo $html_member_box; | |
} | |
function settings( $settings = array() ) { | |
$settings['bc_burnardo'] = array( | |
'attributes' => array( | |
array( | |
'id' => 'avatar', | |
'type' => 'boolean', | |
'default' => 1, | |
'required' => false, | |
'caption' => __( 'Avatar', 'bowe-codes' ) | |
), | |
array( | |
'id' => 'size', | |
'type' => 'int', | |
'default' => 50, | |
'required' => false, | |
'caption' => __( 'Size in pixels', 'bowe-codes' ) | |
), | |
array( | |
'id' => 'class', | |
'type' => 'string', | |
'default' => 'my_member', | |
'required' => false, | |
'caption' => __( 'Css Class', 'bowe-codes' ) | |
) | |
), | |
'description' => __( 'Displays a profile card for the loggedin user' ) | |
); | |
if( bp_is_active( 'xprofile' ) ) { | |
$settings['bc_burnardo']['attributes'][] = array( | |
'id' => 'fields', | |
'type' => 'string', | |
'default' => '', | |
'required' => false, | |
'caption' => __( 'xProfile field Name (separated by a comma if more than one)', 'bowe-codes' ) | |
); | |
} | |
return $settings; | |
} | |
} | |
function burnardo_shortcode() { | |
return new Burnardo_Shortcode(); | |
} | |
add_action( 'bowe_codes_ready', 'burnardo_shortcode' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment