Skip to content

Commit f178936

Browse files
committed
Version 3.0.0 prep
1 parent 583eb0b commit f178936

47 files changed

Lines changed: 584 additions & 582 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

MultisiteLanguageSwitcher.php

Lines changed: 4 additions & 197 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Multisite Language Switcher Plugin
44
*
55
* Plugin Name: Multisite Language Switcher
6-
* Version: 2.10.1
6+
* Version: 3.0.0
77
* Plugin URI: http://msls.co/
88
* Description: A simple but powerful plugin that will help you to manage the relations of your contents in a multilingual multisite-installation.
99
* Author: Dennis Ploetner
@@ -45,207 +45,14 @@
4545
* @author Dennis Ploetner <re@lloc.de>
4646
*/
4747
if ( ! defined( 'MSLS_PLUGIN_VERSION' ) ) {
48-
define( 'MSLS_PLUGIN_VERSION', '2.10.1' );
48+
define( 'MSLS_PLUGIN_VERSION', '3.0.0' );
4949
define( 'MSLS_PLUGIN_PATH', plugin_basename( __FILE__ ) );
5050
define( 'MSLS_PLUGIN__FILE__', __FILE__ );
5151

5252
require_once __DIR__ . '/includes/aliases.php';
5353
require_once __DIR__ . '/includes/deprectated.php';
54+
require_once __DIR__ . '/includes/api.php';
5455

55-
/**
56-
* Get the output for using the links to the translations in your code
57-
*
58-
* @package Msls
59-
* @param mixed $attr
60-
* @return string
61-
*/
62-
function msls_get_switcher( $attr ): string {
63-
$arr = is_array( $attr ) ? $attr : array();
64-
$obj = apply_filters( 'msls_get_output', null );
65-
66-
return ! is_null( $obj ) ? strval( $obj->set_tags( $arr ) ) : '';
67-
}
68-
69-
/**
70-
* Output the links to the translations in your template
71-
*
72-
* You can call this function directly like that
73-
*
74-
* if ( function_exists ( 'the_msls' ) )
75-
* the_msls();
76-
*
77-
* or just use it as shortcode [sc_msls]
78-
*
79-
* @package Msls
80-
* @uses get_the_msls
81-
*
82-
* @param string[] $arr
83-
*/
84-
function msls_the_switcher( array $arr = array() ): void {
85-
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
86-
echo msls_get_switcher( $arr );
87-
}
88-
89-
/**
90-
* Gets the URL of the country flag-icon for a specific locale
91-
*
92-
* @param string $locale
93-
*
94-
* @return string
95-
*/
96-
function msls_get_flag_url( string $locale ): string {
97-
return ( new \lloc\Msls\Options\Options() )->get_flag_url( $locale );
98-
}
99-
100-
/**
101-
* Gets the description for a blog for a specific locale
102-
*
103-
* @param string $locale
104-
* @param string $preset
105-
*
106-
* @return string
107-
*/
108-
function msls_get_blog_description( string $locale, string $preset = '' ): string {
109-
$blog = msls_blog( $locale );
110-
111-
return $blog ? $blog->get_description() : $preset;
112-
}
113-
114-
/**
115-
* Gets the permalink for a translation of the current post in a given language
116-
*
117-
* @param string $locale
118-
* @param string $preset
119-
*
120-
* @return string
121-
*/
122-
function msls_get_permalink( string $locale, string $preset = '' ): string {
123-
$url = null;
124-
$blog = msls_blog( $locale );
125-
126-
if ( $blog ) {
127-
$options = \lloc\Msls\Options\Options::create();
128-
$url = $blog->get_url( $options );
129-
}
130-
131-
return $url ?? $preset;
132-
}
133-
134-
/**
135-
* Looks for the Blog instance for a specific locale
136-
*
137-
* @param string $locale
138-
*
139-
* @return \lloc\Msls\Blog\Blog|null
140-
*/
141-
function msls_blog( string $locale ): ?\lloc\Msls\Blog\Blog {
142-
return msls_blog_collection()->get_blog( $locale );
143-
}
144-
145-
/**
146-
* Gets the Blog Collection instance
147-
*
148-
* @return \lloc\Msls\Blog\Collection
149-
*/
150-
function msls_blog_collection(): \lloc\Msls\Blog\Collection {
151-
return \lloc\Msls\Blog\Collection::instance();
152-
}
153-
154-
/**
155-
* Gets the Options instance
156-
*
157-
* @return \lloc\Msls\Options\Options
158-
*/
159-
function msls_options(): \lloc\Msls\Options\Options {
160-
return \lloc\Msls\Options\Options::instance();
161-
}
162-
163-
/**
164-
* Gets the MslsContentTypes instance
165-
*
166-
* @return \lloc\Msls\ContentTypes\ContentTypes
167-
*/
168-
function msls_content_types(): \lloc\Msls\ContentTypes\ContentTypes {
169-
return \lloc\Msls\ContentTypes\ContentTypes::create();
170-
}
171-
172-
/**
173-
* Gets the MslsPostType instance
174-
*
175-
* @return \lloc\Msls\ContentTypes\PostType
176-
*/
177-
function msls_post_type(): \lloc\Msls\ContentTypes\PostType {
178-
return \lloc\Msls\ContentTypes\PostType::instance();
179-
}
180-
181-
/**
182-
* Gets the MslsTaxonomy instance
183-
*
184-
* @return \lloc\Msls\ContentTypes\Taxonomy
185-
*/
186-
function msls_taxonomy(): \lloc\Msls\ContentTypes\Taxonomy {
187-
return \lloc\Msls\ContentTypes\Taxonomy::instance();
188-
}
189-
190-
/**
191-
* Gets the Output instance
192-
*
193-
* @return \lloc\Msls\Frontend\Output
194-
*/
195-
function msls_output(): \lloc\Msls\Frontend\Output {
196-
return \lloc\Msls\Frontend\Output::create();
197-
}
198-
199-
/**
200-
* Retrieves the OptionsPost instance.
201-
*
202-
* @param int $id
203-
*
204-
* @return \lloc\Msls\Options\Post\Post
205-
*/
206-
function msls_get_post( int $id ): \lloc\Msls\Options\Post\Post {
207-
return new \lloc\Msls\Options\Post\Post( $id );
208-
}
209-
210-
/**
211-
* Retrieves the OptionsTax instance.
212-
*
213-
* Determines the current query based on conditional tags:
214-
* - is_category
215-
* - is_tag
216-
* - is_tax
217-
*
218-
* @param int $id
219-
* @return \lloc\Msls\Options\Tax\OptionsTaxInterface
220-
*/
221-
function msls_get_tax( int $id ): \lloc\Msls\Options\Tax\OptionsTaxInterface {
222-
return \lloc\Msls\Options\Tax\Tax::create( $id );
223-
}
224-
225-
/**
226-
* Retrieves the OptionsQuery instance.
227-
*
228-
* Determines the current query based on conditional tags:
229-
* - is_day
230-
* - is_month
231-
* - is_year
232-
* - is_author
233-
* - is_post_type_archive
234-
*
235-
* @return ?\lloc\Msls\Options\Query\Query
236-
*/
237-
function msls_get_query(): ?\lloc\Msls\Options\Query\Query {
238-
return \lloc\Msls\Options\Query\Query::create();
239-
}
240-
241-
/**
242-
* Trivial void function for actions that do not return anything.
243-
*
244-
* @return void
245-
*/
246-
function msls_return_void(): void {
247-
}
248-
249-
lloc\Msls\MslsPlugin::init();
56+
lloc\Msls\Plugin::init();
25057
lloc\Msls\Cli\Cli::init();
25158
}

