This repository has been archived by the owner on Apr 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
91 lines (69 loc) · 2.75 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
define( 'CRDM_ADVANCED_APP_PATH', realpath( get_stylesheet_directory() ) . DIRECTORY_SEPARATOR );
define( 'CRDM_ADVANCED_APP_VERSION', '0.2.1' );
define( 'CRDM_ADVANCED_TEMPLATE_URL', trailingslashit( get_stylesheet_directory_uri() ) );
define( 'CRDM_ADVANCED_PARENT_TEMPLATE_PATH', realpath( get_template_directory() ) . DIRECTORY_SEPARATOR );
define( 'CRDM_ADVANCED_PARENT_TEMPLATE_URL', trailingslashit( get_template_directory_uri() ) );
class CrdmAdvancedTheme {
public function __construct() {
add_action( 'after_switch_theme', [ $this, 'switchToPreviousThemeIfIncompatibleVersionOfWpOrPhp' ] );
// if incompatible version of WP / PHP => don´t init
if ( ! $this->isCompatibleVersionOfWp() ||
! $this->isCompatibleVersionOfPhp()
) {
return;
}
$this->init();
}
protected function init() {
require CRDM_ADVANCED_APP_PATH . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
require CRDM_ADVANCED_APP_PATH . 'vendor' . DIRECTORY_SEPARATOR . 'aristath' . DIRECTORY_SEPARATOR . 'kirki' . DIRECTORY_SEPARATOR . 'kirki.php'; // init Kirki library
( new Crdm\Setup() );
if ( is_admin() ) {
( new Crdm\Admin\Init() );
} else {
( new Crdm\Front\Init() );
}
}
protected function isCompatibleVersionOfWp() {
if ( isset( $GLOBALS['wp_version'] ) && version_compare( $GLOBALS['wp_version'], '4.9.8', '>=' ) ) {
return true;
}
return false;
}
protected function isCompatibleVersionOfPhp() {
if ( version_compare( PHP_VERSION, '7.0', '>=' ) ) {
return true;
}
return false;
}
public function switchToPreviousThemeIfIncompatibleVersionOfWpOrPhp() {
if ( ! $this->isCompatibleVersionOfPhp() || ! $this->isCompatibleVersionOfWp() ) {
if ( ! $this->isCompatibleVersionOfWp() ) {
add_action( 'admin_notices', function () {
$this->showAdminNotice( esc_html__( 'Šablona ČRDM - rozšířená vyžaduje verzi WordPress 4.9.8 nebo vyšší!', 'crdm-advanced' ), 'warning' );
} );
}
if ( ! $this->isCompatibleVersionOfPhp() ) {
add_action( 'admin_notices', function () {
$this->showAdminNotice( esc_html__( 'Šablona ČRDM - rozšířená vyžaduje verzi PHP 7.0 nebo vyšší!', 'crdm-advanced' ), 'warning' );
} );
}
// Switch back to previous theme
switch_theme( get_option( 'theme_switched' ) );
return false;
}
return true;
}
public function showAdminNotice( $message, $type = 'warning' ) {
$class = 'notice notice-' . $type . ' is-dismissible';
printf( '<div class="%1$s"><p>%2$s</p><button type="button" class="notice-dismiss">
<span class="screen-reader-text">' . __( 'Zavřít', 'crdm-advanced' ) . '</span>
</button></div>', esc_attr( $class ), $message );
}
}
global $crdmAdvancedTheme;
$crdmAdvancedTheme = new CrdmAdvancedTheme();