Skip to content

Commit 1c165f8

Browse files
authored
Merge pull request #392 from lloc/fix-double-output
Fix double output
2 parents 10907d9 + 432bc64 commit 1c165f8

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

Diff for: .distignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ phpdoc.xml
3030
phpstan.neon
3131
phpunit.xml
3232
playwright.config.ts
33-
setup.sh
33+
setup.sh
34+
multisite-language-switcher.zip

Diff for: includes/MslsPostTag.php

+14-15
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
*/
1818
class MslsPostTag extends MslsMain {
1919

20-
protected int $excution_counter = 0;
20+
const EDIT_ACTION = 'msls_post_tag_edit_input';
21+
const ADD_ACTION = 'msls_post_tag_add_input';
2122

2223
/**
2324
* Suggest
@@ -97,6 +98,10 @@ public static function init(): void {
9798
* @param string $taxonomy
9899
*/
99100
public function add_input( string $taxonomy ): void {
101+
if ( did_action( self::ADD_ACTION ) ) {
102+
return;
103+
}
104+
100105
$title_format = '<h3>%s</h3>
101106
<input type="hidden" name="msls_post_type" id="msls_post_type" value="%s"/>
102107
<input type="hidden" name="msls_action" id="msls_action" value="suggest_terms"/>';
@@ -108,6 +113,8 @@ public function add_input( string $taxonomy ): void {
108113
echo '<div class="form-field">';
109114
$this->the_input( null, $title_format, $item_format );
110115
echo '</div>';
116+
117+
do_action( self::ADD_ACTION, $taxonomy );
111118
}
112119

113120
/**
@@ -117,6 +124,10 @@ public function add_input( string $taxonomy ): void {
117124
* @param string $taxonomy
118125
*/
119126
public function edit_input( \WP_Term $tag, string $taxonomy ): void {
127+
if ( did_action( self::EDIT_ACTION ) ) {
128+
return;
129+
}
130+
120131
$title_format = '<tr>
121132
<th colspan="2">
122133
<strong>%s</strong>
@@ -136,6 +147,8 @@ public function edit_input( \WP_Term $tag, string $taxonomy ): void {
136147
</tr>';
137148

138149
$this->the_input( $tag, $title_format, $item_format );
150+
151+
do_action( self::EDIT_ACTION, $tag, $taxonomy );
139152
}
140153

141154
/**
@@ -150,10 +163,6 @@ public function edit_input( \WP_Term $tag, string $taxonomy ): void {
150163
* @return boolean
151164
*/
152165
public function the_input( ?\WP_Term $tag, string $title_format, string $item_format ): bool {
153-
if ( $this->already_executed() ) {
154-
return false;
155-
}
156-
157166
$blogs = $this->collection->get();
158167
if ( $blogs ) {
159168
$term_id = $tag->term_id ?? 0;
@@ -261,14 +270,4 @@ protected function get_select_title(): string {
261270
__( 'Multisite Language Switcher', 'multisite-language-switcher' )
262271
);
263272
}
264-
265-
protected function already_executed(): bool {
266-
if ( $this->excution_counter > 0 ) {
267-
return true;
268-
}
269-
270-
++$this->excution_counter;
271-
272-
return false;
273-
}
274273
}

Diff for: includes/MslsPostTagClassic.php

+15-4
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@
1111
*/
1212
class MslsPostTagClassic extends MslsPostTag {
1313

14+
const EDIT_ACTION = 'msls_post_tag_classic_edit_input';
15+
const ADD_ACTION = 'msls_post_tag_classic_add_input';
16+
1417
/**
1518
* Add the input fields to the add-screen of the taxonomies
1619
*
1720
* @param string $taxonomy
1821
*/
1922
public function add_input( string $taxonomy ): void {
23+
if ( did_action( self::ADD_ACTION ) ) {
24+
return;
25+
}
26+
2027
$title_format = '<h3>%s</h3>';
2128

2229
$item_format = '<label for="msls_input_%1$s">%2$s</label>
@@ -28,6 +35,8 @@ public function add_input( string $taxonomy ): void {
2835
echo '<div class="form-field">';
2936
$this->the_input( null, $title_format, $item_format );
3037
echo '</div>';
38+
39+
do_action( self::ADD_ACTION, $taxonomy );
3140
}
3241

3342
/**
@@ -37,6 +46,10 @@ public function add_input( string $taxonomy ): void {
3746
* @param string $taxonomy
3847
*/
3948
public function edit_input( \WP_Term $tag, string $taxonomy ): void {
49+
if ( did_action( self::EDIT_ACTION ) ) {
50+
return;
51+
}
52+
4053
$title_format = '<tr>
4154
<th colspan="2">
4255
<strong>%s</strong>
@@ -54,6 +67,8 @@ public function edit_input( \WP_Term $tag, string $taxonomy ): void {
5467
</tr>';
5568

5669
$this->the_input( $tag, $title_format, $item_format );
70+
71+
do_action( self::EDIT_ACTION, $tag, $taxonomy );
5772
}
5873

5974
/**
@@ -67,10 +82,6 @@ public function edit_input( \WP_Term $tag, string $taxonomy ): void {
6782
* @return boolean
6883
*/
6984
public function the_input( ?\WP_Term $tag, string $title_format, string $item_format ): bool {
70-
if ( $this->already_executed() ) {
71-
return false;
72-
}
73-
7485
$blogs = $this->collection->get();
7586
if ( ! empty( $blogs ) ) {
7687
$term_id = $tag->term_id ?? 0;

0 commit comments

Comments
 (0)