includes/Admin/Admin.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
use lloc\Msls\Component\Input\Select;
1313
use lloc\Msls\Component\Input\Text;
1414
use lloc\Msls\Link\Link;
15-
use lloc\Msls\MslsMain;
16-
use lloc\Msls\MslsPlugin;
15+
use lloc\Msls\Plugin;
1716
use lloc\Msls\Registry\Registry;
1817
use WP_Post_Type;
1918

@@ -34,7 +33,7 @@
3433
*
3534
* @package Msls
3635
*/
37-
final class Admin extends MslsMain {
36+
final class Admin extends Main {
3837

3938
const MSLS_REGISTER_ACTION = 'msls_admin_register';
4039

@@ -175,7 +174,7 @@ public function has_problems(): void {
175174
);
176175
}
177176

178-
MslsPlugin::message_handler( $message, 'updated fade' );
177+
Plugin::message_handler( $message, 'updated fade' );
179178
}
180179

181180
/**

includes/Admin/CustomColumn.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
use lloc\Msls\Blog\Collection;
1010
use lloc\Msls\Component\Component;
11-
use lloc\Msls\MslsMain;
1211
use lloc\Msls\Options\Options;
1312

1413
/**
@@ -17,7 +16,7 @@
1716
*
1817
* @package Msls
1918
*/
20-
class CustomColumn extends MslsMain {
19+
class CustomColumn extends Main {
2120

2221
public static function init(): void {
2322
$options = msls_options();

includes/Admin/CustomFilter.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@
77
}
88

99
use lloc\Msls\Component\Input\Select;
10-
use lloc\Msls\MslsFields;
11-
use lloc\Msls\MslsMain;
12-
use lloc\Msls\MslsRequest;
13-
use lloc\Msls\Db\SqlCacher;
1410
use lloc\Msls\Db\Query\TranslatedPostIdQuery;
11+
use lloc\Msls\Db\SqlCacher;
12+
use lloc\Msls\Request\Fields;
13+
use lloc\Msls\RestApi\Request;
1514

1615
/**
1716
* Adding custom filter to posts/pages table.
1817
*
1918
* @package Msls
2019
*/
21-
final class CustomFilter extends MslsMain {
20+
final class CustomFilter extends Main {
2221

2322
/**
2423
* @codeCoverageIgnore
@@ -36,7 +35,7 @@ public static function init(): void {
3635
add_filter(
3736
Select::RENDER_FILTER,
3837
function () {
39-
return MslsFields::FIELD_MSLS_FILTER;
38+
return Fields::FIELD_MSLS_FILTER;
4039
}
4140
);
4241
}
@@ -59,10 +58,10 @@ public function add_filter(): void {
5958
$options[ strval( $blog->userblog_id ) ] = sprintf( $format, $blog->get_description() );
6059
}
6160

62-
$id = MslsRequest::get( MslsFields::FIELD_MSLS_FILTER, 0 );
61+
$id = Request::get( Fields::FIELD_MSLS_FILTER, 0 );
6362

6463
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
65-
echo ( new Select( MslsFields::FIELD_MSLS_FILTER, $options, strval( $id ) ) )->render();
64+
echo ( new Select( Fields::FIELD_MSLS_FILTER, $options, strval( $id ) ) )->render();
6665
}
6766
}
6867

@@ -74,11 +73,11 @@ public function add_filter(): void {
7473
* @return bool|\WP_Query
7574
*/
7675
public function execute_filter( \WP_Query $query ) {
77-
if ( ! MslsRequest::has_var( MslsFields::FIELD_MSLS_FILTER ) ) {
76+
if ( ! Request::has_var( Fields::FIELD_MSLS_FILTER ) ) {
7877
return false;
7978
}
8079

81-
$id = MslsRequest::get_var( MslsFields::FIELD_MSLS_FILTER );
80+
$id = Request::get_var( Fields::FIELD_MSLS_FILTER );
8281
$blog = $this->collection->get_object( intval( $id ) );
8382
if ( ! $blog ) {
8483
return false;
Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
<?php declare( strict_types=1 );
22

3-
namespace lloc\Msls;
3+
namespace lloc\Msls\Admin;
44

5+
use lloc\Msls\Plugin;
56
use lloc\Msls\Blog\Blog;
67
use lloc\Msls\Blog\Collection;
78
use lloc\Msls\Component\Component;
9+
use lloc\Msls\Data\LanguageArray;
810
use lloc\Msls\Options\Options;
911
use lloc\Msls\Options\Post\Post;
12+
use lloc\Msls\Request\Fields;
13+
use lloc\Msls\RestApi\Request;
1014

1115
/**
1216
* Abstraction for the hook classes
1317
*
1418
* @package Msls
1519
*/
16-
class MslsMain {
20+
class Main {
1721

1822
const MSLS_SAVE_ACTION = 'msls_main_save';
1923

@@ -42,7 +46,7 @@ final public function __construct( Options $options, Collection $collection ) {
4246
$this->collection = $collection;
4347
}
4448

45-
public static function create(): MslsMain {
49+
public static function create(): Main {
4650
return new static( msls_options(), msls_blog_collection() );
4751
}
4852

@@ -112,7 +116,7 @@ public function is_autosave( $post_id ): bool {
112116
* @return boolean
113117
*/
114118
public function verify_nonce(): bool {
115-
return MslsRequest::has_var( MslsFields::FIELD_MSLS_NONCENAME ) && wp_verify_nonce( MslsRequest::get_var( MslsFields::FIELD_MSLS_NONCENAME ), MslsPlugin::path() );
119+
return Request::has_var( Fields::FIELD_MSLS_NONCENAME ) && wp_verify_nonce( Request::get_var( Fields::FIELD_MSLS_NONCENAME ), Plugin::path() );
116120
}
117121

118122
/**
@@ -157,7 +161,7 @@ protected function save( $object_id, $class_name ): void {
157161
}
158162

159163
$language = $current_blog->get_language();
160-
$msla = new MslsLanguageArray( $this->get_input_array( $object_id ) );
164+
$msla = new LanguageArray( $this->get_input_array( $object_id ) );
161165
$options = new $class_name( $object_id );
162166
$temp = $options->get_arr();
163167

0 commit comments

Comments
 (0)