Skip to content

Commit 638226c

Browse files
committed
did_action and add_action for a custom hook
1 parent 7496514 commit 638226c

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

includes/MslsPostTag.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
*/
1818
class MslsPostTag extends MslsMain {
1919

20+
const EDIT_ACTION = 'msls_post_tag_edit_input';
21+
const ADD_ACTION = 'msls_post_tag_add_input';
22+
2023
/**
2124
* Suggest
2225
*
@@ -95,6 +98,10 @@ public static function init(): void {
9598
* @param string $taxonomy
9699
*/
97100
public function add_input( string $taxonomy ): void {
101+
if ( did_action( self::ADD_ACTION ) ) {
102+
return;
103+
}
104+
98105
$title_format = '<h3>%s</h3>
99106
<input type="hidden" name="msls_post_type" id="msls_post_type" value="%s"/>
100107
<input type="hidden" name="msls_action" id="msls_action" value="suggest_terms"/>';
@@ -106,6 +113,8 @@ public function add_input( string $taxonomy ): void {
106113
echo '<div class="form-field">';
107114
$this->the_input( null, $title_format, $item_format );
108115
echo '</div>';
116+
117+
do_action( self::ADD_ACTION, $taxonomy );
109118
}
110119

111120
/**
@@ -115,6 +124,10 @@ public function add_input( string $taxonomy ): void {
115124
* @param string $taxonomy
116125
*/
117126
public function edit_input( \WP_Term $tag, string $taxonomy ): void {
127+
if ( did_action( self::EDIT_ACTION ) ) {
128+
return;
129+
}
130+
118131
$title_format = '<tr>
119132
<th colspan="2">
120133
<strong>%s</strong>
@@ -134,6 +147,8 @@ public function edit_input( \WP_Term $tag, string $taxonomy ): void {
134147
</tr>';
135148

136149
$this->the_input( $tag, $title_format, $item_format );
150+
151+
do_action( self::EDIT_ACTION, $tag, $taxonomy );
137152
}
138153

139154
/**

includes/MslsPostTagClassic.php

Lines changed: 15 additions & 0 deletions
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
/**

0 commit comments

Comments
 (0)