| | 2700 | /** |
| | 2701 | * Scan the WordPress core files for modified and/or missing files. |
| | 2702 | * |
| | 2703 | * Files that have been modified or that have gone missing may indicate that the site |
| | 2704 | * has been compromised, installation failure, or that the code has been customized. |
| | 2705 | * Users that know the code base should be unaltered will be offered to reinstall or |
| | 2706 | * upgrade WordPress in response. |
| | 2707 | * |
| | 2708 | * @since 6.4.0 |
| | 2709 | * |
| | 2710 | * @return array The test results. |
| | 2711 | */ |
| | 2712 | public function get_test_core_integrity() { |
| | 2713 | $result = array( |
| | 2714 | 'label' => __( 'No changes to the core files are detected' ), |
| | 2715 | 'status' => 'good', |
| | 2716 | 'badge' => array( |
| | 2717 | 'label' => __( 'Security' ), |
| | 2718 | 'color' => 'blue', |
| | 2719 | ), |
| | 2720 | 'description' => __( 'A scan for changes to the core WordPress files was performed. No changes are detected.' ), |
| | 2721 | 'actions' => '', |
| | 2722 | 'test' => 'core_integrity', |
| | 2723 | ); |
| | 2724 | |
| | 2725 | $wp_version = get_bloginfo( 'version' ); |
| | 2726 | $wp_locale = get_locale(); |
| | 2727 | |
| | 2728 | // Retrieve a list of checksums from the remote server for verification |
| | 2729 | |
| | 2730 | $checksums = get_transient( 'health-check-code-integrity-checksums' ); |
| | 2731 | if ( false === $checksums ) { |
| | 2732 | $checksums = get_core_checksums( $wp_version, $wp_locale ); |
| | 2733 | if ( false === $checksums && false !== strpos( $wp_version, '-' ) ) { |
| | 2734 | $checksums = get_core_checksums( (float) $wp_version - 0.1, $wp_locale ); |
| | 2735 | } |
| | 2736 | |
| | 2737 | set_transient( 'health-check-code-integrity-checksums', $checksums, HOUR_IN_SECONDS ); |
| | 2738 | } |
| | 2739 | |
| | 2740 | if ( empty( $checksums ) ) { |
| | 2741 | $result['status'] = 'critical'; |
| | 2742 | $result['label'] = __( 'Unable to scan core files for changes' ); |
| | 2743 | $result['description'] = __( 'The checksum file list could not be downloaded. There maybe a connection issue or a list is not available for this version. Please try to run this test again at a later time.' ); |
| | 2744 | return $result; |
| | 2745 | } |
| | 2746 | |
| | 2747 | $changed_files = false; |
| | 2748 | foreach ( $checksums as $file => $checksum ) { |
| | 2749 | |
| | 2750 | if ( 0 === strncmp( $file, 'wp-content', 10 ) ) { |
| | 2751 | continue; |
| | 2752 | } |
| | 2753 | |
| | 2754 | if ( ! file_exists( ABSPATH . $file ) ) { |
| | 2755 | $changed_files = true; |
| | 2756 | break; |
| | 2757 | } |
| | 2758 | |
| | 2759 | $existing_checksum = md5_file( ABSPATH . $file ); |
| | 2760 | if ( $existing_checksum !== $checksum ) { |
| | 2761 | $changed_files = true; |
| | 2762 | break; |
| | 2763 | } |
| | 2764 | |
| | 2765 | } |
| | 2766 | |
| | 2767 | if ( true === $changed_files ) { |
| | 2768 | |
| | 2769 | $result['status'] = 'recommended'; |
| | 2770 | $result['label'] = __( 'Some core files may have been modified' ); |
| | 2771 | $result['description'] = __( 'Some WordPress core files may have been changed. One reason this check can fail is that you need to install a version that makes use of the right translation files. If you have the ability to do so, a simple fix is to reinstall WordPress. Reinstall of the core system should not affect any plugins, themes, or content that you have posted.' ); |
| | 2772 | $result['actions'] = sprintf( |
| | 2773 | '<a href="%s">%s</a>', |
| | 2774 | esc_url( admin_url( 'update-core.php?force_check=1' ) ), |
| | 2775 | __( 'Reinstall WordPress manually' ) |
| | 2776 | ); |
| | 2777 | |
| | 2778 | } |
| | 2779 | |
| | 2780 | return $result; |
| | 2781 | } |
| | 2782 | |