prefix . 'astr_customizer_snapshots'; $table_safe = esc_sql( $snapshots_table ); $per_page = 10; $paged = astr_safe_get( 'paged', 'int', 1, 'manage_options', false ); $offset = ( $paged - 1 ) * $per_page; $search = astr_safe_get( 's', 'text', '', 'manage_options', false ); $filter = astr_safe_get( 'change_type', 'key', '', 'manage_options', false ); if ( in_array( $filter, [ '0', 'all' ], true ) ) { $filter = ''; } $allowed_orderby = [ 'change_type' => 'change_type', 'user_name' => 'user_name', 'theme' => 'theme', 'time' => 'time', ]; $orderby_key = astr_safe_get( 'orderby', 'key', 'time', 'manage_options', false ); $orderby = $allowed_orderby[ $orderby_key ] ?? 'time'; $order = ( strtoupper( astr_safe_get( 'order', 'text', 'DESC', 'manage_options', false ) ) === 'ASC' ) ? 'ASC' : 'DESC'; $where_parts = []; $args = []; if ( ! empty( $filter ) ) { $where_parts[] = "change_type = %s"; $args[] = $filter; } if ( $search !== '' ) { $like = '%' . $wpdb->esc_like( $search ) . '%'; $where_parts[] = "( CAST(id AS CHAR) LIKE %s OR theme LIKE %s OR user_name LIKE %s OR change_type LIKE %s OR action LIKE %s OR time LIKE %s )"; array_push($args, $like, $like, $like, $like, $like, $like); } $m = astr_safe_get( 'm', 'text', '', 'manage_options', false ); if ( $m !== '' && $m !== '0' ) { $year = absint( substr( $m, 0, 4 ) ); $month = absint( substr( $m, 4, 2 ) ); if ( $year > 0 && $month >= 1 && $month <= 12 ) { $where_parts[] = 'YEAR(`time`) = %d'; $where_parts[] = 'MONTH(`time`) = %d'; $args[] = $year; $args[] = $month; } } $theme_filter = astr_safe_get( 'theme', 'text', '', 'manage_options', false ); if ( $theme_filter !== '' && $theme_filter !== '0' ) { $where_parts[] = 'theme = %s'; $args[] = sanitize_text_field( $theme_filter ); } $where = $where_parts ? 'WHERE ' . implode( ' AND ', $where_parts ) : ''; // --- Counts --- // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching $count_all = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$table_safe}" ); $total_sql = "SELECT COUNT(*) FROM {$table_safe} {$where}"; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter $total = ! empty( $args ) ? (int) $wpdb->get_var( $wpdb->prepare( $total_sql, ...$args ) ) : (int) $wpdb->get_var( $total_sql ); $total_pages = max( 1, ceil( $total / $per_page ) ); // --- Get rows --- $max_limit = 100; $per_page = min($per_page, $max_limit); $offset = max(0, (int) $offset); $sql_base = "SELECT * FROM {$table_safe} $where ORDER BY {$orderby} {$order} LIMIT %d OFFSET %d"; $params = $args; $params[] = $per_page; $params[] = $offset; // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter $rows = $wpdb->get_results( $wpdb->prepare( $sql_base, ...$params ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching $themes = $wpdb->get_results( "SELECT DISTINCT theme FROM {$table_safe} WHERE theme <> '' ORDER BY theme ASC" ); echo '
'; echo '

CSS History

'; echo '
'; if ( astr_safe_get( 'restored', 'text', '', 'manage_options', false ) === 'success' ) { echo '

CSS restored successfully

'; } $query_args = [ 's' => $search, 'm' => $m, 'theme' => $theme_filter, ]; if ( $filter !== '' ) { $query_args['change_type'] = $filter; } $base_url = admin_url( 'admin.php?page=astr-css-history' ); $page = astr_safe_get( 'page', 'key', 'astr-css-history', 'manage_options', false ); // === FILTERS + SEARCH (WP style) === echo '
'; // LEFT: filters echo '
'; echo '
'; echo '
    '; $all_url = remove_query_arg( [ 'change_type', 's', 'm', 'theme', 'paged' ], admin_url( 'admin.php?page=astr-css-history' ) ); echo '
  • All (' . esc_html( $count_all ) . ')
  • '; echo '
