| @@ -6,8 +6,9 @@ | ||
| 6 | 6 | use Templately\Utils\Helper; |
| 7 | 7 | use Templately\Utils\Database; |
| 8 | 8 | use Templately\Utils\Installer; |
| 9 | 9 | use WP_REST_Request; |
| 10 | +use Templately\Utils\Caching; | |
| 10 | 11 | |
| 11 | 12 | use function current_user_can; |
| 12 | 13 | |
| 13 | 14 | |
| @@ -13,8 +14,9 @@ | ||
| 13 | 14 | |
| 14 | 15 | class Dependencies extends API { |
| 15 | 16 | |
| 16 | 17 | private $endpoint = 'dependencies'; |
| 18 | + | |
| 17 | 19 | public $query = 'dependencies{ id, name, icon, plugin_file, plugin_original_slug, is_pro, link }'; |
| 18 | 20 | |
| 19 | 21 | public function __construct() { |
| 20 | 22 | parent::__construct(); |
| @@ -242,76 +244,84 @@ | ||
| 242 | 244 | } |
| 243 | 245 | } |
| 244 | 246 | } |
| 245 | 247 | |
| 246 | - // Category-based plugins | |
| 247 | - $included_categories = array( | |
| 248 | - 'blog-magazine', | |
| 249 | - 'construction', | |
| 250 | - 'ecommerce', | |
| 251 | - 'education', | |
| 252 | - 'entertainment', | |
| 253 | - 'fashion-lifestyle', | |
| 254 | - 'features-services', | |
| 255 | - 'food-restaurant', | |
| 256 | - 'marketing', | |
| 257 | - 'miscellaneous', | |
| 258 | - 'multipurpose', | |
| 259 | - 'nft-cryptocurrency', | |
| 260 | - 'non-profit', | |
| 261 | - 'technology', | |
| 262 | - 'travel', | |
| 263 | - ); | |
| 248 | + if ( $this->should_offer_caching() ) { | |
| 249 | + $caching = Caching::dependency_entry(); | |
| 250 | + Caching::mark_offered(); | |
| 264 | 251 | |
| 265 | - $is_any_category_included = false; | |
| 266 | - if ( ! empty( $categories ) && is_array( $categories ) ) { | |
| 267 | - foreach ( $categories as $category ) { | |
| 268 | - if ( isset( $category['slug'] ) && in_array( $category['slug'], $included_categories, true ) ) { | |
| 269 | - $is_any_category_included = true; | |
| 270 | - break; | |
| 252 | + $new_dependency_list[] = $caching; | |
| 253 | + $new_required_plugins[] = $caching; | |
| 254 | + } else { | |
| 255 | + // Category-based plugins | |
| 256 | + $included_categories = array( | |
| 257 | + 'blog-magazine', | |
| 258 | + 'construction', | |
| 259 | + 'ecommerce', | |
| 260 | + 'education', | |
| 261 | + 'entertainment', | |
| 262 | + 'fashion-lifestyle', | |
| 263 | + 'features-services', | |
| 264 | + 'food-restaurant', | |
| 265 | + 'marketing', | |
| 266 | + 'miscellaneous', | |
| 267 | + 'multipurpose', | |
| 268 | + 'nft-cryptocurrency', | |
| 269 | + 'non-profit', | |
| 270 | + 'technology', | |
| 271 | + 'travel', | |
| 272 | + ); | |
| 273 | + | |
| 274 | + $is_any_category_included = false; | |
| 275 | + if ( ! empty( $categories ) && is_array( $categories ) ) { | |
| 276 | + foreach ( $categories as $category ) { | |
| 277 | + if ( isset( $category['slug'] ) && in_array( $category['slug'], $included_categories, true ) ) { | |
| 278 | + $is_any_category_included = true; | |
| 279 | + break; | |
| 280 | + } | |
| 271 | 281 | } |
| 272 | 282 | } |
| 273 | - } | |
| 274 | 283 | |
| 275 | - if ( $is_any_category_included ) { | |
| 276 | - $nx_plugin = $this->find_plugin_by_name( $all_plugins, 'notificationx/notificationx' ); | |
| 277 | - $notificationx = array( | |
| 278 | - 'name' => 'NotificationX', | |
| 279 | - 'icon' => 'https://ps.w.org/notificationx/assets/icon-256x256.gif?rev=2783824', | |
| 280 | - 'plugin_file' => 'notificationx/notificationx.php', | |
| 281 | - 'plugin_original_slug' => 'notificationx', | |
| 282 | - 'is_pro' => false, | |
| 283 | - 'installed' => $nx_plugin ? ( $nx_plugin['status'] === 'active' ) : false, | |
| 284 | - 'link' => 'https://wordpress.org/plugins/notificationx/', | |
| 285 | - ); | |
| 286 | - $new_dependency_list[] = $notificationx; | |
| 287 | - $new_required_plugins[] = $notificationx; | |
| 288 | - } | |
| 284 | + if ( $is_any_category_included ) { | |
| 285 | + $nx_plugin = $this->find_plugin_by_name( $all_plugins, 'notificationx/notificationx' ); | |
| 286 | + $notificationx = array( | |
| 287 | + 'name' => 'NotificationX', | |
| 288 | + 'icon' => 'https://ps.w.org/notificationx/assets/icon-256x256.gif?rev=2783824', | |
| 289 | + 'plugin_file' => 'notificationx/notificationx.php', | |
| 290 | + 'plugin_original_slug' => 'notificationx', | |
| 291 | + 'is_pro' => false, | |
| 292 | + 'installed' => $nx_plugin ? ( $nx_plugin['status'] === 'active' ) : false, | |
| 293 | + 'link' => 'https://wordpress.org/plugins/notificationx/', | |
| 294 | + ); | |
| 295 | + $new_dependency_list[] = $notificationx; | |
| 296 | + $new_required_plugins[] = $notificationx; | |
| 297 | + } | |
| 289 | 298 | |
| 290 | - // EmbedPress for blog-magazine category | |
| 291 | - $ep_is_any_category_included = false; | |
| 292 | - if ( ! empty( $categories ) && is_array( $categories ) ) { | |
| 293 | - foreach ( $categories as $category ) { | |
| 294 | - if ( isset( $category['slug'] ) && $category['slug'] === 'blog-magazine' ) { | |
| 295 | - $ep_is_any_category_included = true; | |
| 296 | - break; | |
| 299 | + // EmbedPress for blog-magazine category | |
| 300 | + $ep_is_any_category_included = false; | |
| 301 | + if ( ! empty( $categories ) && is_array( $categories ) ) { | |
| 302 | + foreach ( $categories as $category ) { | |
| 303 | + if ( isset( $category['slug'] ) && $category['slug'] === 'blog-magazine' ) { | |
| 304 | + $ep_is_any_category_included = true; | |
| 305 | + break; | |
| 306 | + } | |
| 297 | 307 | } |
| 298 | 308 | } |
| 299 | - } | |
| 300 | 309 | |
| 301 | - if ( $ep_is_any_category_included ) { | |
| 302 | - $ep_plugin = $this->find_plugin_by_name( $all_plugins, 'embedpress/embedpress' ); | |
| 303 | - $embed_press = array( | |
| 304 | - 'name' => 'EmbedPress', | |
| 305 | - 'icon' => 'https://ps.w.org/embedpress/assets/icon-256x256.gif?rev=2783824', | |
| 306 | - 'plugin_file' => 'embedpress/embedpress.php', | |
| 307 | - 'plugin_original_slug' => 'embedpress', | |
| 308 | - 'is_pro' => false, | |
| 309 | - 'installed' => $ep_plugin ? ( $ep_plugin['status'] === 'active' ) : false, | |
| 310 | - 'link' => 'https://wordpress.org/plugins/embedpress/', | |
| 311 | - ); | |
| 312 | - $new_dependency_list[] = $embed_press; | |
| 313 | - $new_required_plugins[] = $embed_press; | |
| 310 | + if ( $ep_is_any_category_included ) { | |
| 311 | + $ep_plugin = $this->find_plugin_by_name( $all_plugins, 'embedpress/embedpress' ); | |
| 312 | + $embed_press = array( | |
| 313 | + 'name' => 'EmbedPress', | |
| 314 | + 'icon' => 'https://ps.w.org/embedpress/assets/icon-256x256.gif?rev=2783824', | |
| 315 | + 'plugin_file' => 'embedpress/embedpress.php', | |
| 316 | + 'plugin_original_slug' => 'embedpress', | |
| 317 | + 'is_pro' => false, | |
| 318 | + 'installed' => $ep_plugin ? ( $ep_plugin['status'] === 'active' ) : false, | |
| 319 | + 'link' => 'https://wordpress.org/plugins/embedpress/', | |
| 320 | + ); | |
| 321 | + $new_dependency_list[] = $embed_press; | |
| 322 | + $new_required_plugins[] = $embed_press; | |
| 323 | + } | |
| 314 | 324 | } |
| 315 | 325 | |
| 316 | 326 | return new \WP_REST_Response( array( |
| 317 | 327 | 'dependencyList' => $new_dependency_list, |
| @@ -316,8 +326,12 @@ | ||
| 316 | 326 | return new \WP_REST_Response( array( |
| 317 | 327 | 'dependencyList' => $new_dependency_list, |
| 318 | 328 | 'requiredPlugins' => $new_required_plugins |
| 319 | 329 | ) ); |
| 330 | + } | |
| 331 | + | |
| 332 | + protected function should_offer_caching(): bool { | |
| 333 | + return Caching::should_offer(); | |
| 320 | 334 | } |
| 321 | 335 | |
| 322 | 336 | /** |
| 323 | 337 | * Helper method to find a plugin by its name/slug |