PluginProbe
OttoKit: All-in-One Automation Platform / 1.1.6
OttoKit: All-in-One Automation Platform v1.1.6
1.1.38 1.1.37 1.1.36 1.1.35 1.1.34 1.1.33 1.1.32 1.1.31 1.1.30 1.1.29 1.1.28 1.1.27 1.1.9 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 All 124 releases
suretriggers / src / Integrations / wordpress / wordpress.php
wordpress.php
142 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WordPress core integrations file
4 *
5 * @since 1.0.0
6 * @package SureTrigger
7 */
8
9 namespace SureTriggers\Integrations\WordPress;
10
11 use SureTriggers\Controllers\IntegrationsController;
12 use SureTriggers\Integrations\Integrations;
13 use SureTriggers\Traits\SingletonLoader;
14
15 /**
16 * Class WordPress
17 *
18 * @package SureTriggers\Integrations\Wordpress
19 */
20 class WordPress extends Integrations {
21
22
23 use SingletonLoader;
24
25 /**
26 * ID
27 *
28 * @var string
29 */
30 protected $id = 'WordPress';
31
32
33 /**
34 * Get user context data.
35 *
36 * @param int $id ID.
37 *
38 * @return array
39 */
40 public static function get_user_context( $id ) {
41
42 $user = get_userdata( $id );
43 $context = [];
44 if ( ! $user ) {
45 return $context;
46 }
47 $context['wp_user_id'] = $user->ID;
48 $context['user_login'] = $user->user_login;
49 $context['display_name'] = $user->display_name;
50 $context['user_firstname'] = $user->user_firstname;
51 $context['user_lastname'] = $user->user_lastname;
52 $context['user_email'] = $user->user_email;
53 $context['user_registered'] = $user->user_registered;
54 $context['user_role'] = $user->roles;
55 return $context;
56 }
57
58 /**
59 * Get sample user context data.
60 *
61 * @return string[]
62 */
63 public static function get_sample_user_context() {
64 return [
65 'wp_user_id' => '1',
66 'user_login' => 'john_doe',
67 'display_name' => 'John Doe',
68 'user_firstname' => 'John',
69 'user_lastname' => 'Doe',
70 'user_email' => 'johnd@gmail.com',
71 'user_registered' => '2024-06-18 09:47:58',
72 'user_role' => 'active',
73 ];
74 }
75
76 /**
77 * Get post context data.
78 *
79 * @param int $id ID.
80 *
81 * @return array
82 */
83 public static function get_post_context( $id ) {
84 return (array) get_post( $id );
85 }
86
87 /**
88 * Gets the post meta
89 *
90 * @param int $id ID.
91 *
92 * @return mixed
93 */
94 public static function get_post_meta( $id ) {
95 return get_post_meta( $id );
96 }
97
98 /**
99 * Validating the Email
100 *
101 * @param string $email email.
102 * @return object{valid: bool, multiple: bool}
103 */
104 public static function validate_email( $email ) {
105 $result = [
106 'valid' => true,
107 'multiple' => false,
108 ];
109
110 if ( str_contains( $email, ',' ) ) {
111 $email_list = explode( ',', $email );
112
113 foreach ( $email_list as $single_email ) {
114 if ( ! is_email( trim( $single_email ) ) ) {
115 $result['valid'] = false;
116 $result['multiple'] = true;
117
118 break;
119 }
120 }
121 } else {
122 if ( ! is_email( trim( $email ) ) ) {
123 $result['valid'] = false;
124 }
125 }
126
127 return (object) $result;
128 }
129
130 /**
131 * Is Plugin depended plugin is installed or not.
132 *
133 * @return bool
134 */
135 public function is_plugin_installed() {
136 return true;
137 }
138
139 }
140
141 IntegrationsController::register( WordPress::class );
142