@@ -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 ;
0 commit comments