true,
)
);
}
/**
* The widget form (for the backend).
*
* @param array $instance The widget instance.
*/
public function form( $instance ) {
// Set widget defaults.
$defaults = array(
'title' => '',
);
// Parse current settings with defaults.
$instance = wp_parse_args( (array) $instance, $defaults );
$title = $instance['title'];
?>
';
// Display widget title if defined.
if ( $title ) {
echo esc_html( $before_title . $title . $after_title );
}
$current_user = wp_get_current_user();
if ( 0 !== $current_user->ID ) {
$accredible = new Accredible_Certificates();
$credentials = $accredible->get_credentials_for_email( $current_user->user_email );
if ( $credentials->credentials ) {
echo '';
}
}
echo '';
// WordPress core after_widget hook (always include).
echo esc_html( $after_widget );
}
/**
* Register the widget.
*/
public static function register_widget() {
register_widget( 'Accredible_Widget' );
}
/**
* The shortcode.
*
* @param array $atts The attributes.
* @param string $content The content.
* @param string $tag The tag.
*/
public static function credential_shortcode( $atts = array(), $content = null, $tag = '' ) {
$output = '';
// Normalize attribute keys, lowercase.
$atts = array_change_key_case( (array) $atts, CASE_LOWER );
// Override default attributes with user attributes.
$atts_to_consume = shortcode_atts(
array(
'image' => 'true',
'limit' => '10',
'style' => 'true',
),
$atts,
$tag
);
$current_user = wp_get_current_user();
if ( 0 !== $current_user->ID ) {
$accredible = new Accredible_Certificates();
$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 ( false === $atts_to_consume['image'] ) {
$output .= '' . esc_html( $credential->name ) . '';
} else {
// The user can choose to remove the default styling.
if ( false === $atts_to_consume['style'] ) {
$output .= '';
} else {
$output .= '
';
}
}
}
}
return $output;
}
}
// Register the widget.
add_action( 'widgets_init', array( 'Accredible_Widget', 'register_widget' ) );
// Register the shortcode.
add_shortcode( 'accredible_credential', array( 'Accredible_Widget', 'credential_shortcode' ) );
}
?>