forked from mansuetoventures/hookpress
-
Notifications
You must be signed in to change notification settings - Fork 1
/
hookpress.php
81 lines (66 loc) · 2.58 KB
/
hookpress.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/*
Plugin Name: HookPress
Plugin URI: http://mitcho.com/code/hookpress/
Description: HookPress turns all of your WordPress-internal hooks into webhooks. Possible uses include generating push notifications or using non-PHP web technology to extend WordPress. Read more about webhooks at <a href='http://webhooks.org/'>the webhooks site</a>.
Version: 1.16
Author: mitcho (Michael Yoshitaka Erlewine)
Author URI: http://mitcho.com/
Donate link: http://tinyurl.com/donatetomitcho
*/
define('HOOKPRESS_PRIORITY',12838790321);
$hookpress_version = "1.15";
require('includes.php');
function hookpress_init() {
global $hookpress_version;
if ( !get_site_option('hookpress_version') ||
version_compare($hookpress_version,get_site_option('hookpress_version')) > 0 )
update_site_option('hookpress_version',$hookpress_version);
add_action('admin_menu', 'hookpress_config_page');
hookpress_register_hooks();
}
add_action('init', 'hookpress_init');
// register ajax service
add_action('wp_ajax_hookpress_get_fields', 'hookpress_ajax_get_fields');
add_action('wp_ajax_hookpress_add_fields', 'hookpress_ajax_add_fields');
add_action('wp_ajax_hookpress_delete_hook', 'hookpress_ajax_delete_hook');
add_action('wp_ajax_hookpress_edit_hook', 'hookpress_ajax_edit_hook');
add_action('wp_ajax_hookpress_get_hooks', 'hookpress_ajax_get_hooks');
add_action('wp_ajax_hookpress_set_enabled', 'hookpress_ajax_set_enabled');
function hookpress_config_page() {
$hook = add_submenu_page('options-general.php', __('Webhooks','hookpress'), __('Webhooks','hookpress'), 'manage_options', 'webhooks', 'hookpress_options');
add_action("load-$hook",'hookpress_load_thickbox');
}
function hookpress_load_thickbox() {
wp_enqueue_script( 'thickbox' );
wp_enqueue_style( 'thickbox' );
}
// Infrastructure:
function hookpress_options() {
global $wpdb, $hookpress_actions, $hookpress_version;
require(str_replace('hookpress.php','options.php',__FILE__));
}
function hookpress_get_hooks() {
return get_site_option('hookpress_webhooks', array());
}
function hookpress_delete_hook($hook_id) {
$webhooks = hookpress_get_hooks();
unset( $webhooks[$hook_id] );
hookpress_save_hooks( $webhooks );
return TRUE;
}
function hookpress_add_hook( $hook ) {
$webhooks = hookpress_get_hooks();
$webhooks[] = $hook;
hookpress_save_hooks($webhooks);
return end(array_keys($webhooks));
}
function hookpress_update_hook( $hook_id, $hook ) {
$webhooks = hookpress_get_hooks();
$webhooks[$hook_id] = $hook;
hookpress_save_hooks($webhooks);
return $hook_id;
}
function hookpress_save_hooks($webhooks) {
update_site_option('hookpress_webhooks', $webhooks);
}