true,
)
);
}
// The widget form (for the backend )
public function form( $instance ) {
// Set widget defaults
$defaults = array(
'title' => '',
);
// Parse current settings with defaults
extract( wp_parse_args( ( array ) $instance, $defaults ) ); ?>
';
// Display widget title if defined
if ( $title ) {
echo $before_title . $title . $after_title;
}
$current_user = wp_get_current_user();
if (0 == $current_user->ID) {
// We don't have a user to get credentials for.
} else {
$accredible = new Accredible_Certificate;
$credentials = $accredible->get_credentials_for_email($current_user->user_email);
if($credentials->credentials){
echo '
';
foreach ($credentials->credentials as $key => $credential) {
echo '
';
}
}
echo '';
// WordPress core after_widget hook (always include )
echo $after_widget;
}
}
// Register the widget
function register_accredible_custom_widget() {
register_widget( 'Accredible_Widget' );
}
add_action( 'widgets_init', 'register_accredible_custom_widget' );
// [accredible_credential image="true" limit="10" style="true"]
function accredible_credential_shortcode($atts = [], $content = null, $tag = ''){
// normalize attribute keys, lowercase
$atts = array_change_key_case((array)$atts, CASE_LOWER);
// override default attributes with user attributes
$atts_to_consume = shortcode_atts([
'image' => 'true',
'limit' => '10',
'style' => 'true'
], $atts, $tag);
$current_user = wp_get_current_user();
if (0 == $current_user->ID) {
// We don't have a user to get credentials for.
} else {
$accredible = new Accredible_Certificate;
$credentials = $accredible->get_credentials_for_email($current_user->user_email);
if($credentials->credentials){
foreach ($credentials->credentials as $key => $credential) {
// The user can set a limit on the number of credentials displayed
if($key >= (int)$atts_to_consume['limit']){
break;
}
// The user can choose between image or link.
if($atts_to_consume['image'] == "false"){
echo '' . $credential->name . '';
} else {
// The user can choose to remove the default styling
if($atts_to_consume['style'] == "false"){
echo '