-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsmntcs-custom-logo-link.php
137 lines (127 loc) · 3.88 KB
/
smntcs-custom-logo-link.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?php
/**
* Plugin Name: SMNTCS Custom Logo Link
* Plugin URI: https://github.com/nielslange/smntcs-custom-logo-link
* Description: Allows to customize the logo link
* Author: Niels Lange <[email protected]>
* Author URI: https://nielslange.de
* Text Domain: smntcs-custom-logo-link
* Version: 2.4
* Requires at least: 3.4
* Requires PHP: 5.6
* License: GPL v2 or later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*
* @package SMNTCS_Custom_Logo_Link
*/
defined( 'ABSPATH' ) || exit;
/**
* Add custom link section to WordPress Customizer
*
* @param WP_Customize_Manager $wp_customize The instance of WP_Customize_Manager.
* @return void
*/
function smntcs_custom_logo_link_register_customize( $wp_customize ) {
$wp_customize->add_section(
'smntcs_custom_logo_link_section',
array(
'priority' => 200,
'title' => __( 'Logo Link', 'smntcs-custom-logo-link' ),
)
);
$wp_customize->add_setting(
'smntcs_custom_logo_link_url',
array(
'type' => 'option',
'sanitize_callback' => 'smntcs_custom_logo_link_sanitize_url',
)
);
$wp_customize->add_control(
'smntcs_custom_logo_link_url',
array(
'label' => __( 'URL', 'smntcs-custom-logo-link' ),
'section' => 'smntcs_custom_logo_link_section',
'type' => 'url',
'input_attrs' => array(
// phpcs:ignore WordPress.WP.I18n.MissingArgDomain
'placeholder' => __( 'http://www.google.com' ),
),
)
);
$wp_customize->add_setting(
'smntcs_custom_logo_link_target',
array(
'default' => '',
'type' => 'option',
'sanitize_callback' => 'wp_validate_boolean',
)
);
$wp_customize->add_control(
'smntcs_custom_logo_link_target',
array(
'label' => __( 'Open link in new window', 'smntcs-custom-logo-link' ),
'section' => 'smntcs_custom_logo_link_section',
'type' => 'checkbox',
)
);
}
add_action( 'customize_register', 'smntcs_custom_logo_link_register_customize' );
/**
* Sanitize URL
*
* @param string $url The original URL.
* @return string $url The updated URL.
*/
function smntcs_custom_logo_link_sanitize_url( $url ) {
return esc_url_raw( $url );
}
/**
* Add settings link on plugin page
*
* @param array $links The original array with customizer links.
* @return array The updated array with customizer links.
*/
function smntcs_custom_logo_link_settings_link( array $links ) {
$admin_url = admin_url( 'customize.php?autofocus[control]=smntcs_custom_logo_link_url' );
$settings_link = sprintf( '<a href="%s">' . __( 'Settings', 'smntcs-custom-logo-link' ) . '</a>', $admin_url );
array_unshift( $links, $settings_link );
return $links;
}
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'smntcs_custom_logo_link_settings_link' );
/**
* Customize logo link (if valid URL had been provided)
*
* @return void
*/
function smntcs_custom_logo_link_enqueue() {
switch ( get_template() ) {
case 'colormag':
require_once plugin_dir_path( __FILE__ ) . 'themes/colormag.php';
break;
case 'customify':
require_once plugin_dir_path( __FILE__ ) . 'themes/customify.php';
break;
case 'generatepress':
require_once plugin_dir_path( __FILE__ ) . 'themes/generatepress.php';
break;
case 'hestia':
require_once plugin_dir_path( __FILE__ ) . 'themes/hestia.php';
break;
case 'neve':
require_once plugin_dir_path( __FILE__ ) . 'themes/neve.php';
break;
case 'oceanwp':
require_once plugin_dir_path( __FILE__ ) . 'themes/oceanwp.php';
break;
case 'shapely':
require_once plugin_dir_path( __FILE__ ) . 'themes/shapely.php';
break;
case 'sydney':
require_once plugin_dir_path( __FILE__ ) . 'themes/sydney.php';
break;
default:
require_once plugin_dir_path( __FILE__ ) . 'themes/default.php';
break;
}
}
add_action( 'wp_head', 'smntcs_custom_logo_link_enqueue', 10, 0 );