Linkify and Advanced Custom fields: Link all WP Authors/Users

<?php /** * More info on dependencies etc.: https://codepad.co/snippet/QM84k6qd * * This workaround adds all Users of a specified role to the WP Plugin Linkify * * Mr. Max Mustermann -> <a href="/authors/max-musterman">Mr. Max Mustermann</a> * */ /** * Get all Users by role */ function get_users_funtion($role = 'subscriber') { return get_users('orderby=nicename&role='.$role); } /** * Programmatically adds more text to be linked. * * @param array $text_to_links Array of text and their associated URLs. */ function my_text_linkifications( $text_to_links ) { // Add text link $users = get_users_funtion(); foreach ($users as $user) { $text_to_links[$user->display_name] = '/author/' . $user->user_nicename . '/'; } // Important! Return the changes. return $text_to_links; } add_filter( 'c2c_linkify_text', __NAMESPACE__. '\\my_text_linkifications' );
This workaround adds all Users of a specified role to the WP Plugin Linkify

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.