-
Notifications
You must be signed in to change notification settings - Fork 0
/
orbis-slack.php
107 lines (86 loc) · 2.42 KB
/
orbis-slack.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/*
Plugin Name: Orbis Slack
Plugin URI: https://www.pronamic.eu/plugins/orbis-slack/
Description: Orbis Slack integrates Orbis with Slack.
Version: 1.0.0
Requires at least: 3.0
Author: Pronamic
Author URI: https://www.pronamic.eu/
Text Domain: orbis
Domain Path: /languages/
License: GPL
GitHub URI: https://github.com/wp-orbis/wp-orbis-slack
*/
class OrbisSlackPlugin {
public function __construct( $file ) {
$this->file = $file;
}
public function setup() {
// Actions
add_action( 'init', array( $this, 'init' ) );
add_action( 'orbis_slack_notify', array( $this, 'send_projects_notifications' ) );
add_filter( 'slack_get_events', array( $this, 'slack_get_events' ) );
}
public function init() {
if ( ! wp_next_scheduled( 'orbis_slack_notify' ) ) {
$timestamp = get_gmt_from_date( date( 'Y-m-d H:i:s', strtotime( '10:00' ) ), 'U' );
wp_schedule_event( $timestamp, 'daily', 'orbis_slack_notify' );
}
if ( filter_has_var( INPUT_GET, 'orbis_slack_test' ) ) {
$this->test();
}
}
public function test() {
$query = new WP_Query( array(
'post_type' => 'orbis_project',
'posts_per_page' => 10,
'date_query' => array(
array(
'column' => 'last_comment_date',
'before' => '1 week ago',
),
),
'meta_query' => array(
array(
'key' => '_orbis_project_is_finished',
'compare' => 'NOT EXISTS'
),
),
) );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
do_action( 'orbis_post_requires_comment', $post );
}
}
}
/**
* Slack events.
*
* @see http://gedex.web.id/wp-slack/
* @see https://github.com/gedex/wp-slack/blob/0.5.1/includes/event-manager.php#L57-L167
* @see https://github.com/gedex/wp-slack-edd/blob/0.1.0/slack-edd.php
*/
public function slack_get_events( $events ) {
$events['orbis_post_requires_comment'] = array(
'action' => 'orbis_post_requires_comment',
'description' => __( 'When an Orbis post requires a comment.', 'orbis-slack' ),
'message' => function( $post ) {
$message = sprintf(
__( 'Orbis post <%s|%s> requires a comment.', 'orbis-slack' ),
get_permalink( $post ),
get_the_title( $post )
);
return $message;
},
);
return $events;
}
public function send_projects_notifications() {
$this->test();
}
}
global $orbis_slack_plugin;
$orbis_slack_plugin = new OrbisSlackPlugin( __FILE__ );
$orbis_slack_plugin->setup();