PluginProbe
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More / 2.0.2
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More v2.0.2
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.10 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 47 releases
content-control / vendor-prefixed / trustedlogin / client / src / Cron.php

Cron.php in Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More 2.0.2, at vendor-prefixed/trustedlogin/client/src/Cron.php

131 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @license GPL-2.0-or-later
4 *
5 * Modified by code-atlantic on 18-September-2023 using Strauss.
6 * @see https://github.com/BrianHenryIE/strauss
7 */
8
9 namespace ContentControl\Vendor\TrustedLogin;
10
11 // Exit if accessed directly
12 if ( ! defined('ABSPATH') ) {
13 exit;
14 }
15
16 use \Exception;
17 use \WP_Error;
18 use \WP_User;
19 use \WP_Admin_Bar;
20
21 final class Cron {
22
23 /**
24 * @var \ContentControl\Vendor\TrustedLogin\Config
25 */
26 private $config;
27
28 /**
29 * @var string
30 */
31 private $hook_name;
32
33 /**
34 * @var null|\ContentControl\Vendor\TrustedLogin\Logging $logging
35 */
36 private $logging;
37
38 /**
39 * Cron constructor.
40 *
41 * @param Config $config
42 * @param Logging|null $logging
43 */
44 public function __construct( Config $config, Logging $logging ) {
45 $this->config = $config;
46 $this->logging = $logging;
47
48 $this->hook_name = 'trustedlogin/' . $this->config->ns() . '/access/revoke';
49 }
50
51 /**
52 *
53 */
54 public function init() {
55 add_action( $this->hook_name, array( $this, 'revoke' ), 1 );
56 }
57
58 /**
59 * @param int $expiration_timestamp
60 * @param string $identifier_hash
61 *
62 * @return bool
63 */
64 public function schedule( $expiration_timestamp, $identifier_hash ) {
65
66 $hash = Encryption::hash( $identifier_hash );
67
68 if ( is_wp_error( $hash ) ) {
69 $this->logging->log( $hash, __METHOD__ );
70
71 return false;
72 }
73
74 $args = array( $hash );
75
76 $scheduled_expiration = wp_schedule_single_event( $expiration_timestamp, $this->hook_name, $args );
77
78 $this->logging->log( 'Scheduled Expiration: ' . var_export( $scheduled_expiration, true ) . '; identifier: ' . $identifier_hash, __METHOD__, 'info' );
79
80 return $scheduled_expiration;
81 }
82
83 /**
84 * @param int $expiration_timestamp
85 * @param string $site_identifier_hash
86 *
87 * @return bool
88 */
89 public function reschedule( $expiration_timestamp, $site_identifier_hash ) {
90
91 $hash = Encryption::hash( $site_identifier_hash );
92
93 if ( is_wp_error( $hash ) ) {
94 $this->logging->log( $hash, __METHOD__ );
95
96 return false;
97 }
98
99 $unschedule_expiration = wp_clear_scheduled_hook( $this->hook_name, array( $hash ) );
100
101 switch( $unschedule_expiration ) {
102 case false:
103 $this->logging->log( sprintf( 'Could not clear scheduled hook for %s', $this->hook_name ), __METHOD__, 'error' );
104 return false;
105 case 0:
106 $this->logging->log( sprintf( 'Cron event not found for %s', $this->hook_name ), __METHOD__, 'error' );
107 return false;
108 }
109
110 return $this->schedule( $expiration_timestamp, $site_identifier_hash );
111 }
112
113 /**
114 * Hooked Action: Revokes access for a specific support user
115 *
116 * @since 1.0.0
117 *
118 * @param string $identifier_hash Identifier hash for the user associated with the cron job
119 * @todo
120 * @return void
121 */
122 public function revoke( $identifier_hash ) {
123
124 $this->logging->log( 'Running cron job to disable user. ID: ' . $identifier_hash, __METHOD__, 'notice' );
125
126 $Client = new Client( $this->config, false );
127
128 $Client->revoke_access( $identifier_hash );
129 }
130 }
131