Esempio n. 1
0
function hookpress_update_hook($hook_id, $hook)
{
    $webhooks = hookpress_get_hooks();
    $webhooks[$hook_id] = $hook;
    hookpress_save_hooks($webhooks);
    return $hook_id;
}
Esempio n. 2
0
function hookpress_ajax_delete_hook()
{
    $nonce = $_POST['_nonce'];
    $webhooks = hookpress_get_hooks();
    if (!isset($_POST['id'])) {
        die("ERROR: no id given");
    }
    $id = (int) $_POST['id'];
    $nonce_compare = 'delete-webhook-' . $id;
    if (!wp_verify_nonce($nonce, $nonce_compare)) {
        die("ERROR: invalid nonce");
    }
    if (!$webhooks[$id]) {
        die("ERROR: no webhook found for that id");
    }
    hookpress_delete_hook($id);
    echo "ok";
    exit;
}
Esempio n. 3
0
function hookpress_generic_action($id, $args)
{
    global $hookpress_version, $wpdb, $hookpress_actions, $hookpress_filters, $wp_version;
    $webhooks = hookpress_get_hooks();
    $desc = $webhooks[$id];
    do_action('hookpress_hook_fired', $desc);
    $obj = array();
    // generate the expected argument names
    if (isset($desc['type']) && $desc['type'] == 'filter') {
        $arg_names = $hookpress_filters[$desc['hook']];
    } else {
        $arg_names = $hookpress_actions[$desc['hook']];
    }
    foreach ($args as $i => $arg) {
        $newobj = array();
        switch ($arg_names[$i]) {
            case 'POST':
            case 'ATTACHMENT':
                $newobj = get_post($arg, ARRAY_A);
                if ($arg_names[$i] == 'POST') {
                    $newobj["post_url"] = get_permalink($newobj["ID"]);
                }
                if (wp_is_post_revision($arg)) {
                    $parent = get_post(wp_is_post_revision($arg));
                    foreach ($parent as $key => $val) {
                        $newobj["parent_{$key}"] = $val;
                    }
                    $newobj["parent_post_url"] = get_permalink($newobj["parent_ID"]);
                }
                break;
            case 'COMMENT':
                $arg = (int) $arg;
                $newobj = (array) get_comment($arg);
                break;
            case 'CATEGORY':
                $newobj = $wpdb->get_row("select * from {$wpdb->categories} where cat_ID = {$arg}", ARRAY_A);
                break;
            case 'USER':
                $newobj = $wpdb->get_row("select * from {$wpdb->users} where ID = {$arg}", ARRAY_A);
                break;
            case 'LINK':
                $newobj = $wpdb->get_row("select * from {$wpdb->links} where link_id = {$arg}", ARRAY_A);
                break;
            case 'TAG_OBJ':
                $newobj = (array) $arg;
                break;
            case 'USER_OBJ':
                $newobj = (array) $arg;
            case 'OLD_USER_OBJ':
                $newobj = array_map(create_function('$x', 'return "old_$x";'), (array) $arg);
            default:
                $newobj[$arg_names[$i]] = $arg;
        }
        $obj = array_merge($obj, $newobj);
    }
    // take only the fields we care about
    $obj_to_post = array_intersect_key($obj, array_flip($desc['fields']));
    $obj_to_post['hook'] = $desc['hook'];
    $user_agent = "HookPress/{$hookpress_version} (compatible; WordPress {$wp_version}; +http://mitcho.com/code/hookpress/)";
    $request = apply_filters('hookpress_request', array('user-agent' => $user_agent, 'body' => $obj_to_post, 'referer' => get_bloginfo('url')));
    return wp_remote_post($desc['url'], $request);
}