Skip to content

Commit 56d7926

Browse files
committed
Issues addressed
1 parent 213c875 commit 56d7926

60 files changed

Lines changed: 370 additions & 163 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: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
/**
33
* Multisite Language Switcher Plugin
44
*
5-
* @copyright Copyright (C) 2011-2022, Dennis Ploetner, re@lloc.de
6-
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 or later
7-
* @wordpress-plugin
8-
*
95
* Plugin Name: Multisite Language Switcher
106
* Version: 2.9.6
117
* Plugin URI: http://msls.co/
@@ -28,6 +24,11 @@
2824
* You should have received a copy of the GNU General Public License
2925
* along with this program; if not, write to the Free Software
3026
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27+
*
28+
* @copyright Copyright (C) 2011-2022, Dennis Ploetner, re@lloc.de
29+
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 or later
30+
* @wordpress-plugin
31+
* @package msls
3132
*/
3233

3334
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
@@ -95,24 +96,25 @@ function get_msls_flag_url( string $locale ): string {
9596
* Gets the description for a blog for a specific locale
9697
*
9798
* @param string $locale
99+
* @param string $preset
98100
*
99101
* @return string
100102
*/
101-
function get_msls_blog_description( string $locale, string $default = '' ): string {
103+
function get_msls_blog_description( string $locale, string $preset = '' ): string {
102104
$blog = msls_blog( $locale );
103105

104-
return $blog ? $blog->get_description() : $default;
106+
return $blog ? $blog->get_description() : $preset;
105107
}
106108

107109
/**
108110
* Gets the permalink for a translation of the current post in a given language
109111
*
110112
* @param string $locale
111-
* @param string $default
113+
* @param string $preset
112114
*
113115
* @return string
114116
*/
115-
function get_msls_permalink( string $locale, string $default = '' ): string {
117+
function get_msls_permalink( string $locale, string $preset = '' ): string {
116118
$url = null;
117119
$blog = msls_blog( $locale );
118120

@@ -121,7 +123,7 @@ function get_msls_permalink( string $locale, string $default = '' ): string {
121123
$url = $blog->get_url( $options );
122124
}
123125

124-
return $url ?? $default;
126+
return $url ?? $preset;
125127
}
126128

127129
/**

includes/Component/Icon.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct() {
3131
* @return string
3232
*/
3333
protected function maybe( string $language, string $prefix = '', string $postfix = '' ): string {
34-
if ( 5 == strlen( $language ) ) {
34+
if ( 5 === strlen( $language ) ) {
3535
$language = strtolower( substr( $language, - 2 ) );
3636
}
3737

includes/Component/Input/Select.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ final class Select extends Component {
1919
protected $options;
2020

2121
/**
22-
* @param string $key Name and ID of the form-element
23-
* @param mixed[] $arr Options as associative array
24-
* @param ?string $selected Values which should be selected
22+
* @param string $key Name and ID of the form-element.
23+
* @param mixed[] $arr Options as an associative array.
24+
* @param ?string $selected Values which should be selected.
2525
*/
2626
public function __construct( string $key, array $arr, ?string $selected = null ) {
2727
$this->key = $key;

includes/Component/Input/Text.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ final class Text extends Component {
3232
* @param string $key
3333
* @param string|null $value
3434
* @param int $size
35-
* @param bool $readonly
35+
* @param bool $read_only
3636
*/
37-
public function __construct( string $key, ?string $value, int $size = self::DEFAULT_SIZE, bool $readonly = false ) {
37+
public function __construct( string $key, ?string $value, int $size = self::DEFAULT_SIZE, bool $read_only = false ) {
3838
$this->key = $key;
3939
$this->value = $value;
4040
$this->size = $size;
41-
$this->readonly = $readonly ? ' readonly="readonly"' : '';
41+
$this->readonly = $read_only ? ' readonly="readonly"' : '';
4242
}
4343

4444
/**

includes/Component/Wrapper.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@
44

55
final class Wrapper extends Component {
66

7+
/**
8+
* @var string
9+
*/
710
protected string $element;
811

12+
/**
13+
* @var string
14+
*/
915
protected string $content;
1016

1117
public function __construct( string $element, string $content ) {

includes/ContentImport/AttachmentPathFinder.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ class AttachmentPathFinder extends MslsRegistryInstance {
1010

1111
/**
1212
* @param array<string, array<string, mixed>> $sources
13-
* @param mixed $sizeArray
14-
* @param string $imageSrc
15-
* @param mixed $imageMeta
16-
* @param int $attachmentId
13+
* @param mixed $size_array
14+
* @param string $image_src
15+
* @param mixed $image_meta
16+
* @param int $attachment_id
1717
*
1818
* @return array<string, mixed>
1919
*/
20-
public function filter_srcset( array $sources, $sizeArray, $imageSrc, $imageMeta, $attachmentId ): array {
21-
if ( ! $msls_imported = $this->has_import_data( $attachmentId ) ) {
20+
public function filter_srcset( array $sources, $size_array, $image_src, $image_meta, $attachment_id ): array {
21+
$msls_imported = $this->has_import_data( $attachment_id );
22+
if ( ! $msls_imported ) {
2223
return $sources;
2324
}
2425

@@ -27,14 +28,14 @@ public function filter_srcset( array $sources, $sizeArray, $imageSrc, $imageMeta
2728
return $sources;
2829
}
2930

30-
$extension = '.' . pathinfo( $source_post->guid, PATHINFO_EXTENSION );
31-
$pattern = '/(-[\\d]+x[\\d]+)*' . preg_quote( $extension, '/' ) . '$/';
32-
$srcWithoutExtension = preg_replace( $pattern, '', $imageSrc );
31+
$extension = '.' . pathinfo( $source_post->guid, PATHINFO_EXTENSION );
32+
$pattern = '/(-[\\d]+x[\\d]+)*' . preg_quote( $extension, '/' ) . '$/';
33+
$src_without_extension = preg_replace( $pattern, '', $image_src );
3334

3435
foreach ( $sources as $key => &$value ) {
3536
preg_match( $pattern, $value['url'], $matches );
3637
$w_and_h = ! empty( $matches[1] ) ? $matches[1] : '';
37-
$value['url'] = $srcWithoutExtension . $w_and_h . $extension;
38+
$value['url'] = $src_without_extension . $w_and_h . $extension;
3839
}
3940

4041
return $sources;
@@ -71,7 +72,8 @@ protected function has_import_data( $attachment_id ) {
7172
* @return string
7273
*/
7374
public function filter_attachment_url( $url, $attachment_id ) {
74-
if ( ! $msls_imported = $this->has_import_data( $attachment_id ) ) {
75+
$msls_imported = $this->has_import_data( $attachment_id );
76+
if ( ! $msls_imported ) {
7577
return $url;
7678
}
7779

includes/ContentImport/ContentImporter.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@ class ContentImporter extends MslsRegistryInstance {
2626
*/
2727
protected MslsMain $main;
2828

29+
/**
30+
* @var ImportLogger|null
31+
*/
2932
protected ?ImportLogger $logger = null;
33+
34+
/**
35+
* @var Relations|null
36+
*/
3037
protected ?Relations $relations = null;
3138

3239
/**
@@ -45,7 +52,7 @@ class ContentImporter extends MslsRegistryInstance {
4552
* @param ?MslsMain $main
4653
*/
4754
public function __construct( ?MslsMain $main = null ) {
48-
$this->main = $main ?: MslsMain::create();
55+
$this->main = ! is_null( $main ) ? $main : MslsMain::create();
4956
}
5057

5158
/**
@@ -84,13 +91,14 @@ public function set_relations( Relations $relations ): void {
8491
* @return string[] The updated, if needed, data array.
8592
*/
8693
public function handle_import( array $data = array() ) {
87-
if ( ! $this->pre_flight_check() || false === $sources = $this->parse_sources() ) {
94+
$sources = $this->parse_sources();
95+
if ( ! $this->pre_flight_check() || false === $sources ) {
8896
return $data;
8997
}
9098

9199
list( $source_blog_id, $source_post_id ) = $sources;
92100

93-
if ( $source_blog_id === get_current_blog_id() ) {
101+
if ( get_current_blog_id() === $source_blog_id ) {
94102
return $data;
95103
}
96104

@@ -148,6 +156,7 @@ protected function pre_flight_check() {
148156
return false;
149157
}
150158

159+
// phpcs:ignore WordPress.Security.NonceVerification.Missing
151160
if ( ! isset( $_POST['msls_import'] ) ) {
152161
return false;
153162
}
@@ -225,7 +234,7 @@ protected function insert_blog_post( $blog_id, array $data = array() ) {
225234
}
226235
$this->handle( true );
227236

228-
$this->has_created_post = $post_id ?: false;
237+
$this->has_created_post = $post_id > 0 ? $post_id : false;
229238

230239
restore_current_blog();
231240

@@ -240,7 +249,7 @@ protected function insert_blog_post( $blog_id, array $data = array() ) {
240249
public function handle( $handle ) {
241250
$this->handle = $handle;
242251

243-
// also prevent MSLS from saving
252+
// Also, prevent MSLS from saving.
244253
if ( false === $handle ) {
245254
add_action( 'msls_main_save', 'msls_return_void' );
246255
} else {
@@ -356,7 +365,7 @@ public function import_content( ImportCoordinates $import_coordinates, array $po
356365
*/
357366
protected function update_inserted_blog_post_data( $blog_id, $post_id, array $data ) {
358367
$data['ID'] = $post_id;
359-
$data['post_status'] = empty( $data['post_status'] ) || $data['post_status'] === 'auto-draft'
368+
$data['post_status'] = empty( $data['post_status'] ) || 'auto-draft' === $data['post_status']
360369
? 'draft'
361370
: $data['post_status'];
362371
$this->insert_blog_post( $blog_id, $data );
@@ -372,7 +381,7 @@ protected function update_inserted_blog_post_data( $blog_id, $post_id, array $da
372381
protected function redirect_to_blog_post( $dest_blog_id, $post_id ) {
373382
switch_to_blog( $dest_blog_id );
374383
$edit_post_link = html_entity_decode( get_edit_post_link( $post_id ) );
375-
wp_redirect( $edit_post_link );
384+
wp_safe_redirect( $edit_post_link );
376385
die();
377386
}
378387

@@ -382,17 +391,18 @@ protected function redirect_to_blog_post( $dest_blog_id, $post_id ) {
382391
* Empty posts would not be saved to database but it's fine if in
383392
* the context of a content import as it will be populated.
384393
*
385-
* @param bool $empty
394+
* @param bool $is_empty
386395
*
387396
* @return bool
388397
*/
389-
public function filter_empty( $empty ) {
398+
public function filter_empty( $is_empty ) {
390399
if ( ! $this->main->verify_nonce() ) {
391-
return $empty;
400+
return $is_empty;
392401
}
393402

403+
// phpcs:ignore WordPress.Security.NonceVerification.Missing
394404
if ( ! isset( $_POST['msls_import'] ) ) {
395-
return $empty;
405+
return $is_empty;
396406
}
397407

398408
return false;

includes/ContentImport/ImportCoordinates.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ public function validate() {
6464
return false;
6565
}
6666

67-
if ( $this->source_lang !== MslsBlogCollection::get_blog_language( $this->source_blog_id ) ) {
67+
if ( MslsBlogCollection::get_blog_language( $this->source_blog_id ) !== $this->source_lang ) {
6868
return false;
6969
}
70-
if ( $this->dest_lang !== MslsBlogCollection::get_blog_language( $this->dest_blog_id ) ) {
70+
if ( MslsBlogCollection::get_blog_language( $this->dest_blog_id ) !== $this->dest_lang ) {
7171
return false;
7272
}
7373

includes/ContentImport/ImportLogger.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
class ImportLogger {
99

10+
/**
11+
* @var string
12+
*/
1013
protected string $levels_delimiter = '/';
1114

1215
/**
@@ -62,7 +65,7 @@ public function save(): void {
6265
*/
6366
$log_writer = apply_filters( 'msls_content_import_log_writer', $default_log_writer, $this->import_coordinates );
6467
if ( empty( $log_writer ) ) {
65-
// we assume that was done on purpose to prevent logging
68+
// We assume that was done on purpose to prevent logging.
6669
return;
6770
}
6871

@@ -71,7 +74,7 @@ public function save(): void {
7174
}
7275

7376
if ( ! $log_writer instanceof LogWriter ) {
74-
// something is fishy, let's use the default one
77+
// Something is fishy, let's use the default one.
7578
$log_writer = $default_log_writer;
7679
}
7780

includes/ContentImport/Importers/BaseImporter.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class BaseImporter implements Importer {
2626
/**
2727
* BaseImporter constructor.
2828
*
29+
* @param ImportCoordinates $import_coordinates
2930
* @param ImportLogger|null $logger
3031
* @param Relations|null $relations
3132
*/
@@ -35,8 +36,8 @@ public function __construct(
3536
Relations $relations = null
3637
) {
3738
$this->import_coordinates = $import_coordinates;
38-
$this->logger = $logger ?: new ImportLogger( $this->import_coordinates );
39-
$this->relations = $relations ?: new Relations( $this->import_coordinates );
39+
$this->logger = ! is_null( $logger ) ? $logger : new ImportLogger( $this->import_coordinates );
40+
$this->relations = ! is_null( $relations ) ? $relations : new Relations( $this->import_coordinates );
4041
}
4142

4243
/**

0 commit comments

Comments
 (0)