dozent_get_user_social_links( null $meta_key = null, int|string|stdClass|WP_User $user_id )
Get all user social links generated by DozentLMS
Description
Pass the specific user ID | Object to get the available social links under an user
Example usage:
$links = dozent_get_user_social_links();
$link = dozent_get_user_social_links( $link_meta_key );
$link = dozent_get_user_social_links( '_dozent_link_website' );
$links = dozent_get_user_social_links( false, $user_id );
$link = dozent_get_user_social_links( $link_meta_key, $user_id );
$link = dozent_get_user_social_links( '_dozent_link_website', $user_id );
Note: pass one key to get specific social link. If you would like to access
saved_value
from the array, you must pass user on the second parameter.
Parameters
- $meta_key
-
(null) (Optional) Meta Key | $links array key
Default value: null
- $user_id
-
(int|string|stdClass|WP_User) (Required) User's ID, a WP_User object, or a user object from the DB.
Return
(mixed|void)
Source
File: includes/core-functions.php
function dozent_get_user_social_links( $meta_key = null, $user_id = 0 ) { $links = []; $links['_dozent_link_website'] = [ 'label' => __( 'Website', 'dozent' ), 'placeholder' => 'https://example.com/', 'icon_classes' => 'dicon-earth', 'saved_value' => '', ]; $links['_dozent_link_facebook'] = [ 'label' => __( 'Facebook', 'dozent' ), 'placeholder' => 'https://facebook.com/username', 'icon_classes' => 'dicon-facebook', 'saved_value' => '', ]; $links['_dozent_link_twitter'] = [ 'label' => __( 'Twitter', 'dozent' ), 'placeholder' => 'https://twitter.com/username', 'icon_classes' => 'dicon-twitter', 'saved_value' => '', ]; $links['_dozent_link_linkedin'] = [ 'label' => __( 'Linkedin', 'dozent' ), 'placeholder' => 'https://linkedin.com/username', 'icon_classes' => 'dicon-linkedin', 'saved_value' => '', ]; $links['_dozent_link_instagram'] = [ 'label' => __( 'Instagram', 'dozent' ), 'placeholder' => 'https://instagram.com/username', 'icon_classes' => 'dicon-instagram', 'saved_value' => '', ]; $links['_dozent_link_vk'] = [ 'label' => __( 'VK', 'dozent' ), 'placeholder' => 'https://vk.com/username', 'icon_classes' => 'dicon-vk', 'saved_value' => '', ]; $user = new WP_User( $user_id ); if ( ! empty( $user->ID ) ) { foreach ( $links as $link_key => $link_value ) { $saved_value = get_user_meta( $user->ID, $link_key, true ); if ( $saved_value ) { $links[ $link_key ]['saved_value'] = $saved_value; } else { unset( $links[ $link_key ] ); } } } if ( $meta_key ) { $link = dozent_array_get( $meta_key, $links ); /** * Filter single social link by given meta key, it will return one single array from the all available social links * * @since DozentLMS 1.0.0 */ return apply_filters( 'dozent_get_user_social_link', $link ); } /** * Filter hook to modify the output of dozent_get_user_social_links(); function * * @since DozentLMS 1.0.0 */ return apply_filters( 'dozent_get_user_social_links', $links ); }
Changelog
Version | Description |
---|---|
DozentLMS 1.0.0 | Introduced. |