| 1 |
<?php |
| 2 |
namespace Elementor\Modules\System_Info\Reporters; |
| 3 |
|
| 4 |
use Elementor\Utils; |
| 5 |
|
| 6 |
if ( ! defined( 'ABSPATH' ) ) { |
| 7 |
exit; // Exit if accessed directly. |
| 8 |
} |
| 9 |
|
| 10 |
/** |
| 11 |
* Elementor user report. |
| 12 |
* |
| 13 |
* Elementor system report handler class responsible for generating a report for |
| 14 |
* the user. |
| 15 |
* |
| 16 |
* @since 1.0.0 |
| 17 |
*/ |
| 18 |
class User extends Base { |
| 19 |
|
| 20 |
public function is_enabled() { |
| 21 |
return (bool) wp_get_current_user()->ID; |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Get user reporter title. |
| 26 |
* |
| 27 |
* Retrieve user reporter title. |
| 28 |
* |
| 29 |
* @since 1.0.0 |
| 30 |
* @access public |
| 31 |
* |
| 32 |
* @return string Reporter title. |
| 33 |
*/ |
| 34 |
public function get_title() { |
| 35 |
return 'User'; |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Get user report fields. |
| 40 |
* |
| 41 |
* Retrieve the required fields for the user report. |
| 42 |
* |
| 43 |
* @since 1.0.0 |
| 44 |
* @access public |
| 45 |
* |
| 46 |
* @return array Required report fields with field ID and field label. |
| 47 |
*/ |
| 48 |
public function get_fields() { |
| 49 |
return [ |
| 50 |
'role' => 'Role', |
| 51 |
'locale' => 'WP Profile lang', |
| 52 |
'agent' => 'User Agent', |
| 53 |
]; |
| 54 |
} |
| 55 |
|
| 56 |
/** |
| 57 |
* Get user role. |
| 58 |
* |
| 59 |
* Retrieve the user role. |
| 60 |
* |
| 61 |
* @since 1.0.0 |
| 62 |
* @access public |
| 63 |
* |
| 64 |
* @return array { |
| 65 |
* Report data. |
| 66 |
* |
| 67 |
* @type string $value The user role. |
| 68 |
* } |
| 69 |
*/ |
| 70 |
public function get_role() { |
| 71 |
$role = null; |
| 72 |
|
| 73 |
$current_user = wp_get_current_user(); |
| 74 |
if ( ! empty( $current_user->roles ) ) { |
| 75 |
$role = $current_user->roles[0]; |
| 76 |
} |
| 77 |
|
| 78 |
return [ |
| 79 |
'value' => $role, |
| 80 |
]; |
| 81 |
} |
| 82 |
|
| 83 |
/** |
| 84 |
* Get user profile language. |
| 85 |
* |
| 86 |
* Retrieve the user profile language. |
| 87 |
* |
| 88 |
* @since 1.0.0 |
| 89 |
* @access public |
| 90 |
* |
| 91 |
* @return array { |
| 92 |
* Report data. |
| 93 |
* |
| 94 |
* @type string $value User profile language. |
| 95 |
* } |
| 96 |
*/ |
| 97 |
public function get_locale() { |
| 98 |
return [ |
| 99 |
'value' => get_locale(), |
| 100 |
]; |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* Get user agent. |
| 105 |
* |
| 106 |
* Retrieve user agent. |
| 107 |
* |
| 108 |
* @since 1.0.0 |
| 109 |
* @access public |
| 110 |
* |
| 111 |
* @return array { |
| 112 |
* Report data. |
| 113 |
* |
| 114 |
* @type string $value HTTP user agent. |
| 115 |
* } |
| 116 |
*/ |
| 117 |
public function get_agent() { |
| 118 |
return [ |
| 119 |
'value' => esc_html( Utils::get_super_global_value( $_SERVER, 'HTTP_USER_AGENT' ) ), |
| 120 |
]; |
| 121 |
} |
| 122 |
} |
| 123 |
|