PluginProbe
Elementor Website Builder – more than just a page builder / 3.24.4
Elementor Website Builder – more than just a page builder v3.24.4
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / core / files / manager.php

manager.php in Elementor Website Builder – more than just a page builder 3.24.4, at core/files/manager.php

212 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\Core\Files;
3
4 use Elementor\Core\Base\Document as Document_Base;
5 use Elementor\Core\Base\Elements_Iteration_Actions\Assets;
6 use Elementor\Core\Common\Modules\Ajax\Module as Ajax;
7 use Elementor\Core\Files\CSS\Global_CSS;
8 use Elementor\Core\Files\CSS\Post as Post_CSS;
9 use Elementor\Core\Page_Assets\Data_Managers\Base as Page_Assets_Data_Manager;
10 use Elementor\Core\Responsive\Files\Frontend;
11 use Elementor\Plugin;
12 use Elementor\Utils;
13
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit; // Exit if accessed directly.
16 }
17
18 /**
19 * Elementor files manager.
20 *
21 * Elementor files manager handler class is responsible for creating files.
22 *
23 * @since 1.2.0
24 */
25 class Manager {
26
27 private $files = [];
28
29 /**
30 * Files manager constructor.
31 *
32 * Initializing the Elementor files manager.
33 *
34 * @since 1.2.0
35 * @access public
36 */
37 public function __construct() {
38 $this->register_actions();
39 }
40
41 public function get( $class, $args ) {
42 $id = $class . '-' . wp_json_encode( $args );
43
44 if ( ! isset( $this->files[ $id ] ) ) {
45 // Create an instance from dynamic args length.
46 $reflection_class = new \ReflectionClass( $class );
47 $this->files[ $id ] = $reflection_class->newInstanceArgs( $args );
48 }
49
50 return $this->files[ $id ];
51 }
52
53 /**
54 * On post delete.
55 *
56 * Delete post CSS immediately after a post is deleted from the database.
57 *
58 * Fired by `deleted_post` action.
59 *
60 * @since 1.2.0
61 * @access public
62 *
63 * @param string $post_id Post ID.
64 */
65 public function on_delete_post( $post_id ) {
66 if ( ! Utils::is_post_support( $post_id ) ) {
67 return;
68 }
69
70 $css_file = Post_CSS::create( $post_id );
71
72 $css_file->delete();
73 }
74
75 /**
76 * On export post meta.
77 *
78 * When exporting data using WXR, skip post CSS file meta key. This way the
79 * export won't contain the post CSS file data used by Elementor.
80 *
81 * Fired by `wxr_export_skip_postmeta` filter.
82 *
83 * @since 1.2.0
84 * @access public
85 *
86 * @param bool $skip Whether to skip the current post meta.
87 * @param string $meta_key Current meta key.
88 *
89 * @return bool Whether to skip the post CSS meta.
90 */
91 public function on_export_post_meta( $skip, $meta_key ) {
92 if ( Post_CSS::META_KEY === $meta_key ) {
93 $skip = true;
94 }
95
96 return $skip;
97 }
98
99 /**
100 * Clear cache.
101 *
102 * Delete all meta containing files data. And delete the actual
103 * files from the upload directory.
104 *
105 * @since 1.2.0
106 * @access public
107 */
108 public function clear_cache() {
109 // Delete files.
110 $path = Base::get_base_uploads_dir() . Base::DEFAULT_FILES_DIR . '*';
111
112 foreach ( glob( $path ) as $file_path ) {
113 unlink( $file_path );
114 }
115
116 delete_post_meta_by_key( Post_CSS::META_KEY );
117 delete_post_meta_by_key( Document_Base::CACHE_META_KEY );
118 delete_post_meta_by_key( Assets::ASSETS_META_KEY );
119
120 delete_option( Global_CSS::META_KEY );
121 delete_option( Frontend::META_KEY );
122
123 $this->reset_assets_data();
124
125 /**
126 * Elementor clear files.
127 *
128 * Fires after Elementor clears files
129 *
130 * @since 2.1.0
131 */
132 do_action( 'elementor/core/files/clear_cache' );
133 }
134
135 public function clear_custom_image_sizes() {
136 if ( ! defined( 'BFITHUMB_UPLOAD_DIR' ) ) {
137 return;
138 }
139
140 $upload_info = wp_upload_dir();
141 $upload_dir = $upload_info['basedir'] . '/' . BFITHUMB_UPLOAD_DIR;
142
143 $path = $upload_dir . '/*';
144
145 foreach ( glob( $path ) as $file_path ) {
146 unlink( $file_path );
147 }
148 }
149
150 /**
151 * Register Ajax Actions
152 *
153 * Deprecated - use the Uploads Manager instead.
154 *
155 * @deprecated 3.5.0
156 *
157 * @param Ajax $ajax
158 */
159 public function register_ajax_actions( Ajax $ajax ) {
160 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.5.0' );
161
162 Plugin::$instance->uploads_manager->register_ajax_actions( $ajax );
163 }
164
165 /**
166 * Ajax Unfiltered Files Upload
167 *
168 * Deprecated - use the Uploads Manager instead.
169 *
170 * @deprecated 3.5.0
171 */
172 public function ajax_unfiltered_files_upload() {
173 Plugin::$instance->modules_manager->get_modules( 'dev-tools' )->deprecation->deprecated_function( __METHOD__, '3.5.0' );
174
175 Plugin::$instance->uploads_manager->enable_unfiltered_files_upload();
176 }
177
178 /**
179 * Register actions.
180 *
181 * Register filters and actions for the files manager.
182 *
183 * @since 1.2.0
184 * @access private
185 */
186 private function register_actions() {
187 add_action( 'deleted_post', [ $this, 'on_delete_post' ] );
188
189 add_filter( 'wxr_export_skip_postmeta', [ $this, 'on_export_post_meta' ], 10, 2 );
190
191 add_action( 'update_option_home', function () {
192 $this->reset_assets_data();
193 } );
194
195 add_action( 'update_option_siteurl', function () {
196 $this->reset_assets_data();
197 } );
198 }
199
200 /**
201 * Reset Assets Data.
202 *
203 * Reset the page assets data.
204 *
205 * @since 3.3.0
206 * @access private
207 */
208 private function reset_assets_data() {
209 delete_option( Page_Assets_Data_Manager::ASSETS_DATA_KEY );
210 }
211 }
212