Completed
Push — add/custom-footer-credit ( 059332 )
by
unknown
38:23 queued 21:54
created

footer-credit.php ➔ footercredit_options()   D

Complexity

Conditions 16
Paths 16

Size

Total Lines 104
Code Lines 79

Duplication

Lines 10
Ratio 9.62 %

Importance

Changes 0
Metric Value
cc 16
eloc 79
nc 16
nop 0
dl 10
loc 104
rs 4.8736
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
Plugin Name: Footer Credit
4
Description: Adjustable Footer Credit
5
Version: 0.4
6
Author: Automattic
7
Author URI: http://automattic.com/
8
License: GPLv2 or later
9
*/
10
11
/**
12
 * Replace footer credit text on WordPress.com
13
 * via wpcom_better_footer_credit_link filter in wp-content/blog-plugins/theme-optimizations.php
14
 *
15
 * @param  string $link
16
 * @param  string $lang
17
 * @return string
18
 */
19
function footercredit_replace_credit( $link, $lang ) {
20
	$credit_option = get_option( 'footercredit' );
21
22
	if ( ! $credit_option ) {
23
		return footercredit_make_credit_link_discoverable( $link );
24
	}
25
26
	if ( $credit_option == 'default' ) {
27
		return footercredit_make_credit_link_discoverable( $link );
28
	}
29
30
	if ( $credit_option == 'hidden' ) {
31
		// we need to show the placeholder in preview
32
		return is_customize_preview() ? '' : footercredit_make_credit_link_discoverable( '<a></a>' );
33
	}
34
35
	$options = footercredit_options();
36
	$credit = $options[ $credit_option ];
37
	$url = localized_wpcom_url( 'https://wordpress.com/?ref=footer_custom_' . $credit_option, $lang );
38
39
	// check for SVG option
40
	if ( $credit_option == 'svg' ) {
41
		$link = '<a href="'. esc_url( $url ) .'" title="' . __( 'Create a website or blog at WordPress.com' ) . '">'. footercredit_svg() .'</a>';
42
	} else {
43
		$link = '<a href="'. esc_url( $url ) .'">'. esc_html( $credit ) .'</a>.';
44
	}
45
46
	return footercredit_make_credit_link_discoverable( $link );
47
}
48
add_filter( 'wpcom_better_footer_credit_link', 'footercredit_replace_credit', 10, 2 );
49
50
/**
51
 * Make the footer credit link discoverable by adding data-type="footer-credit" attribute.
52
 *
53
 * @param string $link
54
 * @param boolean $only_in_preview
55
 * @return string
56
 */
57
function footercredit_make_credit_link_discoverable( $link, $only_in_preview = true ) {
58
	if ( ! $only_in_preview || is_customize_preview() ) {
59
		$link_regex = '#(<a)([^>]*href="https?://(?:www\.)?wordpress\.(?:com|org)[^"]*"[^>]*>)#i';
60
		$link = preg_replace( $link_regex, '$1 data-type="footer-credit"$2', $link );
61
	}
62
63
	return $link;
64
}
65
66
/**
67
 * Replace theme credit text on WordPress.com
68
 * via wpcom_better_footer_theme_link filter in wp-content/blog-plugins/theme-optimizations.php
69
 *
70
 * @param  string $credit
71
 * @return string
72
 */
73
function footercredit_replace_theme( $credit ) {
74
	$credit_option = get_option( 'footercredit' );
75
76
	if ( ! $credit_option ) {
77
		return $credit;
78
	}
79
80
	if ( $credit_option !== 'hidden' ) {
81
		return $credit;
82
	}
83
84
	return '';
85
}
86
add_filter( 'wpcom_better_footer_theme_link', 'footercredit_replace_theme', 10, 2 );
87
88
/**
89
 * The footer credits available in the UI - add future options here
90
 *
91
 * @return array
92
 */
