Skip to content

Raise coverage #302

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 27 additions & 18 deletions includes/MslsAdminIcon.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
<?php
/**
* MslsAdminIcon
* @author Dennis Ploetner <re@lloc.de>
* @since 0.9.8
*/

namespace lloc\Msls;

Expand All @@ -12,6 +7,7 @@

/**
* Handles the icon links in the backend
*
* @package Msls
*/
class MslsAdminIcon {
Expand Down Expand Up @@ -121,7 +117,7 @@ public function set_icon_type( $icon_type ): MslsAdminIcon {
*/
public function set_path(): MslsAdminIcon {
if ( 'post' != $this->type ) {
$query_vars = [ 'post_type' => $this->type ];
$query_vars = array( 'post_type' => $this->type );
$this->path = add_query_arg( $query_vars, $this->path );
}

Expand Down Expand Up @@ -209,12 +205,16 @@ public function get_img(): string {
*/
public function get_a(): string {
if ( empty( $this->href ) ) {
$title = sprintf( __( 'Create a new translation in the %s-blog', 'multisite-language-switcher' ),
$this->language );
$title = sprintf(
__( 'Create a new translation in the %s-blog', 'multisite-language-switcher' ),
$this->language
);
$href = $this->get_edit_new();
} else {
$title = sprintf( __( 'Edit the translation in the %s-blog', 'multisite-language-switcher' ),
$this->language );
$title = sprintf(
__( 'Edit the translation in the %s-blog', 'multisite-language-switcher' ),
$this->language
);
$href = $this->href;
}

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

switch ( $this->icon_type ) {
case MslsAdminIcon::TYPE_FLAG:
$icon = sprintf( '<span class="flag-icon %s">%s</span>',
case self::TYPE_FLAG:
$icon = sprintf(
'<span class="flag-icon %s">%s</span>',
( new IconSvg() )->get( $this->language ),
$this->language
);
break;
case MslsAdminIcon::TYPE_LABEL:
$icon = sprintf( '<span class="language-badge %s">%s</span>',
case self::TYPE_LABEL:
$icon = sprintf(
'<span class="language-badge %s">%s</span>',
$this->language,
( new IconLabel() )->get( $this->language )
);
break;
default:
$icon = sprintf( '<span class="dashicons %s"></span>',
empty( $this->href ) ? 'dashicons-plus' : 'dashicons-edit' );
$icon = sprintf(
'<span class="dashicons %s"></span>',
empty( $this->href ) ? 'dashicons-plus' : 'dashicons-edit'
);
}

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

if ( null !== $this->id && null !== $this->origin_language ) {
$path = add_query_arg( [ 'msls_id' => $this->id, 'msls_lang' => $this->origin_language ], $this->path );
$path = add_query_arg(
array(
'msls_id' => $this->id,
'msls_lang' => $this->origin_language,
),
$this->path
);
}

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

return get_admin_url( get_current_blog_id(), $path );
}

}
15 changes: 5 additions & 10 deletions includes/MslsAdminIconTaxonomy.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
<?php
/**
* MslsAdminIconTaxonomy
* @author Dennis Ploetner <re@lloc.de>
* @since 0.9.8
*/

namespace lloc\Msls;

/**
* Handles backend icons for taxonomies
*
* @package Msls
*/
class MslsAdminIconTaxonomy extends MslsAdminIcon {

/**
* Path
*
* @var string
*/
protected $path = 'edit-tags.php';
Expand All @@ -28,7 +25,7 @@ class MslsAdminIconTaxonomy extends MslsAdminIcon {
* @uses get_edit_term_link()
*/
public function set_href( int $id ): MslsAdminIcon {
$object_type = MslsTaxonomy::instance()->get_post_type();
$object_type = MslsTaxonomy::instance()->get_post_type();

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

Expand All @@ -39,17 +36,15 @@ public function set_href( int $id ): MslsAdminIcon {
* Set the path by type
*
* @return MslsAdminIconTaxonomy
*
*/
public function set_path(): MslsAdminIcon {
$args = [ 'taxonomy' => $this->type ];
$args = array( 'taxonomy' => $this->type );
$post_type = MslsTaxonomy::instance()->get_post_type();

$post_type !== '' && $args['post_type'] = $post_type;
$post_type !== '' && $args['post_type'] = $post_type;

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

return $this;
}

}
2 changes: 1 addition & 1 deletion includes/MslsOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static function create( $id = 0 ) {
$options = new MslsOptionsPost( get_queried_object_id() );
}

add_filter( 'check_url', array( $options, 'check_for_blog_slug' ), 10, 2 );
add_filter( 'msls_get_postlink', array( $options, 'check_for_blog_slug' ), 10, 2 );

return $options;
}
Expand Down
6 changes: 5 additions & 1 deletion includes/MslsOptionsPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ public function get_postlink( $language ) {
$this->with_front = ! empty( $post_object->rewrite['with_front'] );
}

return apply_filters( 'check_url', get_permalink( $post ), $this );
$post_link = get_permalink( $post );

$post_link = apply_filters_deprecated( 'check_url', array( $post_link, $this ), '2.7.1', 'msls_get_postlink' );

return apply_filters( 'msls_get_postlink', $post_link, $this );
}

/**
Expand Down
11 changes: 7 additions & 4 deletions includes/MslsOptionsQuery.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/**
* MslsOptionsQuery
*
* @author Dennis Ploetner <re@lloc.de>
* @since 0.9.8
*/
Expand All @@ -16,6 +17,7 @@ class MslsOptionsQuery extends MslsOptions {

/**
* Rewrite with front
*
* @var bool
*/
public $with_front = true;
Expand Down Expand Up @@ -61,13 +63,14 @@ public static function create( $id = 0 ) {
*/
public function get_postlink( $language ) {
if ( $this->has_value( $language ) ) {
$link = $this->get_current_link();
if ( ! empty( $link ) ) {
return apply_filters( 'check_url', $link, $this );
$post_link = $this->get_current_link();
if ( ! empty( $post_link ) ) {
$post_link = apply_filters_deprecated( 'check_url', array( $post_link, $this ), '2.7.1', 'msls_get_postlink' );

return apply_filters( 'msls_get_postlink', $post_link, $this );
}
}

return '';
}

}
4 changes: 2 additions & 2 deletions includes/MslsOptionsQueryAuthor.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/**
* MslsOptionsQueryAuthor
*
* @author Dennis Ploetner <re@lloc.de>
* @since 0.9.8
*/
Expand All @@ -15,7 +16,7 @@
class MslsOptionsQueryAuthor extends MslsOptionsQuery {

/**
* Check if the array has an non empty item which has $language as a key
* Check if the array has a non-empty item which has $language as a key
*
* @param string $language
*
Expand Down Expand Up @@ -44,5 +45,4 @@ public function has_value( $language ) {
public function get_current_link() {
return get_author_posts_url( $this->get_arg( 0, 0 ) );
}

}
17 changes: 12 additions & 5 deletions includes/MslsOptionsTax.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/**
* MslsOptionsTax
*
* @author Dennis Ploetner <re@lloc.de>
* @since 0.9.8
*/
Expand All @@ -9,18 +10,21 @@

/**
* Taxonomy options
*
* @package Msls
*/
class MslsOptionsTax extends MslsOptions {

/**
* Separator
*
* @var string
*/
protected $sep = '_term_';

/**
* Autoload
*
* @var string
*/
protected $autoload = 'no';
Expand Down Expand Up @@ -58,7 +62,7 @@ public static function create( $id = 0 ) {
}

if ( $req ) {
add_filter( 'check_url', [ $options, 'check_base' ], 9, 2 );
add_filter( 'msls_get_postlink', array( $options, 'check_base' ), 9, 2 );
} else {
global $wp_rewrite;

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

/**
* Get the queried taxonomy
*
* @return string
*/
public function get_tax_query() {
Expand All @@ -92,17 +97,20 @@ public function get_tax_query() {
* @return string
*/
public function get_postlink( $language ) {
$url = '';
$post_link = '';

if ( $this->has_value( $language ) ) {
$url = $this->get_term_link( (int) $this->__get( $language ) );
$post_link = $this->get_term_link( (int) $this->__get( $language ) );
}

return apply_filters( 'check_url', $url, $this );
$post_link = apply_filters_deprecated( 'check_url', array( $post_link, $this ), '2.7.1', 'msls_get_postlink' );

return apply_filters( 'msls_get_postlink', $post_link, $this );
}

/**
* Get current link
*
* @return string
*/
public function get_current_link() {
Expand All @@ -129,5 +137,4 @@ public function get_term_link( $term_id ) {

return '';
}

}
Loading