@@ -46,11 +46,13 @@ function hookpress_print_edit_webhook( $id ){
4646
4747 $ webhooks = hookpress_get_hooks ( );
4848 $ desc = $ webhooks [$ id ];
49-
49+
5050 if ($ desc ['type ' ] == 'action ' )
5151 $ hooks = array_keys ($ hookpress_actions );
5252 if ($ desc ['type ' ] == 'filter ' )
5353 $ hooks = array_keys ($ hookpress_filters );
54+ $ post_types = get_post_types (['public ' => true ]);
55+
5456?>
5557<div id='hookpress-webhook' style='display:block;'>
5658<form id='editform'>
@@ -61,6 +63,21 @@ function hookpress_print_edit_webhook( $id ){
6163<td><input type='radio' id='action' class='newtype' name='newtype' <?php checked ('action ' ,$ desc ['type ' ]);?> > <?php _e ("action " ,"hookpress " );?> </input>
6264<input type='radio' id='filter' class='newtype' name='newtype' <?php checked ('filter ' ,$ desc ['type ' ]);?> > <?php _e ("filter " ,"hookpress " );?> </input></td></tr>
6365<tr>
66+ <tr><td><label style='font-weight: bold' for='edithook'><?php _e ("Post type " ,'hookpress ' );?> : </label></td>
67+ <td>
68+ <select name="post_type" id="post_type" multiple>
69+ <?php
70+ sort ($ post_types );
71+ foreach ($ post_types as $ post_type ) {
72+ if ($ desc ['post_type ' ]){
73+ $ selected = in_array ($ post_type ,$ desc ['post_type ' ])?'selected="true" ' :'' ;
74+ }
75+ $ post_type = esc_html ( $ post_type );
76+ echo "<option value=' $ post_type' $ selected> $ post_type</option> " ;
77+ }?>
78+ </select>
79+ </td></tr>
80+ <tr>
6481<td><label style='font-weight: bold' for='edithook' id='action_or_filter'>
6582<?php
6683if ($ desc ['type ' ] == 'action ' )
@@ -166,12 +183,20 @@ function hookpress_print_webhook_row( $id ) {
166183 $ activeornot = $ desc ['enabled ' ] ? 'active ' : 'inactive ' ;
167184
168185 $ html_safe ['hook ' ] = esc_html ( $ desc ['hook ' ] );
186+ if ( count ( $ desc ['post_type ' ] ) > 1 ) {
187+ $ desc ['post_type ' ] = array_map ( 'esc_html ' , $ desc ['post_type ' ] );
188+ $ html_safe ['post_type ' ] = implode (', ' , $ desc ['post_type ' ] );
189+ } else {
190+ $ html_safe ['post_type ' ] = esc_html ( $ desc ['post_type ' ][0 ] );
191+ }
192+
169193 $ html_safe ['url ' ] = esc_html ( $ desc ['url ' ] );
170194
171195 echo "
172196<tr id=' $ id' class=' $ activeornot'>
173197 <td class='webhook-title'><strong> {$ html_safe ['hook ' ]}</strong>
174198 <div class='row-actions'> $ nonce_action $ nonce_delete<span class='edit'> $ edit | <span class='delete'> $ delete | </span><span class='action'> $ action</span></div></td>
199+ <td class='desc'><p> {$ html_safe ['post_type ' ]}</p></td>
175200 <td class='desc'><p> {$ html_safe ['url ' ]}</p></td>
176201 <td class='desc'><code " .($ desc ['type ' ] == 'filter ' ? " style='background-color:#ECEC9D' title=' " .__ ('The data in the highlighted field is expected to be returned from the webhook, with modification. ' ,'hookpress ' )."' " :"" )."> $ fields</code></td>
177202</tr> \n" ;
@@ -188,6 +213,7 @@ function hookpress_print_webhooks_table() {
188213 <thead>
189214 <tr>
190215 <th scope="col" class="manage-column" style="width:15%"><?php _e ("Hook " ,"hookpress " );?> </th>
216+ <th scope="col" class="manage-column" style="width:25%"><?php _e ("Post Type " ,"hookpress " );?> </th>
191217 <th scope="col" class="manage-column" style="width:25%"><?php _e ("URL " ,"hookpress " );?> </th>
192218 <th scope="col" class="manage-column"><?php _e ("Fields " ,"hookpress " );?> </th>
193219 </tr>
@@ -196,6 +222,7 @@ function hookpress_print_webhooks_table() {
196222 <tfoot>
197223 <tr>
198224 <th scope="col" class="manage-column"><?php _e ("Hook " ,"hookpress " );?> </th>
225+ <th scope="col" class="manage-column"><?php _e ("Post Type " ,"hookpress " );?> </th>
199226 <th scope="col" class="manage-column"><?php _e ("URL " ,"hookpress " );?> </th>
200227 <th scope="col" class="manage-column"><?php _e ("Fields " ,"hookpress " );?> </th>
201228 </tr>
@@ -268,6 +295,10 @@ function hookpress_generic_action($id,$args) {
268295 $ newobj = array ();
269296 switch ($ arg_names [$ i ]) {
270297 case 'POST ' :
298+
299+ if (in_array ($ args [1 ]->post_type ,$ desc ['post_type ' ]) != 1 ){
300+ return ;
301+ }
271302 case 'ATTACHMENT ' :
272303 $ newobj = get_post ($ arg ,ARRAY_A );
273304
0 commit comments