| @@ -1,0 +1,35 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Functions | |
| 4 | + * | |
| 5 | + * @package AutomatorWP\Integrations\wpDiscuz\Functions | |
| 6 | + * @author AutomatorWP <[email protected]>, Ruben Garcia <[email protected]> | |
| 7 | + * @since 1.0.0 | |
| 8 | + */ | |
| 9 | +// Exit if accessed directly | |
| 10 | +if( !defined( 'ABSPATH' ) ) exit; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * Get the comment user ID | |
| 14 | + * | |
| 15 | + * @param WP_Comment $comment | |
| 16 | + * | |
| 17 | + * @return int | |
| 18 | + */ | |
| 19 | +function automatorwp_wpdiscuz_get_commment_user_id( $comment ) { | |
| 20 | + | |
| 21 | + $user_id = absint( $comment->user_id ); | |
| 22 | + | |
| 23 | + // If comment has not assigned a user id and wpDiscuz is configured to use the user email, then need to search this user by email | |
| 24 | + if ( $user_id === 0 && wpDiscuz()->options->login["isUserByEmail"] ) { | |
| 25 | + | |
| 26 | + // Get the user by email | |
| 27 | + $user = get_user_by( 'email', $comment->comment_author_email ); | |
| 28 | + | |
| 29 | + if ( $user ) { | |
| 30 | + $user_id = $user->ID; | |
| 31 | + } | |
| 32 | + } | |
| 33 | + | |
| 34 | + return absint( $user_id ); | |
| 35 | +} | |