PluginProbe
WPSSO Core – Complete Schema Markup and Meta Tags / 22.7.0
WPSSO Core – Complete Schema Markup and Meta Tags v22.7.0
22.7.0 22.6.1 22.6.0 22.5.3 22.5.2 22.5.1 22.4.0 22.3.0 22.2.1 22.2.0 22.1.3 22.1.2 22.1.1 22.1.0 22.0.0 21.13.3 21.13.2 trunk 21.13.1
wpsso / lib / util-reg.php

util-reg.php in WPSSO Core – Complete Schema Markup and Meta Tags 22.7.0, at lib/util-reg.php

153 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * License: GPLv3
4 * License URI: https://www.gnu.org/licenses/gpl.txt
5 * Copyright 2012-2026 Jean-Sebastien Morisset (https://wpsso.com/)
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9
10 die( 'These aren\'t the droids you\'re looking for.' );
11 }
12
13 if ( ! defined( 'WPSSO_PLUGINDIR' ) ) {
14
15 die( 'Do. Or do not. There is no try.' );
16 }
17
18 if ( ! class_exists( 'WpssoUtilReg' ) ) {
19
20 class WpssoUtilReg {
21
22 private $p; // Wpsso class object.
23
24 /*
25 * Instantiated by WpssoUtil->__construct().
26 */
27 public function __construct( &$plugin ) {
28
29 $this->p =& $plugin;
30
31 if ( $this->p->debug->enabled ) {
32
33 $this->p->debug->mark();
34 }
35 }
36
37 /*
38 * Perform a quick sanity check and return the timestamp array.
39 *
40 * Used by WpssoAdminHead->single_notice_review() and WpssoAdminHead->single_notice_upsell().
41 */
42 public function get_ext_reg() {
43
44 $ext_reg = get_option( WPSSO_REG_TS_NAME, array() );
45
46 $have_changes = false;
47
48 /*
49 * Make sure that all known add-ons have been registered.
50 */
51 foreach ( $this->p->cf[ 'plugin' ] as $ext => $info ) {
52
53 if ( empty( $info[ 'version' ] ) ) { // Not active.
54
55 continue;
56 }
57
58 foreach ( array( 'update', 'install', 'activate' ) as $event ) {
59
60 $update_event = false;
61
62 if ( empty( $ext_reg[ $ext . '_' . $event . '_time' ] ) ) {
63
64 $update_event = true;
65
66 } elseif ( $event === 'update' ) {
67
68 if ( empty( $ext_reg[ $ext . '_' . $event . '_version' ] ) ) {
69
70 $update_event = true;
71
72 } elseif ( $ext_reg[ $ext . '_' . $event . '_version' ] !== $info[ 'version' ] ) {
73
74 $update_event = true;
75 }
76 }
77
78 if ( $update_event ) {
79
80 $have_changes = true;
81
82 self::update_ext_event_time( $ext, $info[ 'version' ], $event );
83 }
84 }
85 }
86
87 if ( $have_changes ) {
88
89 $ext_reg = get_option( WPSSO_REG_TS_NAME, array() );
90 }
91
92 return $ext_reg;
93 }
94
95 /*
96 * Called by all add-ons from their activate_plugin() method.
97 */
98 public static function update_ext_version( $ext, $version ) {
99
100 self::update_ext_event_time( $ext, $version, 'update', $version );
101
102 self::update_ext_event_time( $ext, $version, 'install', $protect = true ); // Do not overwrite existing value.
103
104 self::update_ext_event_time( $ext, $version, 'activate' );
105 }
106
107 /*
108 * Returns the event timestamp, or false if the event has not been registered.
109 *
110 * Used by WpssoRegister->activate_plugin() to determine if this is a new install (to add user roles).
111 */
112 public static function get_ext_event_time( $ext, $event ) {
113
114 $ext_reg = get_option( WPSSO_REG_TS_NAME, array() );
115
116 if ( ! empty( $ext_reg[ $ext . '_' . $event . '_time' ] ) ) {
117
118 return $ext_reg[ $ext . '_' . $event . '_time' ];
119 }
120
121 return false;
122 }
123
124 /*
125 * $protect = true | false | version
126 */
127 private static function update_ext_event_time( $ext, $version, $event, $protect = false ) {
128
129 if ( ! is_bool( $protect ) ) { // Version string.
130
131 if ( ! empty( $protect ) ) {
132
133 $event_version = SucomUtilWP::get_options_key( WPSSO_REG_TS_NAME, $ext . '_' . $event . '_version' );
134
135 if ( $event_version === $protect ) {
136
137 $protect = true;
138
139 } else $protect = false;
140
141 } else $protect = true; // Just in case.
142 }
143
144 if ( ! empty( $version ) ) {
145
146 SucomUtilWP::update_options_key( WPSSO_REG_TS_NAME, $ext . '_' . $event . '_version', $version, $protect );
147 }
148
149 SucomUtilWP::update_options_key( WPSSO_REG_TS_NAME, $ext . '_' . $event . '_time', time(), $protect );
150 }
151 }
152 }
153