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

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