diff --git a/includes/MslsAdmin.php b/includes/MslsAdmin.php
index 51028c0e..74faa0ac 100644
--- a/includes/MslsAdmin.php
+++ b/includes/MslsAdmin.php
@@ -49,17 +49,16 @@ public static function init() {
* @param string $capability
*
* @since 2.0
- *
*/
$caps = apply_filters( 'msls_admin_caps', 'manage_options' );
if ( current_user_can( $caps ) ) {
$title = __( 'Multisite Language Switcher', 'multisite-language-switcher' );
- add_options_page( $title, $title, 'manage_options', $obj->get_menu_slug(), [ $obj, 'render' ] );
+ add_options_page( $title, $title, 'manage_options', $obj->get_menu_slug(), array( $obj, 'render' ) );
- add_action( 'admin_init', [ $obj, 'register' ] );
- add_action( 'admin_notices', [ $obj, 'has_problems' ] );
+ add_action( 'admin_init', array( $obj, 'register' ) );
+ add_action( 'admin_notices', array( $obj, 'has_problems' ) );
- add_filter( 'msls_admin_validate', [ $obj, 'set_blog_language' ] );
+ add_filter( 'msls_admin_validate', array( $obj, 'set_blog_language' ) );
}
}
@@ -88,7 +87,7 @@ public function get_options_page_link() {
* You can use every method of the decorated object
*
* @param string $method
- * @param mixed $args
+ * @param mixed $args
*
* @return mixed
*/
@@ -96,24 +95,33 @@ public function __call( $method, $args ) {
$parts = explode( '_', $method, 2 );
if ( is_array( $parts ) && 'rewrite' === $parts[0] ) {
- return $this->render_rewrite( $parts[1] );
+ $this->render_rewrite( $parts[1] );
+ return;
}
- $checkboxes = [
- 'activate_autocomplete' => __( 'Activate experimental autocomplete inputs',
- 'multisite-language-switcher' ),
- 'activate_content_import' => __( 'Activate the content import functionality',
- 'multisite-language-switcher' ),
+ $checkboxes = array(
+ 'activate_autocomplete' => __(
+ 'Activate experimental autocomplete inputs',
+ 'multisite-language-switcher'
+ ),
+ 'activate_content_import' => __(
+ 'Activate the content import functionality',
+ 'multisite-language-switcher'
+ ),
'sort_by_description' => __( 'Sort languages by description', 'multisite-language-switcher' ),
'exclude_current_blog' => __( 'Exclude this blog from output', 'multisite-language-switcher' ),
'only_with_translation' => __( 'Show only links with a translation', 'multisite-language-switcher' ),
'output_current_blog' => __( 'Display link to the current language', 'multisite-language-switcher' ),
'content_filter' => __( 'Add hint for available translations', 'multisite-language-switcher' ),
- ];
+ );
- if ( isset ( $checkboxes[ $method ] ) ) {
- echo ( new Group() )->add( new Checkbox( $method, $this->options->$method ) )->add( new Label( $method,
- $checkboxes[ $method ] ) )->render();
+ if ( isset( $checkboxes[ $method ] ) ) {
+ echo ( new Group() )->add( new Checkbox( $method, $this->options->$method ) )->add(
+ new Label(
+ $method,
+ $checkboxes[ $method ]
+ )
+ )->render();
} else {
$value = ! empty( $this->options->$method ) ? $this->options->$method : '';
echo ( new Text( $method, $value ) )->render();
@@ -122,21 +130,26 @@ public function __call( $method, $args ) {
/**
* There is something wrong? Here comes the message...
+ *
* @return bool
*/
- public function has_problems() {
+ public function has_problems(): bool {
$message = '';
if ( $this->options->is_empty() ) {
$message = sprintf(
- __( 'Multisite Language Switcher is almost ready. You must complete the configuration process.',
- 'multisite-language-switcher' ),
+ __(
+ 'Multisite Language Switcher is almost ready. You must complete the configuration process.',
+ 'multisite-language-switcher'
+ ),
esc_url( admin_url( $this->get_options_page_link() ) )
);
} elseif ( 1 == count( $this->options->get_available_languages() ) ) {
$message = sprintf(
- __( 'There are no language files installed. You can manually install some language files or you could use a plugin to download these files automatically.',
- 'multisite-language-switcher' ),
+ __(
+ 'There are no language files installed. You can manually install some language files or you could use a plugin to download these files automatically.',
+ 'multisite-language-switcher'
+ ),
esc_url( 'http://codex.wordpress.org/Installing_WordPress_in_Your_Language#Manually_Installing_Language_Files' ),
esc_url( 'http://wordpress.org/plugins/wp-native-dashboard/' )
);
@@ -148,13 +161,15 @@ public function has_problems() {
/**
* Render the options-page
*/
- public function render() {
+ public function render(): void {
printf(
'
',
- ( $this->options->is_empty() ? __( 'Configure', 'multisite-language-switcher' ) : __( 'Update',
- 'multisite-language-switcher' ) )
+ ( $this->options->is_empty() ? __( 'Configure', 'multisite-language-switcher' ) : __(
+ 'Update',
+ 'multisite-language-switcher'
+ ) )
);
}
/**
* Create a submenu which contains links to all blogs of the current user
+ *
* @return string
*/
public function subsubsub() {
$icon_type = $this->options->get_icon_type();
- $arr = [];
+ $arr = array();
foreach ( $this->collection->get_plugin_active_blogs() as $blog ) {
$admin_url = get_admin_url( $blog->userblog_id, $this->get_options_page_link() );
$current = $blog->userblog_id == $this->collection->get_current_blog_id() ? ' class="current"' : '';
@@ -183,8 +201,10 @@ public function subsubsub() {
$arr[] = sprintf( '%3$s', $admin_url, $current, $blog->get_title( $icon_type ) );
}
- return empty( $arr ) ? '' : sprintf( '',
- implode( ' | ', $arr ) );
+ return empty( $arr ) ? '' : sprintf(
+ '',
+ implode( ' | ', $arr )
+ );
}
/**
@@ -193,13 +213,13 @@ public function subsubsub() {
* @codeCoverageIgnore
*/
public function register() {
- register_setting( 'msls', 'msls', [ $this, 'validate' ] );
+ register_setting( 'msls', 'msls', array( $this, 'validate' ) );
- $sections = [
+ $sections = array(
'language_section' => __( 'Language Settings', 'multisite-language-switcher' ),
'main_section' => __( 'Main Settings', 'multisite-language-switcher' ),
'advanced_section' => __( 'Advanced Settings', 'multisite-language-switcher' ),
- ];
+ );
global $wp_rewrite;
if ( $wp_rewrite->using_permalinks() ) {
@@ -207,7 +227,7 @@ public function register() {
}
foreach ( $sections as $id => $title ) {
- add_settings_section( $id, $title, [ $this, $id ], __CLASS__ );
+ add_settings_section( $id, $title, array( $this, $id ), __CLASS__ );
}
/**
@@ -216,7 +236,6 @@ public function register() {
* @param string $page
*
* @since 1.0
- *
*/
do_action( 'msls_admin_register', __CLASS__ );
}
@@ -229,7 +248,7 @@ public function register() {
* @return int
*/
public function language_section(): int {
- $map = [ 'blog_language' => __( 'Blog Language', 'multisite-language-switcher' ) ];
+ $map = array( 'blog_language' => __( 'Blog Language', 'multisite-language-switcher' ) );
return $this->add_settings_fields( $map, 'language_section' );
}
@@ -242,7 +261,7 @@ public function language_section(): int {
* @return int
*/
public function main_section(): int {
- $map = [
+ $map = array(
'display' => __( 'Display', 'multisite-language-switcher' ),
'admin_display' => __( 'Admin Display', 'multisite-language-switcher' ),
'sort_by_description' => __( 'Sort languages', 'multisite-language-switcher' ),
@@ -255,7 +274,7 @@ public function main_section(): int {
'after_item' => __( 'Text/HTML after each item', 'multisite-language-switcher' ),
'content_filter' => __( 'Available translations hint', 'multisite-language-switcher' ),
'content_priority' => __( 'Hint priority', 'multisite-language-switcher' ),
- ];
+ );
return $this->add_settings_fields( $map, 'main_section' );
}
@@ -268,13 +287,13 @@ public function main_section(): int {
* @return int
*/
public function advanced_section(): int {
- $map = [
+ $map = array(
'activate_autocomplete' => __( 'Autocomplete', 'multisite-language-switcher' ),
'image_url' => __( 'Custom URL for flag-images', 'multisite-language-switcher' ),
'reference_user' => __( 'Reference user', 'multisite-language-switcher' ),
'exclude_current_blog' => __( 'Exclude blog', 'multisite-language-switcher' ),
'activate_content_import' => __( 'Content import', 'multisite-language-switcher' ),
- ];
+ );
return $this->add_settings_fields( $map, 'advanced_section' );
}
@@ -287,23 +306,23 @@ public function advanced_section(): int {
* @return int
*/
public function rewrites_section(): int {
- $map = [];
- foreach ( get_post_types( [ 'public' => true ], 'objects' ) as $key => $object ) {
- $map["rewrite_{$key}"] = sprintf( __( '%s Slug', 'multisite-language-switcher' ), $object->label );
+ $map = array();
+ foreach ( get_post_types( array( 'public' => true ), 'objects' ) as $key => $object ) {
+ $map[ "rewrite_{$key}" ] = sprintf( __( '%s Slug', 'multisite-language-switcher' ), $object->label );
}
return $this->add_settings_fields( $map, 'rewrites_section' );
}
/**
- * @param array $map
+ * @param array $map
* @param string $section
*
* @return int
*/
protected function add_settings_fields( array $map, string $section ): int {
foreach ( $map as $id => $title ) {
- add_settings_field( $id, $title, [ $this, $id ], __CLASS__, $section, [ 'label_for' => $id ] );
+ add_settings_field( $id, $title, array( $this, $id ), __CLASS__, $section, array( 'label_for' => $id ) );
}
/**
@@ -313,7 +332,6 @@ protected function add_settings_fields( array $map, string $section ): int {
* @param string $section
*
* @since 2.4.4
- *
*/
do_action( "msls_admin_{$section}", __CLASS__, $section );
@@ -341,21 +359,23 @@ public function display() {
* Shows the select-form-field 'admin_display'
*/
public function admin_display() {
- echo ( new Select( 'admin_display',
+ echo ( new Select(
+ 'admin_display',
array(
'flag' => __( 'Flag', 'multisite-language-switcher' ),
- 'label' => __( 'Label', 'multisite-language-switcher' )
+ 'label' => __( 'Label', 'multisite-language-switcher' ),
),
- $this->options->admin_display ) )->render();
+ $this->options->admin_display
+ ) )->render();
}
/**
* Shows the select-form-field 'reference_user'
*/
public function reference_user() {
- $users = [];
+ $users = array();
- foreach ( ( array ) apply_filters( 'msls_reference_users', $this->collection->get_users() ) as $user ) {
+ foreach ( (array) apply_filters( 'msls_reference_users', $this->collection->get_users() ) as $user ) {
$users[ $user->ID ] = $user->user_nicename;
}
@@ -363,8 +383,10 @@ public function reference_user() {
$users = array_slice( $users, 0, self::MAX_REFERENCE_USERS, true );
$message = sprintf(
- __( 'Multisite Language Switcher: Collection for reference user has been truncated because it exceeded the maximum of %s users. Please, use the hook "msls_reference_users" to filter the result before!',
- 'multisite-language-switcher' ),
+ __(
+ 'Multisite Language Switcher: Collection for reference user has been truncated because it exceeded the maximum of %s users. Please, use the hook "msls_reference_users" to filter the result before!',
+ 'multisite-language-switcher'
+ ),
self::MAX_REFERENCE_USERS
);
trigger_error( $message );
@@ -390,7 +412,7 @@ public function description() {
* for the output
*/
public function content_priority() {
- $temp = array_merge( range( 1, 10 ), [ 20, 50, 100 ] );
+ $temp = array_merge( range( 1, 10 ), array( 20, 50, 100 ) );
$arr = array_combine( $temp, $temp );
$selected = empty( $this->options->content_priority ) ? 10 : $this->options->content_priority;
@@ -429,7 +451,6 @@ public function validate( array $arr ) {
* @param array $arr
*
* @since 1.0
- *
*/
$arr = (array) apply_filters( 'msls_admin_validate', $arr );
@@ -457,5 +478,4 @@ public function set_blog_language( array $arr ) {
return $arr;
}
-
}
diff --git a/includes/MslsBlog.php b/includes/MslsBlog.php
index e2da1976..68867248 100644
--- a/includes/MslsBlog.php
+++ b/includes/MslsBlog.php
@@ -1,4 +1,4 @@
-set_language( $this->language )->set_icon_type( $icon_type );
- return sprintf( '%1$s %2$s',
+ return sprintf(
+ '%1$s %2$s',
$this->obj->blogname,
- '' . $icon->get_icon() . '' );
+ '' . $icon->get_icon() . ''
+ );
}
/**
@@ -128,8 +134,10 @@ protected function get_permalink( $options ) {
switch_to_blog( $this->obj->userblog_id );
- if ( is_object( $options ) && method_exists( $options,
- 'has_value' ) && ( $is_home || $options->has_value( $this->get_language() ) ) ) {
+ if ( is_object( $options ) && method_exists(
+ $options,
+ 'has_value'
+ ) && ( $is_home || $options->has_value( $this->get_language() ) ) ) {
$url = apply_filters( 'mlsl_blog_get_permalink', $options->get_permalink( $this->get_language() ), $this );
}
@@ -200,5 +208,4 @@ public function get_blavatar(): string {
return $blavatar_html;
}
-
}
diff --git a/includes/MslsBlogCollection.php b/includes/MslsBlogCollection.php
index bc30695a..22d02c71 100644
--- a/includes/MslsBlogCollection.php
+++ b/includes/MslsBlogCollection.php
@@ -1,9 +1,4 @@
-
- * @since 0.9.8
- */
+current_blog_id = get_current_blog_id();
@@ -72,7 +73,6 @@ public function __construct() {
* @param array $blogs_collection
*
* @since 0.9.8
- *
*/
$blogs_collection = (array) apply_filters(
'msls_blog_collection_construct',
@@ -97,14 +97,14 @@ public function __construct() {
$this->objects[ $blog->userblog_id ] = new MslsBlog( $blog, $description );
}
}
- uasort( $this->objects, [ MslsBlog::class, $this->objects_order ] );
+ uasort( $this->objects, array( MslsBlog::class, $this->objects_order ) );
}
}
/**
* Returns the description of a configured blog or false if it is not configured
*
- * @param int $blog_id
+ * @param int $blog_id
* @param string|bool $description
*
* @return string|bool
@@ -132,8 +132,12 @@ public static function get_configured_blog_description( $blog_id, $description =
* @return array
*/
public function get_blogs_of_reference_user( MslsOptions $options ) {
- $reference_user = $options->has_value( 'reference_user' ) ? $options->reference_user : current( $this->get_users( 'ID',
- 1 ) );
+ $reference_user = $options->has_value( 'reference_user' ) ? $options->reference_user : current(
+ $this->get_users(
+ 'ID',
+ 1
+ )
+ );
$blogs = get_blogs_of_user( $reference_user );
/**
@@ -184,6 +188,7 @@ public function get_blog_id( $language ) {
/**
* Get the id of the current blog
+ *
* @return int
*/
public function get_current_blog_id() {
@@ -212,6 +217,7 @@ public function has_current_blog() {
/**
* Gets current blog as object
+ *
* @return MslsBlog|null
*/
public function get_current_blog() {
@@ -220,6 +226,7 @@ public function get_current_blog() {
/**
* Gets an array with all blog-objects
+ *
* @return MslsBlog[]
*/
public function get_objects() {
@@ -235,7 +242,7 @@ public function get_objects() {
*/
public function is_plugin_active( $blog_id ) {
if ( ! is_array( $this->active_plugins ) ) {
- $this->active_plugins = get_site_option( 'active_sitewide_plugins', [] );
+ $this->active_plugins = get_site_option( 'active_sitewide_plugins', array() );
}
$path = MslsPlugin::path();
@@ -243,17 +250,18 @@ public function is_plugin_active( $blog_id ) {
return true;
}
- $plugins = get_blog_option( $blog_id, 'active_plugins', [] );
+ $plugins = get_blog_option( $blog_id, 'active_plugins', array() );
return in_array( $path, $plugins );
}
/**
* Gets only blogs where the plugin is active
+ *
* @return array
*/
public function get_plugin_active_blogs() {
- $arr = [];
+ $arr = array();
foreach ( $this->get_objects() as $blog ) {
if ( $this->is_plugin_active( $blog->userblog_id ) ) {
@@ -266,6 +274,7 @@ public function get_plugin_active_blogs() {
/**
* Gets an array of all - but not the current - blog-objects
+ *
* @return MslsBlog[]
*/
public function get() {
@@ -285,30 +294,26 @@ public function get() {
*
* @return MslsBlog[]
*/
- public function get_filtered( $filter = false ) {
- if ( ! $filter && $this->current_blog_output ) {
- return $this->get_objects();
- }
-
- return $this->get();
+ public function get_filtered( bool $filter = false ): array {
+ return ! $filter && $this->current_blog_output ? $this->get_objects() : $this->get();
}
/**
* Gets the registered users of the current blog
*
- * @param string $fields
+ * @param string $fields
* @param int|string $number
*
* @return array
*/
public function get_users( $fields = 'all', $number = '' ) {
- $args = [
+ $args = array(
'blog_id' => $this->current_blog_id,
'orderby' => 'registered',
'fields' => $fields,
'number' => $number,
'count_total' => false,
- ];
+ );
$args = (array) apply_filters( 'msls_get_users', $args );
@@ -318,7 +323,7 @@ public function get_users( $fields = 'all', $number = '' ) {
/**
* Returns a specific blog language.
*
- * @param int $blog_id
+ * @param int $blog_id
* @param string $default
*
* @return string
@@ -328,9 +333,8 @@ public static function get_blog_language( $blog_id = null, $default = 'en_US' )
$blog_id = get_current_blog_id();
}
- $language = ( string ) get_blog_option( $blog_id, 'WPLANG' );
+ $language = (string) get_blog_option( $blog_id, 'WPLANG' );
return '' !== $language ? $language : $default;
}
-
-}
\ No newline at end of file
+}
diff --git a/includes/MslsOptions.php b/includes/MslsOptions.php
index 53be6173..9a9c7cc7 100644
--- a/includes/MslsOptions.php
+++ b/includes/MslsOptions.php
@@ -1,6 +1,7 @@
* @since 0.9.8
*/
@@ -11,6 +12,7 @@
/**
* General options class
+ *
* @package Msls
* @property bool $activate_autocomplete
* @property bool output_current_blog
@@ -29,42 +31,49 @@ class MslsOptions extends MslsGetSet {
/**
* Args
+ *
* @var array
*/
protected $args;
/**
* Name
+ *
* @var string
*/
protected $name;
/**
* Exists
+ *
* @var bool
*/
protected $exists = false;
/**
* Separator
+ *
* @var string
*/
protected $sep = '';
/**
* Autoload
+ *
* @var string
*/
protected $autoload = 'yes';
/**
* Available languages
+ *
* @var array
*/
private $available_languages;
/**
* Rewrite with front
+ *
* @var bool
*/
public $with_front;
@@ -99,15 +108,15 @@ public static function create( $id = 0 ) {
$options = new MslsOptionsPost( get_queried_object_id() );
}
- add_filter( 'check_url', [ $options, 'check_for_blog_slug' ], 10, 2 );
+ add_filter( 'check_url', array( $options, 'check_for_blog_slug' ), 10, 2 );
return $options;
}
/**
* Determines if the current page is the main page (front page, search, 404).
- *
- * @return boolean
+ *
+ * @return boolean
*/
public static function is_main_page() {
return is_front_page() || is_search() || is_404();
@@ -115,7 +124,7 @@ public static function is_main_page() {
/**
* Determines if the current page is a category, tag or taxonomy page.
- *
+ *
* @return boolean
*/
public static function is_tax_page() {
@@ -124,7 +133,7 @@ public static function is_tax_page() {
/**
* Determines if the current page is an archive page for a date, author, or any other post type.
- *
+ *
* @return boolean
*/
public static function is_query_page() {
@@ -142,17 +151,18 @@ public function __construct() {
/**
* Gets an element of arg by index
- *
- * The returned value will either be cast to the type of `$retval` or, if nothing is set at this index, it will be the value of `$retval`.
*
- * @param int $idx
- * @param mixed $val
+ * The returned value will either be cast to the type of `$default` or, if nothing is set at this index, it will be the value of `$default`.
+ *
+ * @param int $index
+ * @param mixed $default
*
* @return mixed
*/
- public function get_arg( $idx, $val = null ) {
- $arg = isset( $this->args[ $idx ] ) ? $this->args[ $idx ] : $val;
- settype( $arg, gettype( $val ) );
+ public function get_arg( int $index, $default = null ) {
+ $arg = $this->args[ $index ] ?? $default;
+
+ settype( $arg, gettype( $default ) );
return $arg;
}
@@ -176,6 +186,7 @@ public function save( $arr ) {
/**
* Delete
+ *
* @codeCoverageIgnore
*/
public function delete() {
@@ -200,7 +211,10 @@ public function set( $arr ) {
/**
* Mapping for us language code
*/
- $map = [ 'us' => 'en_US', 'en' => 'en_US' ];
+ $map = array(
+ 'us' => 'en_US',
+ 'en' => 'en_US',
+ );
foreach ( $map as $old => $new ) {
if ( isset( $arr[ $old ] ) ) {
$arr[ $new ] = $arr[ $old ];
@@ -229,7 +243,6 @@ public function get_permalink( $language ) {
* @param string $language
*
* @since 0.9.8
- *
*/
$postlink = (string) apply_filters(
'msls_options_get_permalink',
@@ -253,6 +266,7 @@ public function get_postlink( $language ) {
/**
* Get the queried taxonomy
+ *
* @return string
*/
public function get_tax_query() {
@@ -261,6 +275,7 @@ public function get_tax_query() {
/**
* Get current link
+ *
* @return string
*/
public function get_current_link() {
@@ -269,6 +284,7 @@ public function get_current_link() {
/**
* Is excluded
+ *
* @return bool
*/
public function is_excluded() {
@@ -277,6 +293,7 @@ public function is_excluded() {
/**
* Is content
+ *
* @return bool
*/
public function is_content_filter() {
@@ -285,6 +302,7 @@ public function is_content_filter() {
/**
* Get order
+ *
* @return string
*/
public function get_order() {
@@ -346,7 +364,6 @@ public function get_flag_url( $language ) {
* @param string $url
*
* @since 0.9.9
- *
*/
$url = (string) apply_filters( 'msls_options_get_flag_url', $url );
@@ -359,7 +376,6 @@ public function get_flag_url( $language ) {
* @param string $language
*
* @since 1.0.3
- *
*/
$icon = (string) apply_filters( 'msls_options_get_flag_icon', $icon, $language );
@@ -375,9 +391,9 @@ public function get_flag_url( $language ) {
*/
public function get_available_languages() {
if ( empty( $this->available_languages ) ) {
- $this->available_languages = [
+ $this->available_languages = array(
'en_US' => __( 'American English', 'multisite-language-switcher' ),
- ];
+ );
foreach ( get_available_languages() as $code ) {
$this->available_languages[ esc_attr( $code ) ] = format_code_lang( $code );
@@ -389,7 +405,6 @@ public function get_available_languages() {
* @param array $available_languages
*
* @since 1.0
- *
*/
$this->available_languages = (array) apply_filters(
'msls_options_get_available_languages',
@@ -403,7 +418,7 @@ public function get_available_languages() {
/**
* The 'blog'-slug-problem :/
*
- * @param string $url
+ * @param string $url
* @param MslsOptions $options
*
* @return string
@@ -443,5 +458,4 @@ public static function check_for_blog_slug( $url, $options ) {
public function get_icon_type(): string {
return MslsAdminIcon::TYPE_LABEL === $this->admin_display ? MslsAdminIcon::TYPE_LABEL : MslsAdminIcon::TYPE_FLAG;
}
-
}
diff --git a/includes/MslsOptionsPost.php b/includes/MslsOptionsPost.php
index 08aab29f..c60093c9 100644
--- a/includes/MslsOptionsPost.php
+++ b/includes/MslsOptionsPost.php
@@ -1,26 +1,24 @@
-
- * @since 0.9.8
- */
+with_front = ! empty( $post_object->rewrite['with_front'] );
}
- global $current_site;
- $blog_id = msls_blog_collection()->get_blog_id( $language );
- if ( $current_site->blog_id != $blog_id ) {
- $option = get_blog_option( $blog_id, 'msls' );
- //error_log( print_r( $option, true ) );
- }
-
return apply_filters( 'check_url', get_permalink( $post ), $this );
}
@@ -65,5 +56,4 @@ public function get_postlink( $language ) {
public function get_current_link(): string {
return (string) get_permalink( $this->get_arg( 0, 0 ) );
}
-
}
diff --git a/includes/MslsPostTag.php b/includes/MslsPostTag.php
index aad81a5d..9747d728 100644
--- a/includes/MslsPostTag.php
+++ b/includes/MslsPostTag.php
@@ -1,9 +1,9 @@
-
- * @since 0.9.8
*/
namespace lloc\Msls;
@@ -29,12 +29,12 @@ public static function suggest() {
filter_input( INPUT_POST, 'blog_id', FILTER_SANITIZE_NUMBER_INT )
);
- $args = [
+ $args = array(
'orderby' => 'name',
'order' => 'ASC',
'number' => 10,
'hide_empty' => 0,
- ];
+ );
if ( filter_has_var( INPUT_POST, 's' ) ) {
$args['search'] = sanitize_text_field(
@@ -81,15 +81,15 @@ public static function suggest() {
public static function init() {
$options = msls_options();
$collection = msls_blog_collection();
- $class = $options->activate_autocomplete ? MslsPostTag::class : MslsPostTagClassic::class;
+ $class = $options->activate_autocomplete ? self::class : MslsPostTagClassic::class;
$obj = new $class( $options, $collection );
$taxonomy = MslsContentTypes::create()->acl_request();
if ( '' != $taxonomy ) {
- add_action( "{$taxonomy}_add_form_fields", [ $obj, 'add_input' ] );
- add_action( "{$taxonomy}_edit_form_fields", [ $obj, 'edit_input' ], 10, 2 );
- add_action( "edited_{$taxonomy}", [ $obj, 'set' ] );
- add_action( "create_{$taxonomy}", [ $obj, 'set' ] );
+ add_action( "{$taxonomy}_add_form_fields", array( $obj, 'add_input' ) );
+ add_action( "{$taxonomy}_edit_form_fields", array( $obj, 'edit_input' ), 10, 2 );
+ add_action( "edited_{$taxonomy}", array( $obj, 'set' ) );
+ add_action( "create_{$taxonomy}", array( $obj, 'set' ) );
}
return $obj;
@@ -118,7 +118,7 @@ public function add_input( string $taxonomy ): void {
* Add the input fields to the edit-screen of the taxonomies
*
* @param \WP_Term $tag
- * @param string $taxonomy
+ * @param string $taxonomy
*/
public function edit_input( \WP_Term $tag, string $taxonomy ): void {
$title_format = '
@@ -148,8 +148,8 @@ public function edit_input( \WP_Term $tag, string $taxonomy ): void {
* Returns true if the blogcollection is not empty
*
* @param ?\WP_Term $tag
- * @param string $title_format
- * @param string $item_format
+ * @param string $title_format
+ * @param string $item_format
*
* @return boolean
*/
@@ -160,7 +160,7 @@ public function the_input( ?\WP_Term $tag, string $title_format, string $item_fo
return false;
}
- $count ++;
+ ++$count;
$blogs = $this->collection->get();
if ( $blogs ) {
@@ -258,8 +258,9 @@ public function maybe_set_linked_term( MslsOptionsTax $mydata ) {
* @return string
*/
protected function get_select_title(): string {
- return apply_filters( 'msls_term_select_title',
- __( 'Multisite Language Switcher', 'multisite-language-switcher' ) );
+ return apply_filters(
+ 'msls_term_select_title',
+ __( 'Multisite Language Switcher', 'multisite-language-switcher' )
+ );
}
-
}
diff --git a/tests/TestMslsOptionsPost.php b/tests/TestMslsOptionsPost.php
index 26b8555e..d72bbe9b 100644
--- a/tests/TestMslsOptionsPost.php
+++ b/tests/TestMslsOptionsPost.php
@@ -3,6 +3,7 @@
namespace lloc\MslsTests;
use Brain\Monkey\Functions;
+use Brain\Monkey\Filters;
use lloc\Msls\MslsOptionsPost;
@@ -11,7 +12,7 @@ class TestMslsOptionsPost extends MslsUnitTestCase {
protected function setUp(): void {
parent::setUp();
- Functions\expect( 'get_option' )->once()->andReturn( [ 'de_DE' => 42 ] );
+ Functions\expect( 'get_option' )->once()->andReturn( array( 'de_DE' => 42 ) );
$this->test = new MslsOptionsPost();
}
@@ -26,10 +27,32 @@ public function test_get_postlink_post_is_null(): void {
$this->assertEquals( '', $this->test->get_postlink( 'de_DE' ) );
}
+ public function test_get_postlink_post_is_draft(): void {
+ $post = \Mockery::mock( '\WP_Post' );
+ $post->post_status = 'draft';
+
+ Functions\expect( 'get_post' )->once()->andReturn( $post );
+
+ $this->assertEquals( '', $this->test->get_postlink( 'de_DE' ) );
+ }
+
+ public function test_get_postlink_post_is_published(): void {
+ $post = \Mockery::mock( '\WP_Post' );
+ $post->post_status = 'publish';
+ $post->post_type = 'post';
+
+ Functions\expect( 'get_post' )->once()->andReturn( $post );
+ Functions\expect( 'get_post_type_object' )->once()->andReturn( (object) array( 'rewrite' => array( 'with_front' => true ) ) );
+ Functions\expect( 'get_permalink' )->once()->andReturn( 'https://example.de/a-post' );
+
+ Filters\expectApplied( 'check_url' )->once()->with( 'https://example.de/a-post', $this->test );
+
+ $this->assertEquals( 'https://example.de/a-post', $this->test->get_postlink( 'de_DE' ) );
+ }
+
public function test_get_current_link(): void {
Functions\expect( 'get_permalink' )->once()->andReturn( 'https://example.org/a-post' );
$this->assertEquals( 'https://example.org/a-post', $this->test->get_current_link() );
}
-
}
diff --git a/tests/TestMslsPostTag.php b/tests/TestMslsPostTag.php
index 0e87311f..d8749f18 100644
--- a/tests/TestMslsPostTag.php
+++ b/tests/TestMslsPostTag.php
@@ -16,15 +16,13 @@ class TestMslsPostTag extends MslsUnitTestCase {
protected function setUp(): void {
parent::setUp();
- Functions\when( 'get_option' )->justReturn( [] );
+ Functions\when( 'get_option' )->justReturn( array() );
Functions\expect( 'is_admin' )->andReturn( true );
- Functions\expect( 'get_post_types' )->andReturn( [ 'post', 'page' ] );
+ Functions\expect( 'get_post_types' )->andReturn( array( 'post', 'page' ) );
- foreach ( [ 'de_DE', 'en_US' ] as $locale ) {
+ foreach ( array( 'de_DE', 'en_US' ) as $locale ) {
$blog = \Mockery::mock( MslsBlog::class );
- $blog->shouldReceive( [
- 'get_language' => $locale,
- ] );
+ $blog->shouldReceive( 'get_language' )->andReturn( $locale );
$blogs[] = $blog;
}
@@ -56,7 +54,7 @@ public function test_edit_input(): void {
Functions\expect( 'get_admin_url' )->andReturn( '/wp-admin/edit-tags.php' );
Functions\expect( 'switch_to_blog' )->atLeast();
Functions\expect( 'restore_current_blog' )->atLeast();
- Functions\expect( 'get_terms' )->andReturn( [] );
+ Functions\expect( 'get_terms' )->andReturn( array() );
Functions\expect( 'plugin_dir_path' )->atLeast( 1 )->andReturn( dirname( __DIR__, 1 ) . '/' );
$output = '
@@ -92,5 +90,4 @@ public function test_edit_input(): void {
// second call should not output anything
$this->test->edit_input( $tag, 'test' );
}
-
}