rray $images The array of images selected for adding image dimensions. * * @return array The array without images using data-height-percentage. */ public function disable_image_dimensions_height_percentage( array $images ) { foreach ( $images as $key => $image ) { if ( false !== strpos( strtolower( $image ), 'data-height-percentage' ) ) { unset( $images[ $key ] ); } } return $images; } /** * Disable divi jquery body. * * @since 3.9.3 */ public function disable_divi_jquery_body() { if ( $this->delayjs_html->is_allowed() && defined( 'ET_CORE_VERSION' ) && version_compare( ET_CORE_VERSION, '4.10', '>=' ) ) { add_filter( 'et_builder_enable_jquery_body', '__return_false' ); } } /** * Disable Divi dynamic CSS when RUCSS is activated * * @return void */ public function disable_dynamic_css_on_rucss() { if ( ! $this->options->get( 'remove_unused_css', false ) ) { return; } add_filter( 'et_use_dynamic_css', '__return_false' ); } /** * Remove dynamic late assets action. * * @return void */ public function remove_assets_generated() { remove_all_actions( 'et_dynamic_late_assets_generated' ); } /** * Get layout IDs for a template. * * @param int $template_post_id Template post ID. * * @return array */ private function get_layout_ids( $template_post_id ) { $allowed_post_types = [ 'et_header_layout', 'et_footer_layout', 'et_body_layout', ]; $current_post_type = get_post_type( $template_post_id ); if ( ! in_array( $current_post_type, $allowed_post_types, true ) ) { return []; } global $wpdb; // phpcs:ignore WordPress.DB.DirectDatabaseQuery return (array) $wpdb->get_col( $wpdb->prepare( 'SELECT post_id from ' . $wpdb->postmeta . ' WHERE meta_key = %s AND meta_value = %d', '_' . $current_post_type . '_id', $template_post_id ) ); } /** * Is allowed for RUCSS notice functionality when saving templates. * * @return bool */ private function is_allowed_for_rucss() { return $this->options->get( 'remove_unused_css', 0 ) && current_user_can( 'rocket_manage_options' ); } /** * Save template handler. * * @param int $template_post_id Template post ID. * * @return void */ public function handle_save_template( $template_post_id ) { /** * Filters Bypassing saving template functionality. * * @param bool $bypass Bypass save template functionality. * @param int $template_post_id Currently saved template post id. */ if ( apply_filters( 'rocket_divi_bypass_save_template', false, $template_post_id ) ) { return; } // If the transient is there, we don't need to do the check again as the admin notice will be there already. if ( false !== get_transient( 'rocket_divi_notice' ) ) { return; } $layout_post_ids = $this->get_layout_ids( $template_post_id ); if ( empty( $layout_post_ids ) ) { return; } foreach ( $layout_post_ids as $layout_post_id ) { if ( 'publish' !== get_post_status( $layout_post_id ) ) { continue; } set_transient( 'rocket_divi_notice', true ); return; } } /** * Admin notices handler. * * @return void */ public function handle_divi_admin_notice() { if ( ! $this->is_allowed_for_rucss() ) { return; } $notice = get_transient( 'rocket_divi_notice' ); if ( ! $notice ) { return; } rocket_notice_html( [ 'status' => 'warning', 'dismissible' => '', 'dismiss_button' => 'rocket_divi_notice', 'action' => 'clear_used_css', 'message' => sprintf( '%1$sWP Rocket:%2$s ', '', '' ) . // Splitting it because I think the plugin name is not a translatable string. esc_html__( 'Your Divi template was updated. Clear the Used CSS if the layout, design or CSS styles were changed.', 'rocket' ), ] ); } /** * Clear divi notice. * * @return void */ public function clear_divi_notice() { delete_transient( 'rocket_divi_notice' ); } /** * Remove notice transient when enabling RUCSS. * * @param array $old_value An array of submitted values for the settings. * @param array $new_value An array of previous values for the settings. * * @return void */ public function remove_transient_when_enabling_rucss_option( $old_value, $new_value ) { if ( ! isset( $new_value['remove_unused_css'], $old_value['remove_unused_css'] ) ) { return; } if ( $new_value['remove_unused_css'] === $old_value['remove_unused_css'] ) { return; } if ( ! $new_value['remove_unused_css'] ) { return; } if ( $this->used_css->has_one_completed_row_at_least() ) { return; } $this->clear_divi_notice(); } /** * Set the transient when save changes button is clicked. * * @return void */ public function show_rucss_notice_with_save_changes() { set_transient( 'rocket_divi_notice', true ); } }