93
function footercredit_options() {
94
	$options = array(
95
		'com'       => 'WordPress.com',
96
		'svg'       => __( 'WordPress.com Logo' ),
97
		'acom'      => __( 'A WordPress.com Website' ),
98
		'blog'      => __( 'Blog at WordPress.com' ),
99
		//'website'   => __( 'Website on WordPress.com' ),
100
		//'hosted'    => __( 'Hosted by WordPress.com' ),
101
		'powered'   => __( 'Powered by WordPress.com' ),
102
	);
103
104
	// In this section we override literal translations with better fitting ones, see
105
	// https://dotcom.wordpress.com/2016/06/15/footer-credit-options/#comment-32204
106
107
	switch ( get_locale() ) {
108
109
		case 'ar':
110
			$options['powered'] = 'مُقدَّم من WordPress.com'; // Powered by WordPress.com
111
		break;
112
113
		case 'de':
114
			$options['acom'] = 'Eine WordPress.com-Website'; // A WordPress.com website
115
			$options['blog'] = 'Bloggen bei WordPress.com'; // Blog at WordPress.com
116
			$options['powered'] = 'Erstellt mit WordPress.com'; // Made with WordPress.com
117
		break;
118
119
		case 'es':
120
			$options['acom'] = 'Un sitio web WordPress.com'; // A WordPress.com website
121
			$options['blog'] = 'Crea tu propio blog con WordPress.com'; // Build your own blog with WordPress.com
122
			$options['powered'] = 'Sitio web ofrecido por WordPress.com'; // Website powered by WordPress.com
123
		break;
124
125
		case 'fr':
126
			$options['acom'] = 'Un site WordPress.com'; // A WordPress.com website
127
			$options['blog'] = 'Commencez votre blog avec WordPress.com'; // Start blogging with WordPress.com
128
			$options['powered'] = 'Ce site vous est proposé par WordPress.com'; // This website is powered by WordPress.com
129
		break;
130
131
		case 'he':
132
			$options['acom'] = 'אחסון ב-WordPress.com'; // hosted by WordPress.com
133
			$options['blog'] = 'בלוגים ב-WordPress.com'; // blogs at WordPress.com
134
			$options['powered'] = 'מבית WordPress.com'; // powered by WordPress.com
135
		break;
136
137 View Code Duplication
		case 'id':
138
			$options['acom'] = 'Dibangun di WordPress.com'; // Created using WordPress.com
139
			$options['blog'] = 'Blog di WordPress.com'; // Blog at WordPress.com
140
			$options['powered'] = 'Dikelola oleh WordPress.com'; // Hosted by WordPress.com
141
		break;
142
143
		case 'it':
144
			$options['acom'] = 'Creato su WordPress.com'; // Created on WordPress.com
145
			$options['blog'] = 'Blog su WordPress.com'; // Blog built on WordPress.com
146
			$options['powered'] = 'Fornito da WordPress.com'; // Powered by WordPress.com
147
		break;
148
149
		case 'ko':
150
			$options['acom'] = 'WordPress.com 사이트'; // WordPress.com site
151
			$options['blog'] = 'WordPress.com 기반'; // Built on WordPress.com
152
			$options['powered'] = 'WordPress.com 사용'; // Enabled by Wordpress.com
153
		break;
154
155
		case 'nl':
156
			$options['acom'] = 'Een WordPress.com website'; // A WordPress.com site
157
			$options['blog'] = 'Maak een eigen blog op WordPress.com'; // Create your own blog at WordPress.com
158
			$options['powered'] = 'Mogelijk gemaakt door WordPress.com'; // Made possible by WordPress.com
159
		break;
160
161
		case 'pt-br':
162
			$options['acom'] = 'Site no WordPress.com'; // A WordPress.com site
163
			$options['blog'] = 'Escreva um blog: WordPress.com'; // Write a blog at WordPress.com
164
			$options['powered'] = 'Site hospedado por WordPress.com'; // Site hosted by WordPress.com
165
		break;
166
167
		case 'ru':
168
			$options['acom'] = 'Сайт WordPress.com'; // WordPress.com site
169
			$options['blog'] = 'Ваш собственный блог на WordPress.com'; // Your own blog on WordPress.com
170
			$options['powered'] = 'На платформе WordPress.com'; // Hosted by WordPress.com
171
		break;
172
173
		case 'sv':
174
			$options['acom'] = 'En WordPress.com-webbplats'; // A WordPress.com site
175
			$options['blog'] = 'Bloggen bor hos WordPress.com'; // This blog lives at WordPress.com
176
			$options['powered'] = 'Med kraft från WordPress.com'; // With power from WordPress
177
		break;
178
179
		case 'tr':
180
			$options['acom'] = 'Bir WordPress.com sitenin'; // A WordPress.com site
181
			$options['powered'] = 'Bu sitenin arkasında WordPress.com\'un gücü var'; // This site is powered by WordPress.com
182
		break;
183
184 View Code Duplication
		case 'zh-cn':
185
			$options['acom'] = '本站由 WordPress.com 托管'; // Site hosted by WordPress.com
186
			$options['blog'] = '在 WordPress.com 玩转博客'; // Have fun blogging with WordPress.com
187
			$options['powered'] = '本站由 WordPress.com 托管'; // Site hosted by WordPress.com
188
		break;
189
190
		case 'zh-tw':
191
			$options['blog'] = '在 WordPress.com 建立免費網站或網誌。'; // Create a free website or blog at WordPress.com
192
		break;
193
	}
194
195
	return $options;
196
}
197
198
/**
199
 * Output a small SVG for the WordCamp Logo
200
 *
201
 * @return string
202
 */
