| 1 |
<?php |
| 2 |
/** |
| 3 |
* Global AutomatePlug Functions. |
| 4 |
* |
| 5 |
* @package Automateplug |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Get or prepare user id. |
| 10 |
* |
| 11 |
* @return int|mixed|string|void |
| 12 |
*/ |
| 13 |
function ap_get_current_user_id() { |
| 14 |
|
| 15 |
$user_id = get_current_user_id(); |
| 16 |
|
| 17 |
if ( $user_id ) { |
| 18 |
return $user_id; |
| 19 |
} |
| 20 |
|
| 21 |
if ( ! session_id() ) { //phpcs:ignore |
| 22 |
session_start(); //phpcs:ignore |
| 23 |
} |
| 24 |
|
| 25 |
if ( isset( $_SESSION['ap_user_identifier'] ) ) { |
| 26 |
return $_SESSION['ap_user_identifier']; //phpcs:ignore |
| 27 |
} |
| 28 |
|
| 29 |
$ap_user_id = wp_generate_password( 16, false ); |
| 30 |
$_SESSION['ap_user_identifier'] = $ap_user_id; //phpcs:ignore |
| 31 |
|
| 32 |
return $_SESSION['ap_user_identifier']; //phpcs:ignore |
| 33 |
|
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Get or prepare user id. |
| 38 |
* |
| 39 |
* @param string $email user email. |
| 40 |
* |
| 41 |
* @return int|mixed|string|void |
| 42 |
*/ |
| 43 |
function ap_get_user_id_from_email( $email ) { |
| 44 |
|
| 45 |
if ( empty( $email ) || ! email_exists( $email ) ) { |
| 46 |
return false; |
| 47 |
} |
| 48 |
|
| 49 |
$get_user = get_user_by( 'email', $email ); |
| 50 |
return $get_user->ID; |
| 51 |
|
| 52 |
} |
| 53 |
|
| 54 |
add_action( |
| 55 |
'in_admin_header', |
| 56 |
function () { |
| 57 |
if ( isset( $_GET['page'] ) && 'suretriggers' === sanitize_text_field( $_GET['page'] ) ) { // phpcs:ignore |
| 58 |
remove_all_actions( 'admin_notices' ); |
| 59 |
remove_all_actions( 'all_admin_notices' ); |
| 60 |
} |
| 61 |
}, |
| 62 |
999 |
| 63 |
); |
| 64 |
|
| 65 |
add_action( 'wp_login', 'suretrigger_capture_login_time', 10, 2 ); |
| 66 |
|
| 67 |
/** |
| 68 |
* Login time. |
| 69 |
* |
| 70 |
* @param string $user_login user login. |
| 71 |
* @param object $user user. |
| 72 |
* @return void |
| 73 |
*/ |
| 74 |
function suretrigger_capture_login_time( $user_login, $user ) { |
| 75 |
update_user_meta( $user->ID, 'st_last_login', time() ); |
| 76 |
} |
| 77 |
|