forked from r-a-y/bp-reply-by-email
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader.php
114 lines (92 loc) · 2.67 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
<?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://buddypress.org/community/members/r-a-y/
Version: 1.0-beta1
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();
// generate a unique key if one doesn't exist
if ( !$settings['key'] )
$settings['key'] = uniqid( '' );
// set a default value for the keepalive value
if ( !$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();
}
register_activation_hook( __FILE__, '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!' );
}
register_deactivation_hook( __FILE__, 'bp_rbe_deactivate' );
/**
* BP Reply By Email default extensions.
*
* Currently supports BuddyPress Docs.
* More to come in the future?
*
* @since 1.0-beta2
*/
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;
}
}
add_action( 'bp_include', 'bp_rbe_default_extensions', 20 );
?>