Yoast / wordpress-seo

Yoast SEO for WordPress
https://yoast.com/wordpress/plugins/seo/
Other
1.75k stars 886 forks source link

Make it possible to get contact methods via the frontend too #16391

Open seb86 opened 3 years ago

seb86 commented 3 years ago

Is your feature request related to a problem? Please describe.

I am calling wp_get_user_contact_methods() via my custom theme but none of the contact methods are returning because you have added the filter user_contactmethods to run only in the admin.

Describe the solution you'd like

Move the filtered contact methods so they can be returned at the front and back end of the site.

Why do you think this feature is something we should consider for the Yoast SEO plugins?

Extendability for developers.

AlejandroPerezMartin commented 3 years ago

@seb86 I faced the same issue and found out that you can get those fields from users' meta data using either get_user_meta($USER_ID) or to get a specific field get_user_meta($USER_ID, 'facebook'). All those field names are present in this function: https://github.com/Yoast/wordpress-seo/blob/987967a2a200e832135718e437e8306e0f4333fc/admin/class-admin.php#L277-L286 You could also use get_the_author_meta, the_author_meta...

I hope this helps!

seb86 commented 3 years ago

@AlejandroPerezMartin The whole point of my issue is because i dont know what contact methods could be set. So getting the user meta is not the best approach.

Antonio-Laguna commented 3 years ago

@seb86 what you're requesting could be achieved like this:

$user_meta = get_user_meta($USER_ID);
$network_names = [
    'facebook', 
    'instagram', 
    'linkedin', 
    'myspace', 
    'pinterest', 
    'soundcloud', 
    'tumblr', 
    'twitter', 
    'youtube', 
    'wikipedia'
];
$social_links = [];

foreach ($network_names as $network) {
    if (!empty($user_meta[$network])) {
        $social_links[] = [
            'network' => $network,
            'value' => $user_meta[$network][0]
        ];
    }
}

I agree it could be better but since your issue states you can't bring the data to the front this should cover that need.

seb86 commented 3 years ago

While I agree that it can be done this way @Antonio-Laguna It defeats the whole purpose of using wp_get_user_contact_methods() function which I am using, whether the Yoast plugin is installed or not. Another plugin may choose to add their own contact methods. I should not have to detect by other means what that they are.