|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file adds a custom section in the customizer that recommends the installation of the Kirki plugin. |
|
4
|
|
|
* It can be used as-is in themes (drop-in). |
|
5
|
|
|
* |
|
6
|
|
|
* @package kirki-helpers |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
if ( ! class_exists( 'Kirki' ) ) { |
|
10
|
|
|
|
|
11
|
|
|
if ( class_exists( 'WP_Customize_Section' ) && ! class_exists( 'Kirki_Installer_Section' ) ) { |
|
12
|
|
|
/** |
|
13
|
|
|
* Recommend the installation of Kirki using a custom section. |
|
14
|
|
|
* |
|
15
|
|
|
* @see WP_Customize_Section |
|
16
|
|
|
*/ |
|
17
|
|
|
class Kirki_Installer_Section extends WP_Customize_Section { |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Customize section type. |
|
21
|
|
|
* |
|
22
|
|
|
* @access public |
|
23
|
|
|
* @var string |
|
24
|
|
|
*/ |
|
25
|
|
|
public $type = 'kirki_installer'; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Render the section. |
|
29
|
|
|
* |
|
30
|
|
|
* @access protected |
|
31
|
|
|
*/ |
|
32
|
|
|
protected function render() { |
|
33
|
|
|
// Determine if the plugin is not installed, or just inactive. |
|
34
|
|
|
$plugins = get_plugins(); |
|
35
|
|
|
$installed = false; |
|
36
|
|
|
foreach ( $plugins as $plugin ) { |
|
37
|
|
|
if ( 'Kirki' === $plugin['Name'] || 'Kirki Toolkit' === $plugin['Name'] ) { |
|
38
|
|
|
$installed = true; |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
// Get the plugin-installation URL. |
|
42
|
|
|
$plugin_install_url = add_query_arg( |
|
43
|
|
|
array( |
|
44
|
|
|
'action' => 'install-plugin', |
|
45
|
|
|
'plugin' => 'kirki', |
|
46
|
|
|
), |
|
47
|
|
|
self_admin_url( 'update.php' ) |
|
48
|
|
|
); |
|
49
|
|
|
$plugin_install_url = wp_nonce_url( $plugin_install_url, 'install-plugin_kirki' ); |
|
50
|
|
|
$classes = 'cannot-expand accordion-section control-section control-section-themes control-section-' . $this->type; |
|
51
|
|
|
?> |
|
52
|
|
|
<li id="accordion-section-<?php echo esc_attr( $this->id ); ?>" class="<?php echo esc_attr( $classes ); ?>" style="border-top:none;border-bottom:1px solid #ddd;padding:7px 14px 16px 14px;text-align:right;"> |
|
53
|
|
|
<?php if ( ! $installed ) : ?> |
|
54
|
|
|
<p style="text-align:left;margin-top:0;"><?php esc_attr_e( 'A plugin is required to take advantage of this theme\'s features in the customizer.', 'textdomain' ); ?></p> |
|
55
|
|
|
<a class="install-now button-primary button" data-slug="kirki" href="<?php echo esc_url_raw( $plugin_install_url ); ?>" aria-label="<?php esc_attr_e( 'Install Kirki Toolkit now', 'textdomain' ); ?>" data-name="Kirki Toolkit"> |
|
56
|
|
|
<?php esc_html_e( 'Install Now', 'textdomain' ); ?> |
|
57
|
|
|
</a> |
|
58
|
|
|
<?php else : ?> |
|
59
|
|
|
<p style="text-align:left;margin-top:0;"><?php esc_attr_e( 'You have installed Kirki. Activate it to take advantage of this theme\'s features in the customizer.', 'textdomain' ); ?></p> |
|
60
|
|
|
<a class="install-now button-secondary button change-theme" data-slug="kirki" href="<?php echo esc_url_raw( self_admin_url( 'plugins.php' ) ); ?>" aria-label="<?php esc_attr_e( 'Activate Kirki Toolkit now', 'textdomain' ); ?>" data-name="Kirki Toolkit"> |
|
61
|
|
|
<?php esc_html_e( 'Activate Now', 'textdomain' ); ?> |
|
62
|
|
|
</a> |
|
63
|
|
|
<?php endif; ?> |
|
64
|
|
|
</li> |
|
65
|
|
|
<?php |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if ( ! function_exists( 'kirki_installer_register' ) ) { |
|
71
|
|
|
/** |
|
72
|
|
|
* Registers the section, setting & control for the kirki installer. |
|
73
|
|
|
* |
|
74
|
|
|
* @param object $wp_customize The main customizer object. |
|
75
|
|
|
*/ |
|
76
|
|
|
function kirki_installer_register( $wp_customize ) { |
|
77
|
|
|
$wp_customize->add_section( new Kirki_Installer_Section( $wp_customize, 'kirki_installer', array( |
|
78
|
|
|
'title' => '', |
|
79
|
|
|
'capability' => 'install_plugins', |
|
80
|
|
|
'priority' => 0, |
|
81
|
|
|
) ) ); |
|
82
|
|
|
$wp_customize->add_setting( 'kirki_installer_setting', array( |
|
83
|
|
|
'sanitize_callback' => '__return_true', |
|
84
|
|
|
) ); |
|
85
|
|
|
$wp_customize->add_control( 'kirki_installer_control', array( |
|
86
|
|
|
'section' => 'kirki_installer', |
|
87
|
|
|
'settings' => 'kirki_installer_setting', |
|
88
|
|
|
) ); |
|
89
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
add_action( 'customize_register', 'kirki_installer_register' ); |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|