Skip to content
Open
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
1 change: 1 addition & 0 deletions .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
/src
/tests
AGENTS.md
CLAUDE.md
Changelog.md
Diagrams.md
README.md
Expand Down
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
.phpunit.cache
.phpunit.result.cache
.vscode/
composer.lock
composer.phar
CLAUDE.md
assets/js/msls-widget-block/
assets/js/msls.js
composer.lock
composer.phar
multisite-language-switcher.zip
multisite-language-switcher/
node_modules/
out/
phpunit.xml.bak
tests/coverage/
tests/coverage.xml
tests/coverage/
tests/playwright-report/
tests/playwright-results/
tests/playwright/.env.local
Expand Down
4 changes: 1 addition & 3 deletions .phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
parameters:
level: 6
level: 8
paths:
- MultisiteLanguageSwitcher.php
- includes
bootstrapFiles:
- tests/phpstan/bootstrap.php
ignoreErrors:
- '/^Class lloc\\Msls\\MslsWidget extends generic class WP_Widget but does not specify its types: T$/'
12 changes: 6 additions & 6 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{
"phpVersion": "8.3",
"multisite": true,
"plugins": [
"."
],
"env": {
"tests": {
"config": {
Expand All @@ -19,5 +14,10 @@
},
"mappings": {
"wp-content/plugins/multisite-language-switcher": "."
}
},
"multisite": true,
"phpVersion": "8.3",
"plugins": [
"."
]
}
194 changes: 1 addition & 193 deletions MultisiteLanguageSwitcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,201 +49,9 @@
define( 'MSLS_PLUGIN_PATH', plugin_basename( __FILE__ ) );
define( 'MSLS_PLUGIN__FILE__', __FILE__ );

require_once __DIR__ . '/includes/functions.php';
require_once __DIR__ . '/includes/deprectated.php';

/**
* Get the output for using the links to the translations in your code
*
* @package Msls
* @param mixed $attr
* @return string
*/
function msls_get_switcher( $attr ): string {
$arr = is_array( $attr ) ? $attr : array();
$obj = apply_filters( 'msls_get_output', null );

return ! is_null( $obj ) ? strval( $obj->set_tags( $arr ) ) : '';
}

/**
* Output the links to the translations in your template
*
* You can call this function directly like that
*
* if ( function_exists ( 'the_msls' ) )
* the_msls();
*
* or just use it as shortcode [sc_msls]
*
* @package Msls
* @uses get_the_msls
*
* @param string[] $arr
*/
function msls_the_switcher( array $arr = array() ): void {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo msls_get_switcher( $arr );
}

/**
* Gets the URL of the country flag-icon for a specific locale
*
* @param string $locale
*
* @return string
*/
function msls_get_flag_url( string $locale ): string {
return ( new \lloc\Msls\MslsOptions() )->get_flag_url( $locale );
}

/**
* Gets the description for a blog for a specific locale
*
* @param string $locale
* @param string $preset
*
* @return string
*/
function msls_get_blog_description( string $locale, string $preset = '' ): string {
$blog = msls_blog( $locale );

return $blog ? $blog->get_description() : $preset;
}

/**
* Gets the permalink for a translation of the current post in a given language
*
* @param string $locale
* @param string $preset
*
* @return string
*/
function msls_get_permalink( string $locale, string $preset = '' ): string {
$url = null;
$blog = msls_blog( $locale );

if ( $blog ) {
$options = \lloc\Msls\MslsOptions::create();
$url = $blog->get_url( $options );
}

return $url ?? $preset;
}

/**
* Looks for the MslsBlog instance for a specific locale
*
* @param string $locale
*
* @return \lloc\Msls\MslsBlog|null
*/
function msls_blog( string $locale ): ?\lloc\Msls\MslsBlog {
return msls_blog_collection()->get_blog( $locale );
}

/**
* Gets the MslsBlogCollection instance
*
* @return \lloc\Msls\MslsBlogCollection
*/
function msls_blog_collection(): \lloc\Msls\MslsBlogCollection {
return \lloc\Msls\MslsBlogCollection::instance();
}

/**
* Gets the MslsOptions instance
*
* @return \lloc\Msls\MslsOptions
*/
function msls_options(): \lloc\Msls\MslsOptions {
return \lloc\Msls\MslsOptions::instance();
}

/**
* Gets the MslsContentTypes instance
*
* @return \lloc\Msls\MslsContentTypes
*/
function msls_content_types(): \lloc\Msls\MslsContentTypes {
return \lloc\Msls\MslsContentTypes::create();
}

/**
* Gets the MslsPostType instance
*
* @return \lloc\Msls\MslsPostType
*/
function msls_post_type(): \lloc\Msls\MslsPostType {
return \lloc\Msls\MslsPostType::instance();
}

/**
* Gets the MslsTaxonomy instance
*
* @return \lloc\Msls\MslsTaxonomy
*/
function msls_taxonomy(): \lloc\Msls\MslsTaxonomy {
return \lloc\Msls\MslsTaxonomy::instance();
}

/**
* Gets the MslsOutput instance
*
* @return \lloc\Msls\MslsOutput
*/
function msls_output(): \lloc\Msls\MslsOutput {
return \lloc\Msls\MslsOutput::create();
}

/**
* Retrieves the MslsOptionsPost instance.
*
* @param int $id
* @return \lloc\Msls\MslsOptionsPost
*/
function msls_get_post( int $id ): \lloc\Msls\MslsOptionsPost {
return new \lloc\Msls\MslsOptionsPost( $id );
}

/**
* Retrieves the MslsOptionsTax instance.
*
* Determines the current query based on conditional tags:
* - is_category
* - is_tag
* - is_tax
*
* @param int $id
* @return \lloc\Msls\OptionsTaxInterface
*/
function msls_get_tax( int $id ): \lloc\Msls\OptionsTaxInterface {
return \lloc\Msls\MslsOptionsTax::create( $id );
}

/**
* Retrieves the MslsOptionsQuery instance.
*
* Determines the current query based on conditional tags:
* - is_day
* - is_month
* - is_year
* - is_author
* - is_post_type_archive
*
* @return ?\lloc\Msls\MslsOptionsQuery
*/
function msls_get_query(): ?\lloc\Msls\MslsOptionsQuery {
return \lloc\Msls\MslsOptionsQuery::create();
}

/**
* Trivial void function for actions that do not return anything.
*
* @return void
*/
function msls_return_void(): void {
}

lloc\Msls\MslsPlugin::init();
lloc\Msls\MslsCli::init();
}
4 changes: 2 additions & 2 deletions includes/Component/Input/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class Text extends Component {
protected $key;

/**
* @var string
* @var ?string
*/
protected $value;

Expand Down Expand Up @@ -48,7 +48,7 @@ public function render(): string {
return sprintf(
'<input type="text" class="regular-text" id="%1$s" name="msls[%1$s]" value="%2$s" size="%3$d"%4$s/>',
esc_attr( $this->key ),
esc_attr( $this->value ),
esc_attr( (string) $this->value ),
$this->size,
$this->readonly // phpcs:ignore WordPress.Security.EscapeOutput
);
Expand Down
28 changes: 14 additions & 14 deletions includes/ContentImport/ContentImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
* @param ?MslsMain $main
*/
public function __construct( ?MslsMain $main = null ) {
$this->main = ! is_null( $main ) ? $main : MslsMain::create();
$this->main = $main ?? MslsMain::create();
}

/**
Expand Down Expand Up @@ -175,7 +175,7 @@
/**
* Parses the source blog and post IDs from the $_POST array validating them.
*
* @return int[]|bool
* @return array{int, int}|false
*/
public function parse_sources() {
if ( ! MslsRequest::has_var( 'msls_import' ) ) {
Expand All @@ -202,7 +202,7 @@

$id = get_the_ID();

if ( ! empty( $id ) ) {
if ( false !== $id && $id > 0 ) {
restore_current_blog();

return $id;
Expand All @@ -225,11 +225,11 @@
* @param int $blog_id
* @param array<string, mixed> $data
*
* @return bool|int
* @return int
*/
protected function insert_blog_post( $blog_id, array $data = array() ) {
if ( empty( $data ) ) {
return false;
return 0;
}

switch_to_blog( $blog_id );
Expand All @@ -242,7 +242,7 @@
}
$this->handle( true );

$this->has_created_post = $post_id > 0 ? $post_id : false;
$this->has_created_post = $post_id > 0 ? $post_id : 0;

restore_current_blog();

Expand Down Expand Up @@ -285,7 +285,7 @@
*
* @param ImportCoordinates $import_coordinates
*/
do_action( self::MSLS_BEFORE_IMPORT_ACTION, $import_coordinates );

Check warning on line 288 in includes/ContentImport/ContentImporter.php

View workflow job for this annotation

GitHub Actions / test

WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound

Hook names invoked by a theme/plugin should start with the theme/plugin prefix. Found: "self::MSLS_BEFORE_IMPORT_ACTION".

/**
* Filters the data before the import runs.
Expand All @@ -312,12 +312,12 @@
$importers = Map::instance()->make( $import_coordinates );
}

if ( is_null( $this->get_logger() ) ) {
$this->set_logger( new ImportLogger( $import_coordinates ) );
if ( is_null( $this->logger ) ) {
$this->logger = new ImportLogger( $import_coordinates );
}

if ( is_null( $this->get_relations() ) ) {
$this->set_relations( new Relations( $import_coordinates ) );
if ( is_null( $this->relations ) ) {
$this->relations = new Relations( $import_coordinates );
}

if ( ! empty( $importers ) ) {
Expand All @@ -341,20 +341,20 @@
* Fires after the import ran.
*
* @param ImportCoordinates $import_coordinates
* @param ImportLogger $logger
* @param Relations $relations
* @param ?ImportLogger $logger
* @param ?Relations $relations
*
* @since TBD
*/
do_action( self::MSLS_AFTER_IMPORT_ACTION, $import_coordinates, $this->logger, $this->relations );

Check warning on line 349 in includes/ContentImport/ContentImporter.php

View workflow job for this annotation

GitHub Actions / test

WordPress.NamingConventions.PrefixAllGlobals.DynamicHooknameFound

Hook names invoked by a theme/plugin should start with the theme/plugin prefix. Found: "self::MSLS_AFTER_IMPORT_ACTION".

/**
* Filters the data after the import ran.
*
* @param array $post_fields
* @param ImportCoordinates $import_coordinates
* @param ImportLogger $logger
* @param Relations $relations
* @param ?ImportLogger $logger
* @param ?Relations $relations
*/
return apply_filters(
'msls_content_import_data_after_import',
Expand Down
6 changes: 2 additions & 4 deletions includes/ContentImport/ImportLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected function build_nested_array( $path, $what = '' ): array {
);
$data = json_decode( $json, true );

return $data;
return is_array( $data ) ? $data : array();
}

/**
Expand All @@ -137,9 +137,7 @@ protected function build_nested_array( $path, $what = '' ): array {
* @return string[]
*/
protected function build_path( string $where ): array {
$where_path = explode( $this->levels_delimiter, $where );

return $where_path;
return explode( $this->levels_delimiter, $where );
}

/**
Expand Down
Loading
Loading