'; echo '
'; // RIGHT: search echo '
'; echo '
'; echo ''; foreach ( [ 'orderby', 'order', 'change_type', 'm', 'theme' ] as $k ) { $value = astr_safe_get( $k, 'text', '', 'manage_options', false ); if ( $value !== '' ) { echo ''; } } echo ''; echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; // === Top Table Nav === echo ''; // === Bottom Pagination === echo '
'; if ( $total >= $per_page ) { astr_pagination( $total, $total_pages, $paged ); } echo '
'; // === Modal for Preview === ?>
'; } function astr_capture_old_customizer_state() { if ( ! current_user_can( 'edit_theme_options' ) ) { return; } $theme = get_stylesheet(); set_transient( 'astr_customizer_old_' . $theme, [ 'wp_css' => wp_get_custom_css( $theme ), ], 5 * MINUTE_IN_SECONDS ); } add_action( 'customize_save', 'astr_capture_old_customizer_state', 1 ); function astr_capture_old_global_styles_state( $post_id, $post ) { if ( ! current_user_can( 'edit_theme_options' ) ) { return; } $data = json_decode( $post->post_content, true ); if ( json_last_error() !== JSON_ERROR_NONE ) { return; } $css = $data['styles']['css'] ?? ''; set_transient( 'astr_global_styles_old_css', (string) $css, 5 * MINUTE_IN_SECONDS ); } add_action( 'customize_save', 'astr_capture_old_customizer_state', 1 ); function astr_save_setting( $snapshot_id, $theme, $key, $old_value, $new_value ) { global $wpdb; $settings_table = esc_sql( $wpdb->prefix . 'astr_customizer_settings' ); $snapshot_settings_table = $wpdb->prefix . 'astr_customizer_snapshot_settings'; $theme = sanitize_text_field( $theme ); $key = sanitize_text_field( $key ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching $wpdb->query( $wpdb->prepare( "INSERT INTO {$settings_table} (theme, setting_key) VALUES (%s, %s) ON DUPLICATE KEY UPDATE id = LAST_INSERT_ID(id)", $theme, $key ) ); $setting_id = (int) $wpdb->insert_id; if ( ! $setting_id ) { return false; } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $wpdb->insert( $snapshot_settings_table, [ 'snapshot_id' => $snapshot_id, 'setting_id' => $setting_id, 'old_value' => is_string( $old_value ) ? $old_value : maybe_serialize( $old_value ), 'new_value' => is_string( $new_value ) ? $new_value : maybe_serialize( $new_value ), ] ); } add_action( 'pre_post_update', function ( $post_id ) { if ( get_post_type( $post_id ) !== 'wp_global_styles' ) { return; } $post = get_post( $post_id ); if ( $post ) { astr_capture_old_global_styles_state( $post_id, $post ); } }, 1 ); function astr_record_css_save() { $normalize_css = function($css) { $lines = preg_split('/\R/', $css); $result = []; foreach ($lines as $line) { $line = trim($line); if ($line === '') { continue; } $line = preg_replace('/\s+/', ' ', $line); $result[] = $line; } return implode("\n", $result); }; if ( ! current_user_can( 'edit_theme_options' ) ) { return; } global $wpdb; $theme_slug = get_stylesheet(); $theme_name = wp_get_theme()->get( 'Name' ); $user = wp_get_current_user(); $old = get_transient( 'astr_customizer_old_' . $theme_slug ); if ( ! is_array( $old ) ) { return; } $old_css = $old['wp_css'] ?? ''; $new_css = wp_get_custom_css( $theme_slug ); if ( $normalize_css($old_css) === $normalize_css($new_css) ) { return; } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $wpdb->insert( $wpdb->prefix . 'astr_customizer_snapshots', [ 'theme' => $theme_name, 'user_id' => $user->ID, 'user_name' => $user->display_name, 'change_type' => 'customizer_css', 'action' => 'update', ] ); $snapshot_id = (int) $wpdb->insert_id; astr_save_setting( $snapshot_id, $theme_name, 'customizer_css', $old_css, $new_css ); delete_transient( 'astr_customizer_old_' . $theme_slug ); } add_action( 'customize_save_after', 'astr_record_css_save', 10 ); add_action('save_post_wp_global_styles', function($post_id, $post, $update) { if ( ! current_user_can('edit_theme_options') ) { return; } if (get_transient('astr_skip_global_styles_log')) { return; } $data = json_decode($post->post_content, true); $new_css = $data['styles']['css'] ?? ''; if ( ! is_string( $new_css ) || trim( $new_css ) === '' ) { return; } $old_css = get_transient( 'astr_global_styles_old_css' ); if ( ! is_string( $old_css ) ) { $old_css = ''; } if ( $old_css === $new_css ) { return; } global $wpdb; $theme = wp_get_theme()->get('Name'); $user = wp_get_current_user(); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $wpdb->insert( $wpdb->prefix . 'astr_customizer_snapshots', [ 'theme' => $theme, 'user_id' => $user->ID, 'user_name' => $user->display_name, 'change_type' => 'global_styles_css', 'action' => 'update', ] ); $snapshot_id = (int) $wpdb->insert_id; $settings_table = $wpdb->prefix . 'astr_customizer_settings'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, PluginCheck.Security.DirectDB.UnescapedDBParameter, WordPress.DB.PreparedSQL.InterpolatedNotPrepared $wpdb->query( $wpdb->prepare( "INSERT INTO {$settings_table} (theme, setting_key) VALUES (%s, %s) ON DUPLICATE KEY UPDATE id = LAST_INSERT_ID(id)", $theme, 'global_styles_css' ) ); $setting_id = (int) $wpdb->insert_id; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $wpdb->insert( $wpdb->prefix . 'astr_customizer_snapshot_settings', [ 'snapshot_id' => $snapshot_id, 'setting_id' => $setting_id, 'old_value' => $old_css, 'new_value' => $new_css, ] ); }, 10, 3); function astr_restore_snapshot_handler() { if ( ! current_user_can( 'edit_theme_options' ) ) { wp_die( 'You do not have permission to restore customizer CSS.' ); } if ( ! isset( $_POST['snapshot_id'], $_POST['_wpnonce'] ) ) { wp_die( 'Invalid request.' ); } $nonce = sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ); if ( ! wp_verify_nonce( $nonce, 'astr_restore_snapshot' ) ) { wp_die( 'Nonce verification failed.' ); } global $wpdb; $snapshot_id = isset($_POST['snapshot_id']) ? absint( wp_unslash( $_POST['snapshot_id'] ) ) : 0; $snapshots_table = $wpdb->prefix . 'astr_customizer_snapshots'; $snapshot_settings_table = $wpdb->prefix . 'astr_customizer_snapshot_settings'; $settings_table = $wpdb->prefix . 'astr_customizer_settings'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $table = esc_sql( $snapshots_table ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $snapshot = $wpdb->get_row( $wpdb->prepare( "SELECT id FROM {$table} WHERE id = %d", $snapshot_id ) ); if ( ! $snapshot ) { wp_die( 'Snapshot not found.' ); } $table_ss = esc_sql( $snapshot_settings_table ); $table_s = esc_sql( $settings_table ); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared $query = $wpdb->prepare( "SELECT ss.old_value, s.setting_key FROM {$table_ss} ss JOIN {$table_s} s ON s.id = ss.setting_id WHERE ss.snapshot_id = %d", $snapshot_id ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $row = $wpdb->get_row( $query, ARRAY_A ); if ( empty( $row ) ) { wp_die( 'Snapshot has no CSS data.' ); } $css = maybe_unserialize( $row['old_value'] ?? '' ); switch ( $row['setting_key'] ) { case 'customizer_css': $theme = get_stylesheet(); wp_update_custom_css_post( $css, [ 'stylesheet' => $theme, ] ); break; case 'global_styles_css': $theme_slug = get_stylesheet(); $posts = get_posts( [ 'post_type' => 'wp_global_styles', 'post_status' => 'publish', 'posts_per_page' => -1, ] ); $global_styles_post = null; foreach ( $posts as $post ) { if ( strpos( $post->post_name, $theme_slug ) !== false ) { $global_styles_post = $post; break; } } if ( ! $global_styles_post ) { wp_die( 'Global styles post for current theme not found.' ); } $content = json_decode( $global_styles_post->post_content, true ); if ( ! is_array( $content ) ) { $content = []; } if ( ! isset( $content['styles'] ) ) { $content['styles'] = []; } $content = json_decode($global_styles_post->post_content, true); if ( ! is_array($content) ) { $content = []; } if ( ! isset($content['styles']) || ! is_array($content['styles']) ) { $content['styles'] = []; } $content['styles']['css'] = $css; set_transient('astr_skip_global_styles_log', 1, 60); wp_update_post([ 'ID' => $global_styles_post->ID, 'post_content' => wp_slash( wp_json_encode($content) ), ]); break; } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $wpdb->update( $snapshots_table, [ 'action' => 'restored' ], [ 'id' => $snapshot_id, 'action' => 'update' ], [ '%s' ], [ '%d', '%s' ] ); wp_safe_redirect( add_query_arg( [ 'page' => 'astr-css-history', 'restored' => 'success', ], admin_url( 'admin.php' ) ) ); exit; } add_action( 'admin_post_astr_restore_snapshot', 'astr_restore_snapshot_handler' ); add_action( 'wp_ajax_astr_preview_snapshot', 'astr_preview_snapshot_ajax' ); function astr_preview_snapshot_ajax() { if ( ! current_user_can( 'edit_theme_options' ) ) { wp_send_json_error( 'No permission' ); } $snapshot_id = isset($_POST['snapshot_id']) ? absint(wp_unslash($_POST['snapshot_id'])) : 0; $nonce = isset($_POST['nonce']) ? sanitize_text_field(wp_unslash($_POST['nonce'])) : ''; if ( ! wp_verify_nonce( $nonce, 'astr_preview_snapshot_' . $snapshot_id ) ) { wp_send_json_error( 'Invalid nonce' ); } global $wpdb; $snapshots_table = $wpdb->prefix . 'astr_customizer_snapshots'; $snapshot_settings_table = $wpdb->prefix . 'astr_customizer_snapshot_settings'; $settings_table = $wpdb->prefix . 'astr_customizer_settings'; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $table = esc_sql($snapshots_table); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $snapshot = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$table} WHERE id = %d LIMIT 1", $snapshot_id ) ); if ( ! $snapshot ) { wp_send_json_error( 'Snapshot not found' ); } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $table_ss = esc_sql($snapshot_settings_table); $table_s = esc_sql($settings_table); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $sql = " SELECT ss.old_value, ss.new_value FROM {$table_ss} ss JOIN {$table_s} s ON s.id = ss.setting_id WHERE ss.snapshot_id = %d AND s.setting_key = %s"; // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared $query = $wpdb->prepare( $sql, (int) $snapshot_id, $snapshot->change_type ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $row = $wpdb->get_row( $query, ARRAY_A ); $old_css = (string) ($row['old_value'] ?? ''); $new_css = (string) ($row['new_value'] ?? ''); // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $snapshot = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$table} WHERE id = %d LIMIT 1", $snapshot_id ) ); $is_restored = ( $snapshot->action ?? '' ) === 'restored'; if ( $is_restored ) { $tmp = $old_css; $old_css = $new_css; $new_css = $tmp; } $output = '
'; $output .= '' . esc_html( $snapshot->user_name ) . '
'; $output .= 'updated — ' . esc_html( mysql2date( 'd-m-Y H:i:s', $snapshot->time ) ) . '
'; $output .= esc_html( $snapshot->theme ); $output .= '
'; $output .= '
'; // OLD CSS $output .= '
'; $output .= '
Old CSS
'; $output .= '
'; $output .= '
' . astr_highlight_css_diff( $old_css, $new_css, 'old' ) . '
'; $output .= '
'; // NEW CSS $output .= '
'; $output .= '
New CSS
'; $output .= '
'; $output .= '
' . astr_highlight_css_diff( $old_css, $new_css, 'new' ) . '
'; $output .= '
'; $output .= '
'; wp_send_json_success( $output ); } // Global back-light function function astr_highlight_css_diff($old_css, $new_css, $type = 'new') { $split_css_line = function($line) { $line = trim($line); if ($line === '') { return ['selector' => '', 'property' => '', 'value' => '', 'brace' => '']; } if (preg_match('/^([^:]+):\s*(.*?)([;{}]?)$/', $line, $m)) { return [ 'selector' => trim($m[1]), 'property' => trim($m[1]), 'value' => trim($m[2]), 'brace' => $m[3] ?? '' ]; } return [ 'selector' => $line, 'property' => '', 'value' => '', 'brace' => '' ]; }; $normalize_line = function($line) { $line = trim($line); if ($line === '') { return null; } return preg_replace('/\s+/', ' ', $line); }; $normalize = function($css) { $lines = preg_split('/\R/', $css); $result = []; foreach ($lines as $line) { $line = trim($line); if ($line === '') { continue; } $line = preg_replace('/\s+/', ' ', $line); $result[] = $line; } return $result; }; $old_raw = preg_split('/\R/', $old_css); $new_raw = preg_split('/\R/', $new_css); $old = []; $new = []; foreach ($old_raw as $line) { $norm = $normalize_line($line); if ($norm !== null) { $old[] = $norm; } } foreach ($new_raw as $line) { $norm = $normalize_line($line); if ($norm !== null) { $new[] = $norm; } } $old_count = count($old); $new_count = count($new); $lcs = array_fill(0, $old_count + 1, array_fill(0, $new_count + 1, 0)); for ($i = $old_count - 1; $i >= 0; $i--) { for ($j = $new_count - 1; $j >= 0; $j--) { if ($old[$i] === $new[$j]) { $lcs[$i][$j] = $lcs[$i + 1][$j + 1] + 1; } else { $lcs[$i][$j] = max( $lcs[$i + 1][$j], $lcs[$i][$j + 1] ); } } } $output = []; $i = 0; $j = 0; while ($i < $old_count && $j < $new_count) { if ($old[$i] === $new[$j]) { $line = $type === 'old' ? $old[$i] : $new[$j]; $output[] = esc_html($line); $i++; $j++; continue; } if ( $i < $old_count && $j < $new_count && $old[$i] !== $new[$j] ) { if ( $lcs[$i + 1][$j] > $lcs[$i][$j + 1] ) { if ($type === 'old') { $output[] = '' . esc_html($old[$i]) . ''; } $i++; continue; } if ( $lcs[$i][$j + 1] > $lcs[$i + 1][$j] ) { if ($type === 'new') { $output[] = '' . esc_html($new[$j]) . ''; } $j++; continue; } $old_line = $split_css_line($old[$i]); $new_line = $split_css_line($new[$j]); $found_old_in_new = false; for ($k = $j + 1; $k < min($new_count, $j + 10); $k++) { if ($old[$i] === $new[$k]) { $found_old_in_new = true; break; } } if ($found_old_in_new) { if ($type === 'new') { $output[] = '' . esc_html($new[$j]) . ''; } $j++; continue; } if ( $old_line['property'] === '' && $new_line['property'] === '' ) { preg_match('/^(.*?)(\s*[{}()]?)$/', $old[$i], $old_match); preg_match('/^(.*?)(\s*[{}()]?)$/', $new[$j], $new_match); $old_selector = trim($old_match[1]); $old_brace = $old_match[2] ?? ''; $new_selector = trim($new_match[1]); $new_brace = $new_match[2] ?? ''; if ($type === 'old') { $selector = ($old_selector !== $new_selector) ? '' . esc_html($old_selector) . '' : esc_html($old_selector); $brace = ($old_brace !== $new_brace) ? '' . esc_html($old_brace) . '' : esc_html($old_brace); $output[] = $selector . $brace; } if ($type === 'new') { $selector = ($old_selector !== $new_selector) ? '' . esc_html($new_selector) . '' : esc_html($new_selector); $brace = ($old_brace !== $new_brace) ? '' . esc_html($new_brace) . '' : esc_html($new_brace); $output[] = $selector . $brace; } $i++; $j++; continue; } if ( $old_line['property'] !== '' && $new_line['property'] !== '' ) { if ($type === 'old') { $property = $old_line['property']; $value = $old_line['value']; if ($old_line['property'] !== $new_line['property']) { $property = '' . esc_html($property) . ''; } else { $property = esc_html($property); } if ($old_line['value'] !== $new_line['value']) { $value = '' . esc_html($value) . ''; } else { $value = esc_html($value); } $brace = ($old_line['brace'] !== $new_line['brace']) ? '' . esc_html($old_line['brace']) . '' : esc_html($old_line['brace']); $output[] = $property . ': ' . $value . $brace; } if ($type === 'new') { $property = $new_line['property']; $value = $new_line['value']; if ($old_line['property'] !== $new_line['property']) { $property = '' . esc_html($property) . ''; } else { $property = esc_html($property); } if ($old_line['value'] !== $new_line['value']) { $value = '' . esc_html($value) . ''; } else { $value = esc_html($value); } $brace = ($old_line['brace'] !== $new_line['brace']) ? '' . esc_html($new_line['brace']) . '' : esc_html($new_line['brace']); $output[] = $property . ': ' . $value . $brace; } $i++; $j++; continue; } } if ($lcs[$i + 1][$j] >= $lcs[$i][$j + 1]) { if ($type === 'old') { $old_line = $split_css_line($old[$i]); if ($old_line['type'] === 'selector') { $output[] = '' . esc_html($old_line['selector']) . '' . esc_html($old_line['brace']); } elseif ($old_line['type'] === 'property') { $output[] = esc_html($old_line['property']) . ': ' . '' . esc_html($old_line['value']) . '' . esc_html($old_line['brace']); } else { $output[] = esc_html($old[$i]); } } $i++; } else { if ($type === 'new') { $new_line = $split_css_line($new[$j]); if ($new_line['type'] === 'selector') { $output[] = '' . esc_html($new_line['selector']) . '' . esc_html($new_line['brace']); } elseif ($new_line['type'] === 'property') { $output[] = esc_html($new_line['property']) . ': ' . '' . esc_html($new_line['value']) . '' . esc_html($new_line['brace']); } else { $output[] = esc_html($new[$j]); } } $j++; } } while ($i < $old_count) { if ($type === 'old') { $old_line = $split_css_line($old[$i]); $output[] = esc_html($old_line['selector']) . ': ' . '' . esc_html($old_line['value']) . '' . esc_html($old_line['brace']); } $i++; } while ($j < $new_count) { if ($type === 'new') { $new_line = $split_css_line($new[$j]); $output[] = esc_html($new_line['selector']) . ': ' . '' . esc_html($new_line['value']) . '' . esc_html($new_line['brace']); } $j++; } return implode("\n", $output); }