prefix . 'astr_plugins_history'; $table_safe = esc_sql($table); // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery $wpdb->query("DROP TABLE IF EXISTS {$table_safe}");// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.DirectDatabaseQuery.SchemaChange // phpcs:enable WordPress.DB.DirectDatabaseQuery.DirectQuery } delete_option( 'astr_delete_on_uninstall' ); } add_filter( 'upgrader_pre_install', 'astr_save_all_plugin_versions_before_install', 10, 2 ); function astr_save_all_plugin_versions_before_install( $true, $hook_extra ) { global $astr_all_plugins_versions_before_update; if ( ( isset( $hook_extra['type'] ) && $hook_extra['type'] == 'plugin' ) || isset( $hook_extra['plugin'] ) ) { $installed_plugins = get_plugins(); $astr_all_plugins_versions_before_update = $installed_plugins; } return $true; } add_action( 'activated_plugin', 'astr_plugins_activated', 10, 2 ); add_filter('upgrader_post_install', 'astr_handle_plugin_post_install', 10, 3); function astr_handle_plugin_post_install($response, $hook_extra, $result) { global $wpdb; global $astr_all_plugins_versions_before_update; $table = $wpdb->prefix . 'astr_plugins_history'; if ((isset($hook_extra['type']) && $hook_extra['type'] == 'plugin') || isset($hook_extra['plugin'])) { $current_user = wp_get_current_user(); if (defined('WP_CLI') && WP_CLI) { $user_id = 0; $os_user = astr_get_os_username(); $user_name = 'WP-CLI (' . $os_user . ')'; } else { $user_id = $current_user->ID; $user_name = $user_id ? $current_user->display_name : 'Automatic Update'; } if (isset($result['destination'])) { $plugin_dir = $result['destination']; } else { $plugin_dir = WP_PLUGIN_DIR . '/' . dirname($hook_extra['plugin']); } $plugin_dir = wp_normalize_path($plugin_dir); $plugin_slug = basename($plugin_dir); $plugin_files = glob($plugin_dir . '/*.php'); if ($plugin_files) { foreach ($plugin_files as $plugin_file) { $plugin_file = wp_normalize_path($plugin_file); $plugin_data = get_plugin_data($plugin_file); if (!empty($plugin_data['Name'])) { $relative_plugin_file = str_replace(wp_normalize_path(WP_PLUGIN_DIR) . '/', '', $plugin_file); $old_version = 'Not installed'; if (isset($astr_all_plugins_versions_before_update[$relative_plugin_file])) { $old_version = $astr_all_plugins_versions_before_update[$relative_plugin_file]['Version']; } $new_version = $plugin_data['Version']; $action = ($old_version == 'Not installed') ? 'installed' : 'updated'; if ($action === 'installed') { astr_add_event_to_buffer($plugin_data['Name'], 'installed', $user_name); } if ($action === 'updated') { astr_add_event_to_buffer( $plugin_data['Name'], 'updated', $user_name, $old_version, $new_version ); } if ($action === 'installed') { // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, PluginCheck.Security.DirectDB.UnescapedDBParameter, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared $exists = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$table} WHERE plugin_path = %s", $relative_plugin_file ) ); if (!$exists) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $wpdb->insert( $table, array( 'plugin_path' => $relative_plugin_file, 'plugin_name' => $plugin_data['Name'], 'user_id' => $user_id, 'user_name' => $user_name, 'action' => 'tracking_started', 'time' => current_time('mysql'), 'extra_info' => astr_get_extended_cli_info(), ) ); } } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $wpdb->insert( $table, array( 'plugin_path' => $relative_plugin_file, 'plugin_name' => $plugin_data['Name'], 'user_id' => $user_id, 'user_name' => $user_name, 'action' => $action, 'time' => current_time('mysql'), 'old_version' => ($action == 'updated') ? $old_version : null, 'new_version' => $new_version, 'extra_info' => astr_get_extended_cli_info(), ), array('%s','%s','%d','%s','%s','%s','%s','%s','%s') ); break; } } } } return $response; } function astr_add_plugin_version_history_event( $plugin_file, $old_version, $new_version, $user_name ) { global $wpdb; $table = $wpdb->prefix . 'astr_plugins_history'; $plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_file ); if ( empty( $plugin_data['Name'] ) ) { return; } if ( version_compare( $new_version, $old_version, '>' ) ) { $action = 'updated'; } elseif ( version_compare( $new_version, $old_version, '<' ) ) { $action = 'rolled_back'; } else { $action = 'installed'; } $wpdb->insert( $table, array( 'plugin_path' => $plugin_file, 'plugin_name' => $plugin_data['Name'], 'user_id' => get_current_user_id(), 'user_name' => $user_name, 'action' => $action, 'time' => current_time( 'mysql' ), 'old_version' => $old_version, 'new_version' => $new_version, 'extra_info' => null, ), array( '%s', '%s', '%d', '%s', '%s', '%s', '%s', '%s', '%s' ) ); astr_add_event_to_buffer( $plugin_data['Name'], $action, $user_name, $old_version, $new_version ); } function astr_plugins_activated( $plugin, $network_wide ) { if ( get_transient( 'astr_version_installing' ) ) { return; } global $wpdb; $table = $wpdb->prefix . 'astr_plugins_history'; $current_user = wp_get_current_user(); if ( defined( 'WP_CLI' ) && WP_CLI ) { $user_id = 0; $os_user = astr_get_os_username(); $user_name = 'WP-CLI (' . $os_user . ')'; } else { $user_id = $current_user->ID; $user_name = $current_user->display_name; } $plugin_base_name = plugin_basename( $plugin ); $all_plugins = get_plugins(); $plugin_name = isset( $all_plugins[ $plugin_base_name ]['Name'] ) ? $all_plugins[ $plugin_base_name ]['Name'] : $plugin_base_name; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $wpdb->insert( $table, array( 'plugin_path' => $plugin_base_name, 'plugin_name' => $plugin_name, 'user_id' => $user_id, 'user_name' => $user_name, 'action' => 'activated', 'time' => current_time( 'mysql' ), 'extra_info' => astr_get_extended_cli_info(), ), array( '%s', '%s', '%d', '%s', '%s', '%s', '%s' ) ); if ( $plugin_base_name === 'adwise-sitetrace/adwise-sitetrace.php' ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $wpdb->insert( $table, array( 'plugin_path' => $plugin_base_name, 'plugin_name' => $plugin_name, 'user_id' => $user_id, 'user_name' => $user_name, 'action' => 'tracking_started', 'time' => current_time( 'mysql' ), 'extra_info' => astr_get_extended_cli_info(), ), array( '%s', '%s', '%d', '%s', '%s', '%s', '%s' ) ); } astr_add_event_to_buffer( $plugin_name, 'activated', $user_name ); } add_action( 'deactivated_plugin', 'astr_plugins_deactivated', 10, 2 ); function astr_plugins_deactivated( $plugin, $network_wide ) { if ( get_transient( 'astr_version_installing' ) ) { return; } global $wpdb; $table = $wpdb->prefix . 'astr_plugins_history'; $current_user = wp_get_current_user(); if ( defined( 'WP_CLI' ) && WP_CLI ) { $user_id = 0; $os_user = astr_get_os_username(); $user_name = 'WP-CLI (' . $os_user . ')'; } else { $user_id = $current_user->ID; $user_name = $current_user->display_name; } $plugin_base_name = plugin_basename( $plugin ); $all_plugins = get_plugins(); $plugin_name = isset( $all_plugins[ $plugin_base_name ]['Name'] ) ? $all_plugins[ $plugin_base_name ]['Name'] : $plugin_base_name; // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $wpdb->insert( $table, array( 'plugin_path' => $plugin_base_name, 'plugin_name' => $plugin_name, 'user_id' => $user_id, 'user_name' => $user_name, 'action' => 'deactivated', 'time' => current_time( 'mysql' ), 'extra_info' => astr_get_extended_cli_info(), ), array( '%s', '%s', '%d', '%s', '%s', '%s', '%s' ) ); if ( $plugin_base_name === 'adwise-sitetrace/adwise-sitetrace.php' ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $wpdb->insert( $table, array( 'plugin_path' => $plugin_base_name, 'plugin_name' => $plugin_name, 'user_id' => $user_id, 'user_name' => $user_name, 'action' => 'tracking_stopped', 'time' => current_time( 'mysql' ), 'extra_info' => astr_get_extended_cli_info(), ), array( '%s', '%s', '%d', '%s', '%s', '%s', '%s' ) ); } astr_add_event_to_buffer( $plugin_name, 'deactivated', $user_name ); } add_action( 'deleted_plugin', 'astr_plugin_deleted', 10, 1 ); function astr_plugin_deleted( $plugin ) { global $wpdb; $table = $wpdb->prefix . 'astr_plugins_history'; $current_user = wp_get_current_user(); if ( defined( 'WP_CLI' ) && WP_CLI ) { $user_id = 0; $os_user = astr_get_os_username(); $user_name = 'WP-CLI (' . $os_user . ')'; } else { $user_id = $current_user->ID; $user_name = $current_user->display_name; } $plugin_base_name = plugin_basename( $plugin ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $plugin_name = $wpdb->get_var( $wpdb->prepare( "SELECT plugin_name FROM {$wpdb->prefix}astr_plugins_history WHERE plugin_path = %s ORDER BY time DESC LIMIT 1", $plugin ) ); if ( empty( $plugin_name ) ) { $plugin_name = ucwords( str_replace( array( '-', '_' ), ' ', dirname( $plugin_base_name ) !== '.' ? dirname( $plugin_base_name ) : basename( $plugin_base_name, '.php' ) ) ); } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $wpdb->insert( $table, array( 'plugin_path' => $plugin_base_name, 'plugin_name' => $plugin_name, 'user_id' => $user_id, 'user_name' => $user_name, 'action' => 'removed', 'time' => current_time( 'mysql' ), 'extra_info' => astr_get_extended_cli_info(), ), array( '%s', '%s', '%d', '%s', '%s', '%s', '%s' ) ); astr_add_event_to_buffer( $plugin_name, 'removed', $user_name ); } add_filter( 'upgrader_pre_install', 'astr_store_plugins_versions_before_update', 5, 2 ); function astr_store_plugins_versions_before_update( $response, $hook_extra ) { if ( empty( $hook_extra['type'] ) || $hook_extra['type'] !== 'plugin' ) { return; } global $astr_all_plugins_versions_before_update; $plugins = []; if ( ! empty( $hook_extra['plugins'] ) ) { $plugins = $hook_extra['plugins']; } elseif ( ! empty( $hook_extra['plugin'] ) ) { $plugins = [ $hook_extra['plugin'] ]; } foreach ( $plugins as $plugin_file ) { $all_plugins = get_plugins(); if ( isset( $all_plugins[ $plugin_file ]['Version'] ) ) { $astr_all_plugins_versions_before_update[ $plugin_file ] = [ 'Version' => $all_plugins[ $plugin_file ]['Version'] ]; } } return $response; } function astr_plugins_history_tracking_started() { global $wpdb; $table = $wpdb->prefix . 'astr_plugins_history'; $all_plugins = get_plugins(); $current_user = wp_get_current_user(); $user_id = $current_user->ID ?? 0; $user_name = $current_user->display_name ?? 'System'; foreach ( $all_plugins as $plugin_path => $data ) { if ( $plugin_path === 'adwise-sitetrace/adwise-sitetrace.php' ) { continue; } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $wpdb->insert( $table, array( 'plugin_path' => $plugin_path, 'plugin_name' => $data['Name'] ?? $plugin_path, 'user_id' => $user_id, 'user_name' => $user_name, 'action' => 'tracking_started', 'time' => current_time( 'mysql' ), 'old_version' => null, 'new_version' => $data['Version'] ?? null, 'extra_info' => null, ), array( '%s','%s','%d','%s','%s','%s','%s','%s','%s' ) ); } //Plugins from history that are no longer installed. $installed_plugins = array_keys( $all_plugins ); $history_plugins = $wpdb->get_results( $wpdb->prepare( "SELECT plugin_path, plugin_name FROM {$table} WHERE plugin_path <> %s GROUP BY plugin_path", 'adwise-sitetrace/adwise-sitetrace.php' ) ); foreach ( $history_plugins as $plugin ) { if ( in_array( $plugin->plugin_path, $installed_plugins, true ) ) { continue; } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $wpdb->insert( $table, array( 'plugin_path' => $plugin->plugin_path, 'plugin_name' => $plugin->plugin_name, 'user_id' => $user_id, 'user_name' => $user_name, 'action' => 'tracking_started', 'time' => current_time( 'mysql' ), 'old_version' => null, 'new_version' => $data['Version'] ?? null, 'extra_info' => null, ), array( '%s', '%s', '%d', '%s', '%s', '%s', '%s', '%s', '%s' ) ); } } function astr_plugins_history_tracking_stopped() { global $wpdb; $table = $wpdb->prefix . 'astr_plugins_history'; $all_plugins = get_plugins(); $current_user = wp_get_current_user(); $user_id = $current_user->ID ?? 0; $user_name = $current_user->display_name ?? 'System'; foreach ( $all_plugins as $plugin_path => $data ) { if ( $plugin_path === 'adwise-sitetrace/adwise-sitetrace.php' ) { continue; } // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, PluginCheck.Security.DirectDB.UnescapedDBParameter, WordPress.DB.DirectDatabaseQuery.NoCaching $exists = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$table} WHERE plugin_path = %s LIMIT 1", $plugin_path ) ); if ( ! $exists ) { continue; } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $wpdb->insert( $table, array( 'plugin_path' => $plugin_path, 'plugin_name' => $data['Name'] ?? $plugin_path, 'user_id' => $user_id, 'user_name' => $user_name, 'action' => 'tracking_stopped', 'time' => current_time( 'mysql' ), 'old_version' => null, 'new_version' => $data['Version'] ?? null, 'extra_info' => null, ), array( '%s', '%s', '%d', '%s', '%s', '%s', '%s', '%s', '%s' ) ); } //Plugins from history that are no longer installed. $installed_plugins = array_keys( $all_plugins ); $history_plugins = $wpdb->get_results( $wpdb->prepare( "SELECT plugin_path, plugin_name FROM {$table} WHERE plugin_path <> %s GROUP BY plugin_path", 'adwise-sitetrace/adwise-sitetrace.php' ) ); foreach ( $history_plugins as $plugin ) { if ( in_array( $plugin->plugin_path, $installed_plugins, true ) ) { continue; } // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery $wpdb->insert( $table, array( 'plugin_path' => $plugin->plugin_path, 'plugin_name' => $plugin->plugin_name, 'user_id' => $user_id, 'user_name' => $user_name, 'action' => 'tracking_stopped', 'time' => current_time( 'mysql' ), 'old_version' => null, 'new_version' => $data['Version'] ?? null, 'extra_info' => null, ), array( '%s', '%s', '%d', '%s', '%s', '%s', '%s', '%s', '%s' ) ); } } add_action( 'admin_init', 'astr_handle_history_page_actions' ); function astr_handle_history_page_actions() { if ( ! is_admin() ) { return; } $history_page_url = admin_url( 'admin.php?page=astr-plugins-history' ); if ( isset( $_GET['plugin'] ) && 'adwise-sitetrace/adwise-sitetrace.php' === sanitize_text_field( wp_unslash( $_GET['plugin'] ) ) ) { $history_page_url = admin_url( 'plugins.php' ); } if ( isset( $_POST['astr_pause_plugin'] ) || ( isset( $_POST['plugin'] ) && isset( $_POST['_wpnonce'] ) && isset( $_POST['_wp_http_referer'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), 'astr_pause_plugin_action' ) && ! isset( $_POST['astr_install_plugin_version'] ) ) ) { check_admin_referer('astr_pause_plugin_action'); $plugin = sanitize_text_field( wp_unslash( $_POST['plugin'] ) ); $plugins = get_option('astr_paused_plugin_updates', array()); if (isset($_POST['astr_pause_plugin'])) { $plugins[$plugin] = true; } else { unset($plugins[$plugin]); } update_option('astr_paused_plugin_updates', $plugins); wp_safe_redirect( $history_page_url ); exit; } if ( isset( $_GET['astr_action'], $_GET['plugin'] ) ) { check_admin_referer( 'astr-plugin-action' ); $plugin = sanitize_text_field( wp_unslash( $_GET['plugin'] ) ); $all_plugins = get_plugins(); $plugin_name = isset( $all_plugins[ $plugin ]['Name'] ) ? $all_plugins[ $plugin ]['Name'] : $plugin; $notice_type = ''; if ( $_GET['astr_action'] === 'activate' ) { if ( ! current_user_can( 'activate_plugins' ) ) { wp_die( esc_html__( 'Sorry, you are not allowed to activate plugins.', 'adwise-sitetrace' ) ); } $result = activate_plugin( $plugin, '', false, true ); if ( is_wp_error( $result ) ) { wp_die( esc_html( $result->get_error_message() ) ); } // The activation hook is skipped because the plugin is activated silently. // Record the activation event manually. astr_plugins_activated( $plugin, false ); $notice_type = 'activated'; } if ( $_GET['astr_action'] === 'deactivate' ) { if ( ! current_user_can( 'activate_plugins' ) ) { wp_die( esc_html__( 'Sorry, you are not allowed to deactivate plugins.', 'adwise-sitetrace' ) ); } deactivate_plugins( $plugin ); $notice_type = 'deactivated'; } if ( $_GET['astr_action'] === 'delete' ) { if ( ! current_user_can( 'delete_plugins' ) ) { wp_die( esc_html__( 'Sorry, you are not allowed to delete plugins.', 'adwise-sitetrace' ) ); } if ( is_plugin_active( $plugin ) ) { if ( ! current_user_can( 'activate_plugins' ) ) { wp_die( esc_html__( 'Sorry, you are not allowed to deactivate plugins.', 'adwise-sitetrace' ) ); } deactivate_plugins( $plugin ); } require_once ABSPATH . 'wp-admin/includes/plugin.php'; require_once ABSPATH . 'wp-admin/includes/file.php'; $deleted = delete_plugins( array( $plugin ) ); if ( is_wp_error( $deleted ) ) { $notice_type = 'delete_error'; } else { $notice_type = 'deleted'; } } wp_safe_redirect( add_query_arg( array( 'astr_notice' => $notice_type, 'plugin_name' => rawurlencode( $plugin_name ), ), $history_page_url ) ); exit; } if ( isset( $_POST['astr_install_plugin_version'] ) ) { check_admin_referer( 'astr_install_plugin_version' ); if ( ! current_user_can( 'install_plugins' ) ) { wp_die( esc_html__( 'Sorry, you are not allowed to install plugins.', 'adwise-sitetrace' ) ); } if ( function_exists( 'set_time_limit' ) ) { // phpcs:ignore Squiz.PHP.DiscouragedFunctions.Discouraged @set_time_limit( 300 ); } $plugin = sanitize_text_field( wp_unslash( $_POST['plugin'] ) ); if ( 'adwise-sitetrace/adwise-sitetrace.php' === $plugin ) { $history_page_url = admin_url( 'plugins.php' ); } $slug = isset( $_POST['plugin_slug'] ) ? sanitize_text_field( wp_unslash( $_POST['plugin_slug'] ) ) : ''; $version = isset( $_POST['plugin_version'] ) ? sanitize_text_field( wp_unslash( $_POST['plugin_version'] ) ) : ''; $plugins = get_plugins(); $current_version = $plugins[ $plugin ]['Version'] ?? ''; if ( $current_version === $version ) { $plugin_name = $plugins[ $plugin ]['Name'] ?? $slug; wp_safe_redirect( add_query_arg( array( 'install_version' => 'same', 'plugin_name' => $plugin_name, 'plugin_version' => $version, ), $history_page_url ) ); exit; } $plugins = get_plugins(); $plugin_name = isset( $plugins[ $plugin ]['Name'] ) ? $plugins[ $plugin ]['Name'] : $slug; $download_url = sprintf( 'https://downloads.wordpress.org/plugin/%s.%s.zip', $slug, $version ); require_once ABSPATH . 'wp-admin/includes/file.php'; $temp_file = download_url( $download_url ); if ( is_wp_error( $temp_file ) ) { wp_safe_redirect( add_query_arg( array( 'install_version' => 'error', 'message' => rawurlencode( $temp_file->get_error_message() ), ), $history_page_url ) ); exit; } global $wp_filesystem; WP_Filesystem(); $unzip_dir = get_temp_dir() . 'astr-test-plugin'; if ( $wp_filesystem->exists( $unzip_dir ) ) { $wp_filesystem->delete( $unzip_dir, true ); } wp_mkdir_p( $unzip_dir ); $result = unzip_file( $temp_file, $unzip_dir ); if ( is_wp_error( $result ) ) { wp_safe_redirect( add_query_arg( array( 'install_version' => 'error', 'message' => rawurlencode( $result->get_error_message() ), ), $history_page_url ) ); exit; } $source = trailingslashit( $unzip_dir ) . $slug; // If the archive contains an extra nested folder with the same name, // use it as the actual source directory. $nested_source = trailingslashit( $source ) . $slug; if ( is_dir( $nested_source ) ) { $source = $nested_source; } $destination = trailingslashit( WP_PLUGIN_DIR ) . $slug; $old_plugin_file = $plugin; $old_plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); $old_version = $old_plugin_data['Version'] ?? 'Not installed'; $backup = $destination . '-backup'; $was_active = is_plugin_active( $plugin ); if ( $was_active ) { set_transient( 'astr_version_installing', true, 60 ); deactivate_plugins( $plugin ); } if ( $wp_filesystem->exists( $backup ) ) { $wp_filesystem->delete( $backup, true ); } if ( $wp_filesystem->exists( $destination ) ) { $wp_filesystem->move( $destination, $backup ); } // phpcs:ignore PluginCheck.CodeAnalysis.WriteFile.PluginDirectoryWrite -- Used intentionally to install/restore a selected plugin version into the plugin directory. $result = copy_dir( $source, $destination ); if ( is_wp_error( $result ) ) { if ( $wp_filesystem->exists( $destination ) ) { $wp_filesystem->delete( $destination, true ); } if ( $wp_filesystem->exists( $backup ) ) { $wp_filesystem->move( $backup, $destination ); } wp_safe_redirect( add_query_arg( array( 'install_version' => 'error', 'message' => rawurlencode( $result->get_error_message() ), ), $history_page_url ) ); exit; } if ( $wp_filesystem->exists( $backup ) ) { $wp_filesystem->delete( $backup, true ); } $new_plugin_data = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin ); $new_version = $new_plugin_data['Version'] ?? ''; $current_user = wp_get_current_user(); astr_add_plugin_version_history_event( $plugin, $old_version, $new_version, $current_user->display_name ); if ( $was_active && current_user_can( 'activate_plugins' ) ) { activate_plugin( $plugin ); } delete_transient( 'astr_version_installing' ); $wp_filesystem->delete( $unzip_dir, true ); if ( file_exists( $temp_file ) ) { wp_delete_file( $temp_file ); } wp_safe_redirect( add_query_arg( array( 'install_version' => 'success', 'plugin_name' => $plugin_name, 'plugin_version' => $version, ), $history_page_url ) ); exit; } } function astr_plugins_history_page() { $active = astr_get_current_admin_page(); astr_render_admin_tabs( $active ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( isset( $_GET['install_version'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( isset( $_GET['install_version'] ) && 'success' === $_GET['install_version'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended $plugin_name = sanitize_text_field( wp_unslash( $_GET['plugin_name'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $plugin_version = sanitize_text_field( wp_unslash( $_GET['plugin_version'] ?? '' ) ); ?>
| action; $time = gmdate('d-m-Y H:i:s', strtotime($last_event->time)); $uname = $last_event->user_name; $ov = $last_event->old_version; $nv = $last_event->new_version; $version_changelog = ''; if ( in_array( $action, array( 'updated', 'rolled_back' ), true ) && ! empty( $nv ) ) { $version_changelog = astr_get_plugin_version_changelog_safe( $plugin_path, $nv ); } ?> |
0 && strlen( $nv ) > 0 ) {
$label = "Updated ({$ov} → {$nv})";
}
if ( $action === 'rolled_back' && strlen( $ov ) > 0 && strlen( $nv ) > 0 ) {
$label = "Reverted ({$ov} → {$nv})";
}
if ($action === 'installed') { $label = 'Installed'; }
echo esc_html($label);
if ( ! empty( $version_changelog ) ) {
echo '';
echo ' ';
echo ' ' . esc_html( $plugin_name ) . ' ';
echo '' . esc_html( $label ) . ' ';
echo ''; echo ' ';
$changelog = astr_format_plugin_changelog( $version_changelog );
$changelog = str_replace(
'';
}
?>
|
extra_info)) {
echo ' ';
$info = json_decode($last_event->extra_info, true);
if (!is_array($info)) { $info = []; }
if (is_array($info)) {
echo ' ';
echo ' ';
}
}
?>
' . esc_html($plugin_name) . ' ';
echo '' . esc_html(ucfirst($action)) . ' — ' . esc_html($time) . ' ';
echo ''; echo '
|
||
|
0 && strlen( $nv ) > 0 ) { $label = "Updated ({$ov} → {$nv})"; }
if ( $action === 'rolled_back' && strlen( $ov ) > 0 && strlen( $nv ) > 0 ) {
$label = "Reverted ({$ov} → {$nv})";
}
echo esc_html( $label );
if ( ! empty( $version_changelog ) ) {
echo '';
echo ' ';
echo ' ' . esc_html( $plugin_name ) . ' ';
echo '' . esc_html( $label ) . ' ';
echo ''; echo ' ';
$changelog = astr_format_plugin_changelog( $version_changelog );
$changelog = str_replace(
'';
}
?>
|
extra_info ) ) {
echo '';
$info = json_decode( $event->extra_info, true );
if ( ! is_array( $info ) ) { $info = []; }
if ( is_array( $info ) ) {
echo ' ';
echo ' ';
}
}
?>
' . esc_html( $plugin_name ) . ' ';
echo '' . esc_html( ucfirst( $action ) ) . ' — ' . esc_html( $time ) . ' ';
echo ''; echo '
|
|||
' . $m[1] . ' ' . $m[2] . '
'; } else { $clean = trim( $line, "= \t\n\r\0\x0B" ); if ( preg_match( '/^(\d+(?:\.\d+)+)\s*[–-]\s*(\d{4}-\d{2}-\d{2})$/u', $clean, $m ) ) { $output .= '' . $m[1] . ' ' . $m[2] . '
'; } elseif ( preg_match( '/^(\d+(?:\.\d+)+)\s+\((\d{4}[\/-]\d{2}[\/-]\d{2}|.+)\)$/u', $clean, $m ) ) { $output .= '' . $m[1] . ' (' . $m[2] . ')
'; } else { $output .= '' . $clean . '
'; } } continue; } // Date. if ( preg_match( '/^(?:[A-Za-z]+\s+\d{1,2}(?:st|nd|rd|th)?,\s+\d{4}|\d{4}-\d{2}-\d{2})$/', $line ) ) { if ( $list_open ) { $output .= ''; $list_open = false; } $output .= '' . $line . '
'; continue; } if ( ! $list_open ) { $output .= '