From 2c5ffd5250b9531f41abeb3cb6de18c5051c1972 Mon Sep 17 00:00:00 2001 From: ashubawork Date: Fri, 7 Apr 2023 11:33:22 +0300 Subject: [PATCH] - basic list of override templates --- includes/admin/core/class-admin-settings.php | 99 ++++++++++++++++++++ templates/message.php | 9 +- templates/profile.php | 6 +- templates/searchform.php | 8 +- 4 files changed, 117 insertions(+), 5 deletions(-) diff --git a/includes/admin/core/class-admin-settings.php b/includes/admin/core/class-admin-settings.php index e452c81a..c448377c 100644 --- a/includes/admin/core/class-admin-settings.php +++ b/includes/admin/core/class-admin-settings.php @@ -3020,6 +3020,46 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) { public function settings_override_templates_tab( $html, $section_fields ) { + $outdated_files = array(); + $scan_files = $this->scan_template_files( um_path . '/templates/' ); + foreach ( $scan_files as $key => $file ) { + if ( ! str_contains( $file, 'email/' ) ) { + $located = apply_filters( 'um_located_template', $file, get_stylesheet_directory() . '/ultimate-member/' ); + if ( file_exists( $located ) ) { + $theme_file = $located; + } elseif ( file_exists( get_stylesheet_directory() . '/ultimate-member/templates/' . $file ) ) { + $theme_file = get_stylesheet_directory() . '/ultimate-member/templates/' . $file; + } else { + $theme_file = false; + } + if ( ! empty( $theme_file ) ) { + $core_file = $file; + + $core_version = $this->get_file_version( um_path . '/templates/' . $core_file ); + $theme_version = $this->get_file_version( $theme_file ); + + $status = esc_html__( 'Theme version up to date', 'ultimate-member' ); + $status_code = 1; + if ( version_compare( $theme_version, $core_version, '<' ) ) { + $status = esc_html__( 'Theme version is out of date', 'ultimate-member' ); + $status_code = 0; + } + if ( '' === $theme_version ) { + $status = esc_html__( 'Theme version is empty', 'ultimate-member' ); + $status_code = 0; + } + $outdated_files[] = array( + 'core_version' => $core_version, + 'theme_version' => $theme_version, + 'core_file' => stristr( um_path . 'templates/' . $core_file, 'wp-content' ), + 'theme_file' => stristr( $theme_file, 'wp-content' ), + 'status' => $status, + 'status_code' => $status_code, + ); + } + } + } + ob_start(); ?>

@@ -3034,6 +3074,65 @@ if ( ! class_exists( 'um\admin\core\Admin_Settings' ) ) { } + /** + * Scan the template files. + * + * @param string $template_path Path to the template directory. + * @return array + */ + public static function scan_template_files( $template_path ) { + $files = @scandir( $template_path ); // @codingStandardsIgnoreLine. + $result = array(); + + if ( ! empty( $files ) ) { + + foreach ( $files as $key => $value ) { + + if ( ! in_array( $value, array( '.', '..' ), true ) ) { + + if ( is_dir( $template_path . DIRECTORY_SEPARATOR . $value ) ) { + $sub_files = self::scan_template_files( $template_path . DIRECTORY_SEPARATOR . $value ); + foreach ( $sub_files as $sub_file ) { + $result[] = $value . DIRECTORY_SEPARATOR . $sub_file; + } + } else { + $result[] = $value; + } + } + } + } + return $result; + } + + + public static function get_file_version( $file ) { + + // Avoid notices if file does not exist. + if ( ! file_exists( $file ) ) { + return ''; + } + + // We don't need to write to the file, so just open for reading. + $fp = fopen( $file, 'r' ); // @codingStandardsIgnoreLine. + + // Pull only the first 8kiB of the file in. + $file_data = fread( $fp, 8192 ); // @codingStandardsIgnoreLine. + + // PHP will close file handle, but we are good citizens. + fclose( $fp ); // @codingStandardsIgnoreLine. + + // Make sure we catch CR-only line endings. + $file_data = str_replace( "\r", "\n", $file_data ); + $version = ''; + + if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( '@version', '/' ) . '(.*)$/mi', $file_data, $match ) && $match[1] ) { + $version = _cleanup_header_comment( $match[1] ); + } + + return $version; + } + + /** * @param $html * @param $section_fields diff --git a/templates/message.php b/templates/message.php index 58572f36..b2d6c5d4 100644 --- a/templates/message.php +++ b/templates/message.php @@ -1,4 +1,9 @@ - +

@@ -8,4 +13,4 @@ printf( __( '%s', 'ultimate-member' ), $this->custom_message ); ?>
- \ No newline at end of file + diff --git a/templates/profile.php b/templates/profile.php index 7ca2fb9e..6c85989c 100644 --- a/templates/profile.php +++ b/templates/profile.php @@ -1,4 +1,8 @@ - +
diff --git a/templates/searchform.php b/templates/searchform.php index 7761c452..0e08d9a7 100644 --- a/templates/searchform.php +++ b/templates/searchform.php @@ -1,4 +1,8 @@ - +
@@ -9,4 +13,4 @@
-
\ No newline at end of file +