Skip to content

Commit

Permalink
Merge pull request #392 from lloc/fix-double-output
Browse files Browse the repository at this point in the history
Fix double output
  • Loading branch information
lloc authored Oct 13, 2024
2 parents 10907d9 + 432bc64 commit 1c165f8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .distignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ phpdoc.xml
phpstan.neon
phpunit.xml
playwright.config.ts
setup.sh
setup.sh
multisite-language-switcher.zip
29 changes: 14 additions & 15 deletions includes/MslsPostTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
*/
class MslsPostTag extends MslsMain {

protected int $excution_counter = 0;
const EDIT_ACTION = 'msls_post_tag_edit_input';
const ADD_ACTION = 'msls_post_tag_add_input';

/**
* Suggest
Expand Down Expand Up @@ -97,6 +98,10 @@ public static function init(): void {
* @param string $taxonomy
*/
public function add_input( string $taxonomy ): void {
if ( did_action( self::ADD_ACTION ) ) {
return;
}

$title_format = '<h3>%s</h3>
<input type="hidden" name="msls_post_type" id="msls_post_type" value="%s"/>
<input type="hidden" name="msls_action" id="msls_action" value="suggest_terms"/>';
Expand All @@ -108,6 +113,8 @@ public function add_input( string $taxonomy ): void {
echo '<div class="form-field">';
$this->the_input( null, $title_format, $item_format );
echo '</div>';

do_action( self::ADD_ACTION, $taxonomy );
}

/**
Expand All @@ -117,6 +124,10 @@ public function add_input( string $taxonomy ): void {
* @param string $taxonomy
*/
public function edit_input( \WP_Term $tag, string $taxonomy ): void {
if ( did_action( self::EDIT_ACTION ) ) {
return;
}

$title_format = '<tr>
<th colspan="2">
<strong>%s</strong>
Expand All @@ -136,6 +147,8 @@ public function edit_input( \WP_Term $tag, string $taxonomy ): void {
</tr>';

$this->the_input( $tag, $title_format, $item_format );

do_action( self::EDIT_ACTION, $tag, $taxonomy );
}

/**
Expand All @@ -150,10 +163,6 @@ public function edit_input( \WP_Term $tag, string $taxonomy ): void {
* @return boolean
*/
public function the_input( ?\WP_Term $tag, string $title_format, string $item_format ): bool {
if ( $this->already_executed() ) {
return false;
}

$blogs = $this->collection->get();
if ( $blogs ) {
$term_id = $tag->term_id ?? 0;
Expand Down Expand Up @@ -261,14 +270,4 @@ protected function get_select_title(): string {
__( 'Multisite Language Switcher', 'multisite-language-switcher' )
);
}

protected function already_executed(): bool {
if ( $this->excution_counter > 0 ) {
return true;
}

++$this->excution_counter;

return false;
}
}
19 changes: 15 additions & 4 deletions includes/MslsPostTagClassic.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@
*/
class MslsPostTagClassic extends MslsPostTag {

const EDIT_ACTION = 'msls_post_tag_classic_edit_input';
const ADD_ACTION = 'msls_post_tag_classic_add_input';

/**
* Add the input fields to the add-screen of the taxonomies
*
* @param string $taxonomy
*/
public function add_input( string $taxonomy ): void {
if ( did_action( self::ADD_ACTION ) ) {
return;
}

$title_format = '<h3>%s</h3>';

$item_format = '<label for="msls_input_%1$s">%2$s</label>
Expand All @@ -28,6 +35,8 @@ public function add_input( string $taxonomy ): void {
echo '<div class="form-field">';
$this->the_input( null, $title_format, $item_format );
echo '</div>';

do_action( self::ADD_ACTION, $taxonomy );
}

/**
Expand All @@ -37,6 +46,10 @@ public function add_input( string $taxonomy ): void {
* @param string $taxonomy
*/
public function edit_input( \WP_Term $tag, string $taxonomy ): void {
if ( did_action( self::EDIT_ACTION ) ) {
return;
}

$title_format = '<tr>
<th colspan="2">
<strong>%s</strong>
Expand All @@ -54,6 +67,8 @@ public function edit_input( \WP_Term $tag, string $taxonomy ): void {
</tr>';

$this->the_input( $tag, $title_format, $item_format );

do_action( self::EDIT_ACTION, $tag, $taxonomy );
}

/**
Expand All @@ -67,10 +82,6 @@ public function edit_input( \WP_Term $tag, string $taxonomy ): void {
* @return boolean
*/
public function the_input( ?\WP_Term $tag, string $title_format, string $item_format ): bool {
if ( $this->already_executed() ) {
return false;
}

$blogs = $this->collection->get();
if ( ! empty( $blogs ) ) {
$term_id = $tag->term_id ?? 0;
Expand Down

0 comments on commit 1c165f8

Please sign in to comment.