@@ -6,16 +6,16 @@ |
||
6 | 6 | |
7 | 7 | class ComposerStaticInitca2d76f00d9dc05bb61631fe434b572d |
8 | 8 | { |
9 | - public static $classMap = array ( |
|
10 | - 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', |
|
11 | - 'Wordlift\\Modules\\Events\\Options_Entity\\Events_Options_Entity_Include_Exclude' => __DIR__ . '/../..' . '/includes/Options_Entity/Events_Options_Entity_Include_Exclude.php', |
|
12 | - 'Wordlift\\Modules\\Events\\Post_Entity\\Events_Post_Entity_Jsonld' => __DIR__ . '/../..' . '/includes/Post_Entity/Events_Post_Entity_Jsonld.php', |
|
13 | - 'Wordlift\\Modules\\Events\\Term_Entity\\Events_Term_Entity_Jsonld' => __DIR__ . '/../..' . '/includes/Term_Entity/Events_Term_Entity_Jsonld.php', |
|
9 | + public static $classMap = array( |
|
10 | + 'Composer\\InstalledVersions' => __DIR__.'/..'.'/composer/InstalledVersions.php', |
|
11 | + 'Wordlift\\Modules\\Events\\Options_Entity\\Events_Options_Entity_Include_Exclude' => __DIR__.'/../..'.'/includes/Options_Entity/Events_Options_Entity_Include_Exclude.php', |
|
12 | + 'Wordlift\\Modules\\Events\\Post_Entity\\Events_Post_Entity_Jsonld' => __DIR__.'/../..'.'/includes/Post_Entity/Events_Post_Entity_Jsonld.php', |
|
13 | + 'Wordlift\\Modules\\Events\\Term_Entity\\Events_Term_Entity_Jsonld' => __DIR__.'/../..'.'/includes/Term_Entity/Events_Term_Entity_Jsonld.php', |
|
14 | 14 | ); |
15 | 15 | |
16 | 16 | public static function getInitializer(ClassLoader $loader) |
17 | 17 | { |
18 | - return \Closure::bind(function () use ($loader) { |
|
18 | + return \Closure::bind(function() use ($loader) { |
|
19 | 19 | $loader->classMap = ComposerStaticInitca2d76f00d9dc05bb61631fe434b572d::$classMap; |
20 | 20 | |
21 | 21 | }, null, ClassLoader::class); |
@@ -6,8 +6,8 @@ |
||
6 | 6 | $baseDir = dirname($vendorDir); |
7 | 7 | |
8 | 8 | return array( |
9 | - 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', |
|
10 | - 'Wordlift\\Modules\\Events\\Options_Entity\\Events_Options_Entity_Include_Exclude' => $baseDir . '/includes/Options_Entity/Events_Options_Entity_Include_Exclude.php', |
|
11 | - 'Wordlift\\Modules\\Events\\Post_Entity\\Events_Post_Entity_Jsonld' => $baseDir . '/includes/Post_Entity/Events_Post_Entity_Jsonld.php', |
|
12 | - 'Wordlift\\Modules\\Events\\Term_Entity\\Events_Term_Entity_Jsonld' => $baseDir . '/includes/Term_Entity/Events_Term_Entity_Jsonld.php', |
|
9 | + 'Composer\\InstalledVersions' => $vendorDir.'/composer/InstalledVersions.php', |
|
10 | + 'Wordlift\\Modules\\Events\\Options_Entity\\Events_Options_Entity_Include_Exclude' => $baseDir.'/includes/Options_Entity/Events_Options_Entity_Include_Exclude.php', |
|
11 | + 'Wordlift\\Modules\\Events\\Post_Entity\\Events_Post_Entity_Jsonld' => $baseDir.'/includes/Post_Entity/Events_Post_Entity_Jsonld.php', |
|
12 | + 'Wordlift\\Modules\\Events\\Term_Entity\\Events_Term_Entity_Jsonld' => $baseDir.'/includes/Term_Entity/Events_Term_Entity_Jsonld.php', |
|
13 | 13 | ); |
@@ -6,29 +6,29 @@ |
||
6 | 6 | |
7 | 7 | class Include_Exclude_API { |
8 | 8 | |
9 | - /** |
|
10 | - * @var Api_Service |
|
11 | - */ |
|
12 | - private $api_service; |
|
9 | + /** |
|
10 | + * @var Api_Service |
|
11 | + */ |
|
12 | + private $api_service; |
|
13 | 13 | |
14 | - /** |
|
15 | - * @param Api_Service $api_service |
|
16 | - */ |
|
17 | - public function __construct( Api_Service $api_service ) { |
|
18 | - $this->api_service = $api_service; |
|
19 | - } |
|
14 | + /** |
|
15 | + * @param Api_Service $api_service |
|
16 | + */ |
|
17 | + public function __construct( Api_Service $api_service ) { |
|
18 | + $this->api_service = $api_service; |
|
19 | + } |
|
20 | 20 | |
21 | - /** |
|
22 | - * Update. |
|
23 | - * |
|
24 | - * @param $payload |
|
25 | - */ |
|
26 | - public function update( $payload ) { |
|
27 | - $this->api_service->request( |
|
28 | - 'PUT', |
|
29 | - '/accounts/me/include-excludes', |
|
30 | - array( 'content-type' => 'application/json' ), |
|
31 | - wp_json_encode( $payload ) |
|
32 | - ); |
|
33 | - } |
|
21 | + /** |
|
22 | + * Update. |
|
23 | + * |
|
24 | + * @param $payload |
|
25 | + */ |
|
26 | + public function update( $payload ) { |
|
27 | + $this->api_service->request( |
|
28 | + 'PUT', |
|
29 | + '/accounts/me/include-excludes', |
|
30 | + array( 'content-type' => 'application/json' ), |
|
31 | + wp_json_encode( $payload ) |
|
32 | + ); |
|
33 | + } |
|
34 | 34 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * @param Api_Service $api_service |
16 | 16 | */ |
17 | - public function __construct( Api_Service $api_service ) { |
|
17 | + public function __construct(Api_Service $api_service) { |
|
18 | 18 | $this->api_service = $api_service; |
19 | 19 | } |
20 | 20 | |
@@ -23,12 +23,12 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @param $payload |
25 | 25 | */ |
26 | - public function update( $payload ) { |
|
26 | + public function update($payload) { |
|
27 | 27 | $this->api_service->request( |
28 | 28 | 'PUT', |
29 | 29 | '/accounts/me/include-excludes', |
30 | - array( 'content-type' => 'application/json' ), |
|
31 | - wp_json_encode( $payload ) |
|
30 | + array('content-type' => 'application/json'), |
|
31 | + wp_json_encode($payload) |
|
32 | 32 | ); |
33 | 33 | } |
34 | 34 | } |
@@ -6,60 +6,60 @@ |
||
6 | 6 | use Wordlift\Modules\Include_Exclude_Push_Config\Include_Exclude_API; |
7 | 7 | |
8 | 8 | if ( ! defined( 'ABSPATH' ) ) { |
9 | - exit; |
|
9 | + exit; |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | // Bail out if the feature isn't enabled. |
13 | 13 | if ( ! apply_filters( 'wl_feature__enable__include-exclude', false ) ) { // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
14 | - return; |
|
14 | + return; |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | // Autoloader for dependencies. |
18 | 18 | if ( file_exists( __DIR__ . '/third-party/vendor/scoper-autoload.php' ) ) { |
19 | - require __DIR__ . '/third-party/vendor/scoper-autoload.php'; |
|
19 | + require __DIR__ . '/third-party/vendor/scoper-autoload.php'; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | // Autoloader for plugin itself. |
23 | 23 | if ( file_exists( __DIR__ . '/includes/vendor/autoload.php' ) ) { |
24 | - require __DIR__ . '/includes/vendor/autoload.php'; |
|
24 | + require __DIR__ . '/includes/vendor/autoload.php'; |
|
25 | 25 | } |
26 | 26 | |
27 | 27 | function __wl_include_exclude_push_config() { |
28 | - // Get the configuration. |
|
29 | - $config = get_option( 'wl_exclude_include_urls_settings', array() ); |
|
28 | + // Get the configuration. |
|
29 | + $config = get_option( 'wl_exclude_include_urls_settings', array() ); |
|
30 | 30 | |
31 | - // Set the default data. |
|
32 | - if ( ! is_array( $config ) || empty( $config ) || ! isset( $config['include_exclude'] ) || ! isset( $config['urls'] ) ) { |
|
33 | - $config = get_option( |
|
34 | - 'wl_exclude_include_urls_settings', |
|
35 | - array( |
|
36 | - 'include_exclude' => 'exclude', |
|
37 | - 'urls' => '', |
|
38 | - ) |
|
39 | - ); |
|
40 | - } |
|
31 | + // Set the default data. |
|
32 | + if ( ! is_array( $config ) || empty( $config ) || ! isset( $config['include_exclude'] ) || ! isset( $config['urls'] ) ) { |
|
33 | + $config = get_option( |
|
34 | + 'wl_exclude_include_urls_settings', |
|
35 | + array( |
|
36 | + 'include_exclude' => 'exclude', |
|
37 | + 'urls' => '', |
|
38 | + ) |
|
39 | + ); |
|
40 | + } |
|
41 | 41 | |
42 | - // Map the configuration to the payload. |
|
43 | - $payload = array_map( |
|
44 | - function ( $item ) use ( $config ) { |
|
45 | - return array( |
|
46 | - 'url' => |
|
47 | - ( 1 === preg_match( '@^https?://.*$@', $item ) ? $item : get_home_url( null, $item ) ), |
|
48 | - 'flag' => strtoupper( $config['include_exclude'] ), |
|
49 | - ); |
|
50 | - }, |
|
51 | - array_filter( preg_split( '/[\r\n]+/', $config['urls'] ) ) |
|
52 | - ); |
|
42 | + // Map the configuration to the payload. |
|
43 | + $payload = array_map( |
|
44 | + function ( $item ) use ( $config ) { |
|
45 | + return array( |
|
46 | + 'url' => |
|
47 | + ( 1 === preg_match( '@^https?://.*$@', $item ) ? $item : get_home_url( null, $item ) ), |
|
48 | + 'flag' => strtoupper( $config['include_exclude'] ), |
|
49 | + ); |
|
50 | + }, |
|
51 | + array_filter( preg_split( '/[\r\n]+/', $config['urls'] ) ) |
|
52 | + ); |
|
53 | 53 | |
54 | - // Load the service. |
|
55 | - $container_builder = new ContainerBuilder(); |
|
56 | - $loader = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) ); |
|
57 | - $loader->load( 'services.yml' ); |
|
58 | - $container_builder->compile(); |
|
54 | + // Load the service. |
|
55 | + $container_builder = new ContainerBuilder(); |
|
56 | + $loader = new YamlFileLoader( $container_builder, new FileLocator( __DIR__ ) ); |
|
57 | + $loader->load( 'services.yml' ); |
|
58 | + $container_builder->compile(); |
|
59 | 59 | |
60 | - /** @var Include_Exclude_API $api */ |
|
61 | - $api = $container_builder->get( 'Wordlift\Modules\Include_Exclude_Push_Config\Include_Exclude_API' ); |
|
62 | - $api->update( $payload ); |
|
60 | + /** @var Include_Exclude_API $api */ |
|
61 | + $api = $container_builder->get( 'Wordlift\Modules\Include_Exclude_Push_Config\Include_Exclude_API' ); |
|
62 | + $api->update( $payload ); |
|
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @since 3.33.6 |
48 | 48 | */ |
49 | 49 | if ( ! apply_filters( 'wl_is_enabled', true ) ) { |
50 | - return; |
|
50 | + return; |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; |
@@ -76,33 +76,33 @@ discard block |
||
76 | 76 | */ |
77 | 77 | function activate_wordlift() { |
78 | 78 | |
79 | - $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
79 | + $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
80 | 80 | |
81 | - $log->info( 'Activating WordLift...' ); |
|
81 | + $log->info( 'Activating WordLift...' ); |
|
82 | 82 | |
83 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
84 | - Wordlift_Activator::activate(); |
|
83 | + require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
84 | + Wordlift_Activator::activate(); |
|
85 | 85 | |
86 | - /** |
|
87 | - * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks. |
|
88 | - * |
|
89 | - * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue. |
|
90 | - * @since 3.19.2 |
|
91 | - */ |
|
92 | - Wordlift_Http_Api::activate(); |
|
86 | + /** |
|
87 | + * Tell the {@link Wordlift_Http_Api} class that we're activating, to let it run activation tasks. |
|
88 | + * |
|
89 | + * @see https://github.com/insideout10/wordlift-plugin/issues/820 related issue. |
|
90 | + * @since 3.19.2 |
|
91 | + */ |
|
92 | + Wordlift_Http_Api::activate(); |
|
93 | 93 | |
94 | - // Ensure the post type is registered before flushing the rewrite rules. |
|
95 | - Wordlift_Entity_Post_Type_Service::get_instance()->register(); |
|
96 | - flush_rewrite_rules(); |
|
97 | - /** |
|
98 | - * @since 3.27.7 |
|
99 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
100 | - */ |
|
101 | - Top_Entities::activate(); |
|
94 | + // Ensure the post type is registered before flushing the rewrite rules. |
|
95 | + Wordlift_Entity_Post_Type_Service::get_instance()->register(); |
|
96 | + flush_rewrite_rules(); |
|
97 | + /** |
|
98 | + * @since 3.27.7 |
|
99 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
100 | + */ |
|
101 | + Top_Entities::activate(); |
|
102 | 102 | |
103 | - if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) { |
|
104 | - wp_schedule_event( time(), 'daily', 'wl_daily_cron' ); |
|
105 | - } |
|
103 | + if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) { |
|
104 | + wp_schedule_event( time(), 'daily', 'wl_daily_cron' ); |
|
105 | + } |
|
106 | 106 | |
107 | 107 | } |
108 | 108 | |
@@ -112,23 +112,23 @@ discard block |
||
112 | 112 | */ |
113 | 113 | function deactivate_wordlift() { |
114 | 114 | |
115 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
116 | - Wordlift_Deactivator::deactivate(); |
|
117 | - Wordlift_Http_Api::deactivate(); |
|
118 | - Ttl_Cache_Cleaner::deactivate(); |
|
119 | - /** |
|
120 | - * @since 3.27.7 |
|
121 | - * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
122 | - */ |
|
123 | - Top_Entities::deactivate(); |
|
124 | - /** |
|
125 | - * @since 3.27.8 |
|
126 | - * Remove notification flag on deactivation. |
|
127 | - */ |
|
128 | - Key_Validation_Notice::remove_notification_flag(); |
|
129 | - flush_rewrite_rules(); |
|
130 | - |
|
131 | - wp_clear_scheduled_hook( 'wl_daily_cron' ); |
|
115 | + require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
116 | + Wordlift_Deactivator::deactivate(); |
|
117 | + Wordlift_Http_Api::deactivate(); |
|
118 | + Ttl_Cache_Cleaner::deactivate(); |
|
119 | + /** |
|
120 | + * @since 3.27.7 |
|
121 | + * @see https://github.com/insideout10/wordlift-plugin/issues/1214 |
|
122 | + */ |
|
123 | + Top_Entities::deactivate(); |
|
124 | + /** |
|
125 | + * @since 3.27.8 |
|
126 | + * Remove notification flag on deactivation. |
|
127 | + */ |
|
128 | + Key_Validation_Notice::remove_notification_flag(); |
|
129 | + flush_rewrite_rules(); |
|
130 | + |
|
131 | + wp_clear_scheduled_hook( 'wl_daily_cron' ); |
|
132 | 132 | |
133 | 133 | } |
134 | 134 | |
@@ -151,84 +151,84 @@ discard block |
||
151 | 151 | * @since 1.0.0 |
152 | 152 | */ |
153 | 153 | function run_wordlift() { |
154 | - /** |
|
155 | - * Filter: wl_feature__enable__widgets. |
|
156 | - * |
|
157 | - * @param bool whether the widgets needed to be registered, defaults to true. |
|
158 | - * |
|
159 | - * @return bool |
|
160 | - * @since 3.27.6 |
|
161 | - */ |
|
162 | - if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
163 | - add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
164 | - add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
165 | - add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
166 | - } |
|
167 | - add_filter( 'widget_text', 'do_shortcode' ); |
|
168 | - |
|
169 | - /** |
|
170 | - * Filter: wl_feature__enable__analysis |
|
171 | - * |
|
172 | - * @param bool Whether to send api request to analysis or not |
|
173 | - * |
|
174 | - * @return bool |
|
175 | - * @since 3.27.6 |
|
176 | - */ |
|
177 | - if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
178 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
179 | - } else { |
|
180 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
181 | - } |
|
182 | - |
|
183 | - $plugin = new Wordlift(); |
|
184 | - $plugin->run(); |
|
185 | - |
|
186 | - // Initialize the TTL Cache Cleaner. |
|
187 | - new Ttl_Cache_Cleaner(); |
|
188 | - |
|
189 | - // Load the new Post Adapter. |
|
190 | - new Post_Adapter(); |
|
191 | - |
|
192 | - // Load the API Data Hooks. |
|
193 | - new Api_Data_Hooks(); |
|
194 | - |
|
195 | - add_action( |
|
196 | - 'plugins_loaded', |
|
197 | - function () { |
|
198 | - // All features from registry should be initialized here. |
|
199 | - $features_registry = Features_Registry::get_instance(); |
|
200 | - $features_registry->initialize_all_features(); |
|
201 | - }, |
|
202 | - 5 |
|
203 | - ); |
|
204 | - |
|
205 | - add_action( |
|
206 | - 'plugins_loaded', |
|
207 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
208 | - function () use ( $plugin ) { |
|
209 | - |
|
210 | - new Wordlift_Products_Navigator_Shortcode_REST(); |
|
211 | - |
|
212 | - // Register the Dataset module, requires `$api_service`. |
|
213 | - require_once plugin_dir_path( __FILE__ ) . 'classes/dataset/index.php'; |
|
214 | - require_once plugin_dir_path( __FILE__ ) . 'classes/shipping-data/index.php'; |
|
215 | - |
|
216 | - /* |
|
154 | + /** |
|
155 | + * Filter: wl_feature__enable__widgets. |
|
156 | + * |
|
157 | + * @param bool whether the widgets needed to be registered, defaults to true. |
|
158 | + * |
|
159 | + * @return bool |
|
160 | + * @since 3.27.6 |
|
161 | + */ |
|
162 | + if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
163 | + add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
164 | + add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
165 | + add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
166 | + } |
|
167 | + add_filter( 'widget_text', 'do_shortcode' ); |
|
168 | + |
|
169 | + /** |
|
170 | + * Filter: wl_feature__enable__analysis |
|
171 | + * |
|
172 | + * @param bool Whether to send api request to analysis or not |
|
173 | + * |
|
174 | + * @return bool |
|
175 | + * @since 3.27.6 |
|
176 | + */ |
|
177 | + if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
178 | + add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
179 | + } else { |
|
180 | + add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
181 | + } |
|
182 | + |
|
183 | + $plugin = new Wordlift(); |
|
184 | + $plugin->run(); |
|
185 | + |
|
186 | + // Initialize the TTL Cache Cleaner. |
|
187 | + new Ttl_Cache_Cleaner(); |
|
188 | + |
|
189 | + // Load the new Post Adapter. |
|
190 | + new Post_Adapter(); |
|
191 | + |
|
192 | + // Load the API Data Hooks. |
|
193 | + new Api_Data_Hooks(); |
|
194 | + |
|
195 | + add_action( |
|
196 | + 'plugins_loaded', |
|
197 | + function () { |
|
198 | + // All features from registry should be initialized here. |
|
199 | + $features_registry = Features_Registry::get_instance(); |
|
200 | + $features_registry->initialize_all_features(); |
|
201 | + }, |
|
202 | + 5 |
|
203 | + ); |
|
204 | + |
|
205 | + add_action( |
|
206 | + 'plugins_loaded', |
|
207 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
208 | + function () use ( $plugin ) { |
|
209 | + |
|
210 | + new Wordlift_Products_Navigator_Shortcode_REST(); |
|
211 | + |
|
212 | + // Register the Dataset module, requires `$api_service`. |
|
213 | + require_once plugin_dir_path( __FILE__ ) . 'classes/dataset/index.php'; |
|
214 | + require_once plugin_dir_path( __FILE__ ) . 'classes/shipping-data/index.php'; |
|
215 | + |
|
216 | + /* |
|
217 | 217 | * Require the Entity annotation cleanup module. |
218 | 218 | * |
219 | 219 | * @since 3.34.6 |
220 | 220 | */ |
221 | - require_once plugin_dir_path( __FILE__ ) . 'classes/cleanup/index.php'; |
|
221 | + require_once plugin_dir_path( __FILE__ ) . 'classes/cleanup/index.php'; |
|
222 | 222 | |
223 | - /* |
|
223 | + /* |
|
224 | 224 | * Import LOD entities. |
225 | 225 | * |
226 | 226 | * @since 3.35.0 |
227 | 227 | */ |
228 | - require_once plugin_dir_path( __FILE__ ) . 'classes/lod-import/index.php'; |
|
228 | + require_once plugin_dir_path( __FILE__ ) . 'classes/lod-import/index.php'; |
|
229 | 229 | |
230 | - } |
|
231 | - ); |
|
230 | + } |
|
231 | + ); |
|
232 | 232 | |
233 | 233 | } |
234 | 234 | |
@@ -242,50 +242,50 @@ discard block |
||
242 | 242 | */ |
243 | 243 | function wordlift_plugin_autoload_register() { |
244 | 244 | |
245 | - spl_autoload_register( |
|
246 | - function ( $class_name ) { |
|
245 | + spl_autoload_register( |
|
246 | + function ( $class_name ) { |
|
247 | 247 | |
248 | - // Bail out if these are not our classes. |
|
249 | - if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
250 | - return false; |
|
251 | - } |
|
248 | + // Bail out if these are not our classes. |
|
249 | + if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
250 | + return false; |
|
251 | + } |
|
252 | 252 | |
253 | - $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
253 | + $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
254 | 254 | |
255 | - preg_match( '|^wordlift\\\\(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
255 | + preg_match( '|^wordlift\\\\(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
256 | 256 | |
257 | - $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
258 | - $file = 'class-' . $matches[2] . '.php'; |
|
257 | + $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
258 | + $file = 'class-' . $matches[2] . '.php'; |
|
259 | 259 | |
260 | - $full_path = plugin_dir_path( __FILE__ ) . 'classes' . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $file; |
|
260 | + $full_path = plugin_dir_path( __FILE__ ) . 'classes' . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $file; |
|
261 | 261 | |
262 | - if ( ! file_exists( $full_path ) ) { |
|
263 | - return false; |
|
264 | - } |
|
262 | + if ( ! file_exists( $full_path ) ) { |
|
263 | + return false; |
|
264 | + } |
|
265 | 265 | |
266 | - try { |
|
267 | - require_once $full_path; |
|
268 | - } catch ( Exception $e ) { |
|
269 | - // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log |
|
270 | - error_log( "[WordLift] $full_path not found, cannot include." ); |
|
271 | - } |
|
266 | + try { |
|
267 | + require_once $full_path; |
|
268 | + } catch ( Exception $e ) { |
|
269 | + // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log |
|
270 | + error_log( "[WordLift] $full_path not found, cannot include." ); |
|
271 | + } |
|
272 | 272 | |
273 | - return true; |
|
274 | - } |
|
275 | - ); |
|
273 | + return true; |
|
274 | + } |
|
275 | + ); |
|
276 | 276 | |
277 | 277 | } |
278 | 278 | |
279 | 279 | function wl_block_categories( $categories ) { |
280 | - return array_merge( |
|
281 | - $categories, |
|
282 | - array( |
|
283 | - array( |
|
284 | - 'slug' => 'wordlift', |
|
285 | - 'title' => __( 'WordLift', 'wordlift' ), |
|
286 | - ), |
|
287 | - ) |
|
288 | - ); |
|
280 | + return array_merge( |
|
281 | + $categories, |
|
282 | + array( |
|
283 | + array( |
|
284 | + 'slug' => 'wordlift', |
|
285 | + 'title' => __( 'WordLift', 'wordlift' ), |
|
286 | + ), |
|
287 | + ) |
|
288 | + ); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
@@ -293,19 +293,19 @@ discard block |
||
293 | 293 | * this has to be removed when removing the legacy fields from the ui. |
294 | 294 | */ |
295 | 295 | function wl_enqueue_leaflet( $in_footer = false ) { |
296 | - // Leaflet. |
|
297 | - wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' ); |
|
298 | - wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer ); |
|
296 | + // Leaflet. |
|
297 | + wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' ); |
|
298 | + wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer ); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | add_filter( 'block_categories', 'wl_block_categories', 10 ); |
302 | 302 | |
303 | 303 | // Temporary fix for a typo in WooCommerce Extension. |
304 | 304 | add_filter( |
305 | - 'wl_feature__enable__dataset', |
|
306 | - function ( $value ) { |
|
307 | - return apply_filters( 'wl_features__enable__dataset', $value ); |
|
308 | - } |
|
305 | + 'wl_feature__enable__dataset', |
|
306 | + function ( $value ) { |
|
307 | + return apply_filters( 'wl_features__enable__dataset', $value ); |
|
308 | + } |
|
309 | 309 | ); |
310 | 310 | |
311 | 311 | require_once __DIR__ . '/modules/food-kg/load.php'; |
@@ -320,35 +320,35 @@ discard block |
||
320 | 320 | require_once __DIR__ . '/modules/events/load.php'; |
321 | 321 | |
322 | 322 | function _wl_update_plugins_raptive_domain( $update, $plugin_data, $plugin_file ) { |
323 | - // Bail out if it's not our plugin. |
|
324 | - $update_uri = $plugin_data['UpdateURI']; |
|
325 | - if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) { |
|
326 | - return $update; |
|
327 | - } |
|
328 | - |
|
329 | - $response = wp_remote_get( "$update_uri?nocache=" . time() ); |
|
330 | - |
|
331 | - if ( is_wp_error( $response ) ) { |
|
332 | - return $update; |
|
333 | - } |
|
334 | - |
|
335 | - try { |
|
336 | - return json_decode( wp_remote_retrieve_body( $response ) ); |
|
337 | - } catch ( Exception $e ) { |
|
338 | - return $update; |
|
339 | - } |
|
323 | + // Bail out if it's not our plugin. |
|
324 | + $update_uri = $plugin_data['UpdateURI']; |
|
325 | + if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) { |
|
326 | + return $update; |
|
327 | + } |
|
328 | + |
|
329 | + $response = wp_remote_get( "$update_uri?nocache=" . time() ); |
|
330 | + |
|
331 | + if ( is_wp_error( $response ) ) { |
|
332 | + return $update; |
|
333 | + } |
|
334 | + |
|
335 | + try { |
|
336 | + return json_decode( wp_remote_retrieve_body( $response ) ); |
|
337 | + } catch ( Exception $e ) { |
|
338 | + return $update; |
|
339 | + } |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | add_action( |
343 | - 'update_plugins_adthrive.wordlift.io', |
|
344 | - '_wl_update_plugins_raptive_domain', |
|
345 | - 10, |
|
346 | - 3 |
|
343 | + 'update_plugins_adthrive.wordlift.io', |
|
344 | + '_wl_update_plugins_raptive_domain', |
|
345 | + 10, |
|
346 | + 3 |
|
347 | 347 | ); |
348 | 348 | |
349 | 349 | add_action( |
350 | - 'update_plugins_raptive.wordlift.io', |
|
351 | - '_wl_update_plugins_raptive_domain', |
|
352 | - 10, |
|
353 | - 3 |
|
350 | + 'update_plugins_raptive.wordlift.io', |
|
351 | + '_wl_update_plugins_raptive_domain', |
|
352 | + 10, |
|
353 | + 3 |
|
354 | 354 | ); |
@@ -31,26 +31,26 @@ discard block |
||
31 | 31 | use Wordlift\Features\Features_Registry; |
32 | 32 | use Wordlift\Post\Post_Adapter; |
33 | 33 | |
34 | -define( 'WORDLIFT_PLUGIN_FILE', __FILE__ ); |
|
35 | -define( 'WORDLIFT_VERSION', '3.47.0-0' ); |
|
34 | +define('WORDLIFT_PLUGIN_FILE', __FILE__); |
|
35 | +define('WORDLIFT_VERSION', '3.47.0-0'); |
|
36 | 36 | |
37 | 37 | // ## DO NOT REMOVE THIS LINE: WHITELABEL PLACEHOLDER ## |
38 | 38 | |
39 | -require_once plugin_dir_path( __FILE__ ) . '/libraries/action-scheduler/action-scheduler.php'; |
|
40 | -require_once __DIR__ . '/modules/common/load.php'; |
|
41 | -require_once __DIR__ . '/modules/app/load.php'; |
|
42 | -require_once __DIR__ . '/modules/include-exclude/load.php'; |
|
39 | +require_once plugin_dir_path(__FILE__).'/libraries/action-scheduler/action-scheduler.php'; |
|
40 | +require_once __DIR__.'/modules/common/load.php'; |
|
41 | +require_once __DIR__.'/modules/app/load.php'; |
|
42 | +require_once __DIR__.'/modules/include-exclude/load.php'; |
|
43 | 43 | |
44 | 44 | /** |
45 | 45 | * Filter to disable WLP on any request, defaults to true. |
46 | 46 | * |
47 | 47 | * @since 3.33.6 |
48 | 48 | */ |
49 | -if ( ! apply_filters( 'wl_is_enabled', true ) ) { |
|
49 | +if ( ! apply_filters('wl_is_enabled', true)) { |
|
50 | 50 | return; |
51 | 51 | } |
52 | 52 | |
53 | -require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php'; |
|
53 | +require_once plugin_dir_path(__FILE__).'vendor/autoload.php'; |
|
54 | 54 | |
55 | 55 | /* |
56 | 56 | * We introduce the WordLift autoloader, since we start using classes in namespaces, i.e. Wordlift\Http. |
@@ -60,15 +60,15 @@ discard block |
||
60 | 60 | wordlift_plugin_autoload_register(); |
61 | 61 | |
62 | 62 | // Include WordLift constants. |
63 | -require_once plugin_dir_path( __FILE__ ) . 'wordlift-constants.php'; |
|
63 | +require_once plugin_dir_path(__FILE__).'wordlift-constants.php'; |
|
64 | 64 | |
65 | 65 | // Load modules. |
66 | -require_once plugin_dir_path( __FILE__ ) . 'modules/core/wordlift-core.php'; |
|
66 | +require_once plugin_dir_path(__FILE__).'modules/core/wordlift-core.php'; |
|
67 | 67 | |
68 | -require_once plugin_dir_path( __FILE__ ) . 'deprecations.php'; |
|
68 | +require_once plugin_dir_path(__FILE__).'deprecations.php'; |
|
69 | 69 | |
70 | 70 | // Load early to enable/disable features. |
71 | -require_once plugin_dir_path( __FILE__ ) . 'classes/features/index.php'; |
|
71 | +require_once plugin_dir_path(__FILE__).'classes/features/index.php'; |
|
72 | 72 | |
73 | 73 | /** |
74 | 74 | * The code that runs during plugin activation. |
@@ -76,11 +76,11 @@ discard block |
||
76 | 76 | */ |
77 | 77 | function activate_wordlift() { |
78 | 78 | |
79 | - $log = Wordlift_Log_Service::get_logger( 'activate_wordlift' ); |
|
79 | + $log = Wordlift_Log_Service::get_logger('activate_wordlift'); |
|
80 | 80 | |
81 | - $log->info( 'Activating WordLift...' ); |
|
81 | + $log->info('Activating WordLift...'); |
|
82 | 82 | |
83 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-activator.php'; |
|
83 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-activator.php'; |
|
84 | 84 | Wordlift_Activator::activate(); |
85 | 85 | |
86 | 86 | /** |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | */ |
101 | 101 | Top_Entities::activate(); |
102 | 102 | |
103 | - if ( ! wp_next_scheduled( 'wl_daily_cron' ) ) { |
|
104 | - wp_schedule_event( time(), 'daily', 'wl_daily_cron' ); |
|
103 | + if ( ! wp_next_scheduled('wl_daily_cron')) { |
|
104 | + wp_schedule_event(time(), 'daily', 'wl_daily_cron'); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | } |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | */ |
113 | 113 | function deactivate_wordlift() { |
114 | 114 | |
115 | - require_once plugin_dir_path( __FILE__ ) . 'includes/class-wordlift-deactivator.php'; |
|
115 | + require_once plugin_dir_path(__FILE__).'includes/class-wordlift-deactivator.php'; |
|
116 | 116 | Wordlift_Deactivator::deactivate(); |
117 | 117 | Wordlift_Http_Api::deactivate(); |
118 | 118 | Ttl_Cache_Cleaner::deactivate(); |
@@ -128,18 +128,18 @@ discard block |
||
128 | 128 | Key_Validation_Notice::remove_notification_flag(); |
129 | 129 | flush_rewrite_rules(); |
130 | 130 | |
131 | - wp_clear_scheduled_hook( 'wl_daily_cron' ); |
|
131 | + wp_clear_scheduled_hook('wl_daily_cron'); |
|
132 | 132 | |
133 | 133 | } |
134 | 134 | |
135 | -register_activation_hook( __FILE__, 'activate_wordlift' ); |
|
136 | -register_deactivation_hook( __FILE__, 'deactivate_wordlift' ); |
|
135 | +register_activation_hook(__FILE__, 'activate_wordlift'); |
|
136 | +register_deactivation_hook(__FILE__, 'deactivate_wordlift'); |
|
137 | 137 | |
138 | 138 | /** |
139 | 139 | * The core plugin class that is used to define internationalization, |
140 | 140 | * admin-specific hooks, and public-facing site hooks. |
141 | 141 | */ |
142 | -require plugin_dir_path( __FILE__ ) . 'includes/class-wordlift.php'; |
|
142 | +require plugin_dir_path(__FILE__).'includes/class-wordlift.php'; |
|
143 | 143 | |
144 | 144 | /** |
145 | 145 | * Begins execution of the plugin. |
@@ -159,12 +159,12 @@ discard block |
||
159 | 159 | * @return bool |
160 | 160 | * @since 3.27.6 |
161 | 161 | */ |
162 | - if ( apply_filters( 'wl_feature__enable__widgets', true ) ) { |
|
163 | - add_action( 'widgets_init', 'wl_register_chord_widget' ); |
|
164 | - add_action( 'widgets_init', 'wl_register_geo_widget' ); |
|
165 | - add_action( 'widgets_init', 'wl_register_timeline_widget' ); |
|
162 | + if (apply_filters('wl_feature__enable__widgets', true)) { |
|
163 | + add_action('widgets_init', 'wl_register_chord_widget'); |
|
164 | + add_action('widgets_init', 'wl_register_geo_widget'); |
|
165 | + add_action('widgets_init', 'wl_register_timeline_widget'); |
|
166 | 166 | } |
167 | - add_filter( 'widget_text', 'do_shortcode' ); |
|
167 | + add_filter('widget_text', 'do_shortcode'); |
|
168 | 168 | |
169 | 169 | /** |
170 | 170 | * Filter: wl_feature__enable__analysis |
@@ -174,10 +174,10 @@ discard block |
||
174 | 174 | * @return bool |
175 | 175 | * @since 3.27.6 |
176 | 176 | */ |
177 | - if ( apply_filters( 'wl_feature__enable__analysis', true ) ) { |
|
178 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_action' ); |
|
177 | + if (apply_filters('wl_feature__enable__analysis', true)) { |
|
178 | + add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_action'); |
|
179 | 179 | } else { |
180 | - add_action( 'wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action' ); |
|
180 | + add_action('wp_ajax_wl_analyze', 'wl_ajax_analyze_disabled_action'); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | $plugin = new Wordlift(); |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | |
195 | 195 | add_action( |
196 | 196 | 'plugins_loaded', |
197 | - function () { |
|
197 | + function() { |
|
198 | 198 | // All features from registry should be initialized here. |
199 | 199 | $features_registry = Features_Registry::get_instance(); |
200 | 200 | $features_registry->initialize_all_features(); |
@@ -205,27 +205,27 @@ discard block |
||
205 | 205 | add_action( |
206 | 206 | 'plugins_loaded', |
207 | 207 | // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
208 | - function () use ( $plugin ) { |
|
208 | + function() use ($plugin) { |
|
209 | 209 | |
210 | 210 | new Wordlift_Products_Navigator_Shortcode_REST(); |
211 | 211 | |
212 | 212 | // Register the Dataset module, requires `$api_service`. |
213 | - require_once plugin_dir_path( __FILE__ ) . 'classes/dataset/index.php'; |
|
214 | - require_once plugin_dir_path( __FILE__ ) . 'classes/shipping-data/index.php'; |
|
213 | + require_once plugin_dir_path(__FILE__).'classes/dataset/index.php'; |
|
214 | + require_once plugin_dir_path(__FILE__).'classes/shipping-data/index.php'; |
|
215 | 215 | |
216 | 216 | /* |
217 | 217 | * Require the Entity annotation cleanup module. |
218 | 218 | * |
219 | 219 | * @since 3.34.6 |
220 | 220 | */ |
221 | - require_once plugin_dir_path( __FILE__ ) . 'classes/cleanup/index.php'; |
|
221 | + require_once plugin_dir_path(__FILE__).'classes/cleanup/index.php'; |
|
222 | 222 | |
223 | 223 | /* |
224 | 224 | * Import LOD entities. |
225 | 225 | * |
226 | 226 | * @since 3.35.0 |
227 | 227 | */ |
228 | - require_once plugin_dir_path( __FILE__ ) . 'classes/lod-import/index.php'; |
|
228 | + require_once plugin_dir_path(__FILE__).'classes/lod-import/index.php'; |
|
229 | 229 | |
230 | 230 | } |
231 | 231 | ); |
@@ -243,31 +243,31 @@ discard block |
||
243 | 243 | function wordlift_plugin_autoload_register() { |
244 | 244 | |
245 | 245 | spl_autoload_register( |
246 | - function ( $class_name ) { |
|
246 | + function($class_name) { |
|
247 | 247 | |
248 | 248 | // Bail out if these are not our classes. |
249 | - if ( 0 !== strpos( $class_name, 'Wordlift\\' ) ) { |
|
249 | + if (0 !== strpos($class_name, 'Wordlift\\')) { |
|
250 | 250 | return false; |
251 | 251 | } |
252 | 252 | |
253 | - $class_name_lc = strtolower( str_replace( '_', '-', $class_name ) ); |
|
253 | + $class_name_lc = strtolower(str_replace('_', '-', $class_name)); |
|
254 | 254 | |
255 | - preg_match( '|^wordlift\\\\(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches ); |
|
255 | + preg_match('|^wordlift\\\\(?:(.*)\\\\)?(.+?)$|', $class_name_lc, $matches); |
|
256 | 256 | |
257 | - $path = str_replace( '\\', DIRECTORY_SEPARATOR, $matches[1] ); |
|
258 | - $file = 'class-' . $matches[2] . '.php'; |
|
257 | + $path = str_replace('\\', DIRECTORY_SEPARATOR, $matches[1]); |
|
258 | + $file = 'class-'.$matches[2].'.php'; |
|
259 | 259 | |
260 | - $full_path = plugin_dir_path( __FILE__ ) . 'classes' . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . $file; |
|
260 | + $full_path = plugin_dir_path(__FILE__).'classes'.DIRECTORY_SEPARATOR.$path.DIRECTORY_SEPARATOR.$file; |
|
261 | 261 | |
262 | - if ( ! file_exists( $full_path ) ) { |
|
262 | + if ( ! file_exists($full_path)) { |
|
263 | 263 | return false; |
264 | 264 | } |
265 | 265 | |
266 | 266 | try { |
267 | 267 | require_once $full_path; |
268 | - } catch ( Exception $e ) { |
|
268 | + } catch (Exception $e) { |
|
269 | 269 | // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log |
270 | - error_log( "[WordLift] $full_path not found, cannot include." ); |
|
270 | + error_log("[WordLift] $full_path not found, cannot include."); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | return true; |
@@ -276,13 +276,13 @@ discard block |
||
276 | 276 | |
277 | 277 | } |
278 | 278 | |
279 | -function wl_block_categories( $categories ) { |
|
279 | +function wl_block_categories($categories) { |
|
280 | 280 | return array_merge( |
281 | 281 | $categories, |
282 | 282 | array( |
283 | 283 | array( |
284 | 284 | 'slug' => 'wordlift', |
285 | - 'title' => __( 'WordLift', 'wordlift' ), |
|
285 | + 'title' => __('WordLift', 'wordlift'), |
|
286 | 286 | ), |
287 | 287 | ) |
288 | 288 | ); |
@@ -292,49 +292,49 @@ discard block |
||
292 | 292 | * This function is created temporarily to handle the legacy library, |
293 | 293 | * this has to be removed when removing the legacy fields from the ui. |
294 | 294 | */ |
295 | -function wl_enqueue_leaflet( $in_footer = false ) { |
|
295 | +function wl_enqueue_leaflet($in_footer = false) { |
|
296 | 296 | // Leaflet. |
297 | - wp_enqueue_style( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.css', array(), '1.6.0' ); |
|
298 | - wp_enqueue_script( 'wl-leaflet', plugin_dir_url( __FILE__ ) . 'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer ); |
|
297 | + wp_enqueue_style('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.css', array(), '1.6.0'); |
|
298 | + wp_enqueue_script('wl-leaflet', plugin_dir_url(__FILE__).'js/leaflet/leaflet.js', array(), '1.6.0', $in_footer); |
|
299 | 299 | } |
300 | 300 | |
301 | -add_filter( 'block_categories', 'wl_block_categories', 10 ); |
|
301 | +add_filter('block_categories', 'wl_block_categories', 10); |
|
302 | 302 | |
303 | 303 | // Temporary fix for a typo in WooCommerce Extension. |
304 | 304 | add_filter( |
305 | 305 | 'wl_feature__enable__dataset', |
306 | - function ( $value ) { |
|
307 | - return apply_filters( 'wl_features__enable__dataset', $value ); |
|
306 | + function($value) { |
|
307 | + return apply_filters('wl_features__enable__dataset', $value); |
|
308 | 308 | } |
309 | 309 | ); |
310 | 310 | |
311 | -require_once __DIR__ . '/modules/food-kg/load.php'; |
|
312 | -require_once __DIR__ . '/modules/gardening-kg/load.php'; |
|
313 | -require_once __DIR__ . '/modules/acf4so/load.php'; |
|
314 | -require_once __DIR__ . '/modules/dashboard/load.php'; |
|
315 | -require_once __DIR__ . '/modules/pods/load.php'; |
|
316 | -require_once __DIR__ . '/modules/include-exclude-push-config/load.php'; |
|
317 | -require_once __DIR__ . '/modules/super-resolution/load.php'; |
|
318 | -require_once __DIR__ . '/modules/redeem-code/load.php'; |
|
319 | -require_once __DIR__ . '/modules/raptive-setup/load.php'; |
|
320 | -require_once __DIR__ . '/modules/events/load.php'; |
|
321 | - |
|
322 | -function _wl_update_plugins_raptive_domain( $update, $plugin_data, $plugin_file ) { |
|
311 | +require_once __DIR__.'/modules/food-kg/load.php'; |
|
312 | +require_once __DIR__.'/modules/gardening-kg/load.php'; |
|
313 | +require_once __DIR__.'/modules/acf4so/load.php'; |
|
314 | +require_once __DIR__.'/modules/dashboard/load.php'; |
|
315 | +require_once __DIR__.'/modules/pods/load.php'; |
|
316 | +require_once __DIR__.'/modules/include-exclude-push-config/load.php'; |
|
317 | +require_once __DIR__.'/modules/super-resolution/load.php'; |
|
318 | +require_once __DIR__.'/modules/redeem-code/load.php'; |
|
319 | +require_once __DIR__.'/modules/raptive-setup/load.php'; |
|
320 | +require_once __DIR__.'/modules/events/load.php'; |
|
321 | + |
|
322 | +function _wl_update_plugins_raptive_domain($update, $plugin_data, $plugin_file) { |
|
323 | 323 | // Bail out if it's not our plugin. |
324 | 324 | $update_uri = $plugin_data['UpdateURI']; |
325 | - if ( 'wordlift/wordlift.php' !== $plugin_file || ! isset( $update_uri ) ) { |
|
325 | + if ('wordlift/wordlift.php' !== $plugin_file || ! isset($update_uri)) { |
|
326 | 326 | return $update; |
327 | 327 | } |
328 | 328 | |
329 | - $response = wp_remote_get( "$update_uri?nocache=" . time() ); |
|
329 | + $response = wp_remote_get("$update_uri?nocache=".time()); |
|
330 | 330 | |
331 | - if ( is_wp_error( $response ) ) { |
|
331 | + if (is_wp_error($response)) { |
|
332 | 332 | return $update; |
333 | 333 | } |
334 | 334 | |
335 | 335 | try { |
336 | - return json_decode( wp_remote_retrieve_body( $response ) ); |
|
337 | - } catch ( Exception $e ) { |
|
336 | + return json_decode(wp_remote_retrieve_body($response)); |
|
337 | + } catch (Exception $e) { |
|
338 | 338 | return $update; |
339 | 339 | } |
340 | 340 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | 'version' => 'dev-develop', |
6 | 6 | 'reference' => '8ecf5a41e6c7973462fa86644e2e9ef88737d2b7', |
7 | 7 | 'type' => 'wordpress-plugin', |
8 | - 'install_path' => __DIR__ . '/../../', |
|
8 | + 'install_path' => __DIR__.'/../../', |
|
9 | 9 | 'aliases' => array(), |
10 | 10 | 'dev' => true, |
11 | 11 | ), |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | 'version' => 'dev-develop', |
16 | 16 | 'reference' => '8ecf5a41e6c7973462fa86644e2e9ef88737d2b7', |
17 | 17 | 'type' => 'wordpress-plugin', |
18 | - 'install_path' => __DIR__ . '/../../', |
|
18 | + 'install_path' => __DIR__.'/../../', |
|
19 | 19 | 'aliases' => array(), |
20 | 20 | 'dev_requirement' => false, |
21 | 21 | ), |
@@ -12,115 +12,115 @@ |
||
12 | 12 | */ |
13 | 13 | class Events_Post_Entity_Jsonld { |
14 | 14 | |
15 | - /** |
|
16 | - * The {@link Api_Service} used to communicate with the remote APIs. |
|
17 | - * |
|
18 | - * @access private |
|
19 | - * @var Api_Service |
|
20 | - */ |
|
21 | - private $api_service; |
|
22 | - |
|
23 | - /** |
|
24 | - * @param Api_Service $api_service |
|
25 | - */ |
|
26 | - public function __construct( Api_Service $api_service ) { |
|
27 | - $this->api_service = $api_service; |
|
28 | - } |
|
29 | - |
|
30 | - /** |
|
31 | - * Register hooks. |
|
32 | - */ |
|
33 | - public function register_hooks() { |
|
34 | - add_filter( 'wl_after_get_jsonld', array( $this, 'set_events_request' ), 90, 3 ); |
|
35 | - } |
|
36 | - |
|
37 | - /** |
|
38 | - * Set events request. |
|
39 | - * |
|
40 | - * @param $jsonld_arr array The final jsonld before outputting to page. |
|
41 | - * @param $post_id int The post id for which the jsonld is generated. |
|
42 | - * @param $context int A context for the JSON-LD generation, valid values in Jsonld_Context_Enum |
|
43 | - * |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - public function set_events_request( $jsonld_arr, $post_id, $context ) { |
|
47 | - // If context is not PAGE, return early. |
|
48 | - if ( Jsonld_Context_Enum::PAGE !== $context ) { |
|
49 | - return $jsonld_arr; |
|
50 | - } |
|
51 | - |
|
52 | - // Flag to indicate if we should make an API request. |
|
53 | - $change_status = false; |
|
54 | - |
|
55 | - // Fetch the initial 'about' and 'mentions' counts from post meta. |
|
56 | - $counts = [ |
|
57 | - 'about' => get_post_meta( $post_id, 'wl_about_count', true ) ? (int) get_post_meta( $post_id, 'wl_about_count', true ) : 0, |
|
58 | - 'mentions' => get_post_meta( $post_id, 'wl_mentions_count', true ) |
|
59 | - ? (int) get_post_meta( $post_id, 'wl_mentions_count', true ) |
|
60 | - : 0, |
|
61 | - ]; |
|
62 | - |
|
63 | - // Check if $jsonld_arr is not empty |
|
64 | - if ( ! empty( $jsonld_arr[0] ) ) { |
|
65 | - // Get data from the array. |
|
66 | - $data = $jsonld_arr[0]; |
|
67 | - |
|
68 | - // Iterate over the counts array. |
|
69 | - foreach ( $counts as $type => $type_count ) { |
|
70 | - // Check if data has 'about' or 'mentions' and the count is different from the existing meta value. |
|
71 | - if ( isset( $data[ $type ] ) ) { |
|
72 | - $new_count = count( $data[ $type ] ); |
|
73 | - |
|
74 | - if ( $type_count !== $new_count ) { |
|
75 | - // Set flag to true if counts have changed. |
|
76 | - $change_status = true; |
|
77 | - |
|
78 | - // Update the counts array with new count. |
|
79 | - $counts[ $type ] = $new_count; |
|
80 | - |
|
81 | - // Update post meta with new count. |
|
82 | - update_post_meta( $post_id, 'wl_' . $type . '_count', $new_count ); |
|
83 | - } |
|
84 | - } // If the 'about' or 'mentions' has become empty, set it to 0. |
|
85 | - else if ( $type_count > 0 ) { |
|
86 | - $change_status = true; |
|
87 | - $counts[ $type ] = 0; |
|
88 | - update_post_meta( $post_id, 'wl_' . $type . '_count', 0 ); |
|
89 | - } |
|
90 | - } |
|
91 | - } // If the $jsonld_arr is empty but the counts were previously more than 0. |
|
92 | - else { |
|
93 | - foreach ( $counts as $type => $type_count ) { |
|
94 | - if ( $type_count > 0 ) { |
|
95 | - $change_status = true; |
|
96 | - $counts[ $type ] = 0; |
|
97 | - update_post_meta( $post_id, 'wl_' . $type . '_count', 0 ); |
|
98 | - } |
|
99 | - } |
|
100 | - } |
|
101 | - |
|
102 | - // If the count has changed, make the API request. |
|
103 | - if ( $change_status ) { |
|
104 | - $this->api_service->request( |
|
105 | - 'POST', |
|
106 | - '/plugin/events', |
|
107 | - array( 'Content-Type' => 'application/json' ), |
|
108 | - wp_json_encode( |
|
109 | - array( |
|
110 | - 'source' => 'jsonld', |
|
111 | - 'args' => array( |
|
112 | - array( 'about_count' => $counts['about'] ), |
|
113 | - array( 'mentions_count' => $counts['mentions'] ), |
|
114 | - ), |
|
115 | - 'url' => get_permalink( $post_id ), |
|
116 | - ) |
|
117 | - ), |
|
118 | - 0.001, |
|
119 | - null, |
|
120 | - array( 'blocking' => false ) |
|
121 | - ); |
|
122 | - } |
|
123 | - |
|
124 | - return $jsonld_arr; |
|
125 | - } |
|
15 | + /** |
|
16 | + * The {@link Api_Service} used to communicate with the remote APIs. |
|
17 | + * |
|
18 | + * @access private |
|
19 | + * @var Api_Service |
|
20 | + */ |
|
21 | + private $api_service; |
|
22 | + |
|
23 | + /** |
|
24 | + * @param Api_Service $api_service |
|
25 | + */ |
|
26 | + public function __construct( Api_Service $api_service ) { |
|
27 | + $this->api_service = $api_service; |
|
28 | + } |
|
29 | + |
|
30 | + /** |
|
31 | + * Register hooks. |
|
32 | + */ |
|
33 | + public function register_hooks() { |
|
34 | + add_filter( 'wl_after_get_jsonld', array( $this, 'set_events_request' ), 90, 3 ); |
|
35 | + } |
|
36 | + |
|
37 | + /** |
|
38 | + * Set events request. |
|
39 | + * |
|
40 | + * @param $jsonld_arr array The final jsonld before outputting to page. |
|
41 | + * @param $post_id int The post id for which the jsonld is generated. |
|
42 | + * @param $context int A context for the JSON-LD generation, valid values in Jsonld_Context_Enum |
|
43 | + * |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + public function set_events_request( $jsonld_arr, $post_id, $context ) { |
|
47 | + // If context is not PAGE, return early. |
|
48 | + if ( Jsonld_Context_Enum::PAGE !== $context ) { |
|
49 | + return $jsonld_arr; |
|
50 | + } |
|
51 | + |
|
52 | + // Flag to indicate if we should make an API request. |
|
53 | + $change_status = false; |
|
54 | + |
|
55 | + // Fetch the initial 'about' and 'mentions' counts from post meta. |
|
56 | + $counts = [ |
|
57 | + 'about' => get_post_meta( $post_id, 'wl_about_count', true ) ? (int) get_post_meta( $post_id, 'wl_about_count', true ) : 0, |
|
58 | + 'mentions' => get_post_meta( $post_id, 'wl_mentions_count', true ) |
|
59 | + ? (int) get_post_meta( $post_id, 'wl_mentions_count', true ) |
|
60 | + : 0, |
|
61 | + ]; |
|
62 | + |
|
63 | + // Check if $jsonld_arr is not empty |
|
64 | + if ( ! empty( $jsonld_arr[0] ) ) { |
|
65 | + // Get data from the array. |
|
66 | + $data = $jsonld_arr[0]; |
|
67 | + |
|
68 | + // Iterate over the counts array. |
|
69 | + foreach ( $counts as $type => $type_count ) { |
|
70 | + // Check if data has 'about' or 'mentions' and the count is different from the existing meta value. |
|
71 | + if ( isset( $data[ $type ] ) ) { |
|
72 | + $new_count = count( $data[ $type ] ); |
|
73 | + |
|
74 | + if ( $type_count !== $new_count ) { |
|
75 | + // Set flag to true if counts have changed. |
|
76 | + $change_status = true; |
|
77 | + |
|
78 | + // Update the counts array with new count. |
|
79 | + $counts[ $type ] = $new_count; |
|
80 | + |
|
81 | + // Update post meta with new count. |
|
82 | + update_post_meta( $post_id, 'wl_' . $type . '_count', $new_count ); |
|
83 | + } |
|
84 | + } // If the 'about' or 'mentions' has become empty, set it to 0. |
|
85 | + else if ( $type_count > 0 ) { |
|
86 | + $change_status = true; |
|
87 | + $counts[ $type ] = 0; |
|
88 | + update_post_meta( $post_id, 'wl_' . $type . '_count', 0 ); |
|
89 | + } |
|
90 | + } |
|
91 | + } // If the $jsonld_arr is empty but the counts were previously more than 0. |
|
92 | + else { |
|
93 | + foreach ( $counts as $type => $type_count ) { |
|
94 | + if ( $type_count > 0 ) { |
|
95 | + $change_status = true; |
|
96 | + $counts[ $type ] = 0; |
|
97 | + update_post_meta( $post_id, 'wl_' . $type . '_count', 0 ); |
|
98 | + } |
|
99 | + } |
|
100 | + } |
|
101 | + |
|
102 | + // If the count has changed, make the API request. |
|
103 | + if ( $change_status ) { |
|
104 | + $this->api_service->request( |
|
105 | + 'POST', |
|
106 | + '/plugin/events', |
|
107 | + array( 'Content-Type' => 'application/json' ), |
|
108 | + wp_json_encode( |
|
109 | + array( |
|
110 | + 'source' => 'jsonld', |
|
111 | + 'args' => array( |
|
112 | + array( 'about_count' => $counts['about'] ), |
|
113 | + array( 'mentions_count' => $counts['mentions'] ), |
|
114 | + ), |
|
115 | + 'url' => get_permalink( $post_id ), |
|
116 | + ) |
|
117 | + ), |
|
118 | + 0.001, |
|
119 | + null, |
|
120 | + array( 'blocking' => false ) |
|
121 | + ); |
|
122 | + } |
|
123 | + |
|
124 | + return $jsonld_arr; |
|
125 | + } |
|
126 | 126 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | /** |
24 | 24 | * @param Api_Service $api_service |
25 | 25 | */ |
26 | - public function __construct( Api_Service $api_service ) { |
|
26 | + public function __construct(Api_Service $api_service) { |
|
27 | 27 | $this->api_service = $api_service; |
28 | 28 | } |
29 | 29 | |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * Register hooks. |
32 | 32 | */ |
33 | 33 | public function register_hooks() { |
34 | - add_filter( 'wl_after_get_jsonld', array( $this, 'set_events_request' ), 90, 3 ); |
|
34 | + add_filter('wl_after_get_jsonld', array($this, 'set_events_request'), 90, 3); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -43,9 +43,9 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @return array |
45 | 45 | */ |
46 | - public function set_events_request( $jsonld_arr, $post_id, $context ) { |
|
46 | + public function set_events_request($jsonld_arr, $post_id, $context) { |
|
47 | 47 | // If context is not PAGE, return early. |
48 | - if ( Jsonld_Context_Enum::PAGE !== $context ) { |
|
48 | + if (Jsonld_Context_Enum::PAGE !== $context) { |
|
49 | 49 | return $jsonld_arr; |
50 | 50 | } |
51 | 51 | |
@@ -54,70 +54,70 @@ discard block |
||
54 | 54 | |
55 | 55 | // Fetch the initial 'about' and 'mentions' counts from post meta. |
56 | 56 | $counts = [ |
57 | - 'about' => get_post_meta( $post_id, 'wl_about_count', true ) ? (int) get_post_meta( $post_id, 'wl_about_count', true ) : 0, |
|
58 | - 'mentions' => get_post_meta( $post_id, 'wl_mentions_count', true ) |
|
59 | - ? (int) get_post_meta( $post_id, 'wl_mentions_count', true ) |
|
57 | + 'about' => get_post_meta($post_id, 'wl_about_count', true) ? (int) get_post_meta($post_id, 'wl_about_count', true) : 0, |
|
58 | + 'mentions' => get_post_meta($post_id, 'wl_mentions_count', true) |
|
59 | + ? (int) get_post_meta($post_id, 'wl_mentions_count', true) |
|
60 | 60 | : 0, |
61 | 61 | ]; |
62 | 62 | |
63 | 63 | // Check if $jsonld_arr is not empty |
64 | - if ( ! empty( $jsonld_arr[0] ) ) { |
|
64 | + if ( ! empty($jsonld_arr[0])) { |
|
65 | 65 | // Get data from the array. |
66 | 66 | $data = $jsonld_arr[0]; |
67 | 67 | |
68 | 68 | // Iterate over the counts array. |
69 | - foreach ( $counts as $type => $type_count ) { |
|
69 | + foreach ($counts as $type => $type_count) { |
|
70 | 70 | // Check if data has 'about' or 'mentions' and the count is different from the existing meta value. |
71 | - if ( isset( $data[ $type ] ) ) { |
|
72 | - $new_count = count( $data[ $type ] ); |
|
71 | + if (isset($data[$type])) { |
|
72 | + $new_count = count($data[$type]); |
|
73 | 73 | |
74 | - if ( $type_count !== $new_count ) { |
|
74 | + if ($type_count !== $new_count) { |
|
75 | 75 | // Set flag to true if counts have changed. |
76 | 76 | $change_status = true; |
77 | 77 | |
78 | 78 | // Update the counts array with new count. |
79 | - $counts[ $type ] = $new_count; |
|
79 | + $counts[$type] = $new_count; |
|
80 | 80 | |
81 | 81 | // Update post meta with new count. |
82 | - update_post_meta( $post_id, 'wl_' . $type . '_count', $new_count ); |
|
82 | + update_post_meta($post_id, 'wl_'.$type.'_count', $new_count); |
|
83 | 83 | } |
84 | 84 | } // If the 'about' or 'mentions' has become empty, set it to 0. |
85 | - else if ( $type_count > 0 ) { |
|
85 | + else if ($type_count > 0) { |
|
86 | 86 | $change_status = true; |
87 | - $counts[ $type ] = 0; |
|
88 | - update_post_meta( $post_id, 'wl_' . $type . '_count', 0 ); |
|
87 | + $counts[$type] = 0; |
|
88 | + update_post_meta($post_id, 'wl_'.$type.'_count', 0); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | } // If the $jsonld_arr is empty but the counts were previously more than 0. |
92 | 92 | else { |
93 | - foreach ( $counts as $type => $type_count ) { |
|
94 | - if ( $type_count > 0 ) { |
|
93 | + foreach ($counts as $type => $type_count) { |
|
94 | + if ($type_count > 0) { |
|
95 | 95 | $change_status = true; |
96 | - $counts[ $type ] = 0; |
|
97 | - update_post_meta( $post_id, 'wl_' . $type . '_count', 0 ); |
|
96 | + $counts[$type] = 0; |
|
97 | + update_post_meta($post_id, 'wl_'.$type.'_count', 0); |
|
98 | 98 | } |
99 | 99 | } |
100 | 100 | } |
101 | 101 | |
102 | 102 | // If the count has changed, make the API request. |
103 | - if ( $change_status ) { |
|
103 | + if ($change_status) { |
|
104 | 104 | $this->api_service->request( |
105 | 105 | 'POST', |
106 | 106 | '/plugin/events', |
107 | - array( 'Content-Type' => 'application/json' ), |
|
107 | + array('Content-Type' => 'application/json'), |
|
108 | 108 | wp_json_encode( |
109 | 109 | array( |
110 | 110 | 'source' => 'jsonld', |
111 | 111 | 'args' => array( |
112 | - array( 'about_count' => $counts['about'] ), |
|
113 | - array( 'mentions_count' => $counts['mentions'] ), |
|
112 | + array('about_count' => $counts['about']), |
|
113 | + array('mentions_count' => $counts['mentions']), |
|
114 | 114 | ), |
115 | - 'url' => get_permalink( $post_id ), |
|
115 | + 'url' => get_permalink($post_id), |
|
116 | 116 | ) |
117 | 117 | ), |
118 | 118 | 0.001, |
119 | 119 | null, |
120 | - array( 'blocking' => false ) |
|
120 | + array('blocking' => false) |
|
121 | 121 | ); |
122 | 122 | } |
123 | 123 |
@@ -11,163 +11,163 @@ |
||
11 | 11 | * @package Wordlift\Modules\Events\Options_Entity |
12 | 12 | */ |
13 | 13 | class Events_Options_Entity_Include_Exclude { |
14 | - /** |
|
15 | - * The {@link Api_Service} used to communicate with the remote APIs. |
|
16 | - * |
|
17 | - * @access private |
|
18 | - * @var Api_Service |
|
19 | - */ |
|
20 | - private $api_service; |
|
21 | - |
|
22 | - /** |
|
23 | - * @param Api_Service $api_service |
|
24 | - */ |
|
25 | - public function __construct( Api_Service $api_service ) { |
|
26 | - $this->api_service = $api_service; |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * Register hooks. |
|
31 | - */ |
|
32 | - public function register_hooks() { |
|
33 | - add_action( 'update_option_wl_exclude_include_urls_settings', array( $this, 'event_update' ), 15, 0 ); |
|
34 | - add_action( 'update_option_wl_exclude_include_urls_settings', array( $this, 'save_old_config' ), 99, 0 ); |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * Include exclude event update. |
|
40 | - * |
|
41 | - * @throws Exception If the application fails to load the services configuration file or if the URL cannot be processed. |
|
42 | - */ |
|
43 | - public function event_update() { |
|
44 | - // Get the configurations. |
|
45 | - $config = get_option( 'wl_exclude_include_urls_settings', array() ); |
|
46 | - $old_config = get_option( 'wl_exclude_include_urls_settings_old', array() ); |
|
47 | - |
|
48 | - // Get included and excluded URLs. |
|
49 | - $urls = $this->get_urls( $config, $old_config ); |
|
50 | - |
|
51 | - // Call API method for each URL. |
|
52 | - foreach ( $urls['included'] as $url ) { |
|
53 | - $this->send_event( $url, 'include' ); |
|
54 | - } |
|
55 | - foreach ( $urls['excluded'] as $url ) { |
|
56 | - $this->send_event( $url, 'exclude' ); |
|
57 | - } |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Save old config. |
|
62 | - */ |
|
63 | - public function save_old_config() { |
|
64 | - // Get the current configuration. |
|
65 | - $config = get_option( 'wl_exclude_include_urls_settings', array() ); |
|
66 | - |
|
67 | - // Save the current configuration to another option. |
|
68 | - update_option( 'wl_exclude_include_urls_settings_old', $config ); |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * Get included and excluded urls. |
|
74 | - * |
|
75 | - * @param $config |
|
76 | - * @param $old_config |
|
77 | - * |
|
78 | - * @return array |
|
79 | - */ |
|
80 | - private function get_urls( $config, $old_config ) { |
|
81 | - // Get the payload for both new and old values: |
|
82 | - $payload_new = $this->get_payload( $config ); |
|
83 | - $payload_old = $this->get_payload( $old_config ); |
|
84 | - |
|
85 | - // Extract URLs from payloads. |
|
86 | - $urls_new = array_column( $payload_new, 'url' ); |
|
87 | - $urls_old = array_column( $payload_old, 'url' ); |
|
88 | - |
|
89 | - // If both $urls_new and $urls_old are empty, there is no URL to process. |
|
90 | - if ( empty( $urls_new ) && empty( $urls_old ) ) { |
|
91 | - return [ |
|
92 | - 'included' => [], |
|
93 | - 'excluded' => [], |
|
94 | - ]; |
|
95 | - } |
|
96 | - |
|
97 | - // Find added and removed URLs. |
|
98 | - $urls_added = array_diff( $urls_new, $urls_old ); |
|
99 | - $urls_removed = array_diff( $urls_old, $urls_new ); |
|
100 | - |
|
101 | - // Determine included and excluded URLs. |
|
102 | - $included = ( 'include' === strtolower( $config['include_exclude'] ) ) ? $urls_added : $urls_removed; |
|
103 | - $excluded = ( 'include' === strtolower( $config['include_exclude'] ) ) ? $urls_removed : $urls_added; |
|
104 | - |
|
105 | - // Check if filter type has changed. |
|
106 | - $filter_changed = strtolower( $config['include_exclude'] ) !== strtolower( $old_config['include_exclude'] ); |
|
107 | - |
|
108 | - if ( $filter_changed ) { |
|
109 | - // Filter type changed, so we reverse the logic of adding URLs to included and excluded arrays. |
|
110 | - $included = ( 'include' === strtolower( $config['include_exclude'] ) ) ? $urls_new : $urls_removed; |
|
111 | - $excluded = ( 'include' === strtolower( $config['include_exclude'] ) ) ? $urls_removed : $urls_new; |
|
112 | - } |
|
113 | - |
|
114 | - return [ |
|
115 | - 'included' => $included, |
|
116 | - 'excluded' => $excluded, |
|
117 | - ]; |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Get payload. |
|
122 | - * |
|
123 | - * @param $config |
|
124 | - * |
|
125 | - * @return array|array[] |
|
126 | - */ |
|
127 | - private function get_payload( $config ) { |
|
128 | - // Set the default data. |
|
129 | - if ( ! is_array( $config ) || empty( $config ) || ! isset( $config['include_exclude'] ) || ! isset( $config['urls'] ) ) { |
|
130 | - $config = array( |
|
131 | - 'include_exclude' => 'exclude', |
|
132 | - 'urls' => '', |
|
133 | - ); |
|
134 | - } |
|
135 | - |
|
136 | - // Map the configuration to the payload. |
|
137 | - return array_map( |
|
138 | - function ( $item ) use ( $config ) { |
|
139 | - return array( |
|
140 | - 'url' => ( 1 === preg_match( '@^https?://.*$@', $item ) ? $item : get_home_url( null, $item ) ), |
|
141 | - 'flag' => strtoupper( $config['include_exclude'] ), |
|
142 | - ); |
|
143 | - }, |
|
144 | - array_filter( preg_split( '/[\r\n]+/', $config['urls'] ) ) |
|
145 | - ); |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Send event. |
|
150 | - * |
|
151 | - * @param $url |
|
152 | - * @param $value |
|
153 | - */ |
|
154 | - private function send_event( $url, $value ) { |
|
155 | - $this->api_service->request( |
|
156 | - 'POST', |
|
157 | - '/plugin/events', |
|
158 | - array( 'content-type' => 'application/json' ), |
|
159 | - wp_json_encode( |
|
160 | - array( |
|
161 | - 'source' => 'include-exclude', |
|
162 | - 'args' => array( |
|
163 | - array( 'value' => $value ), |
|
164 | - ), |
|
165 | - 'url' => $url, |
|
166 | - ) |
|
167 | - ), |
|
168 | - 0.001, |
|
169 | - null, |
|
170 | - array( 'blocking' => false ) |
|
171 | - ); |
|
172 | - } |
|
14 | + /** |
|
15 | + * The {@link Api_Service} used to communicate with the remote APIs. |
|
16 | + * |
|
17 | + * @access private |
|
18 | + * @var Api_Service |
|
19 | + */ |
|
20 | + private $api_service; |
|
21 | + |
|
22 | + /** |
|
23 | + * @param Api_Service $api_service |
|
24 | + */ |
|
25 | + public function __construct( Api_Service $api_service ) { |
|
26 | + $this->api_service = $api_service; |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * Register hooks. |
|
31 | + */ |
|
32 | + public function register_hooks() { |
|
33 | + add_action( 'update_option_wl_exclude_include_urls_settings', array( $this, 'event_update' ), 15, 0 ); |
|
34 | + add_action( 'update_option_wl_exclude_include_urls_settings', array( $this, 'save_old_config' ), 99, 0 ); |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * Include exclude event update. |
|
40 | + * |
|
41 | + * @throws Exception If the application fails to load the services configuration file or if the URL cannot be processed. |
|
42 | + */ |
|
43 | + public function event_update() { |
|
44 | + // Get the configurations. |
|
45 | + $config = get_option( 'wl_exclude_include_urls_settings', array() ); |
|
46 | + $old_config = get_option( 'wl_exclude_include_urls_settings_old', array() ); |
|
47 | + |
|
48 | + // Get included and excluded URLs. |
|
49 | + $urls = $this->get_urls( $config, $old_config ); |
|
50 | + |
|
51 | + // Call API method for each URL. |
|
52 | + foreach ( $urls['included'] as $url ) { |
|
53 | + $this->send_event( $url, 'include' ); |
|
54 | + } |
|
55 | + foreach ( $urls['excluded'] as $url ) { |
|
56 | + $this->send_event( $url, 'exclude' ); |
|
57 | + } |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Save old config. |
|
62 | + */ |
|
63 | + public function save_old_config() { |
|
64 | + // Get the current configuration. |
|
65 | + $config = get_option( 'wl_exclude_include_urls_settings', array() ); |
|
66 | + |
|
67 | + // Save the current configuration to another option. |
|
68 | + update_option( 'wl_exclude_include_urls_settings_old', $config ); |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * Get included and excluded urls. |
|
74 | + * |
|
75 | + * @param $config |
|
76 | + * @param $old_config |
|
77 | + * |
|
78 | + * @return array |
|
79 | + */ |
|
80 | + private function get_urls( $config, $old_config ) { |
|
81 | + // Get the payload for both new and old values: |
|
82 | + $payload_new = $this->get_payload( $config ); |
|
83 | + $payload_old = $this->get_payload( $old_config ); |
|
84 | + |
|
85 | + // Extract URLs from payloads. |
|
86 | + $urls_new = array_column( $payload_new, 'url' ); |
|
87 | + $urls_old = array_column( $payload_old, 'url' ); |
|
88 | + |
|
89 | + // If both $urls_new and $urls_old are empty, there is no URL to process. |
|
90 | + if ( empty( $urls_new ) && empty( $urls_old ) ) { |
|
91 | + return [ |
|
92 | + 'included' => [], |
|
93 | + 'excluded' => [], |
|
94 | + ]; |
|
95 | + } |
|
96 | + |
|
97 | + // Find added and removed URLs. |
|
98 | + $urls_added = array_diff( $urls_new, $urls_old ); |
|
99 | + $urls_removed = array_diff( $urls_old, $urls_new ); |
|
100 | + |
|
101 | + // Determine included and excluded URLs. |
|
102 | + $included = ( 'include' === strtolower( $config['include_exclude'] ) ) ? $urls_added : $urls_removed; |
|
103 | + $excluded = ( 'include' === strtolower( $config['include_exclude'] ) ) ? $urls_removed : $urls_added; |
|
104 | + |
|
105 | + // Check if filter type has changed. |
|
106 | + $filter_changed = strtolower( $config['include_exclude'] ) !== strtolower( $old_config['include_exclude'] ); |
|
107 | + |
|
108 | + if ( $filter_changed ) { |
|
109 | + // Filter type changed, so we reverse the logic of adding URLs to included and excluded arrays. |
|
110 | + $included = ( 'include' === strtolower( $config['include_exclude'] ) ) ? $urls_new : $urls_removed; |
|
111 | + $excluded = ( 'include' === strtolower( $config['include_exclude'] ) ) ? $urls_removed : $urls_new; |
|
112 | + } |
|
113 | + |
|
114 | + return [ |
|
115 | + 'included' => $included, |
|
116 | + 'excluded' => $excluded, |
|
117 | + ]; |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Get payload. |
|
122 | + * |
|
123 | + * @param $config |
|
124 | + * |
|
125 | + * @return array|array[] |
|
126 | + */ |
|
127 | + private function get_payload( $config ) { |
|
128 | + // Set the default data. |
|
129 | + if ( ! is_array( $config ) || empty( $config ) || ! isset( $config['include_exclude'] ) || ! isset( $config['urls'] ) ) { |
|
130 | + $config = array( |
|
131 | + 'include_exclude' => 'exclude', |
|
132 | + 'urls' => '', |
|
133 | + ); |
|
134 | + } |
|
135 | + |
|
136 | + // Map the configuration to the payload. |
|
137 | + return array_map( |
|
138 | + function ( $item ) use ( $config ) { |
|
139 | + return array( |
|
140 | + 'url' => ( 1 === preg_match( '@^https?://.*$@', $item ) ? $item : get_home_url( null, $item ) ), |
|
141 | + 'flag' => strtoupper( $config['include_exclude'] ), |
|
142 | + ); |
|
143 | + }, |
|
144 | + array_filter( preg_split( '/[\r\n]+/', $config['urls'] ) ) |
|
145 | + ); |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Send event. |
|
150 | + * |
|
151 | + * @param $url |
|
152 | + * @param $value |
|
153 | + */ |
|
154 | + private function send_event( $url, $value ) { |
|
155 | + $this->api_service->request( |
|
156 | + 'POST', |
|
157 | + '/plugin/events', |
|
158 | + array( 'content-type' => 'application/json' ), |
|
159 | + wp_json_encode( |
|
160 | + array( |
|
161 | + 'source' => 'include-exclude', |
|
162 | + 'args' => array( |
|
163 | + array( 'value' => $value ), |
|
164 | + ), |
|
165 | + 'url' => $url, |
|
166 | + ) |
|
167 | + ), |
|
168 | + 0.001, |
|
169 | + null, |
|
170 | + array( 'blocking' => false ) |
|
171 | + ); |
|
172 | + } |
|
173 | 173 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | /** |
23 | 23 | * @param Api_Service $api_service |
24 | 24 | */ |
25 | - public function __construct( Api_Service $api_service ) { |
|
25 | + public function __construct(Api_Service $api_service) { |
|
26 | 26 | $this->api_service = $api_service; |
27 | 27 | } |
28 | 28 | |
@@ -30,8 +30,8 @@ discard block |
||
30 | 30 | * Register hooks. |
31 | 31 | */ |
32 | 32 | public function register_hooks() { |
33 | - add_action( 'update_option_wl_exclude_include_urls_settings', array( $this, 'event_update' ), 15, 0 ); |
|
34 | - add_action( 'update_option_wl_exclude_include_urls_settings', array( $this, 'save_old_config' ), 99, 0 ); |
|
33 | + add_action('update_option_wl_exclude_include_urls_settings', array($this, 'event_update'), 15, 0); |
|
34 | + add_action('update_option_wl_exclude_include_urls_settings', array($this, 'save_old_config'), 99, 0); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | |
@@ -42,18 +42,18 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function event_update() { |
44 | 44 | // Get the configurations. |
45 | - $config = get_option( 'wl_exclude_include_urls_settings', array() ); |
|
46 | - $old_config = get_option( 'wl_exclude_include_urls_settings_old', array() ); |
|
45 | + $config = get_option('wl_exclude_include_urls_settings', array()); |
|
46 | + $old_config = get_option('wl_exclude_include_urls_settings_old', array()); |
|
47 | 47 | |
48 | 48 | // Get included and excluded URLs. |
49 | - $urls = $this->get_urls( $config, $old_config ); |
|
49 | + $urls = $this->get_urls($config, $old_config); |
|
50 | 50 | |
51 | 51 | // Call API method for each URL. |
52 | - foreach ( $urls['included'] as $url ) { |
|
53 | - $this->send_event( $url, 'include' ); |
|
52 | + foreach ($urls['included'] as $url) { |
|
53 | + $this->send_event($url, 'include'); |
|
54 | 54 | } |
55 | - foreach ( $urls['excluded'] as $url ) { |
|
56 | - $this->send_event( $url, 'exclude' ); |
|
55 | + foreach ($urls['excluded'] as $url) { |
|
56 | + $this->send_event($url, 'exclude'); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
@@ -62,10 +62,10 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function save_old_config() { |
64 | 64 | // Get the current configuration. |
65 | - $config = get_option( 'wl_exclude_include_urls_settings', array() ); |
|
65 | + $config = get_option('wl_exclude_include_urls_settings', array()); |
|
66 | 66 | |
67 | 67 | // Save the current configuration to another option. |
68 | - update_option( 'wl_exclude_include_urls_settings_old', $config ); |
|
68 | + update_option('wl_exclude_include_urls_settings_old', $config); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | |
@@ -77,17 +77,17 @@ discard block |
||
77 | 77 | * |
78 | 78 | * @return array |
79 | 79 | */ |
80 | - private function get_urls( $config, $old_config ) { |
|
80 | + private function get_urls($config, $old_config) { |
|
81 | 81 | // Get the payload for both new and old values: |
82 | - $payload_new = $this->get_payload( $config ); |
|
83 | - $payload_old = $this->get_payload( $old_config ); |
|
82 | + $payload_new = $this->get_payload($config); |
|
83 | + $payload_old = $this->get_payload($old_config); |
|
84 | 84 | |
85 | 85 | // Extract URLs from payloads. |
86 | - $urls_new = array_column( $payload_new, 'url' ); |
|
87 | - $urls_old = array_column( $payload_old, 'url' ); |
|
86 | + $urls_new = array_column($payload_new, 'url'); |
|
87 | + $urls_old = array_column($payload_old, 'url'); |
|
88 | 88 | |
89 | 89 | // If both $urls_new and $urls_old are empty, there is no URL to process. |
90 | - if ( empty( $urls_new ) && empty( $urls_old ) ) { |
|
90 | + if (empty($urls_new) && empty($urls_old)) { |
|
91 | 91 | return [ |
92 | 92 | 'included' => [], |
93 | 93 | 'excluded' => [], |
@@ -95,20 +95,20 @@ discard block |
||
95 | 95 | } |
96 | 96 | |
97 | 97 | // Find added and removed URLs. |
98 | - $urls_added = array_diff( $urls_new, $urls_old ); |
|
99 | - $urls_removed = array_diff( $urls_old, $urls_new ); |
|
98 | + $urls_added = array_diff($urls_new, $urls_old); |
|
99 | + $urls_removed = array_diff($urls_old, $urls_new); |
|
100 | 100 | |
101 | 101 | // Determine included and excluded URLs. |
102 | - $included = ( 'include' === strtolower( $config['include_exclude'] ) ) ? $urls_added : $urls_removed; |
|
103 | - $excluded = ( 'include' === strtolower( $config['include_exclude'] ) ) ? $urls_removed : $urls_added; |
|
102 | + $included = ('include' === strtolower($config['include_exclude'])) ? $urls_added : $urls_removed; |
|
103 | + $excluded = ('include' === strtolower($config['include_exclude'])) ? $urls_removed : $urls_added; |
|
104 | 104 | |
105 | 105 | // Check if filter type has changed. |
106 | - $filter_changed = strtolower( $config['include_exclude'] ) !== strtolower( $old_config['include_exclude'] ); |
|
106 | + $filter_changed = strtolower($config['include_exclude']) !== strtolower($old_config['include_exclude']); |
|
107 | 107 | |
108 | - if ( $filter_changed ) { |
|
108 | + if ($filter_changed) { |
|
109 | 109 | // Filter type changed, so we reverse the logic of adding URLs to included and excluded arrays. |
110 | - $included = ( 'include' === strtolower( $config['include_exclude'] ) ) ? $urls_new : $urls_removed; |
|
111 | - $excluded = ( 'include' === strtolower( $config['include_exclude'] ) ) ? $urls_removed : $urls_new; |
|
110 | + $included = ('include' === strtolower($config['include_exclude'])) ? $urls_new : $urls_removed; |
|
111 | + $excluded = ('include' === strtolower($config['include_exclude'])) ? $urls_removed : $urls_new; |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | return [ |
@@ -124,9 +124,9 @@ discard block |
||
124 | 124 | * |
125 | 125 | * @return array|array[] |
126 | 126 | */ |
127 | - private function get_payload( $config ) { |
|
127 | + private function get_payload($config) { |
|
128 | 128 | // Set the default data. |
129 | - if ( ! is_array( $config ) || empty( $config ) || ! isset( $config['include_exclude'] ) || ! isset( $config['urls'] ) ) { |
|
129 | + if ( ! is_array($config) || empty($config) || ! isset($config['include_exclude']) || ! isset($config['urls'])) { |
|
130 | 130 | $config = array( |
131 | 131 | 'include_exclude' => 'exclude', |
132 | 132 | 'urls' => '', |
@@ -135,13 +135,13 @@ discard block |
||
135 | 135 | |
136 | 136 | // Map the configuration to the payload. |
137 | 137 | return array_map( |
138 | - function ( $item ) use ( $config ) { |
|
138 | + function($item) use ($config) { |
|
139 | 139 | return array( |
140 | - 'url' => ( 1 === preg_match( '@^https?://.*$@', $item ) ? $item : get_home_url( null, $item ) ), |
|
141 | - 'flag' => strtoupper( $config['include_exclude'] ), |
|
140 | + 'url' => (1 === preg_match('@^https?://.*$@', $item) ? $item : get_home_url(null, $item)), |
|
141 | + 'flag' => strtoupper($config['include_exclude']), |
|
142 | 142 | ); |
143 | 143 | }, |
144 | - array_filter( preg_split( '/[\r\n]+/', $config['urls'] ) ) |
|
144 | + array_filter(preg_split('/[\r\n]+/', $config['urls'])) |
|
145 | 145 | ); |
146 | 146 | } |
147 | 147 | |
@@ -151,23 +151,23 @@ discard block |
||
151 | 151 | * @param $url |
152 | 152 | * @param $value |
153 | 153 | */ |
154 | - private function send_event( $url, $value ) { |
|
154 | + private function send_event($url, $value) { |
|
155 | 155 | $this->api_service->request( |
156 | 156 | 'POST', |
157 | 157 | '/plugin/events', |
158 | - array( 'content-type' => 'application/json' ), |
|
158 | + array('content-type' => 'application/json'), |
|
159 | 159 | wp_json_encode( |
160 | 160 | array( |
161 | 161 | 'source' => 'include-exclude', |
162 | 162 | 'args' => array( |
163 | - array( 'value' => $value ), |
|
163 | + array('value' => $value), |
|
164 | 164 | ), |
165 | 165 | 'url' => $url, |
166 | 166 | ) |
167 | 167 | ), |
168 | 168 | 0.001, |
169 | 169 | null, |
170 | - array( 'blocking' => false ) |
|
170 | + array('blocking' => false) |
|
171 | 171 | ); |
172 | 172 | } |
173 | 173 | } |
@@ -13,137 +13,137 @@ |
||
13 | 13 | */ |
14 | 14 | class Events_Term_Entity_Jsonld { |
15 | 15 | |
16 | - /** |
|
17 | - * The {@link Api_Service} used to communicate with the remote APIs. |
|
18 | - * |
|
19 | - * @access private |
|
20 | - * @var Api_Service |
|
21 | - */ |
|
22 | - private $api_service; |
|
23 | - |
|
24 | - /** |
|
25 | - * @param Api_Service $api_service |
|
26 | - */ |
|
27 | - public function __construct( Api_Service $api_service ) { |
|
28 | - $this->api_service = $api_service; |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
32 | - * Register hooks. |
|
33 | - */ |
|
34 | - public function register_hooks() { |
|
35 | - add_filter( 'wl_term_jsonld_array', array( $this, 'set_events_request' ), 90, 3 ); |
|
36 | - } |
|
37 | - |
|
38 | - /** |
|
39 | - * Set term jsonld array event. |
|
40 | - * |
|
41 | - * @param $data array An array containing jsonld for term and entities. |
|
42 | - * @param $term_id int The term id for which the jsonld is generated. |
|
43 | - * @param $context int A context for the JSON-LD generation, valid values in Jsonld_Context_Enum |
|
44 | - * |
|
45 | - * @return array |
|
46 | - */ |
|
47 | - public function set_events_request( $data, $term_id, $context ) { |
|
48 | - /** @var $jsonld_arr array The final jsonld before outputting to page. */ |
|
49 | - $jsonld_arr = $data['jsonld']; |
|
50 | - |
|
51 | - // If context is not PAGE, return early. |
|
52 | - if ( Jsonld_Context_Enum::PAGE !== $context ) { |
|
53 | - return $data; |
|
54 | - } |
|
55 | - |
|
56 | - // Flag to indicate if we should make an API request. |
|
57 | - $change_status = false; |
|
58 | - |
|
59 | - // Fetch the initial 'about' and 'mentions' counts from term meta. |
|
60 | - $counts = [ |
|
61 | - 'about' => get_term_meta( $term_id, 'wl_about_count', true ) ? (int) get_term_meta( $term_id, 'wl_about_count', true ) : 0, |
|
62 | - 'mentions' => get_term_meta( $term_id, 'wl_mentions_count', true ) |
|
63 | - ? (int) get_term_meta( $term_id, 'wl_mentions_count', true ) |
|
64 | - : 0, |
|
65 | - ]; |
|
66 | - |
|
67 | - // Check if $jsonld_arr is not empty |
|
68 | - if ( ! empty( $jsonld_arr[0] ) ) { |
|
69 | - // Get data from the array. |
|
70 | - $data_arr = $jsonld_arr[0]; |
|
71 | - |
|
72 | - // Iterate over the counts array. |
|
73 | - foreach ( $counts as $type => $type_count ) { |
|
74 | - // Check if data has 'about' or 'mentions' and the count is different from the existing meta value. |
|
75 | - if ( isset( $data_arr[ $type ] ) ) { |
|
76 | - $new_count = count( $data_arr[ $type ] ); |
|
77 | - if ( $type_count !== $new_count ) { |
|
78 | - // Set flag to true if counts have changed. |
|
79 | - $change_status = true; |
|
80 | - |
|
81 | - // Update the counts array with new count. |
|
82 | - $counts[ $type ] = $new_count; |
|
83 | - |
|
84 | - // Update term meta with new count. |
|
85 | - update_term_meta( $term_id, 'wl_' . $type . '_count', $new_count ); |
|
86 | - } |
|
87 | - } // If the 'about' or 'mentions' has become empty, set it to 0. |
|
88 | - else if ( $type_count > 0 ) { |
|
89 | - $change_status = true; |
|
90 | - $counts[ $type ] = 0; |
|
91 | - update_term_meta( $term_id, 'wl_' . $type . '_count', 0 ); |
|
92 | - } |
|
93 | - } |
|
94 | - } // If the $jsonld_arr is empty but the counts were previously more than 0. |
|
95 | - else { |
|
96 | - foreach ( $counts as $type => $type_count ) { |
|
97 | - if ( $type_count > 0 ) { |
|
98 | - $change_status = true; |
|
99 | - $counts[ $type ] = 0; |
|
100 | - update_term_meta( $term_id, 'wl_' . $type . '_count', 0 ); |
|
101 | - } |
|
102 | - } |
|
103 | - } |
|
104 | - |
|
105 | - // If the count has changed, make the API request. |
|
106 | - if ( $change_status ) { |
|
107 | - $this->api_service->request( |
|
108 | - 'POST', |
|
109 | - '/plugin/events', |
|
110 | - array( 'Content-Type' => 'application/json' ), |
|
111 | - wp_json_encode( |
|
112 | - array( |
|
113 | - 'source' => 'jsonld', |
|
114 | - 'args' => array( |
|
115 | - array( 'about_count' => $counts['about'] ), |
|
116 | - array( 'mentions_count' => $counts['mentions'] ), |
|
117 | - ), |
|
118 | - 'url' => $this->get_term_url( $term_id ), |
|
119 | - ) |
|
120 | - ), |
|
121 | - 0.001, |
|
122 | - null, |
|
123 | - array( 'blocking' => false ) |
|
124 | - ); |
|
125 | - } |
|
126 | - |
|
127 | - return $data; |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Get term url. |
|
132 | - * |
|
133 | - * @param $id |
|
134 | - * |
|
135 | - * @return array|false|int|mixed|string|\WP_Error|\WP_Term|null |
|
136 | - */ |
|
137 | - private function get_term_url( $id ) { |
|
138 | - if ( null === $id ) { |
|
139 | - return isset( $_SERVER['REQUEST_URI'] ) ? filter_var( wp_unslash( $_SERVER['REQUEST_URI'] ), FILTER_SANITIZE_URL ) : ''; |
|
140 | - } |
|
141 | - |
|
142 | - $maybe_url = get_term_meta( $id, Wordlift_Url_Property_Service::META_KEY, true ); |
|
143 | - if ( ! empty( $maybe_url ) ) { |
|
144 | - return $maybe_url; |
|
145 | - } |
|
146 | - |
|
147 | - return get_term_link( $id ); |
|
148 | - } |
|
16 | + /** |
|
17 | + * The {@link Api_Service} used to communicate with the remote APIs. |
|
18 | + * |
|
19 | + * @access private |
|
20 | + * @var Api_Service |
|
21 | + */ |
|
22 | + private $api_service; |
|
23 | + |
|
24 | + /** |
|
25 | + * @param Api_Service $api_service |
|
26 | + */ |
|
27 | + public function __construct( Api_Service $api_service ) { |
|
28 | + $this->api_service = $api_service; |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | + * Register hooks. |
|
33 | + */ |
|
34 | + public function register_hooks() { |
|
35 | + add_filter( 'wl_term_jsonld_array', array( $this, 'set_events_request' ), 90, 3 ); |
|
36 | + } |
|
37 | + |
|
38 | + /** |
|
39 | + * Set term jsonld array event. |
|
40 | + * |
|
41 | + * @param $data array An array containing jsonld for term and entities. |
|
42 | + * @param $term_id int The term id for which the jsonld is generated. |
|
43 | + * @param $context int A context for the JSON-LD generation, valid values in Jsonld_Context_Enum |
|
44 | + * |
|
45 | + * @return array |
|
46 | + */ |
|
47 | + public function set_events_request( $data, $term_id, $context ) { |
|
48 | + /** @var $jsonld_arr array The final jsonld before outputting to page. */ |
|
49 | + $jsonld_arr = $data['jsonld']; |
|
50 | + |
|
51 | + // If context is not PAGE, return early. |
|
52 | + if ( Jsonld_Context_Enum::PAGE !== $context ) { |
|
53 | + return $data; |
|
54 | + } |
|
55 | + |
|
56 | + // Flag to indicate if we should make an API request. |
|
57 | + $change_status = false; |
|
58 | + |
|
59 | + // Fetch the initial 'about' and 'mentions' counts from term meta. |
|
60 | + $counts = [ |
|
61 | + 'about' => get_term_meta( $term_id, 'wl_about_count', true ) ? (int) get_term_meta( $term_id, 'wl_about_count', true ) : 0, |
|
62 | + 'mentions' => get_term_meta( $term_id, 'wl_mentions_count', true ) |
|
63 | + ? (int) get_term_meta( $term_id, 'wl_mentions_count', true ) |
|
64 | + : 0, |
|
65 | + ]; |
|
66 | + |
|
67 | + // Check if $jsonld_arr is not empty |
|
68 | + if ( ! empty( $jsonld_arr[0] ) ) { |
|
69 | + // Get data from the array. |
|
70 | + $data_arr = $jsonld_arr[0]; |
|
71 | + |
|
72 | + // Iterate over the counts array. |
|
73 | + foreach ( $counts as $type => $type_count ) { |
|
74 | + // Check if data has 'about' or 'mentions' and the count is different from the existing meta value. |
|
75 | + if ( isset( $data_arr[ $type ] ) ) { |
|
76 | + $new_count = count( $data_arr[ $type ] ); |
|
77 | + if ( $type_count !== $new_count ) { |
|
78 | + // Set flag to true if counts have changed. |
|
79 | + $change_status = true; |
|
80 | + |
|
81 | + // Update the counts array with new count. |
|
82 | + $counts[ $type ] = $new_count; |
|
83 | + |
|
84 | + // Update term meta with new count. |
|
85 | + update_term_meta( $term_id, 'wl_' . $type . '_count', $new_count ); |
|
86 | + } |
|
87 | + } // If the 'about' or 'mentions' has become empty, set it to 0. |
|
88 | + else if ( $type_count > 0 ) { |
|
89 | + $change_status = true; |
|
90 | + $counts[ $type ] = 0; |
|
91 | + update_term_meta( $term_id, 'wl_' . $type . '_count', 0 ); |
|
92 | + } |
|
93 | + } |
|
94 | + } // If the $jsonld_arr is empty but the counts were previously more than 0. |
|
95 | + else { |
|
96 | + foreach ( $counts as $type => $type_count ) { |
|
97 | + if ( $type_count > 0 ) { |
|
98 | + $change_status = true; |
|
99 | + $counts[ $type ] = 0; |
|
100 | + update_term_meta( $term_id, 'wl_' . $type . '_count', 0 ); |
|
101 | + } |
|
102 | + } |
|
103 | + } |
|
104 | + |
|
105 | + // If the count has changed, make the API request. |
|
106 | + if ( $change_status ) { |
|
107 | + $this->api_service->request( |
|
108 | + 'POST', |
|
109 | + '/plugin/events', |
|
110 | + array( 'Content-Type' => 'application/json' ), |
|
111 | + wp_json_encode( |
|
112 | + array( |
|
113 | + 'source' => 'jsonld', |
|
114 | + 'args' => array( |
|
115 | + array( 'about_count' => $counts['about'] ), |
|
116 | + array( 'mentions_count' => $counts['mentions'] ), |
|
117 | + ), |
|
118 | + 'url' => $this->get_term_url( $term_id ), |
|
119 | + ) |
|
120 | + ), |
|
121 | + 0.001, |
|
122 | + null, |
|
123 | + array( 'blocking' => false ) |
|
124 | + ); |
|
125 | + } |
|
126 | + |
|
127 | + return $data; |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Get term url. |
|
132 | + * |
|
133 | + * @param $id |
|
134 | + * |
|
135 | + * @return array|false|int|mixed|string|\WP_Error|\WP_Term|null |
|
136 | + */ |
|
137 | + private function get_term_url( $id ) { |
|
138 | + if ( null === $id ) { |
|
139 | + return isset( $_SERVER['REQUEST_URI'] ) ? filter_var( wp_unslash( $_SERVER['REQUEST_URI'] ), FILTER_SANITIZE_URL ) : ''; |
|
140 | + } |
|
141 | + |
|
142 | + $maybe_url = get_term_meta( $id, Wordlift_Url_Property_Service::META_KEY, true ); |
|
143 | + if ( ! empty( $maybe_url ) ) { |
|
144 | + return $maybe_url; |
|
145 | + } |
|
146 | + |
|
147 | + return get_term_link( $id ); |
|
148 | + } |
|
149 | 149 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | /** |
25 | 25 | * @param Api_Service $api_service |
26 | 26 | */ |
27 | - public function __construct( Api_Service $api_service ) { |
|
27 | + public function __construct(Api_Service $api_service) { |
|
28 | 28 | $this->api_service = $api_service; |
29 | 29 | } |
30 | 30 | |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * Register hooks. |
33 | 33 | */ |
34 | 34 | public function register_hooks() { |
35 | - add_filter( 'wl_term_jsonld_array', array( $this, 'set_events_request' ), 90, 3 ); |
|
35 | + add_filter('wl_term_jsonld_array', array($this, 'set_events_request'), 90, 3); |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | /** |
@@ -44,12 +44,12 @@ discard block |
||
44 | 44 | * |
45 | 45 | * @return array |
46 | 46 | */ |
47 | - public function set_events_request( $data, $term_id, $context ) { |
|
47 | + public function set_events_request($data, $term_id, $context) { |
|
48 | 48 | /** @var $jsonld_arr array The final jsonld before outputting to page. */ |
49 | 49 | $jsonld_arr = $data['jsonld']; |
50 | 50 | |
51 | 51 | // If context is not PAGE, return early. |
52 | - if ( Jsonld_Context_Enum::PAGE !== $context ) { |
|
52 | + if (Jsonld_Context_Enum::PAGE !== $context) { |
|
53 | 53 | return $data; |
54 | 54 | } |
55 | 55 | |
@@ -58,69 +58,69 @@ discard block |
||
58 | 58 | |
59 | 59 | // Fetch the initial 'about' and 'mentions' counts from term meta. |
60 | 60 | $counts = [ |
61 | - 'about' => get_term_meta( $term_id, 'wl_about_count', true ) ? (int) get_term_meta( $term_id, 'wl_about_count', true ) : 0, |
|
62 | - 'mentions' => get_term_meta( $term_id, 'wl_mentions_count', true ) |
|
63 | - ? (int) get_term_meta( $term_id, 'wl_mentions_count', true ) |
|
61 | + 'about' => get_term_meta($term_id, 'wl_about_count', true) ? (int) get_term_meta($term_id, 'wl_about_count', true) : 0, |
|
62 | + 'mentions' => get_term_meta($term_id, 'wl_mentions_count', true) |
|
63 | + ? (int) get_term_meta($term_id, 'wl_mentions_count', true) |
|
64 | 64 | : 0, |
65 | 65 | ]; |
66 | 66 | |
67 | 67 | // Check if $jsonld_arr is not empty |
68 | - if ( ! empty( $jsonld_arr[0] ) ) { |
|
68 | + if ( ! empty($jsonld_arr[0])) { |
|
69 | 69 | // Get data from the array. |
70 | 70 | $data_arr = $jsonld_arr[0]; |
71 | 71 | |
72 | 72 | // Iterate over the counts array. |
73 | - foreach ( $counts as $type => $type_count ) { |
|
73 | + foreach ($counts as $type => $type_count) { |
|
74 | 74 | // Check if data has 'about' or 'mentions' and the count is different from the existing meta value. |
75 | - if ( isset( $data_arr[ $type ] ) ) { |
|
76 | - $new_count = count( $data_arr[ $type ] ); |
|
77 | - if ( $type_count !== $new_count ) { |
|
75 | + if (isset($data_arr[$type])) { |
|
76 | + $new_count = count($data_arr[$type]); |
|
77 | + if ($type_count !== $new_count) { |
|
78 | 78 | // Set flag to true if counts have changed. |
79 | 79 | $change_status = true; |
80 | 80 | |
81 | 81 | // Update the counts array with new count. |
82 | - $counts[ $type ] = $new_count; |
|
82 | + $counts[$type] = $new_count; |
|
83 | 83 | |
84 | 84 | // Update term meta with new count. |
85 | - update_term_meta( $term_id, 'wl_' . $type . '_count', $new_count ); |
|
85 | + update_term_meta($term_id, 'wl_'.$type.'_count', $new_count); |
|
86 | 86 | } |
87 | 87 | } // If the 'about' or 'mentions' has become empty, set it to 0. |
88 | - else if ( $type_count > 0 ) { |
|
88 | + else if ($type_count > 0) { |
|
89 | 89 | $change_status = true; |
90 | - $counts[ $type ] = 0; |
|
91 | - update_term_meta( $term_id, 'wl_' . $type . '_count', 0 ); |
|
90 | + $counts[$type] = 0; |
|
91 | + update_term_meta($term_id, 'wl_'.$type.'_count', 0); |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | } // If the $jsonld_arr is empty but the counts were previously more than 0. |
95 | 95 | else { |
96 | - foreach ( $counts as $type => $type_count ) { |
|
97 | - if ( $type_count > 0 ) { |
|
96 | + foreach ($counts as $type => $type_count) { |
|
97 | + if ($type_count > 0) { |
|
98 | 98 | $change_status = true; |
99 | - $counts[ $type ] = 0; |
|
100 | - update_term_meta( $term_id, 'wl_' . $type . '_count', 0 ); |
|
99 | + $counts[$type] = 0; |
|
100 | + update_term_meta($term_id, 'wl_'.$type.'_count', 0); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | } |
104 | 104 | |
105 | 105 | // If the count has changed, make the API request. |
106 | - if ( $change_status ) { |
|
106 | + if ($change_status) { |
|
107 | 107 | $this->api_service->request( |
108 | 108 | 'POST', |
109 | 109 | '/plugin/events', |
110 | - array( 'Content-Type' => 'application/json' ), |
|
110 | + array('Content-Type' => 'application/json'), |
|
111 | 111 | wp_json_encode( |
112 | 112 | array( |
113 | 113 | 'source' => 'jsonld', |
114 | 114 | 'args' => array( |
115 | - array( 'about_count' => $counts['about'] ), |
|
116 | - array( 'mentions_count' => $counts['mentions'] ), |
|
115 | + array('about_count' => $counts['about']), |
|
116 | + array('mentions_count' => $counts['mentions']), |
|
117 | 117 | ), |
118 | - 'url' => $this->get_term_url( $term_id ), |
|
118 | + 'url' => $this->get_term_url($term_id), |
|
119 | 119 | ) |
120 | 120 | ), |
121 | 121 | 0.001, |
122 | 122 | null, |
123 | - array( 'blocking' => false ) |
|
123 | + array('blocking' => false) |
|
124 | 124 | ); |
125 | 125 | } |
126 | 126 | |
@@ -134,16 +134,16 @@ discard block |
||
134 | 134 | * |
135 | 135 | * @return array|false|int|mixed|string|\WP_Error|\WP_Term|null |
136 | 136 | */ |
137 | - private function get_term_url( $id ) { |
|
138 | - if ( null === $id ) { |
|
139 | - return isset( $_SERVER['REQUEST_URI'] ) ? filter_var( wp_unslash( $_SERVER['REQUEST_URI'] ), FILTER_SANITIZE_URL ) : ''; |
|
137 | + private function get_term_url($id) { |
|
138 | + if (null === $id) { |
|
139 | + return isset($_SERVER['REQUEST_URI']) ? filter_var(wp_unslash($_SERVER['REQUEST_URI']), FILTER_SANITIZE_URL) : ''; |
|
140 | 140 | } |
141 | 141 | |
142 | - $maybe_url = get_term_meta( $id, Wordlift_Url_Property_Service::META_KEY, true ); |
|
143 | - if ( ! empty( $maybe_url ) ) { |
|
142 | + $maybe_url = get_term_meta($id, Wordlift_Url_Property_Service::META_KEY, true); |
|
143 | + if ( ! empty($maybe_url)) { |
|
144 | 144 | return $maybe_url; |
145 | 145 | } |
146 | 146 | |
147 | - return get_term_link( $id ); |
|
147 | + return get_term_link($id); |
|
148 | 148 | } |
149 | 149 | } |