PluginProbe
Elementor Website Builder – more than just a page builder / 3.22.1
Elementor Website Builder – more than just a page builder v3.22.1
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.22.1, at core/files/manager.php

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