Skip to content

Commit 2299d55

Browse files
committed
Optimized code
1 parent a8ee200 commit 2299d55

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

includes/MslsCustomFilter.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,6 @@ function () {
4949
* @uses selected
5050
*/
5151
public function add_filter(): void {
52-
$id = (
53-
filter_has_var( INPUT_GET, self::FILTER_NAME ) ?
54-
filter_input( INPUT_GET, self::FILTER_NAME, FILTER_SANITIZE_NUMBER_INT ) :
55-
'0'
56-
);
57-
5852
$blogs = $this->collection->get();
5953
if ( $blogs ) {
6054
$options = array( '' => esc_html( __( 'Show all posts', 'multisite-language-switcher' ) ) );
@@ -65,6 +59,12 @@ public function add_filter(): void {
6559
);
6660
}
6761

62+
$id = (
63+
filter_has_var( INPUT_GET, self::FILTER_NAME ) ?
64+
filter_input( INPUT_GET, self::FILTER_NAME, FILTER_SANITIZE_NUMBER_INT ) :
65+
'0'
66+
);
67+
6868
echo ( new Select( self::FILTER_NAME, $options, $id ) )->render();
6969
}
7070
}
@@ -84,15 +84,15 @@ public function execute_filter( \WP_Query $query ) {
8484
$id = filter_input( INPUT_GET, self::FILTER_NAME, FILTER_SANITIZE_NUMBER_INT );
8585
$blog = $this->collection->get_object( intval( $id ) );
8686

87-
if ( $blog ) {
88-
$sql_cache = MslsSqlCacher::create( __CLASS__, __METHOD__ );
87+
if ( ! $blog ) {
88+
return false;
89+
}
8990

90-
// load post we need to exclude (they already have a translation) from search query
91-
$query->query_vars['post__not_in'] = ( new TranslatedPostIdQuery( $sql_cache ) )( $blog->get_language() );
91+
$sql_cache = MslsSqlCacher::create( __CLASS__, __METHOD__ );
9292

93-
return $query;
94-
}
93+
// load post we need to exclude (they already have a translation) from search query
94+
$query->query_vars['post__not_in'] = ( new TranslatedPostIdQuery( $sql_cache ) )( $blog->get_language() );
9595

96-
return false;
96+
return $query;
9797
}
9898
}

0 commit comments

Comments
 (0)