-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcolophon.php
162 lines (148 loc) · 4.39 KB
/
colophon.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
/*
Plugin Name: Colophon
Plugin URI: https://github.com/a8cteam51/colophon
Description: Sets Team 51 footer links to WordPress.com and Pressable.
Version: 1.2.0
Author: WordPress.com Special Projects
Author URI: https://wpspecialprojects.wordpress.com/
License: GPLv3
*/
if ( ! function_exists( 'team51_credits' ) ) :
/**
* A colophon-generating method for WordPress Special Projects Sites.
*
* Usage: team51_credits( 'separator= | ' );
*
* @param array{separator?: string, wpcom?: string, pressable?: string} $args The Args passed to the function.
*
* @return void
*/
function team51_credits( $args = array() ) {
$args = wp_parse_args(
$args,
array(
'separator' => ' ',
/* translators: %s: WordPress. */
'wpcom' => sprintf( __( 'Proudly powered by %s.', 'team51' ), 'WordPress' ),
/* translators: %s: Pressable. */
'pressable' => sprintf( __( 'Hosted by %s.', 'team51' ), 'Pressable' ),
)
);
$credit_links = array();
$parsed_url = wp_parse_url( get_site_url(), PHP_URL_HOST );
$partner_domain = $parsed_url ? $parsed_url : 'wpspecialprojects.com';
if ( $args['wpcom'] ) {
$wpcom_link = apply_filters(
'team51_credits_link_wpcom',
add_query_arg(
array(
'partner_domain' => $partner_domain,
'utm_source' => 'Automattic',
'utm_medium' => 'colophon',
'utm_campaign' => 'Concierge Referral',
'utm_term' => $partner_domain,
),
'https://wordpress.com/wp/'
)
);
$credit_links['wpcom'] = sprintf(
'<a href="%1$s" class="imprint" target="_blank" rel="nofollow">%2$s</a>',
esc_url( $wpcom_link ),
esc_html( $args['wpcom'] )
);
}
if ( $args['pressable'] ) {
$pressable_link = apply_filters(
'team51_credits_link_pressable',
add_query_arg(
array(
'utm_source' => 'Automattic',
'utm_medium' => 'rpc',
'utm_campaign' => 'Concierge Referral',
'utm_term' => $partner_domain,
),
'https://pressable.com/'
)
);
$credit_links['pressable'] = sprintf(
'<a href="%1$s" class="imprint" target="_blank" rel="nofollow">%2$s</a>',
esc_url( $pressable_link ),
esc_html( $args['pressable'] )
);
}
/**
* Filter the output links.
*
* This will enable folks to add additional links, remove links, or
* reroute links to internationalized versions if needed.
*
* @param array $credit_links The associative array of credit links.
* @param array $args The parsed arguments used by `team51_credits()`.
*/
$credit_links = apply_filters( 'team51_credit_links', $credit_links, $args );
echo implode(
esc_html( $args['separator'] ),
$credit_links //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, this cant be escaped as it runs through a filter
);
}
add_action( 'team51_credits', 'team51_credits', 10, 1 );
endif;
if ( ! function_exists( 'team51_credits_shortcode' ) ) :
/**
* The Shortcode for `[team51-credits /]` or `[team51-credits separator=" | " /]` or the like.
*
* Can also be used in the Shortcode block.
*
* @param array{separator?: string, wpcom?: string, pressable?: string} $atts The Args passed to the function.
*
* @return string
*/
function team51_credits_shortcode( $atts ) {
$pairs = array(
'separator' => ' ',
/* translators: %s: WordPress. */
'wpcom' => sprintf( __( 'Proudly powered by %s.', 'team51' ), 'WordPress' ),
/* translators: %s: Pressable. */
'pressable' => sprintf( __( 'Hosted by %s.', 'team51' ), 'Pressable' ),
);
$atts = shortcode_atts( $pairs, $atts, 'team51-credits' );
ob_start();
team51_credits( $atts );
return ob_get_clean();
}
add_action(
'init',
function () {
add_shortcode( 'team51-credits', 'team51_credits_shortcode' );
}
);
endif;
if ( ! function_exists( 'team51_current_year_shortcode' ) ) :
/**
* The Shortcode for `[team51-current-year]`.
*
* Can also be used in the Shortcode block.
*
* @param array{format?: string} $atts The Args passed to the function.
*
* @return string
*/
function team51_current_year_shortcode( $atts ) {
$atts = shortcode_atts(
array(
'format' => 'Y',
),
$atts,
'team51-current-year'
);
$current_year = gmdate( $atts['format'] );
return esc_html( $current_year );
}
add_action(
'init',
function () {
add_shortcode( 'team51-current-year', 'team51_current_year_shortcode' );
}
);
endif;