| 1 |
<?php |
| 2 |
/** |
| 3 |
* Theme Compatibility Notice |
| 4 |
* |
| 5 |
* Displays admin notice for theme compatibility issues. |
| 6 |
* Warns users if their theme version is outdated and requires update. |
| 7 |
* |
| 8 |
* @package Forumax |
| 9 |
*/ |
| 10 |
|
| 11 |
defined( 'ABSPATH' ) || exit; |
| 12 |
|
| 13 |
/** |
| 14 |
* Display admin notice for theme compatibility |
| 15 |
* |
| 16 |
* Checks if the active theme meets the minimum required version |
| 17 |
* for Forumax compatibility and displays a warning notice if not. |
| 18 |
* |
| 19 |
* The notice is not shown if: |
| 20 |
* - The theme is up to date |
| 21 |
* - A child theme is active and its parent theme (Docy, Docly, or Ama) meets the required version |
| 22 |
* |
| 23 |
* @return void |
| 24 |
*/ |
| 25 |
function forumax_theme_compatibility_notice() { |
| 26 |
$theme = wp_get_theme(); |
| 27 |
$theme_name = $theme->get( 'Name' ); |
| 28 |
$current_theme_v = $theme->get( 'Version' ); |
| 29 |
$parent_theme = $theme->parent(); |
| 30 |
|
| 31 |
// Set required version for each theme |
| 32 |
$my_themes = array( |
| 33 |
'Docy' => '4.4.0', |
| 34 |
'Docly' => '2.3.2', |
| 35 |
'Ama' => '1.7.1', |
| 36 |
); |
| 37 |
|
| 38 |
foreach ( $my_themes as $name => $required_v ) { |
| 39 |
// Check if theme name contains one of our themes |
| 40 |
if ( stripos( $theme_name, $name ) !== false ) { |
| 41 |
|
| 42 |
// Don't show notice if a child theme is active and parent theme meets the required version |
| 43 |
if ( $parent_theme ) { |
| 44 |
$parent_theme_name = $parent_theme->get( 'Name' ); |
| 45 |
$parent_theme_version = $parent_theme->get( 'Version' ); |
| 46 |
|
| 47 |
// If parent theme matches and meets the required version, don't show the notice |
| 48 |
if ( $name === $parent_theme_name && version_compare( $parent_theme_version, $required_v, '>=' ) ) { |
| 49 |
return; // Don't show the notice |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
// Check if current version is less than required version |
| 54 |
if ( version_compare( $current_theme_v, $required_v, '<' ) ) { |
| 55 |
?> |
| 56 |
<div class="notice notice-error" style="border-left-color: #dc3232; padding: 15px;"> |
| 57 |
<div style="display: flex; align-items: flex-start; gap: 15px;"> |
| 58 |
<span style="font-size: 40px; line-height: 1;">⚠️</span> |
| 59 |
<div style="flex: 1;"> |
| 60 |
<h2 style="margin: 0 0 10px 0; color: #dc3232; font-size: 18px;"> |
| 61 |
<?php esc_html_e( 'CRITICAL: Immediate Action Required!', 'forumax' ); ?> |
| 62 |
</h2> |
| 63 |
<p style="font-size: 15px; margin: 0 0 10px 0; line-height: 1.6;"> |
| 64 |
<strong><?php esc_html_e( 'Your site may break or malfunction!', 'forumax' ); ?></strong> |
| 65 |
</p> |
| 66 |
<p style="font-size: 14px; margin: 0 0 15px 0; line-height: 1.6;"> |
| 67 |
<?php |
| 68 |
printf( |
| 69 |
/* translators: 1: Theme name, 2: Current version, 3: Required version */ |
| 70 |
esc_html__( 'Your %1$s theme is outdated (version %2$s). Please update to version %3$s or higher. We have made significant changes to the Forumax plugin, and using an outdated theme will cause compatibility issues and may break your website.', 'forumax' ), |
| 71 |
'<strong>' . esc_html( $theme_name ) . '</strong>', |
| 72 |
'<code style="background: #fff3cd; padding: 2px 6px; border-radius: 3px; color: #856404;">' . esc_html( $current_theme_v ) . '</code>', |
| 73 |
'<code style="background: #d4edda; padding: 2px 6px; border-radius: 3px; color: #155724; font-weight: bold;">' . esc_html( $required_v ) . '</code>' |
| 74 |
); |
| 75 |
?> |
| 76 |
</p> |
| 77 |
<div style="background: #fff3cd; border-left: 4px solid #ffc107; padding: 12px; margin-bottom: 15px;"> |
| 78 |
<p style="margin: 0; font-size: 13px; color: #856404;"> |
| 79 |
<strong><?php esc_html_e( '⚡ What has changed:', 'forumax' ); ?></strong><br> |
| 80 |
<?php esc_html_e( 'We have completely restructured the Forumax plugin with new features, improved performance, and enhanced security. Your current theme version is not compatible with these updates.', 'forumax' ); ?> |
| 81 |
</p> |
| 82 |
</div> |
| 83 |
<p style="margin: 0;"> |
| 84 |
<a href="<?php echo esc_url( admin_url( 'update-core.php' ) ); ?>" class="button button-primary" style="background: #dc3232; border-color: #dc3232; font-size: 14px; height: auto; padding: 8px 20px;"> |
| 85 |
<?php esc_html_e( '🔄 Update Theme Now', 'forumax' ); ?> |
| 86 |
</a> |
| 87 |
<span style="margin-left: 15px; color: #666; font-size: 13px;"> |
| 88 |
<?php esc_html_e( 'This update is mandatory for your site to function properly.', 'forumax' ); ?> |
| 89 |
</span> |
| 90 |
</p> |
| 91 |
</div> |
| 92 |
</div> |
| 93 |
</div> |
| 94 |
<style> |
| 95 |
.notice.notice-error h2 { |
| 96 |
font-size: 18px !important; |
| 97 |
} |
| 98 |
</style> |
| 99 |
<?php |
| 100 |
} |
| 101 |
break; // Stop loop once theme is found |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
add_action( 'admin_notices', 'forumax_theme_compatibility_notice' ); |
| 106 |
|