PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.4.0
ShopBuilder – WooCommerce Builder For Elementor v3.4.0
3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.3.0 All 62 releases
shopbuilder / app / Controllers / Admin / Notice / CachePermission.php

CachePermission.php in ShopBuilder – WooCommerce Builder For Elementor 3.4.0, at app/Controllers/Admin/Notice/CachePermission.php

81 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Cache Permission Notice class.
4 *
5 * Displays an admin notice when the asset optimization cache directory
6 * is not writable, and disables optimization until resolved.
7 *
8 * @package RadiusTheme\SB
9 */
10
11 namespace RadiusTheme\SB\Controllers\Admin\Notice;
12
13 use RadiusTheme\SB\Helpers\Fns;
14 use RadiusTheme\SB\Traits\SingletonTrait;
15
16 // Do not allow directly accessing this file.
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit( 'This script cannot be accessed directly.' );
19 }
20
21 /**
22 * Cache Permission Notice class.
23 */
24 class CachePermission {
25
26 use SingletonTrait;
27
28 /**
29 * Class constructor.
30 */
31 private function __construct() {
32 add_action( 'admin_init', [ $this, 'check_cache_dir_permission' ] );
33 }
34
35 /**
36 * Check if the cache directory is writable.
37 *
38 * @return void
39 */
40 public function check_cache_dir_permission() {
41 if ( ! Fns::is_optimization_setting_on() ) {
42 return;
43 }
44
45 $upload = wp_upload_dir();
46 $cache_dir = trailingslashit( $upload['basedir'] ) . 'shopbuilder_uploads/cache/';
47
48 if ( ! file_exists( $cache_dir ) ) {
49 wp_mkdir_p( $cache_dir );
50 }
51
52 if ( ! wp_is_writable( $cache_dir ) ) {
53 add_action( 'admin_notices', [ $this, 'display_notice' ] );
54 }
55 }
56
57 /**
58 * Display the admin notice.
59 *
60 * @return void
61 */
62 public function display_notice() {
63 $upload = wp_upload_dir();
64 $cache_dir = trailingslashit( $upload['basedir'] ) . 'shopbuilder_uploads/cache/';
65 ?>
66 <div class="notice notice-error">
67 <p>
68 <strong><?php esc_html_e( 'ShopBuilder:', 'shopbuilder' ); ?></strong>
69 <?php
70 printf(
71 /* translators: %s: cache directory path */
72 esc_html__( 'The cache directory %s is not writable. The Asset Optimization setting will not work until the server has write permission to this directory. Please contact your hosting provider to fix the file permissions.', 'shopbuilder' ),
73 '<code>' . esc_html( $cache_dir ) . '</code>'
74 );
75 ?>
76 </p>
77 </div>
78 <?php
79 }
80 }
81