. * * Register filters and actions for the files manager. * * @since 1.2.0 * @access private */ private function register_actions() { add_action( 'deleted_post', [ $this, 'on_delete_post' ] ); add_filter( 'wxr_export_skip_postmeta', [ $this, 'on_export_post_meta' ], 10, 2 ); add_action( 'update_option_home', function () { $this->reset_assets_data(); } ); add_action( 'update_option_siteurl', function () { $this->reset_assets_data(); } ); add_action( 'rest_api_init', [ $this, 'register_endpoints' ] ); } /** * Reset Assets Data. * * Reset the page assets data. * * @since 3.3.0 * @access private */ private function reset_assets_data() { delete_option( Page_Assets_Data_Manager::ASSETS_DATA_KEY ); } /** * Generate CSS. * * Generates CSS for all posts built with Elementor. * * @since 3.25.0 * @access public */ public function generate_css() { $batch_size = apply_filters( 'elementor/core/files/generate_css/batch_size', 100 ); $processed_posts = 0; while ( true ) { $args = [ 'post_type' => get_post_types(), 'posts_per_page' => $batch_size, 'meta_query' => [ [ 'key' => Document_Base::BUILT_WITH_ELEMENTOR_META_KEY, 'compare' => 'EXISTS', ], ], 'offset' => $processed_posts, 'fields' => 'ids', ]; $query = new \WP_Query( $args ); if ( empty( $query->posts ) ) { break; } foreach ( $query->posts as $post_id ) { $document = Plugin::$instance->documents->get_doc_for_frontend( $post_id ); if ( $document ) { $css_file = Post_CSS::create( $post_id ); $css_file->update(); } } $processed_posts += $batch_size; } /** * Elementor Generate CSS files. * * Fires after Elementor generates new CSS files * * @since 3.25.0 */ do_action( 'elementor/core/files/after_generate_css' ); } public function register_endpoints() { register_rest_route( 'elementor/v1', '/cache', [ 'methods' => \WP_REST_Server::DELETABLE, 'callback' => [ $this, 'clear_cache' ], 'permission_callback' => function() { return current_user_can( 'manage_options' ); }, ] ); } }