function hookpress_ajax_get_fields() { global $wpdb, $hookpress_actions, $hookpress_filters; if ($_POST['type'] == 'action') { $args = $hookpress_actions[$_POST['hook']]; } if ($_POST['type'] == 'filter') { $args = $hookpress_filters[$_POST['hook']]; } $fields = array(); foreach ($args as $arg) { if (ereg('[A-Z]+', $arg)) { $fields = array_merge($fields, hookpress_get_fields($arg)); } else { $fields[] = $arg; } } header("Content-Type: text/html; charset=UTF-8"); if ($_POST['type'] == 'filter') { $first = array_shift($fields); echo "<option value='{$first}' selected='selected' class='first'>{$first}</option>"; } sort($fields); foreach ($fields as $field) { echo "<option value='{$field}'>{$field}</option>"; } exit; }
function hookpress_print_edit_webhook($id) { global $wpdb, $hookpress_actions, $hookpress_filters; $webhooks = hookpress_get_hooks(); $desc = $webhooks[$id]; if ($desc['type'] == 'action') { $hooks = array_keys($hookpress_actions); } if ($desc['type'] == 'filter') { $hooks = array_keys($hookpress_filters); } ?> <div id='hookpress-webhook' style='display:block;'> <form id='editform'> <input type="hidden" name="edit-hook-id" id="edit-hook-id" value="<?php echo $id; ?> " /> <input type="hidden" name="enabled" id="enabled" value="<?php echo $desc['enabled']; ?> " /> <table> <tr><td><label style='font-weight: bold' for='edithook'><?php _e("WordPress hook type", 'hookpress'); ?> : </label></td> <td><input type='radio' id='action' class='newtype' name='newtype' <?php checked('action', $desc['type']); ?> > <?php _e("action", "hookpress"); ?> </input> <input type='radio' id='filter' class='newtype' name='newtype' <?php checked('filter', $desc['type']); ?> > <?php _e("filter", "hookpress"); ?> </input></td></tr> <tr> <td><label style='font-weight: bold' for='edithook' id='action_or_filter'> <?php if ($desc['type'] == 'action') { echo 'Action:'; } if ($desc['type'] == 'filter') { echo 'Filter:'; } ?> </label></td> <td><select name='edithook' id='edithook'> <?php sort($hooks); foreach ($hooks as $hook) { $selected = $hook == $desc['hook'] ? 'selected="true"' : ''; $hook = esc_html($hook); echo "<option value='{$hook}' {$selected}>{$hook}</option>"; } $nonce_submit = "<input type='hidden' id='submit-nonce' name='submit-nonce' value='" . wp_create_nonce('submit-webhook') . "' />"; ?> </select></td></tr> <tr><td style='vertical-align: top'><label style='font-weight: bold' for='editfields'><?php _e("Fields", 'hookpress'); ?> : </label> <br/> <small><?php _e("Ctrl-click on Windows or Command-click on Mac to select multiple. The <code>hook</code> field with the relevant hook name is always sent."); ?> </small> <br/> <span id='filtermessage'><small><?php _e('The first argument of a filter must always be sent and should be returned by the webhook, with modification.', 'hookpress'); ?> </small></span> </td> <td> <select style='vertical-align: top' name='editfields' id='editfields' multiple='multiple' size='8'> <?php global $wpdb, $hookpress_actions, $hookpress_filters; if ($desc['type'] == 'action') { $args = $hookpress_actions[$desc['hook']]; } if ($desc['type'] == 'filter') { $args = $hookpress_filters[$desc['hook']]; } $fields = array(); foreach ($args as $arg) { if (preg_match('/[A-Z]+/', $arg)) { $fields = array_merge($fields, hookpress_get_fields($arg)); } else { $fields[] = $arg; } } if ($desc['type'] == 'filter') { $first = array_shift($fields); $first = esc_html($first); echo "<option value='{$first}' selected='selected' class='first'>{$first}</option>"; } sort($fields); foreach ($fields as $field) { $selected = ''; foreach ($desc['fields'] as $cmp) { if ($cmp == $field) { $selected = 'selected="true"'; } } $field = esc_html($field); echo "<option value='{$field}' {$selected}>{$field}</option>"; } $desc['url'] = esc_html($desc['url']); ?> </select></td></tr> <tr><td><label style='font-weight: bold' for='newurl'><?php _e("URL", 'hookpress'); ?> : </label></td> <td><input name='editurl' id='editurl' size='40' value="<?php echo $desc['url']; ?> "></input></td></tr> </table> <?php echo $nonce_submit; ?> <center><span id='editindicator'></span><br/> <input type='button' class='button' id='editsubmit' value='<?php _e('Save webhook', 'hookpress'); ?> '/> <input type='button' class='button' id='editcancel' value='<?php _e('Cancel'); ?> '/></center> </form> </div> <?php }