This repository was archived by the owner on May 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathccbpress-slack.php
188 lines (161 loc) · 4.38 KB
/
ccbpress-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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
/**
* Plugin Name: Slack for CCBPress
* Plugin URI: http://ccbpress.com/
* Description: Retrieve data from CCB into Slack.
* Version: 1.0.0
* Author: FireTree Design, LLC <info@firetreedesign.com>
* Author URI: https://firetreedesign.com/
* Text Domain: ccbpress-slack
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'CCBPress_Slack' ) ) :
/**
* CCBPress Slack class
*/
class CCBPress_Slack {
/**
* @var CCBPress_Slack The one true CCBPress_Slack
*
* @since 1.0.0
*/
private static $instance;
/**
* Main CCBPress_Slack Instance
*
* Insures that only one instance of CCBPress_Slack exists in memory at any
* one time.
*
* @since 1.0
* @static
* @staticvar array $instance
* @uses CCBPress_Slack::includes() Include the required files
* @see CCBPress_Slack()
* @return The one true CCBPress_Slack
*/
public static function instance() {
if ( ! isset( self::$instance ) && ! ( self::$instance instanceof CCBPress_Slack ) ) {
self::$instance = new CCBPress_Slack;
self::$instance->setup_constants();
self::$instance->register_addon();
self::$instance->includes();
}
return self::$instance;
}
/**
* Setup plugin constants
*
* @access private
*
* @since 1.0.0
*
* @return void
*/
private function setup_constants() {
// Plugin File
if ( ! defined( 'CCBPRESS_SLACK_PLUGIN_FILE' ) ) {
define( 'CCBPRESS_SLACK_PLUGIN_FILE', __FILE__ );
}
// Plugin Folder Path
if ( ! defined( 'CCBPRESS_SLACK_PLUGIN_DIR' ) ) {
define( 'CCBPRESS_SLACK_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
}
// Plugin Folder URL
if ( ! defined( 'CCBPRESS_SLACK_PLUGIN_URL' ) ) {
define( 'CCBPRESS_SLACK_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
}
}
/**
* Register the addon with CCBPress Core
*
* @since 1.0.0
*
* @return void
*/
private function register_addon() {
$addon = new CCBPress_Addon( array(
'services' => array(
'individual_search',
),
) );
$options = new CCBPress_Options( array(
'settings' => array(
'tabs' => array(
array(
'tab_id' => 'slack',
'settings_id' => 'ccbpress_settings_slack',
'title' => __('Slack', 'ccbpress-slack'),
'submit' => TRUE,
),
),
'actions' => array(
array(
'tab_id' => 'slack',
'type' => 'secondary',
'class' => 'ccbpress-slack-help',
'link' => '#',
'target' => NULL,
'title' => '<span class="dashicons dashicons-info" style="vertical-align: text-bottom;"></span> ' . __('How to get a token', 'ccbpress-slack'),
),
),
),
) );
}
/**
* Include required files
*
* @access private
*
* @since 1.0
*
* @return void
*/
private function includes() {
require_once CCBPRESS_SLACK_PLUGIN_DIR . 'includes/ccb-connection.php';
require_once CCBPRESS_SLACK_PLUGIN_DIR . 'includes/settings-settings.php';
require_once CCBPRESS_SLACK_PLUGIN_DIR . 'includes/wp-rest-api.php';
require_once CCBPRESS_SLACK_PLUGIN_DIR . 'includes/admin-scripts.php';
}
}
endif; // End if class_exists check
/**
* Initialize the CCBPress_Slack class
*
* @since 1.0.0
*
* @return void
*/
function CCBPress_Slack() {
if ( class_exists( 'CCBPress_Core' ) ) {
return CCBPress_Slack::instance();
} else {
add_action( 'admin_init', 'CCBPress_Slack_Deactivate' );
add_action( 'admin_notices', 'CCBPress_Slack_Deactivate_Notice' );
}
}
add_action( 'plugins_loaded', 'CCBPress_Slack');
/**
* Deactivate our plugin
*
* @since 1.0.0
*
* @return void
*/
function CCBPress_Slack_Deactivate() {
deactivate_plugins( plugin_basename( __FILE__ ) );
}
/**
* Show a notice explaining why our plugin was deactivated
*
* @since 1.0.0
*
* @return void
*/
function CCBPress_Slack_Deactivate_Notice() {
echo '<div class="updated"><p><strong>Slack for CCBPress</strong> requires <strong>CCBPress Core</strong> be installed and activated; the plug-in has been <strong>deactivated</strong>.</p></div>';
if ( isset( $_GET['activate'] ) )
unset( $_GET['activate'] );
}