-
Notifications
You must be signed in to change notification settings - Fork 0
/
bp-emails-for-bbp.php
150 lines (127 loc) · 3.9 KB
/
bp-emails-for-bbp.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
<?php
/**
* Plugin Name: BP Emails for BBP
* Plugin URI: https://github.com/thebrandonallen/bp-emails-for-bbp
* Description: Send bbPress forum and topic subscription emails using Buddypress' email API.
* Author: Brandon Allen
* Author URI: https://github.com/thebrandonallen
* Text Domain: bp-emails-for-bbp
* Domain Path: /languages
* Version: 0.2.3
*
* Copyright (C) 2016-2018 Brandon Allen (https://github.com/thebrandonallen)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* @package BP_Emails_For_BBP
*/
// Exit if access directly.
defined( 'ABSPATH' ) || exit;
/**
* Loads BP Emails for BBP if the minimum requirements are met.
*
* @since 0.2.0
*
* @return void
*/
function bp_emails_for_bbp_loader() {
load_plugin_textdomain( 'bp-emails-for-bbp' );
// Check for compatible versions of BuddyPress and bbPress.
if ( bpebbp_compatability_check() ) {
add_action( 'admin_notices', 'bpebbp_admin_notices' );
return;
}
// Include the necessary files.
bpebbp_includes();
// Initialize BP Emails for BBP.
BP_Emails_For_BBP::get_instance();
// Maybe load the admin.
bpebbp_load_admin();
}
add_action( 'plugins_loaded', 'bp_emails_for_bbp_loader', 20 );
/**
* Check if the current install meets the minimum requirements.
*
* @since 0.2.0
*
* @return array
*/
function bpebbp_compatability_check() {
static $errors;
if ( null !== $errors ) {
return $errors;
}
// Set some default variables.
$errors = array();
// Check for bbPress 2.5+.
if ( ! function_exists( 'bbp_get_version' ) || ! version_compare( bbp_get_version(), '2.5', '>=' ) ) {
$errors[] = esc_html__( 'You must be using bbPress 2.5 or greater.', 'bp-emails-for-bbp' );
}
// Check for BuddyPress 2.5+.
if ( ! function_exists( 'bp_send_email' ) ) {
$errors[] = esc_html__( 'You must be using BuddyPress 2.5 or greater.', 'bp-emails-for-bbp' );
}
return $errors;
}
/**
* Output admin notices.
*
* @since 0.2.0
*
* @return void
*/
function bpebbp_admin_notices() {
// Bail if there are no error messages.
$errors = bpebbp_compatability_check();
if ( ! $errors ) {
return;
}
// Bail if the user can't install plugins.
if ( ! current_user_can( 'install_plugins' ) ) {
return;
}
// Set up the message.
$messages = esc_html__( "Yikes! Looks like some things aren't right. You should deactivate BP Emails for BBP, or fix the following issues.", 'bp-emails-for-bbp' );
$messages .= ' <strong><em>' . implode( '</em></strong> <strong><em>', $errors ) . '</em></strong>';
// Output the message.
printf( '<div id="message" class="notice notice-error"><p>%s</p></div>', $messages );
}
/**
* Include our base files.
*
* @since 0.2.0
*/
function bpebbp_includes() {
$dir = dirname( __FILE__ );
require $dir . '/classes/class-bp-emails-for-bbp.php';
require $dir . '/classes/class-wp-async-task.php';
require $dir . '/classes/class-bpebbp-async-new-reply-email.php';
require $dir . '/classes/class-bpebbp-async-new-topic-email.php';
}
/**
* Conditionally loads the admin.
*
* @since 0.2.0
*
* @return void
*/
function bpebbp_load_admin() {
// Bail if we're not in the admin.
if ( ! is_admin() ) {
return;
}
require dirname( __FILE__ ) . '/classes/class-bpebbp-admin.php';
BPEBBP_Admin::get_instance();
}