-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwp-node-wordpress.php
More file actions
56 lines (40 loc) · 1.1 KB
/
wp-node-wordpress.php
File metadata and controls
56 lines (40 loc) · 1.1 KB
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
<?php
/*
Plugin Name: wp-node-wordpress
Plugin URI: http://www.arnaldocapo.com/
Description: Provides signal communications between your Node.JS environment and WordPress
Version: 1
Author: Arnaldo Capo
Author URI: http://www.arnaldocapo.com/
*/
function wp_node__send_post($args) {
$result = wp_remote_post( WP_NODE_CLEAR_CACHE_ENDPOINT, $args );
if ( is_wp_error($result) )
error_log( $result->get_error_message() );
}
add_action( 'save_post', function( $post_id ) {
// Let's ignore only if this is a revision
if ( wp_is_post_revision( $post_id ) )
return;
$args = array(
'body' => array(
'secret' => WP_NODE_SECRET,
'post_id' => $post_id,
'type' => 'post'
),
);
wp_node__send_post( $args );
});
add_action( 'edit_category', function($category_id){
$categories = split( ';', get_category_parents( $category_id, false, ';' ) );
array_pop( $categories );
$args = array(
'body' => array(
'secret' => WP_NODE_SECRET,
'type' => 'categories',
'categories' => $categories
),
);
wp_node__send_post( $args );
});
?>