Skip to content

Commit 0e6b02c

Browse files
authored
Raise coverage (#302)
* Raise coverage * Added Types * Cleanup & tests added * get_args reviewed * Filter 'check_url' replaced with 'msls_get_postlink'
1 parent a588a67 commit 0e6b02c

7 files changed

+59
-41
lines changed

includes/MslsAdminIcon.php

+27-18
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
<?php
2-
/**
3-
* MslsAdminIcon
4-
* @author Dennis Ploetner <[email protected]>
5-
* @since 0.9.8
6-
*/
72

83
namespace lloc\Msls;
94

@@ -12,6 +7,7 @@
127

138
/**
149
* Handles the icon links in the backend
10+
*
1511
* @package Msls
1612
*/
1713
class MslsAdminIcon {
@@ -121,7 +117,7 @@ public function set_icon_type( $icon_type ): MslsAdminIcon {
121117
*/
122118
public function set_path(): MslsAdminIcon {
123119
if ( 'post' != $this->type ) {
124-
$query_vars = [ 'post_type' => $this->type ];
120+
$query_vars = array( 'post_type' => $this->type );
125121
$this->path = add_query_arg( $query_vars, $this->path );
126122
}
127123

@@ -209,12 +205,16 @@ public function get_img(): string {
209205
*/
210206
public function get_a(): string {
211207
if ( empty( $this->href ) ) {
212-
$title = sprintf( __( 'Create a new translation in the %s-blog', 'multisite-language-switcher' ),
213-
$this->language );
208+
$title = sprintf(
209+
__( 'Create a new translation in the %s-blog', 'multisite-language-switcher' ),
210+
$this->language
211+
);
214212
$href = $this->get_edit_new();
215213
} else {
216-
$title = sprintf( __( 'Edit the translation in the %s-blog', 'multisite-language-switcher' ),
217-
$this->language );
214+
$title = sprintf(
215+
__( 'Edit the translation in the %s-blog', 'multisite-language-switcher' ),
216+
$this->language
217+
);
218218
$href = $this->href;
219219
}
220220

@@ -232,21 +232,25 @@ public function get_icon(): string {
232232
}
233233

234234
switch ( $this->icon_type ) {
235-
case MslsAdminIcon::TYPE_FLAG:
236-
$icon = sprintf( '<span class="flag-icon %s">%s</span>',
235+
case self::TYPE_FLAG:
236+
$icon = sprintf(
237+
'<span class="flag-icon %s">%s</span>',
237238
( new IconSvg() )->get( $this->language ),
238239
$this->language
239240
);
240241
break;
241-
case MslsAdminIcon::TYPE_LABEL:
242-
$icon = sprintf( '<span class="language-badge %s">%s</span>',
242+
case self::TYPE_LABEL:
243+
$icon = sprintf(
244+
'<span class="language-badge %s">%s</span>',
243245
$this->language,
244246
( new IconLabel() )->get( $this->language )
245247
);
246248
break;
247249
default:
248-
$icon = sprintf( '<span class="dashicons %s"></span>',
249-
empty( $this->href ) ? 'dashicons-plus' : 'dashicons-edit' );
250+
$icon = sprintf(
251+
'<span class="dashicons %s"></span>',
252+
empty( $this->href ) ? 'dashicons-plus' : 'dashicons-edit'
253+
);
250254
}
251255

252256
return $icon;
@@ -261,7 +265,13 @@ public function get_edit_new(): string {
261265
$path = $this->path;
262266

263267
if ( null !== $this->id && null !== $this->origin_language ) {
264-
$path = add_query_arg( [ 'msls_id' => $this->id, 'msls_lang' => $this->origin_language ], $this->path );
268+
$path = add_query_arg(
269+
array(
270+
'msls_id' => $this->id,
271+
'msls_lang' => $this->origin_language,
272+
),
273+
$this->path
274+
);
265275
}
266276

267277
/**
@@ -275,5 +285,4 @@ public function get_edit_new(): string {
275285

276286
return get_admin_url( get_current_blog_id(), $path );
277287
}
278-
279288
}

includes/MslsAdminIconTaxonomy.php

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
<?php
2-
/**
3-
* MslsAdminIconTaxonomy
4-
* @author Dennis Ploetner <[email protected]>
5-
* @since 0.9.8
6-
*/
72

83
namespace lloc\Msls;
94

105
/**
116
* Handles backend icons for taxonomies
7+
*
128
* @package Msls
139
*/
1410
class MslsAdminIconTaxonomy extends MslsAdminIcon {
1511

1612
/**
1713
* Path
14+
*
1815
* @var string
1916
*/
2017
protected $path = 'edit-tags.php';
@@ -28,7 +25,7 @@ class MslsAdminIconTaxonomy extends MslsAdminIcon {
2825
* @uses get_edit_term_link()
2926
*/
3027
public function set_href( int $id ): MslsAdminIcon {
31-
$object_type = MslsTaxonomy::instance()->get_post_type();
28+
$object_type = MslsTaxonomy::instance()->get_post_type();
3229

3330
$this->href = get_edit_term_link( $id, $this->type, $object_type );
3431

@@ -39,17 +36,15 @@ public function set_href( int $id ): MslsAdminIcon {
3936
* Set the path by type
4037
*
4138
* @return MslsAdminIconTaxonomy
42-
*
4339
*/
4440
public function set_path(): MslsAdminIcon {
45-
$args = [ 'taxonomy' => $this->type ];
41+
$args = array( 'taxonomy' => $this->type );
4642
$post_type = MslsTaxonomy::instance()->get_post_type();
4743

48-
$post_type !== '' && $args['post_type'] = $post_type;
44+
$post_type !== '' && $args['post_type'] = $post_type;
4945

5046
$this->path = add_query_arg( $args, $this->path );
5147

5248
return $this;
5349
}
54-
5550
}

includes/MslsOptions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static function create( $id = 0 ) {
108108
$options = new MslsOptionsPost( get_queried_object_id() );
109109
}
110110

111-
add_filter( 'check_url', array( $options, 'check_for_blog_slug' ), 10, 2 );
111+
add_filter( 'msls_get_postlink', array( $options, 'check_for_blog_slug' ), 10, 2 );
112112

113113
return $options;
114114
}

includes/MslsOptionsPost.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ public function get_postlink( $language ) {
4545
$this->with_front = ! empty( $post_object->rewrite['with_front'] );
4646
}
4747

48-
return apply_filters( 'check_url', get_permalink( $post ), $this );
48+
$post_link = get_permalink( $post );
49+
50+
$post_link = apply_filters_deprecated( 'check_url', array( $post_link, $this ), '2.7.1', 'msls_get_postlink' );
51+
52+
return apply_filters( 'msls_get_postlink', $post_link, $this );
4953
}
5054

5155
/**

includes/MslsOptionsQuery.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
/**
33
* MslsOptionsQuery
4+
*
45
* @author Dennis Ploetner <[email protected]>
56
* @since 0.9.8
67
*/
@@ -16,6 +17,7 @@ class MslsOptionsQuery extends MslsOptions {
1617

1718
/**
1819
* Rewrite with front
20+
*
1921
* @var bool
2022
*/
2123
public $with_front = true;
@@ -61,13 +63,14 @@ public static function create( $id = 0 ) {
6163
*/
6264
public function get_postlink( $language ) {
6365
if ( $this->has_value( $language ) ) {
64-
$link = $this->get_current_link();
65-
if ( ! empty( $link ) ) {
66-
return apply_filters( 'check_url', $link, $this );
66+
$post_link = $this->get_current_link();
67+
if ( ! empty( $post_link ) ) {
68+
$post_link = apply_filters_deprecated( 'check_url', array( $post_link, $this ), '2.7.1', 'msls_get_postlink' );
69+
70+
return apply_filters( 'msls_get_postlink', $post_link, $this );
6771
}
6872
}
6973

7074
return '';
7175
}
72-
7376
}

includes/MslsOptionsQueryAuthor.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
/**
33
* MslsOptionsQueryAuthor
4+
*
45
* @author Dennis Ploetner <[email protected]>
56
* @since 0.9.8
67
*/
@@ -15,7 +16,7 @@
1516
class MslsOptionsQueryAuthor extends MslsOptionsQuery {
1617

1718
/**
18-
* Check if the array has an non empty item which has $language as a key
19+
* Check if the array has a non-empty item which has $language as a key
1920
*
2021
* @param string $language
2122
*
@@ -44,5 +45,4 @@ public function has_value( $language ) {
4445
public function get_current_link() {
4546
return get_author_posts_url( $this->get_arg( 0, 0 ) );
4647
}
47-
4848
}

includes/MslsOptionsTax.php

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
/**
33
* MslsOptionsTax
4+
*
45
* @author Dennis Ploetner <[email protected]>
56
* @since 0.9.8
67
*/
@@ -9,18 +10,21 @@
910

1011
/**
1112
* Taxonomy options
13+
*
1214
* @package Msls
1315
*/
1416
class MslsOptionsTax extends MslsOptions {
1517

1618
/**
1719
* Separator
20+
*
1821
* @var string
1922
*/
2023
protected $sep = '_term_';
2124

2225
/**
2326
* Autoload
27+
*
2428
* @var string
2529
*/
2630
protected $autoload = 'no';
@@ -58,7 +62,7 @@ public static function create( $id = 0 ) {
5862
}
5963

6064
if ( $req ) {
61-
add_filter( 'check_url', [ $options, 'check_base' ], 9, 2 );
65+
add_filter( 'msls_get_postlink', array( $options, 'check_base' ), 9, 2 );
6266
} else {
6367
global $wp_rewrite;
6468

@@ -70,6 +74,7 @@ public static function create( $id = 0 ) {
7074

7175
/**
7276
* Get the queried taxonomy
77+
*
7378
* @return string
7479
*/
7580
public function get_tax_query() {
@@ -92,17 +97,20 @@ public function get_tax_query() {
9297
* @return string
9398
*/
9499
public function get_postlink( $language ) {
95-
$url = '';
100+
$post_link = '';
96101

97102
if ( $this->has_value( $language ) ) {
98-
$url = $this->get_term_link( (int) $this->__get( $language ) );
103+
$post_link = $this->get_term_link( (int) $this->__get( $language ) );
99104
}
100105

101-
return apply_filters( 'check_url', $url, $this );
106+
$post_link = apply_filters_deprecated( 'check_url', array( $post_link, $this ), '2.7.1', 'msls_get_postlink' );
107+
108+
return apply_filters( 'msls_get_postlink', $post_link, $this );
102109
}
103110

104111
/**
105112
* Get current link
113+
*
106114
* @return string
107115
*/
108116
public function get_current_link() {
@@ -129,5 +137,4 @@ public function get_term_link( $term_id ) {
129137

130138
return '';
131139
}
132-
133140
}

0 commit comments

Comments
 (0)