-
Notifications
You must be signed in to change notification settings - Fork 9
/
loader.php
137 lines (111 loc) · 3.37 KB
/
loader.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
<?php
/*
Plugin Name: BuddyPress Reply By Email
Description: Reply to BuddyPress items from the comfort of your email inbox.
Author: r-a-y
Author URI: http://profiles.wordpress.org/r-a-y
Version: 1.0-RC11.dev
License: GPLv2 or later
*/
/**
* BuddyPress Reply By Email
*
* @package BP_Reply_By_Email
* @subpackage Loader
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
// pertinent constants
define( 'BP_RBE_DIR', dirname( __FILE__ ) );
define( 'BP_RBE_URL', plugin_dir_url( __FILE__ ) );
/**
* Loads BP Reply By Email only if BuddyPress is activated
*/
function bp_rbe_init() {
global $bp_rbe;
require( BP_RBE_DIR . '/bp-rbe-core.php' );
// initialize!
$bp_rbe = new BP_Reply_By_Email;
$bp_rbe->init();
// admin area
if ( is_admin() ) {
require( BP_RBE_DIR . '/includes/bp-rbe-admin.php' );
new BP_Reply_By_Email_Admin;
}
}
add_action( 'bp_include', 'bp_rbe_init' );
/**
* Adds default settings when plugin is activated
*/
function bp_rbe_activate() {
// Load the bp-rbe functions file
require( BP_RBE_DIR . '/includes/bp-rbe-functions.php' );
if ( ! $settings = bp_get_option( 'bp-rbe' ) ) {
$settings = array();
}
// Set default mode to Inbound if no mode exists
if ( ! isset( $settings['mode'] ) ) {
$settings['mode'] = 'inbound';
}
// generate a unique key if one doesn't exist
if ( ! isset( $settings['key'] ) ) {
$settings['key'] = uniqid( '' );
}
// set a default value for the keepalive value
if ( ! isset( $settings['keepalive'] ) ) {
$settings['keepalive'] = bp_rbe_get_execution_time( 'minutes' );
}
bp_update_option( 'bp-rbe', $settings );
// remove remnants from any previous failed attempts to stop the inbox
bp_rbe_cleanup();
}
add_action( 'activate_' . basename( BP_RBE_DIR ) . '/loader.php', 'bp_rbe_activate' );
/**
* Remove our scheduled function from WP and stop the IMAP loop.
*/
function bp_rbe_deactivate() {
// stop IMAP connection if active
if ( bp_rbe_is_connected() ) {
bp_rbe_stop_imap();
// give plugin a chance to stop IMAP connection as it could be sleeping
sleep( 10 );
bp_rbe_log( 'Daisy, Daisy, give me your answer, do...' );
}
// remove remnants from any previous failed attempts to stop the inbox
bp_rbe_cleanup();
bp_rbe_log( 'Plugin deactivated!' );
}
add_action( 'deactivate_' . basename( BP_RBE_DIR ) . '/loader.php', 'bp_rbe_deactivate' );
/**
* BP Reply By Email default extensions.
*
* Currently supports BuddyPress Docs and bbPress
* More to come in the future?
*
* @since 1.0-RC1
* @since 1.0-RC6 Added BP Groupblog support.
*/
function bp_rbe_default_extensions() {
// if RBE requirements aren't fulfilled, stop now!
if ( ! bp_rbe_is_required_completed() )
return;
// BuddyPress Docs
if ( defined( 'BP_DOCS_VERSION' ) ) {
require( BP_RBE_DIR . '/includes/bp-rbe-extend-bpdocs.php' );
// initialize the BP Docs RBE extension!
new BP_Docs_Comment_RBE_Extension;
}
// bbPress
if ( function_exists( 'bbpress' ) ) {
require( BP_RBE_DIR . '/includes/bp-rbe-extend-bbpress.php' );
// initialize the bbPress RBE extension!
new BBP_RBE_Extension;
}
// BP Groupblog
if ( function_exists( 'bp_groupblog_format_activity_action_new_groupblog_comment' ) ) {
require BP_RBE_DIR . '/includes/bp-rbe-extend-bpgroupblog.php';
// initialize the BP Groupblog RBE extension!
new BP_Groupblog_Comment_RBE_Extension;
}
}
add_action( 'bp_include', 'bp_rbe_default_extensions', 20 );