203
function footercredit_svg() {
204
	return	'<svg style="fill: currentColor; position: relative; top: 1px;" width="14px" height="15px" viewBox="0 0 14 15" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-labelledby="title" role="img">
205
				<title id="title">'. __( 'Create a website or blog at WordPress.com' ) .'</title>
206
				<path d="M12.5225848,4.97949746 C13.0138466,5.87586309 13.2934037,6.90452431 13.2934037,7.99874074 C13.2934037,10.3205803 12.0351007,12.3476807 10.1640538,13.4385638 L12.0862862,7.88081544 C12.4453251,6.98296834 12.5648813,6.26504621 12.5648813,5.62667922 C12.5648813,5.39497674 12.549622,5.17994084 12.5225848,4.97949746 L12.5225848,4.97949746 Z M7.86730089,5.04801561 C8.24619178,5.02808979 8.58760099,4.98823815 8.58760099,4.98823815 C8.9267139,4.94809022 8.88671369,4.44972248 8.54745263,4.46957423 C8.54745263,4.46957423 7.52803983,4.54957381 6.86996227,4.54957381 C6.25158863,4.54957381 5.21247202,4.46957423 5.21247202,4.46957423 C4.87306282,4.44972248 4.83328483,4.96816418 5.17254589,4.98823815 C5.17254589,4.98823815 5.49358462,5.02808979 5.83269753,5.04801561 L6.81314716,7.73459399 L5.43565839,11.8651647 L3.14394256,5.04801561 C3.52312975,5.02808979 3.86416859,4.98823815 3.86416859,4.98823815 C4.20305928,4.94809022 4.16305906,4.44972248 3.82394616,4.46957423 C3.82394616,4.46957423 2.80475558,4.54957381 2.14660395,4.54957381 C2.02852925,4.54957381 1.88934333,4.54668493 1.74156477,4.54194422 C2.86690406,2.83350881 4.80113651,1.70529256 6.99996296,1.70529256 C8.638342,1.70529256 10.1302017,2.33173369 11.2498373,3.35765419 C11.222726,3.35602457 11.1962815,3.35261718 11.1683554,3.35261718 C10.5501299,3.35261718 10.1114609,3.89113285 10.1114609,4.46957423 C10.1114609,4.98823815 10.4107217,5.42705065 10.7296864,5.94564049 C10.969021,6.36482346 11.248578,6.90326506 11.248578,7.68133501 C11.248578,8.21992476 11.0413918,8.84503256 10.7696866,9.71584277 L10.1417574,11.8132391 L7.86730089,5.04801561 Z M6.99996296,14.2927074 C6.38218192,14.2927074 5.78595654,14.2021153 5.22195356,14.0362644 L7.11048207,8.54925635 L9.04486267,13.8491542 C9.05760348,13.8802652 9.07323319,13.9089317 9.08989995,13.9358945 C8.43574834,14.1661896 7.73285573,14.2927074 6.99996296,14.2927074 L6.99996296,14.2927074 Z M0.706448182,7.99874074 C0.706448182,7.08630113 0.902152921,6.22015756 1.25141403,5.43749503 L4.25357806,13.6627848 C2.15393732,12.6427902 0.706448182,10.4898387 0.706448182,7.99874074 L0.706448182,7.99874074 Z M6.99996296,0.999 C3.14016476,0.999 0,4.13905746 0,7.99874074 C0,11.8585722 3.14016476,14.999 6.99996296,14.999 C10.8596871,14.999 14,11.8585722 14,7.99874074 C14,4.13905746 10.8596871,0.999 6.99996296,0.999 L6.99996296,0.999 Z" id="wordpress-logo-simplified-cmyk" stroke="none" fill=“currentColor” fill-rule="evenodd"></path>
207
			</svg>';
208
}
209
210
require_once dirname( __FILE__ ) . '/customizer.php';
211