-
-
Save dgoze/0168f95b4581a71c02623a13077855db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Setting Ajax handlers | |
add_action( 'wp_ajax_nopriv_get_author_info', array( $this, 'bps_get_author_info_cb' ) ); | |
add_action( 'wp_ajax_get_author_info', array( $this, 'bps_get_author_info_cb' ) ); | |
/** | |
* Function used to get author info for popup on article | |
*/ | |
public function bps_get_author_info_cb() { | |
global $coauthors_plus; | |
//Checking nonce | |
check_ajax_referer( 'special-ajax-nonce', 'security' ); | |
$user_id = $_POST['author_id']; | |
if ( ! $user_id ) { | |
wp_send_json( [ 'error' => 'No user id found' ] ); | |
exit; | |
} | |
//Guest Author | |
$curauth = $coauthors_plus->get_coauthor_by( 'id', $user_id ); //Getting user obj | |
if ( ! $curauth ) { | |
wp_send_json( [ 'error' => 'No user found' ] ); | |
exit; | |
} | |
//Guest author data | |
$user_photo = get_the_post_thumbnail( $curauth->ID, 'user-thumbnail' ); | |
$response = array( | |
'author_thumbnail' => $user_photo, | |
'author_bio' => $curauth->description, | |
'author_nicename' => $curauth->user_nicename, | |
); | |
wp_send_json( $response ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment