-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-footer-credits.php
135 lines (121 loc) · 3.36 KB
/
class-footer-credits.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
<?php
/**
* Stand-alone footer credits class.
*
* @package FooterCredits
* @since 1.0.0
* @link https://github.com/cedaro/footer-credits
* @copyright Copyright (c) 2015 Cedaro, LLC
* @license GPL-2.0+
*/
/**
* Footer credits class.
*
* @package FooterCredits
* @since 1.0.0
*/
class Cedaro_Footer_Credits {
/**
* Load the credits functionality.
*
* @since 1.0.0
*/
public function register_hooks() {
$filter = sprintf( '%s_credits', str_replace( '/src', '', get_template() ) );
add_filter( $filter, array( $this, 'credits_text' ), 1000 );
add_filter( 'footer_credits', array( $this, 'credits_text' ), 1000 );
add_action( 'customize_register', array( $this, 'customize_register' ), 20 );
}
/**
* Update the credits text.
*
* @since 1.0.0
*
* @param string $text Credits text.
* @return string
*/
public function credits_text( $text ) {
$settings = wp_parse_args( (array) get_option( 'footer_credits' ), array(
'placement' => '',
'text' => '',
) );
switch ( $settings['placement'] ) {
case 'after' :
$text .= ' ' . $settings['text'];
break;
case 'before' :
$text = $settings['text'] . ' ' . $text;
break;
case 'remove' :
$text = '';
break;
case 'replace' :
$text = $settings['text'];
break;
}
$search = array( '{{year}}' );
$replace = array( date( 'Y' ) );
$text = str_replace( $search, $replace, $text );
$text = wptexturize( trim( $text ) );
$text = convert_chars( $text );
$text = $this->allowed_tags( $text );
return $text;
}
/**
* Register Customizer settings.
*
* @since 1.0.0
*
* @param WP_Customize_Manager $wp_customize Customizer manager object.
*/
public function customize_register( $wp_customize ) {
$wp_customize->add_section( 'footer_credits', array(
'title' => __( 'Credits', 'footer-credits' ),
'priority' => 1000,
) );
$wp_customize->add_setting( 'footer_credits[text]', array(
'default' => '',
'capability' => 'edit_theme_options',
'sanitize_callback' => array( $this, 'allowed_tags' ),
'type' => 'option',
) );
$wp_customize->add_control( 'footer_credits_text', array(
'label' => __( 'Credits', 'footer-credits' ),
'section' => 'footer_credits',
'settings' => 'footer_credits[text]',
'type' => 'textarea',
) );
$wp_customize->add_setting( 'footer_credits[placement]', array(
'capability' => 'edit_theme_options',
'sanitize_callback' => 'sanitize_text_field',
'type' => 'option',
) );
$wp_customize->add_control( 'footer_credits_placement', array(
'choices' => array(
'' => '',
'before' => __( 'Before', 'footer-credits' ),
'after' => __( 'After', 'footer-credits' ),
'replace' => __( 'Replace', 'footer-credits' ),
'remove' => __( 'Remove All', 'footer-credits' )
),
'label' => __( 'Placement', 'footer-credits' ),
'section' => 'footer_credits',
'settings' => 'footer_credits[placement]',
'type' => 'select',
) );
}
/**
* Allow only the $allowedtags array in a string.
*
* @since 1.0.0
*
* @param string $string Unsanitized string.
* @return string Sanitized string.
*/
public function allowed_tags( $text ) {
$allowedtags = wp_kses_allowed_html();
$allowedtags['a']['rel'] = true;
$allowedtags['br'] = array();
return wp_kses( $text, $allowedtags );
}
}