Version Description
- 6th September 2016 =
- Fixed: Custom User Roles were showing 0 users in the 'To' field.
- Added: Generic CSS classes to BNFW admin.
- Updated: German Translation to show English in certain places where translation text breaks the WP Admin UI.
- Full code review and submission to WordPress VIP!
Download this release
Release Info
Developer | voltronik |
Plugin | Better Notifications for WordPress |
Version | 1.5.2 |
Comparing to | |
See all releases |
Code changes from version 1.5.1 to 1.5.2
- README.txt +8 -2
- assets/css/bnfw.css +16 -8
- bnfw.php +17 -3
- includes/admin/bnfw-settings.php +52 -45
- includes/admin/class-bnfw-notification.php +498 -425
- includes/engine/class-bnfw-engine.php +59 -31
- includes/helpers/ajax-helpers.php +7 -7
- includes/helpers/helpers.php +15 -6
- includes/import.php +24 -11
- includes/license/class-bnfw-license-setting.php +35 -34
- includes/license/class-bnfw-license.php +29 -19
- includes/overrides.php +17 -17
- includes/tmp.php +0 -43
- languages/bnfw-de_DE.po +1 -1
README.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: voltronik
|
|
3 |
Donate link: https://betternotificationsforwp.com/donate/
|
4 |
Tags: notifications, email, mail, alerts, roles, user, users, admin, HTML, plain, wp_mail, shortcode, customize, post, page, updated, pending review, scheduled, category, tag, term, custom post type, comment, akismet, trackback, pingback, lost password, welcome, new user, bulk, notice, trigger, CC, BCC, from, author
|
5 |
Requires at least: 3.5
|
6 |
-
Tested up to: 4.
|
7 |
-
Stable tag: 1.5.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -178,6 +178,12 @@ An older version might work but this is untested. A lot of the newer features re
|
|
178 |
|
179 |
== Changelog ==
|
180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
= 1.5.1 - 5th August July 2016 =
|
182 |
* Fixed: 'Text' mode in the WYSIWYG editor didn't show any buttons when the BNFW Per-post Override Add-on was activated.
|
183 |
|
3 |
Donate link: https://betternotificationsforwp.com/donate/
|
4 |
Tags: notifications, email, mail, alerts, roles, user, users, admin, HTML, plain, wp_mail, shortcode, customize, post, page, updated, pending review, scheduled, category, tag, term, custom post type, comment, akismet, trackback, pingback, lost password, welcome, new user, bulk, notice, trigger, CC, BCC, from, author
|
5 |
Requires at least: 3.5
|
6 |
+
Tested up to: 4.6
|
7 |
+
Stable tag: 1.5.2
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
178 |
|
179 |
== Changelog ==
|
180 |
|
181 |
+
= 1.5.2 - 6th September 2016 =
|
182 |
+
* Fixed: Custom User Roles were showing 0 users in the 'To' field.
|
183 |
+
* Added: Generic CSS classes to BNFW admin.
|
184 |
+
* Updated: German Translation to show English in certain places where translation text breaks the WP Admin UI.
|
185 |
+
* Full code review and submission to WordPress VIP!
|
186 |
+
|
187 |
= 1.5.1 - 5th August July 2016 =
|
188 |
* Fixed: 'Text' mode in the WYSIWYG editor didn't show any buttons when the BNFW Per-post Override Add-on was activated.
|
189 |
|
assets/css/bnfw.css
CHANGED
@@ -1,12 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
#user-password-msg {
|
2 |
display: none;
|
3 |
}
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
|
11 |
/* Fix 'jump' when hovering over 'x' in select2 box */
|
12 |
/*ul.select2-choices li.select2-search-choice a {
|
@@ -23,6 +31,6 @@
|
|
23 |
line-height: 0;
|
24 |
}
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
1 |
+
/* Generic classes */
|
2 |
+
.hidden {
|
3 |
+
display: none;
|
4 |
+
}
|
5 |
+
|
6 |
+
.show {
|
7 |
+
display: block;
|
8 |
+
}
|
9 |
+
|
10 |
#user-password-msg {
|
11 |
display: none;
|
12 |
}
|
13 |
|
14 |
+
#user-password-msg div {
|
15 |
+
background: #FFFFE1;
|
16 |
+
padding: 15px;
|
17 |
+
}
|
|
|
18 |
|
19 |
/* Fix 'jump' when hovering over 'x' in select2 box */
|
20 |
/*ul.select2-choices li.select2-search-choice a {
|
31 |
line-height: 0;
|
32 |
}
|
33 |
|
34 |
+
ul.select2-selection__rendered {
|
35 |
+
line-height: 1.3;
|
36 |
+
}
|
bnfw.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
* Plugin Name: Better Notifications for WordPress
|
4 |
* Plugin URI: https://wordpress.org/plugins/bnfw/
|
5 |
* Description: Send customisable emails to your users for different WordPress notifications.
|
6 |
-
* Version: 1.5.
|
7 |
* Author: Voltronik
|
8 |
* Author URI: https://betternotificationsforwp.com/
|
9 |
* Author Email: hello@betternotificationsforwp.com
|
@@ -188,7 +188,7 @@ class BNFW {
|
|
188 |
public function plugin_action_links( $links, $file ) {
|
189 |
$plugin_file = 'bnfw/bnfw.php';
|
190 |
if ( $file == $plugin_file ) {
|
191 |
-
$settings_link = '<a href="' . admin_url( 'edit.php?post_type=bnfw_notification&page=bnfw-settings' ) . '">' . 'Settings' . '</a>';
|
192 |
array_unshift( $links, $settings_link );
|
193 |
}
|
194 |
return $links;
|
@@ -345,7 +345,8 @@ class BNFW {
|
|
345 |
* @since 1.0
|
346 |
*/
|
347 |
function on_lost_password() {
|
348 |
-
$
|
|
|
349 |
if ( $user ) {
|
350 |
$this->send_notification( 'admin-password', $user->ID );
|
351 |
}
|
@@ -355,6 +356,12 @@ class BNFW {
|
|
355 |
* Change the title of the password reset email that is sent to the user.
|
356 |
*
|
357 |
* @since 1.1
|
|
|
|
|
|
|
|
|
|
|
|
|
358 |
*/
|
359 |
public function change_password_email_title( $title, $user_login = '', $user_data = '' ) {
|
360 |
$notifications = $this->notifier->get_notifications( 'user-password' );
|
@@ -378,6 +385,13 @@ class BNFW {
|
|
378 |
* Change the message of the password reset email.
|
379 |
*
|
380 |
* @since 1.1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
381 |
*/
|
382 |
public function change_password_email_message( $message, $key, $user_login = '', $user_data = '' ) {
|
383 |
$notifications = $this->notifier->get_notifications( 'user-password' );
|
3 |
* Plugin Name: Better Notifications for WordPress
|
4 |
* Plugin URI: https://wordpress.org/plugins/bnfw/
|
5 |
* Description: Send customisable emails to your users for different WordPress notifications.
|
6 |
+
* Version: 1.5.2
|
7 |
* Author: Voltronik
|
8 |
* Author URI: https://betternotificationsforwp.com/
|
9 |
* Author Email: hello@betternotificationsforwp.com
|
188 |
public function plugin_action_links( $links, $file ) {
|
189 |
$plugin_file = 'bnfw/bnfw.php';
|
190 |
if ( $file == $plugin_file ) {
|
191 |
+
$settings_link = '<a href="' . esc_url( admin_url( 'edit.php?post_type=bnfw_notification&page=bnfw-settings' ) ) . '">' . esc_html__( 'Settings', 'bnfw' ) . '</a>';
|
192 |
array_unshift( $links, $settings_link );
|
193 |
}
|
194 |
return $links;
|
345 |
* @since 1.0
|
346 |
*/
|
347 |
function on_lost_password() {
|
348 |
+
$user_login = sanitize_text_field( $_POST['user_login'] );
|
349 |
+
$user = get_user_by( 'login', $user_login );
|
350 |
if ( $user ) {
|
351 |
$this->send_notification( 'admin-password', $user->ID );
|
352 |
}
|
356 |
* Change the title of the password reset email that is sent to the user.
|
357 |
*
|
358 |
* @since 1.1
|
359 |
+
*
|
360 |
+
* @param string $title
|
361 |
+
* @param string $user_login
|
362 |
+
* @param string $user_data
|
363 |
+
*
|
364 |
+
* @return string
|
365 |
*/
|
366 |
public function change_password_email_title( $title, $user_login = '', $user_data = '' ) {
|
367 |
$notifications = $this->notifier->get_notifications( 'user-password' );
|
385 |
* Change the message of the password reset email.
|
386 |
*
|
387 |
* @since 1.1
|
388 |
+
*
|
389 |
+
* @param string $message
|
390 |
+
* @param string $key
|
391 |
+
* @param string $user_login
|
392 |
+
* @param string $user_data
|
393 |
+
*
|
394 |
+
* @return string
|
395 |
*/
|
396 |
public function change_password_email_message( $message, $key, $user_login = '', $user_data = '' ) {
|
397 |
$notifications = $this->notifier->get_notifications( 'user-password' );
|
includes/admin/bnfw-settings.php
CHANGED
@@ -11,13 +11,14 @@ function bnfw_admin_menu() {
|
|
11 |
// New Notifications Sub-menu
|
12 |
add_submenu_page(
|
13 |
'edit.php?post_type=bnfw_notification',
|
14 |
-
|
15 |
-
|
16 |
'manage_options',
|
17 |
'bnfw-settings',
|
18 |
'bnfw_settings_page'
|
19 |
);
|
20 |
}
|
|
|
21 |
// Add the Admin pages to the WordPress menu
|
22 |
add_action( 'admin_menu', 'bnfw_admin_menu' );
|
23 |
add_action( 'admin_menu', 'bnfw_menu_item_links', 12 );
|
@@ -33,22 +34,21 @@ add_action( 'admin_head', 'bnfw_menu_item_link_targets' );
|
|
33 |
function bnfw_settings_page() {
|
34 |
ob_start(); ?>
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
<h2><?php _e( 'BNFW Settings', 'bnfw' ); ?></h2>
|
39 |
|
40 |
-
|
41 |
<?php
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
|
46 |
-
|
47 |
?>
|
48 |
-
|
49 |
-
|
50 |
|
51 |
-
|
52 |
}
|
53 |
|
54 |
/**
|
@@ -75,25 +75,25 @@ function bnfw_menu_item_links() {
|
|
75 |
}
|
76 |
|
77 |
function bnfw_menu_item_link_targets() {
|
78 |
-
?>
|
79 |
<script type="text/javascript">
|
80 |
-
|
81 |
-
|
82 |
-
$('#bnfw-menu-item-documentation').parent().attr('target', '_blank');
|
83 |
-
$('#bnfw-menu-item-documentation').hover(function() {
|
84 |
-
$(this).css('color', '#a0e6f1');
|
85 |
-
}, function() {
|
86 |
-
$(this).css('color', '#73daeb');
|
87 |
-
});
|
88 |
|
89 |
// Add-ons Link
|
90 |
-
$('#bnfw-menu-item-addons').parent().attr('target', '_blank');
|
91 |
-
$('#bnfw-menu-item-addons').hover(function() {
|
92 |
-
$(this).css('color', '#ff9b8c');
|
93 |
-
}, function() {
|
94 |
-
$(this).css('color', '#ff6f59');
|
95 |
-
});
|
96 |
-
});
|
97 |
</script>
|
98 |
<?php }
|
99 |
|
@@ -122,12 +122,12 @@ function bnfw_general_options() {
|
|
122 |
// Suppress notifications for SPAM comments
|
123 |
add_settings_field(
|
124 |
'bnfw_suppress_spam', // Field ID
|
125 |
-
|
126 |
'bnfw_suppress_spam_checkbox', // Name of function that renders options on the page
|
127 |
'bnfw-settings', // Page to show on
|
128 |
'bnfw_general_options_section', // Associate with which settings section?
|
129 |
array(
|
130 |
-
|
131 |
)
|
132 |
);
|
133 |
|
@@ -140,16 +140,17 @@ function bnfw_general_options() {
|
|
140 |
// Suppress notifications for SPAM comments
|
141 |
add_settings_field(
|
142 |
'bnfw_email_format', // Field ID
|
143 |
-
|
144 |
'bnfw_email_format_radio', // Name of function that renders options on the page
|
145 |
'bnfw-settings', // Page to show on
|
146 |
'bnfw_general_options_section', // Associate with which settings section?
|
147 |
array(
|
148 |
-
|
149 |
)
|
150 |
);
|
151 |
|
152 |
}
|
|
|
153 |
add_action( 'admin_init', 'bnfw_general_options', 10 );
|
154 |
|
155 |
/* ------------------------------------------------------------------------ *
|
@@ -159,7 +160,8 @@ add_action( 'admin_init', 'bnfw_general_options', 10 );
|
|
159 |
/**
|
160 |
*
|
161 |
*/
|
162 |
-
function bnfw_general_options_callback() {
|
|
|
163 |
|
164 |
/* ------------------------------------------------------------------------ *
|
165 |
* Settings Page - Settings Field Callbacks
|
@@ -169,31 +171,36 @@ function bnfw_general_options_callback() {}
|
|
169 |
* Suppress SPAM checkbox.
|
170 |
*
|
171 |
* @since 1.0
|
172 |
-
*
|
|
|
173 |
*/
|
174 |
function bnfw_suppress_spam_checkbox( $args ) {
|
175 |
-
?>
|
176 |
-
|
177 |
-
|
178 |
-
|
|
|
179 |
}
|
180 |
|
181 |
/**
|
182 |
* Show email format radio
|
183 |
*
|
184 |
* @since 1.4
|
|
|
185 |
* @param array $args
|
186 |
*/
|
187 |
function bnfw_email_format_radio( $args ) {
|
188 |
$email_format = get_option( 'bnfw_email_format', 'html' );
|
189 |
-
?>
|
190 |
<label>
|
191 |
-
<input type="radio" value="html"
|
|
|
192 |
</label>
|
193 |
-
<br
|
194 |
<label>
|
195 |
-
<input type="radio" value="text"
|
|
|
196 |
</label>
|
197 |
-
<p><i><?php echo $args[0]; ?></i></p>
|
198 |
-
<?php
|
199 |
}
|
11 |
// New Notifications Sub-menu
|
12 |
add_submenu_page(
|
13 |
'edit.php?post_type=bnfw_notification',
|
14 |
+
esc_html__( 'Notification Settings', 'bnfw' ),
|
15 |
+
esc_html__( 'Settings', 'bnfw' ),
|
16 |
'manage_options',
|
17 |
'bnfw-settings',
|
18 |
'bnfw_settings_page'
|
19 |
);
|
20 |
}
|
21 |
+
|
22 |
// Add the Admin pages to the WordPress menu
|
23 |
add_action( 'admin_menu', 'bnfw_admin_menu' );
|
24 |
add_action( 'admin_menu', 'bnfw_menu_item_links', 12 );
|
34 |
function bnfw_settings_page() {
|
35 |
ob_start(); ?>
|
36 |
|
37 |
+
<div class="wrap">
|
38 |
+
<h2><?php esc_html_e( 'BNFW Settings', 'bnfw' ); ?></h2>
|
|
|
39 |
|
40 |
+
<form method="post" action="options.php" class="bnfw-form">
|
41 |
<?php
|
42 |
+
settings_errors();
|
43 |
+
settings_fields( 'bnfw-settings' );
|
44 |
+
do_settings_sections( 'bnfw-settings' );
|
45 |
|
46 |
+
submit_button( 'Save Settings' );
|
47 |
?>
|
48 |
+
</form>
|
49 |
+
</div>
|
50 |
|
51 |
+
<?php echo ob_get_clean();
|
52 |
}
|
53 |
|
54 |
/**
|
75 |
}
|
76 |
|
77 |
function bnfw_menu_item_link_targets() {
|
78 |
+
?>
|
79 |
<script type="text/javascript">
|
80 |
+
jQuery( document ).ready( function ( $ ) {
|
81 |
+
// Documentation Link
|
82 |
+
$( '#bnfw-menu-item-documentation' ).parent().attr( 'target', '_blank' );
|
83 |
+
$( '#bnfw-menu-item-documentation' ).hover( function () {
|
84 |
+
$( this ).css( 'color', '#a0e6f1' );
|
85 |
+
}, function () {
|
86 |
+
$( this ).css( 'color', '#73daeb' );
|
87 |
+
} );
|
88 |
|
89 |
// Add-ons Link
|
90 |
+
$( '#bnfw-menu-item-addons' ).parent().attr( 'target', '_blank' );
|
91 |
+
$( '#bnfw-menu-item-addons' ).hover( function () {
|
92 |
+
$( this ).css( 'color', '#ff9b8c' );
|
93 |
+
}, function () {
|
94 |
+
$( this ).css( 'color', '#ff6f59' );
|
95 |
+
} );
|
96 |
+
} );
|
97 |
</script>
|
98 |
<?php }
|
99 |
|
122 |
// Suppress notifications for SPAM comments
|
123 |
add_settings_field(
|
124 |
'bnfw_suppress_spam', // Field ID
|
125 |
+
esc_html__( 'Suppress SPAM comment notification', 'bnfw' ), // Label to the left
|
126 |
'bnfw_suppress_spam_checkbox', // Name of function that renders options on the page
|
127 |
'bnfw-settings', // Page to show on
|
128 |
'bnfw_general_options_section', // Associate with which settings section?
|
129 |
array(
|
130 |
+
esc_html__( "Don't send notifications for comments marked as SPAM by Akismet", 'bnfw' )
|
131 |
)
|
132 |
);
|
133 |
|
140 |
// Suppress notifications for SPAM comments
|
141 |
add_settings_field(
|
142 |
'bnfw_email_format', // Field ID
|
143 |
+
esc_html__( 'Default Email Format', 'bnfw' ), // Label to the left
|
144 |
'bnfw_email_format_radio', // Name of function that renders options on the page
|
145 |
'bnfw-settings', // Page to show on
|
146 |
'bnfw_general_options_section', // Associate with which settings section?
|
147 |
array(
|
148 |
+
esc_html__( 'This will apply to all emails sent out via WordPress, even those from other plugins. For more details, please see the ', 'bnfw' ) . '<a href="https://wordpress.org/plugins/bnfw/faq/" target="_blank">FAQ</a>.'
|
149 |
)
|
150 |
);
|
151 |
|
152 |
}
|
153 |
+
|
154 |
add_action( 'admin_init', 'bnfw_general_options', 10 );
|
155 |
|
156 |
/* ------------------------------------------------------------------------ *
|
160 |
/**
|
161 |
*
|
162 |
*/
|
163 |
+
function bnfw_general_options_callback() {
|
164 |
+
}
|
165 |
|
166 |
/* ------------------------------------------------------------------------ *
|
167 |
* Settings Page - Settings Field Callbacks
|
171 |
* Suppress SPAM checkbox.
|
172 |
*
|
173 |
* @since 1.0
|
174 |
+
*
|
175 |
+
* @param $args
|
176 |
*/
|
177 |
function bnfw_suppress_spam_checkbox( $args ) {
|
178 |
+
?>
|
179 |
+
<input type="checkbox" id="bnfw_suppress_spam" name="bnfw_suppress_spam"
|
180 |
+
value="1" <?php checked( 1, get_option( 'bnfw_suppress_spam' ), true ); ?>>
|
181 |
+
<label for="bnfw_suppress_spam"><?php echo esc_html( $args[0] ); ?></label>
|
182 |
+
<?php
|
183 |
}
|
184 |
|
185 |
/**
|
186 |
* Show email format radio
|
187 |
*
|
188 |
* @since 1.4
|
189 |
+
*
|
190 |
* @param array $args
|
191 |
*/
|
192 |
function bnfw_email_format_radio( $args ) {
|
193 |
$email_format = get_option( 'bnfw_email_format', 'html' );
|
194 |
+
?>
|
195 |
<label>
|
196 |
+
<input type="radio" value="html"
|
197 |
+
name="bnfw_email_format" <?php checked( $email_format, 'html', true ); ?>><?php esc_html_e( 'HTML Formatting', 'bnfw' ); ?>
|
198 |
</label>
|
199 |
+
<br/>
|
200 |
<label>
|
201 |
+
<input type="radio" value="text"
|
202 |
+
name="bnfw_email_format" <?php checked( $email_format, 'text', true ); ?>><?php esc_html_e( 'Plain Text', 'bnfw' ); ?>
|
203 |
</label>
|
204 |
+
<p><i><?php echo esc_html( $args[0] ); ?></i></p>
|
205 |
+
<?php
|
206 |
}
|
includes/admin/class-bnfw-notification.php
CHANGED
@@ -1,21 +1,20 @@
|
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
* BNFW Notification.
|
4 |
*
|
5 |
* @since 1.0
|
6 |
*/
|
7 |
-
|
8 |
class BNFW_Notification {
|
9 |
|
10 |
-
const POST_TYPE
|
11 |
const META_KEY_PREFIX = 'bnfw_';
|
12 |
-
const TEST_MAIL_ARG
|
13 |
|
14 |
/**
|
15 |
*
|
16 |
*/
|
17 |
public function __construct() {
|
18 |
-
|
19 |
add_action( 'init', array( $this, 'register_post_type' ) );
|
20 |
add_action( 'do_meta_boxes', array( $this, 'remove_meta_boxes' ) );
|
21 |
add_action( 'add_meta_boxes_' . self::POST_TYPE, array( $this, 'add_meta_boxes' ) );
|
@@ -41,62 +40,62 @@ class BNFW_Notification {
|
|
41 |
*/
|
42 |
public function register_post_type() {
|
43 |
register_post_type( self::POST_TYPE, array(
|
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 |
/**
|
@@ -137,252 +136,298 @@ class BNFW_Notification {
|
|
137 |
* Render the settings meta box.
|
138 |
*
|
139 |
* @since 1.0
|
140 |
-
*
|
|
|
141 |
*/
|
142 |
public function render_settings_meta_box( $post ) {
|
143 |
-
wp_nonce_field(
|
144 |
-
// Action
|
145 |
-
self::POST_TYPE,
|
146 |
-
// Name.
|
147 |
-
self::POST_TYPE . '_nonce'
|
148 |
-
);
|
149 |
|
150 |
$setting = $this->read_settings( $post->ID );
|
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 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
<?php
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
<?php
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
223 |
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
?>
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
?>
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
263 |
|
264 |
-
<label>
|
265 |
-
<input type="radio" name="email-formatting" value="text" <?php checked( 'text', $setting['email-formatting'] ); ?>>
|
266 |
-
<?php esc_html_e( 'Plain Text', 'bnfw' ); ?>
|
267 |
-
</label>
|
268 |
-
</td>
|
269 |
-
</tr>
|
270 |
-
|
271 |
-
<tr valign="top" id="toggle-fields">
|
272 |
-
<th>
|
273 |
-
<?php esc_attr_e( 'Additional Email Fields', 'bnfw' ); ?>
|
274 |
-
</th>
|
275 |
-
<td>
|
276 |
-
<input type="checkbox" id="show-fields" name="show-fields" value="true" <?php checked( $setting['show-fields'], 'true', true ); ?>>
|
277 |
-
<label for="show-fields"><?php esc_html_e( 'Set "From" Name & Email, CC, BCC', 'bnfw' ); ?></label>
|
278 |
-
</td>
|
279 |
-
</tr>
|
280 |
-
|
281 |
-
<tr valign="top" id="email">
|
282 |
-
<th scope="row">
|
283 |
-
<?php _e( 'From Name and Email', 'bnfw' ); ?>
|
284 |
-
</th>
|
285 |
-
<td>
|
286 |
-
<input type="text" name="from-name" value="<?php echo $setting['from-name']; ?>" placeholder="Site Name" style="width: 37.35%">
|
287 |
-
<input type="email" name="from-email" value="<?php echo $setting['from-email']; ?>" placeholder="Admin Email" style="width: 37.3%">
|
288 |
-
</td>
|
289 |
-
</tr>
|
290 |
-
|
291 |
-
<tr valign="top" id="cc">
|
292 |
-
<th scope="row">
|
293 |
-
<?php _e( 'CC', 'bnfw' ); ?>
|
294 |
-
</th>
|
295 |
-
|
296 |
-
<td>
|
297 |
-
<select multiple name="cc[]" class="<?php echo bnfw_get_user_select_class(); ?>" data-placeholder="Select User Roles / Users" style="width:75%">
|
298 |
-
<?php bnfw_render_users_dropdown( $setting['cc'] ); ?>
|
299 |
-
</select>
|
300 |
-
</td>
|
301 |
-
</tr>
|
302 |
-
|
303 |
-
<tr valign="top" id="bcc">
|
304 |
-
<th scope="row">
|
305 |
-
<?php _e( 'BCC', 'bnfw' ); ?>
|
306 |
-
</th>
|
307 |
-
|
308 |
-
<td>
|
309 |
-
<select multiple name="bcc[]" class="<?php echo bnfw_get_user_select_class(); ?>" data-placeholder="Select User Roles / Users" style="width:75%">
|
310 |
-
<?php bnfw_render_users_dropdown( $setting['bcc'] ); ?>
|
311 |
-
</select>
|
312 |
-
</td>
|
313 |
-
</tr>
|
314 |
-
|
315 |
-
<tr valign="top" id="post-author">
|
316 |
-
<th> </th>
|
317 |
-
<td>
|
318 |
-
<label>
|
319 |
-
<input type="checkbox" id="only-post-author" name="only-post-author" value="true" <?php checked( 'true', $setting['only-post-author'] ); ?>>
|
320 |
-
<?php _e( 'Send this notification to the Author only', 'bnfw' ); ?>
|
321 |
-
</label>
|
322 |
-
</td>
|
323 |
-
</tr>
|
324 |
-
|
325 |
-
<tr valign="top" id="users">
|
326 |
-
<th scope="row">
|
327 |
-
<?php _e( 'Send To', 'bnfw' ); ?>
|
328 |
-
</th>
|
329 |
-
<td>
|
330 |
-
<select multiple id="users-select" name="users[]" class="<?php echo bnfw_get_user_select_class(); ?>" data-placeholder="Select User Roles / Users" style="width:75%">
|
331 |
-
<?php bnfw_render_users_dropdown( $setting['users'] ); ?>
|
332 |
-
</select>
|
333 |
-
</td>
|
334 |
-
</tr>
|
335 |
-
|
336 |
-
<tr valign="top" id="current-user">
|
337 |
-
<th> </th>
|
338 |
-
<td>
|
339 |
-
<label>
|
340 |
-
<input type="checkbox" name="disable-current-user" value="true" <?php checked( 'true', $setting['disable-current-user'] ); ?>>
|
341 |
-
<?php _e( 'Disable this Notification for the User that triggered it', 'bnfw' ); ?>
|
342 |
-
</label>
|
343 |
-
</td>
|
344 |
-
</tr>
|
345 |
-
|
346 |
-
<tr valign="top">
|
347 |
-
<th scope="row">
|
348 |
-
<?php _e( 'Subject', 'bnfw' ); ?>
|
349 |
-
</th>
|
350 |
-
<td>
|
351 |
-
<input type="text" name="subject" value="<?php echo esc_attr( $setting['subject'] ); ?>" style="width:75%;">
|
352 |
-
</td>
|
353 |
-
</tr>
|
354 |
-
|
355 |
-
<tr valign="top">
|
356 |
-
<th scope="row">
|
357 |
-
<?php _e( 'Message Body', 'bnfw' ); ?>
|
358 |
-
<div class="wp-ui-text-highlight">
|
359 |
-
<p>
|
360 |
-
<br />
|
361 |
-
<span class="dashicons dashicons-editor-help"></span> <?php _e( 'Need some help?', 'bnfw' ); ?>
|
362 |
-
</p>
|
363 |
-
<p>
|
364 |
-
<a href="https://betternotificationsforwp.com/documentation/?utm_source=WP%20Admin%20Notification%20Editor%20-%20'Documentation'&utm_medium=referral" target="_blank" class="button-secondary"><?php _e( 'Documentation', 'bnfw' ); ?></a>
|
365 |
-
</p>
|
366 |
-
<p>
|
367 |
-
<a href="" target="_blank" id="shortcode-help" class="button-secondary"><?php _e( 'Shortcode Help', 'bnfw' ); ?></a>
|
368 |
-
</p>
|
369 |
-
</div>
|
370 |
-
</th>
|
371 |
-
<td>
|
372 |
-
<?php wp_editor( $setting['message'], 'notification_message', array( 'media_buttons' => true ) ); ?>
|
373 |
-
<p> </p>
|
374 |
-
<div id="disable-autop">
|
375 |
<label>
|
376 |
-
<input type="
|
377 |
-
|
|
|
378 |
</label>
|
379 |
-
</
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
386 |
}
|
387 |
|
388 |
/**
|
@@ -424,7 +469,7 @@ class BNFW_Notification {
|
|
424 |
wp_enqueue_style( 'bnfw', plugins_url( '../assets/css/bnfw.css', dirname( __FILE__ ) ), array( 'dashicons', 'select2' ), '0.1' );
|
425 |
|
426 |
$strings = array(
|
427 |
-
'empty_user' =>
|
428 |
);
|
429 |
|
430 |
wp_localize_script( 'bnfw', 'BNFW', $strings );
|
@@ -434,7 +479,8 @@ class BNFW_Notification {
|
|
434 |
* Save the meta box's post metadata.
|
435 |
*
|
436 |
* @since 1.0
|
437 |
-
*
|
|
|
438 |
*/
|
439 |
public function save_meta_data( $post_id ) {
|
440 |
if ( self::POST_TYPE !== get_post_type( $post_id ) ) {
|
@@ -460,8 +506,8 @@ class BNFW_Notification {
|
|
460 |
}
|
461 |
|
462 |
$setting = array(
|
463 |
-
'notification' => $_POST['notification'],
|
464 |
-
'subject' => $_POST['subject'],
|
465 |
'message' => $_POST['notification_message'],
|
466 |
'disabled' => isset( $_POST['disabled'] ) ? sanitize_text_field( $_POST['disabled'] ) : 'false',
|
467 |
'email-formatting' => isset( $_POST['email-formatting'] ) ? sanitize_text_field( $_POST['email-formatting'] ) : 'html',
|
@@ -472,15 +518,15 @@ class BNFW_Notification {
|
|
472 |
);
|
473 |
|
474 |
if ( isset( $_POST['users'] ) ) {
|
475 |
-
$setting['users'] = $_POST['users'];
|
476 |
}
|
477 |
|
478 |
if ( isset( $_POST['show-fields'] ) && 'true' == $_POST['show-fields'] ) {
|
479 |
$setting['show-fields'] = 'true';
|
480 |
$setting['from-name'] = sanitize_text_field( $_POST['from-name'] );
|
481 |
$setting['from-email'] = sanitize_email( $_POST['from-email'] );
|
482 |
-
$setting['cc'] = isset( $_POST['cc'] ) ? $_POST['cc'] : '';
|
483 |
-
$setting['bcc'] = isset( $_POST['bcc'] ) ? $_POST['bcc'] : '';
|
484 |
} else {
|
485 |
$setting['show-fields'] = 'false';
|
486 |
}
|
@@ -490,7 +536,7 @@ class BNFW_Notification {
|
|
490 |
$this->save_settings( $post_id, $setting );
|
491 |
|
492 |
if ( isset( $_POST['send-test-email'] ) ) {
|
493 |
-
if ( 'true' == $_POST['send-test-email'] ) {
|
494 |
BNFW::factory()->engine->send_test_email( $setting );
|
495 |
add_filter( 'redirect_post_location', array( $this, 'test_mail_sent' ) );
|
496 |
}
|
@@ -512,25 +558,26 @@ class BNFW_Notification {
|
|
512 |
* @since 1.3
|
513 |
*/
|
514 |
public function admin_notices() {
|
515 |
-
if ( isset( $_GET[self::TEST_MAIL_ARG ] ) ) {
|
516 |
-
|
517 |
-
|
518 |
-
?>
|
519 |
<div class="updated below-h2">
|
520 |
-
<p><?php echo
|
521 |
</div>
|
522 |
-
<?php
|
523 |
-
|
524 |
-
|
525 |
}
|
526 |
|
527 |
/**
|
528 |
* Save settings in post meta.
|
529 |
*
|
530 |
-
* @since
|
531 |
* @access private
|
532 |
-
*
|
533 |
-
* @param
|
|
|
534 |
*/
|
535 |
private function save_settings( $post_id, $setting ) {
|
536 |
foreach ( $setting as $key => $value ) {
|
@@ -542,7 +589,9 @@ class BNFW_Notification {
|
|
542 |
* Read settings from post meta.
|
543 |
*
|
544 |
* @since 1.0
|
|
|
545 |
* @param int $post_id
|
|
|
546 |
* @return array
|
547 |
*/
|
548 |
public function read_settings( $post_id ) {
|
@@ -587,6 +636,7 @@ class BNFW_Notification {
|
|
587 |
}
|
588 |
|
589 |
$setting['id'] = $post_id;
|
|
|
590 |
return $setting;
|
591 |
}
|
592 |
|
@@ -594,11 +644,13 @@ class BNFW_Notification {
|
|
594 |
* Change the post updated message for notification post type.
|
595 |
*
|
596 |
* @since 1.0
|
597 |
-
*
|
598 |
-
* @
|
|
|
|
|
599 |
*/
|
600 |
public function post_updated_messages( $messages ) {
|
601 |
-
$messages[ self::POST_TYPE ] = array_fill( 0, 11,
|
602 |
|
603 |
return $messages;
|
604 |
}
|
@@ -607,74 +659,82 @@ class BNFW_Notification {
|
|
607 |
* Render submit div meta box.
|
608 |
*
|
609 |
* @since 1.0
|
610 |
-
*
|
|
|
611 |
*/
|
612 |
public function render_submitdiv( $post ) {
|
613 |
global $post;
|
614 |
-
?>
|
615 |
-
<div class="submitbox" id="submitpost">
|
616 |
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
|
626 |
-
<?php
|
627 |
-
|
628 |
-
?>
|
629 |
-
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
|
|
|
|
|
|
|
|
|
|
670 |
}
|
671 |
|
672 |
/**
|
673 |
* Get notifications based on type.
|
674 |
*
|
675 |
* @since 1.0
|
|
|
676 |
* @param array|string $types
|
677 |
-
* @param bool
|
|
|
678 |
* @return array WP_Post objects
|
679 |
*/
|
680 |
public function get_notifications( $types, $exclude_disabled = true ) {
|
@@ -683,7 +743,7 @@ class BNFW_Notification {
|
|
683 |
}
|
684 |
|
685 |
$args = array(
|
686 |
-
'post_type'
|
687 |
'meta_query' => array(
|
688 |
array(
|
689 |
'key' => self::META_KEY_PREFIX . 'notification',
|
@@ -702,7 +762,8 @@ class BNFW_Notification {
|
|
702 |
}
|
703 |
|
704 |
$wp_query = new WP_Query();
|
705 |
-
$posts
|
|
|
706 |
return $posts;
|
707 |
}
|
708 |
|
@@ -711,8 +772,9 @@ class BNFW_Notification {
|
|
711 |
*
|
712 |
* @since 1.1
|
713 |
*
|
714 |
-
* @param string $type
|
715 |
-
* @param bool
|
|
|
716 |
* @return bool True if present, False otherwise
|
717 |
*/
|
718 |
public function notification_exists( $type, $exclude_disabled = true ) {
|
@@ -728,16 +790,18 @@ class BNFW_Notification {
|
|
728 |
/**
|
729 |
* Custom columns for this post type.
|
730 |
*
|
731 |
-
* @since
|
732 |
* @filter manage_{post_type}_posts_columns
|
733 |
-
*
|
|
|
|
|
734 |
* @return array
|
735 |
*/
|
736 |
public function columns_header( $columns ) {
|
737 |
-
$columns['type'] =
|
738 |
-
$columns['disabled'] =
|
739 |
-
$columns['subject'] =
|
740 |
-
$columns['users'] =
|
741 |
|
742 |
return $columns;
|
743 |
}
|
@@ -745,17 +809,18 @@ class BNFW_Notification {
|
|
745 |
/**
|
746 |
* Custom column appears in each row.
|
747 |
*
|
748 |
-
* @since
|
749 |
* @action manage_{post_type}_posts_custom_column
|
750 |
-
*
|
751 |
-
* @param
|
|
|
752 |
*/
|
753 |
public function custom_column_row( $column, $post_id ) {
|
754 |
$setting = $this->read_settings( $post_id );
|
755 |
switch ( $column ) {
|
756 |
case 'disabled':
|
757 |
if ( 'true' != $setting['disabled'] ) {
|
758 |
-
printf('<span class="dashicons dashicons-yes"></span>');
|
759 |
}
|
760 |
break;
|
761 |
case 'type':
|
@@ -766,7 +831,7 @@ class BNFW_Notification {
|
|
766 |
break;
|
767 |
case 'users':
|
768 |
if ( 'true' === $setting['only-post-author'] ) {
|
769 |
-
echo
|
770 |
} else {
|
771 |
$users = $this->get_names_from_users( $setting['users'] );
|
772 |
echo implode( ', ', $users );
|
@@ -779,8 +844,8 @@ class BNFW_Notification {
|
|
779 |
*
|
780 |
* @since 1.3.9
|
781 |
*
|
782 |
-
* @param string
|
783 |
-
* @param int
|
784 |
*/
|
785 |
do_action( 'bnfw_notification_table_column', $column, $post_id );
|
786 |
}
|
@@ -791,9 +856,9 @@ class BNFW_Notification {
|
|
791 |
* @since 1.2
|
792 |
*/
|
793 |
private function get_names_from_users( $users ) {
|
794 |
-
$email_list
|
795 |
-
$user_ids
|
796 |
-
$user_roles
|
797 |
$names_from_user_ids = array();
|
798 |
|
799 |
foreach ( $users as $user ) {
|
@@ -817,66 +882,67 @@ class BNFW_Notification {
|
|
817 |
/**
|
818 |
* Get name of the notification based on slug.
|
819 |
*
|
820 |
-
* @param mixed
|
|
|
821 |
* @return unknown
|
822 |
*/
|
823 |
private function get_notifications_name( $slug ) {
|
824 |
$name = '';
|
825 |
switch ( $slug ) {
|
826 |
case 'new-comment':
|
827 |
-
$name =
|
828 |
break;
|
829 |
case 'new-trackback':
|
830 |
-
$name =
|
831 |
break;
|
832 |
case 'new-pingback':
|
833 |
-
$name =
|
834 |
break;
|
835 |
case 'reply-comment':
|
836 |
-
$name =
|
837 |
break;
|
838 |
case 'user-password':
|
839 |
-
$name =
|
840 |
break;
|
841 |
case 'admin-password':
|
842 |
-
$name =
|
843 |
break;
|
844 |
case 'new-user':
|
845 |
-
$name =
|
846 |
break;
|
847 |
case 'welcome-email':
|
848 |
-
$name =
|
849 |
break;
|
850 |
case 'admin-user':
|
851 |
-
$name =
|
852 |
break;
|
853 |
case 'user-role':
|
854 |
-
$name =
|
855 |
break;
|
856 |
case 'admin-role':
|
857 |
-
$name =
|
858 |
break;
|
859 |
case 'new-post':
|
860 |
-
$name =
|
861 |
break;
|
862 |
case 'update-post':
|
863 |
-
$name =
|
864 |
break;
|
865 |
case 'pending-post':
|
866 |
-
$name =
|
867 |
break;
|
868 |
case 'future-post':
|
869 |
-
$name =
|
870 |
break;
|
871 |
case 'newterm-category':
|
872 |
-
$name =
|
873 |
break;
|
874 |
case 'newterm-post_tag':
|
875 |
-
$name =
|
876 |
break;
|
877 |
default:
|
878 |
-
$splited
|
879 |
-
$label
|
880 |
$post_obj = get_post_type_object( $splited[1] );
|
881 |
|
882 |
if ( null != $post_obj ) {
|
@@ -885,29 +951,29 @@ class BNFW_Notification {
|
|
885 |
|
886 |
switch ( $splited[0] ) {
|
887 |
case 'new':
|
888 |
-
$name =
|
889 |
break;
|
890 |
case 'update':
|
891 |
-
$name =
|
892 |
break;
|
893 |
case 'pending':
|
894 |
-
$name = $label .
|
895 |
break;
|
896 |
case 'future':
|
897 |
-
$name = $label .
|
898 |
break;
|
899 |
case 'comment':
|
900 |
-
$name = $label .
|
901 |
break;
|
902 |
case 'commentreply':
|
903 |
-
$name = $label .
|
904 |
break;
|
905 |
case 'newterm':
|
906 |
$tax = get_taxonomy( $splited[1] );
|
907 |
if ( ! $tax ) {
|
908 |
-
$name =
|
909 |
} else {
|
910 |
-
$name =
|
911 |
}
|
912 |
break;
|
913 |
}
|
@@ -922,9 +988,11 @@ class BNFW_Notification {
|
|
922 |
/**
|
923 |
* Custom row actions for this post type.
|
924 |
*
|
925 |
-
* @since
|
926 |
* @filter post_row_actions
|
927 |
-
*
|
|
|
|
|
928 |
* @return array
|
929 |
*/
|
930 |
public function custom_row_actions( $actions ) {
|
@@ -942,9 +1010,14 @@ class BNFW_Notification {
|
|
942 |
* Find if a string starts with another string.
|
943 |
*
|
944 |
* @since 1.2
|
|
|
|
|
|
|
|
|
|
|
945 |
*/
|
946 |
public function starts_with( $haystack, $needle ) {
|
947 |
// search backwards starting from haystack length characters from the end
|
948 |
-
return '' === $needle || strrpos( $haystack, $needle, -strlen( $haystack ) ) !== false;
|
949 |
}
|
950 |
}
|
1 |
<?php
|
2 |
+
|
3 |
/**
|
4 |
* BNFW Notification.
|
5 |
*
|
6 |
* @since 1.0
|
7 |
*/
|
|
|
8 |
class BNFW_Notification {
|
9 |
|
10 |
+
const POST_TYPE = 'bnfw_notification';
|
11 |
const META_KEY_PREFIX = 'bnfw_';
|
12 |
+
const TEST_MAIL_ARG = 'test-mail';
|
13 |
|
14 |
/**
|
15 |
*
|
16 |
*/
|
17 |
public function __construct() {
|
|
|
18 |
add_action( 'init', array( $this, 'register_post_type' ) );
|
19 |
add_action( 'do_meta_boxes', array( $this, 'remove_meta_boxes' ) );
|
20 |
add_action( 'add_meta_boxes_' . self::POST_TYPE, array( $this, 'add_meta_boxes' ) );
|
40 |
*/
|
41 |
public function register_post_type() {
|
42 |
register_post_type( self::POST_TYPE, array(
|
43 |
+
'labels' => array(
|
44 |
+
'name' => esc_html__( 'Notifications', 'bnfw' ),
|
45 |
+
'singular_name' => esc_html__( 'Notification', 'bnfw' ),
|
46 |
+
'add_new' => esc_html__( 'Add New', 'bnfw' ),
|
47 |
+
'menu_name' => esc_html__( 'Notifications', 'bnfw' ),
|
48 |
+
'name_admin_bar' => esc_html__( 'Notifications', 'bnfw' ),
|
49 |
+
'add_new_item' => esc_html__( 'Add New Notification', 'bnfw' ),
|
50 |
+
'edit_item' => esc_html__( 'Edit Notification', 'bnfw' ),
|
51 |
+
'new_item' => esc_html__( 'New Notification', 'bnfw' ),
|
52 |
+
'view_item' => esc_html__( 'View Notification', 'bnfw' ),
|
53 |
+
'search_items' => esc_html__( 'Search Notifications', 'bnfw' ),
|
54 |
+
'not_found' => esc_html__( 'No Notifications found', 'bnfw' ),
|
55 |
+
'not_found_in_trash' => esc_html__( 'No Notifications found in trash', 'bnfw' ),
|
56 |
+
'all_items' => esc_html__( 'All Notifications', 'bnfw' )
|
57 |
+
),
|
58 |
+
'public' => false,
|
59 |
+
'show_in_nav_menus' => true,
|
60 |
+
'show_in_admin_bar' => true,
|
61 |
+
'has_archive' => false,
|
62 |
+
'show_ui' => true,
|
63 |
+
'show_in_menu' => true,
|
64 |
+
'menu_icon' => 'dashicons-email-alt',
|
65 |
+
'menu_position' => 100,
|
66 |
+
'rewrite' => false,
|
67 |
+
'map_meta_cap' => false,
|
68 |
+
'capabilities' => array(
|
69 |
+
|
70 |
+
// meta caps (don't assign these to roles)
|
71 |
+
'edit_post' => 'manage_options',
|
72 |
+
'read_post' => 'manage_options',
|
73 |
+
'delete_post' => 'manage_options',
|
74 |
+
|
75 |
+
// primitive/meta caps
|
76 |
+
'create_posts' => 'manage_options',
|
77 |
+
|
78 |
+
// primitive caps used outside of map_meta_cap()
|
79 |
+
'edit_posts' => 'manage_options',
|
80 |
+
'edit_others_posts' => 'manage_options',
|
81 |
+
'publish_posts' => 'manage_options',
|
82 |
+
'read_private_posts' => 'manage_options',
|
83 |
+
|
84 |
+
// primitive caps used inside of map_meta_cap()
|
85 |
+
'read' => 'manage_options',
|
86 |
+
'delete_posts' => 'manage_options',
|
87 |
+
'delete_private_posts' => 'manage_options',
|
88 |
+
'delete_published_posts' => 'manage_options',
|
89 |
+
'delete_others_posts' => 'manage_options',
|
90 |
+
'edit_private_posts' => 'manage_options',
|
91 |
+
'edit_published_posts' => 'manage_options',
|
92 |
+
),
|
93 |
|
94 |
+
// What features the post type supports.
|
95 |
+
'supports' => array(
|
96 |
+
'title',
|
97 |
+
),
|
98 |
+
) );
|
99 |
}
|
100 |
|
101 |
/**
|
136 |
* Render the settings meta box.
|
137 |
*
|
138 |
* @since 1.0
|
139 |
+
*
|
140 |
+
* @param WP_Post $post
|
141 |
*/
|
142 |
public function render_settings_meta_box( $post ) {
|
143 |
+
wp_nonce_field( self::POST_TYPE, self::POST_TYPE . '_nonce' );
|
|
|
|
|
|
|
|
|
|
|
144 |
|
145 |
$setting = $this->read_settings( $post->ID );
|
146 |
+
?>
|
147 |
+
<table class="form-table">
|
148 |
+
<tbody>
|
149 |
+
<tr valign="top">
|
150 |
+
<th scope="row">
|
151 |
+
<label for="notification"><?php esc_html_e( 'Notification For', 'bnfw' ); ?></label>
|
152 |
+
</th>
|
153 |
+
<td>
|
154 |
+
<select name="notification" id="notification" class="select2"
|
155 |
+
data-placeholder="Select the notification type" style="width:75%">
|
156 |
+
<optgroup label="WordPress Defaults">
|
157 |
+
<option
|
158 |
+
value="new-comment" <?php selected( 'new-comment', $setting['notification'] ); ?>><?php esc_html_e( 'New Comment / Awaiting Moderation', 'bnfw' ); ?></option>
|
159 |
+
<option
|
160 |
+
value="new-trackback" <?php selected( 'new-trackback', $setting['notification'] ); ?>><?php esc_html_e( 'New Trackback', 'bnfw' ); ?></option>
|
161 |
+
<option
|
162 |
+
value="new-pingback" <?php selected( 'new-pingback', $setting['notification'] ); ?>><?php esc_html_e( 'New Pingback', 'bnfw' ); ?></option>
|
163 |
+
<option
|
164 |
+
value="admin-password" <?php selected( 'admin-password', $setting['notification'] ); ?>><?php esc_html_e( 'Lost Password - For Admin', 'bnfw' ); ?></option>
|
165 |
+
<option
|
166 |
+
value="admin-user" <?php selected( 'admin-user', $setting['notification'] ); ?>><?php esc_html_e( 'New User Registration - For Admin', 'bnfw' ); ?></option>
|
167 |
+
</optgroup>
|
168 |
+
<optgroup label="Transactional">
|
169 |
+
<option
|
170 |
+
value="user-password" <?php selected( 'user-password', $setting['notification'] ); ?>><?php esc_html_e( 'Lost Password - For User', 'bnfw' ); ?></option>
|
171 |
+
<option
|
172 |
+
value="new-user" <?php selected( 'new-user', $setting['notification'] ); ?>><?php esc_html_e( 'New User Registration - For User', 'bnfw' ); ?></option>
|
173 |
+
<option
|
174 |
+
value="welcome-email" <?php selected( 'welcome-email', $setting['notification'] ); ?>><?php esc_html_e( 'New User - Post-registration Email', 'bnfw' ); ?></option>
|
175 |
+
<option
|
176 |
+
value="admin-role" <?php selected( 'admin-role', $setting['notification'] ); ?>><?php esc_html_e( 'User Role Changed - For Admin', 'bnfw' ); ?></option>
|
177 |
+
<option
|
178 |
+
value="user-role" <?php selected( 'user-role', $setting['notification'] ); ?>><?php esc_html_e( 'User Role Changed - For User', 'bnfw' ); ?></option>
|
179 |
+
<option
|
180 |
+
value="reply-comment" <?php selected( 'reply-comment', $setting['notification'] ); ?>><?php esc_html_e( 'Comment Reply', 'bnfw' ); ?></option>
|
181 |
+
</optgroup>
|
182 |
+
<optgroup label="Posts">
|
183 |
+
<option
|
184 |
+
value="new-post" <?php selected( 'new-post', $setting['notification'] ); ?>><?php esc_html_e( 'New Post Published', 'bnfw' ); ?></option>
|
185 |
+
<option
|
186 |
+
value="update-post" <?php selected( 'update-post', $setting['notification'] ); ?>><?php esc_html_e( 'Post Updated', 'bnfw' ); ?></option>
|
187 |
+
<option
|
188 |
+
value="pending-post" <?php selected( 'pending-post', $setting['notification'] ); ?>><?php esc_html_e( 'Post Pending Review', 'bnfw' ); ?></option>
|
189 |
+
<option
|
190 |
+
value="future-post" <?php selected( 'future-post', $setting['notification'] ); ?>><?php esc_html_e( 'Post Scheduled', 'bnfw' ); ?></option>
|
191 |
+
<option
|
192 |
+
value="newterm-category" <?php selected( 'newterm-category', $setting['notification'] ); ?>><?php esc_html_e( 'New Category', 'bnfw' ); ?></option>
|
193 |
+
<option
|
194 |
+
value="newterm-post_tag" <?php selected( 'newterm-post_tag', $setting['notification'] ); ?>><?php esc_html_e( 'New Tag', 'bnfw' ); ?></option>
|
195 |
+
<?php do_action( 'bnfw_after_notification_options', 'post', 'Post', $setting ); ?>
|
196 |
+
</optgroup>
|
197 |
+
<optgroup label="Page">
|
198 |
+
<option
|
199 |
+
value="new-page" <?php selected( 'new-page', $setting['notification'] ); ?>><?php esc_html_e( 'New Page Published', 'bnfw' ); ?></option>
|
200 |
+
<option
|
201 |
+
value="update-page" <?php selected( 'update-page', $setting['notification'] ); ?>><?php esc_html_e( 'Page Updated', 'bnfw' ); ?></option>
|
202 |
+
<option
|
203 |
+
value="pending-page" <?php selected( 'pending-page', $setting['notification'] ); ?>><?php esc_html_e( 'Page Pending Review', 'bnfw' ); ?></option>
|
204 |
+
<option
|
205 |
+
value="future-page" <?php selected( 'future-page', $setting['notification'] ); ?>><?php esc_html_e( 'Page Scheduled', 'bnfw' ); ?></option>
|
206 |
+
<option
|
207 |
+
value="comment-page" <?php selected( 'comment-page', $setting['notification'] ); ?>><?php esc_html_e( 'Page - New Comment', 'bnfw' ); ?></option>
|
208 |
+
<option
|
209 |
+
value="commentreply-page" <?php selected( 'commentreply-page', $setting['notification'] ); ?>><?php esc_html_e( 'Page - Comment Reply', 'bnfw' ); ?></option>
|
210 |
+
<?php do_action( 'bnfw_after_notification_options', 'page', 'Page', $setting ); ?>
|
211 |
+
</optgroup>
|
212 |
+
<?php
|
213 |
+
$types = get_post_types( array(
|
214 |
+
'public' => true,
|
215 |
+
'_builtin' => false,
|
216 |
+
), 'names'
|
217 |
+
);
|
218 |
+
|
219 |
+
foreach ( $types as $type ) {
|
220 |
+
if ( $type != self::POST_TYPE ) {
|
221 |
+
$post_obj = get_post_type_object( $type );
|
222 |
+
$label = $post_obj->labels->singular_name;
|
223 |
+
?>
|
224 |
+
<optgroup
|
225 |
+
label="<?php esc_attr( printf( "%s - '%s'", esc_html__( 'Custom Post Type', 'bnfw' ), $label ) ); ?>">
|
226 |
+
<option
|
227 |
+
value="new-<?php echo esc_attr( $type ); ?>" <?php selected( 'new-' . $type, $setting['notification'] ); ?>><?php echo esc_html__( 'New ', 'bnfw' ), "'$label'"; ?></option>
|
228 |
+
<option
|
229 |
+
value="update-<?php echo esc_attr( $type ); ?>" <?php selected( 'update-' . $type, $setting['notification'] ); ?>><?php echo "'$label' " . esc_html__( 'Update ', 'bnfw' ); ?></option>
|
230 |
+
<option
|
231 |
+
value="pending-<?php echo esc_attr( $type ); ?>" <?php selected( 'pending-' . $type, $setting['notification'] ); ?>><?php echo "'$label' ", esc_html__( 'Pending Review', 'bnfw' ); ?></option>
|
232 |
+
<option
|
233 |
+
value="future-<?php echo esc_attr( $type ); ?>" <?php selected( 'future-' . $type, $setting['notification'] ); ?>><?php echo "'$label' ", esc_html__( 'Scheduled', 'bnfw' ); ?></option>
|
234 |
+
<option
|
235 |
+
value="comment-<?php echo esc_attr( $type ); ?>" <?php selected( 'comment-' . $type, $setting['notification'] ); ?>><?php echo "'$label' ", esc_html__( 'New Comment', 'bnfw' ); ?></option>
|
236 |
+
<option
|
237 |
+
value="commentreply-<?php echo esc_attr( $type ); ?>" <?php selected( 'commentreply-' . $type, $setting['notification'] ); ?>><?php echo "'$label' ", esc_html__( 'Comment Reply', 'bnfw' ); ?></option>
|
238 |
+
<?php do_action( 'bnfw_after_notification_options', $type, $label, $setting ); ?>
|
239 |
+
</optgroup>
|
240 |
+
<?php
|
241 |
+
}
|
242 |
+
}
|
243 |
|
244 |
+
$taxs = get_taxonomies(
|
245 |
+
array(
|
246 |
+
'public' => true,
|
247 |
+
'_builtin' => false,
|
248 |
+
),
|
249 |
+
'objects'
|
250 |
+
);
|
251 |
+
|
252 |
+
if ( count( $taxs ) > 0 ) {
|
253 |
+
?>
|
254 |
+
<optgroup label="<?php esc_html_e( 'Custom Taxonomy', 'bnfw' ); ?>">
|
255 |
+
<?php
|
256 |
+
foreach ( $taxs as $tax ) {
|
257 |
+
$tax_name = 'newterm-' . $tax->name;
|
258 |
+
?>
|
259 |
+
<option
|
260 |
+
value="<?php echo esc_attr( $tax_name ); ?>" <?php selected( $tax_name, $setting['notification'] ); ?>><?php printf( "%s '%s'", esc_html__( 'New', 'bnfw' ), $tax->labels->name ); ?></option>
|
261 |
+
<?php
|
262 |
+
}
|
263 |
+
?>
|
264 |
+
</optgroup>
|
265 |
+
<?php
|
266 |
+
}
|
267 |
+
?>
|
268 |
+
</select>
|
269 |
+
</td>
|
270 |
+
</tr>
|
271 |
+
|
272 |
+
<?php do_action( 'bnfw_after_notification_dropdown', $setting ); ?>
|
273 |
+
|
274 |
+
<tr valign="top" id="user-password-msg">
|
275 |
+
<td> </td>
|
276 |
+
<td>
|
277 |
+
<div>
|
278 |
+
<p style="margin-top: 0;"><?php esc_html_e( "This notification doesn't support additional email fields.", 'bnfw' ); ?></p>
|
279 |
+
</div>
|
280 |
+
</td>
|
281 |
+
</tr>
|
282 |
+
|
283 |
+
<tr valign="top" id="email-formatting">
|
284 |
+
<th>
|
285 |
+
<?php esc_html_e( 'Email Formatting', 'bnfw' ); ?>
|
286 |
+
</th>
|
287 |
+
<td>
|
288 |
+
<label style="margin-right: 20px;">
|
289 |
+
<input type="radio" name="email-formatting"
|
290 |
+
value="html" <?php checked( 'html', $setting['email-formatting'] ); ?>>
|
291 |
+
<?php esc_html_e( 'HTML Formatting', 'bnfw' ); ?>
|
292 |
+
</label>
|
293 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
294 |
<label>
|
295 |
+
<input type="radio" name="email-formatting"
|
296 |
+
value="text" <?php checked( 'text', $setting['email-formatting'] ); ?>>
|
297 |
+
<?php esc_html_e( 'Plain Text', 'bnfw' ); ?>
|
298 |
</label>
|
299 |
+
</td>
|
300 |
+
</tr>
|
301 |
+
|
302 |
+
<tr valign="top" id="toggle-fields">
|
303 |
+
<th>
|
304 |
+
<?php esc_html_e( 'Additional Email Fields', 'bnfw' ); ?>
|
305 |
+
</th>
|
306 |
+
<td>
|
307 |
+
<input type="checkbox" id="show-fields" name="show-fields"
|
308 |
+
value="true" <?php checked( $setting['show-fields'], 'true', true ); ?>>
|
309 |
+
<label for="show-fields"><?php esc_html_e( 'Set "From" Name & Email, CC, BCC', 'bnfw' ); ?></label>
|
310 |
+
</td>
|
311 |
+
</tr>
|
312 |
+
|
313 |
+
<tr valign="top" id="email">
|
314 |
+
<th scope="row">
|
315 |
+
<?php esc_html_e( 'From Name and Email', 'bnfw' ); ?>
|
316 |
+
</th>
|
317 |
+
<td>
|
318 |
+
<input type="text" name="from-name" value="<?php echo esc_attr( $setting['from-name'] ); ?>"
|
319 |
+
placeholder="Site Name" style="width: 37.35%">
|
320 |
+
<input type="email" name="from-email" value="<?php echo esc_attr( $setting['from-email'] ); ?>"
|
321 |
+
placeholder="Admin Email" style="width: 37.3%">
|
322 |
+
</td>
|
323 |
+
</tr>
|
324 |
+
|
325 |
+
<tr valign="top" id="cc">
|
326 |
+
<th scope="row">
|
327 |
+
<?php esc_html_e( 'CC', 'bnfw' ); ?>
|
328 |
+
</th>
|
329 |
+
|
330 |
+
<td>
|
331 |
+
<select multiple name="cc[]" class="<?php echo sanitize_html_class( bnfw_get_user_select_class() ); ?>"
|
332 |
+
data-placeholder="Select User Roles / Users" style="width:75%">
|
333 |
+
<?php bnfw_render_users_dropdown( $setting['cc'] ); ?>
|
334 |
+
</select>
|
335 |
+
</td>
|
336 |
+
</tr>
|
337 |
+
|
338 |
+
<tr valign="top" id="bcc">
|
339 |
+
<th scope="row">
|
340 |
+
<?php esc_html_e( 'BCC', 'bnfw' ); ?>
|
341 |
+
</th>
|
342 |
+
|
343 |
+
<td>
|
344 |
+
<select multiple name="bcc[]" class="<?php echo sanitize_html_class( bnfw_get_user_select_class() ); ?>"
|
345 |
+
data-placeholder="Select User Roles / Users" style="width:75%">
|
346 |
+
<?php bnfw_render_users_dropdown( $setting['bcc'] ); ?>
|
347 |
+
</select>
|
348 |
+
</td>
|
349 |
+
</tr>
|
350 |
+
|
351 |
+
<tr valign="top" id="post-author">
|
352 |
+
<th></th>
|
353 |
+
<td>
|
354 |
+
<label>
|
355 |
+
<input type="checkbox" id="only-post-author" name="only-post-author"
|
356 |
+
value="true" <?php checked( 'true', $setting['only-post-author'] ); ?>>
|
357 |
+
<?php esc_html_e( 'Send this notification to the Author only', 'bnfw' ); ?>
|
358 |
+
</label>
|
359 |
+
</td>
|
360 |
+
</tr>
|
361 |
+
|
362 |
+
<tr valign="top" id="users">
|
363 |
+
<th scope="row">
|
364 |
+
<?php esc_html_e( 'Send To', 'bnfw' ); ?>
|
365 |
+
</th>
|
366 |
+
<td>
|
367 |
+
<select multiple id="users-select" name="users[]"
|
368 |
+
class="<?php echo sanitize_html_class( bnfw_get_user_select_class() ); ?>"
|
369 |
+
data-placeholder="Select User Roles / Users" style="width:75%">
|
370 |
+
<?php bnfw_render_users_dropdown( $setting['users'] ); ?>
|
371 |
+
</select>
|
372 |
+
</td>
|
373 |
+
</tr>
|
374 |
+
|
375 |
+
<tr valign="top" id="current-user">
|
376 |
+
<th></th>
|
377 |
+
<td>
|
378 |
+
<label>
|
379 |
+
<input type="checkbox" name="disable-current-user"
|
380 |
+
value="true" <?php checked( 'true', $setting['disable-current-user'] ); ?>>
|
381 |
+
<?php esc_html_e( 'Disable this Notification for the User that triggered it', 'bnfw' ); ?>
|
382 |
+
</label>
|
383 |
+
</td>
|
384 |
+
</tr>
|
385 |
+
|
386 |
+
<tr valign="top">
|
387 |
+
<th scope="row">
|
388 |
+
<?php esc_html_e( 'Subject', 'bnfw' ); ?>
|
389 |
+
</th>
|
390 |
+
<td>
|
391 |
+
<input type="text" name="subject" value="<?php echo esc_attr( $setting['subject'] ); ?>"
|
392 |
+
style="width:75%;">
|
393 |
+
</td>
|
394 |
+
</tr>
|
395 |
+
|
396 |
+
<tr valign="top">
|
397 |
+
<th scope="row">
|
398 |
+
<?php esc_html_e( 'Message Body', 'bnfw' ); ?>
|
399 |
+
<div class="wp-ui-text-highlight">
|
400 |
+
<p>
|
401 |
+
<br/>
|
402 |
+
<span
|
403 |
+
class="dashicons dashicons-editor-help"></span> <?php esc_html_e( 'Need some help?', 'bnfw' ); ?>
|
404 |
+
</p>
|
405 |
+
<p>
|
406 |
+
<a href="https://betternotificationsforwp.com/documentation/?utm_source=WP%20Admin%20Notification%20Editor%20-%20'Documentation'&utm_medium=referral"
|
407 |
+
target="_blank" class="button-secondary"><?php esc_html_e( 'Documentation', 'bnfw' ); ?></a>
|
408 |
+
</p>
|
409 |
+
<p>
|
410 |
+
<a href="" target="_blank" id="shortcode-help"
|
411 |
+
class="button-secondary"><?php esc_html_e( 'Shortcode Help', 'bnfw' ); ?></a>
|
412 |
+
</p>
|
413 |
+
</div>
|
414 |
+
</th>
|
415 |
+
<td>
|
416 |
+
<?php wp_editor( $setting['message'], 'notification_message', array( 'media_buttons' => true ) ); ?>
|
417 |
+
<p> </p>
|
418 |
+
<div id="disable-autop">
|
419 |
+
<label>
|
420 |
+
<input type="checkbox" name="disable-autop"
|
421 |
+
value="true" <?php checked( 'true', $setting['disable-autop'] ); ?>>
|
422 |
+
<?php esc_html_e( 'Stop additional paragraph and line break HTML from being inserted into my notifications', 'bnfw' ); ?>
|
423 |
+
</label>
|
424 |
+
</div>
|
425 |
+
</td>
|
426 |
+
</tr>
|
427 |
+
|
428 |
+
</tbody>
|
429 |
+
</table>
|
430 |
+
<?php
|
431 |
}
|
432 |
|
433 |
/**
|
469 |
wp_enqueue_style( 'bnfw', plugins_url( '../assets/css/bnfw.css', dirname( __FILE__ ) ), array( 'dashicons', 'select2' ), '0.1' );
|
470 |
|
471 |
$strings = array(
|
472 |
+
'empty_user' => esc_html__( 'You must choose at least one User or User Role to send the notification to before you can save', 'bnfw' ),
|
473 |
);
|
474 |
|
475 |
wp_localize_script( 'bnfw', 'BNFW', $strings );
|
479 |
* Save the meta box's post metadata.
|
480 |
*
|
481 |
* @since 1.0
|
482 |
+
*
|
483 |
+
* @param int $post_id The ID of the post being saved.
|
484 |
*/
|
485 |
public function save_meta_data( $post_id ) {
|
486 |
if ( self::POST_TYPE !== get_post_type( $post_id ) ) {
|
506 |
}
|
507 |
|
508 |
$setting = array(
|
509 |
+
'notification' => sanitize_text_field( $_POST['notification'] ),
|
510 |
+
'subject' => sanitize_text_field( $_POST['subject'] ),
|
511 |
'message' => $_POST['notification_message'],
|
512 |
'disabled' => isset( $_POST['disabled'] ) ? sanitize_text_field( $_POST['disabled'] ) : 'false',
|
513 |
'email-formatting' => isset( $_POST['email-formatting'] ) ? sanitize_text_field( $_POST['email-formatting'] ) : 'html',
|
518 |
);
|
519 |
|
520 |
if ( isset( $_POST['users'] ) ) {
|
521 |
+
$setting['users'] = array_map( 'sanitize_text_field', $_POST['users'] );
|
522 |
}
|
523 |
|
524 |
if ( isset( $_POST['show-fields'] ) && 'true' == $_POST['show-fields'] ) {
|
525 |
$setting['show-fields'] = 'true';
|
526 |
$setting['from-name'] = sanitize_text_field( $_POST['from-name'] );
|
527 |
$setting['from-email'] = sanitize_email( $_POST['from-email'] );
|
528 |
+
$setting['cc'] = isset( $_POST['cc'] ) ? array_map( 'sanitize_text_field', $_POST['cc'] ) : '';
|
529 |
+
$setting['bcc'] = isset( $_POST['bcc'] ) ? array_map( 'sanitize_text_field', $_POST['bcc'] ) : '';
|
530 |
} else {
|
531 |
$setting['show-fields'] = 'false';
|
532 |
}
|
536 |
$this->save_settings( $post_id, $setting );
|
537 |
|
538 |
if ( isset( $_POST['send-test-email'] ) ) {
|
539 |
+
if ( 'true' == sanitize_text_field( $_POST['send-test-email'] ) ) {
|
540 |
BNFW::factory()->engine->send_test_email( $setting );
|
541 |
add_filter( 'redirect_post_location', array( $this, 'test_mail_sent' ) );
|
542 |
}
|
558 |
* @since 1.3
|
559 |
*/
|
560 |
public function admin_notices() {
|
561 |
+
if ( isset( $_GET[ self::TEST_MAIL_ARG ] ) ) {
|
562 |
+
$screen = get_current_screen();
|
563 |
+
if ( in_array( $screen->post_type, array( self::POST_TYPE ) ) ) {
|
564 |
+
?>
|
565 |
<div class="updated below-h2">
|
566 |
+
<p><?php echo esc_html__( 'Test Notification Sent.', 'bnfw' ); ?></p>
|
567 |
</div>
|
568 |
+
<?php
|
569 |
+
}
|
570 |
+
}
|
571 |
}
|
572 |
|
573 |
/**
|
574 |
* Save settings in post meta.
|
575 |
*
|
576 |
+
* @since 1.0
|
577 |
* @access private
|
578 |
+
*
|
579 |
+
* @param $post_id
|
580 |
+
* @param $setting
|
581 |
*/
|
582 |
private function save_settings( $post_id, $setting ) {
|
583 |
foreach ( $setting as $key => $value ) {
|
589 |
* Read settings from post meta.
|
590 |
*
|
591 |
* @since 1.0
|
592 |
+
*
|
593 |
* @param int $post_id
|
594 |
+
*
|
595 |
* @return array
|
596 |
*/
|
597 |
public function read_settings( $post_id ) {
|
636 |
}
|
637 |
|
638 |
$setting['id'] = $post_id;
|
639 |
+
|
640 |
return $setting;
|
641 |
}
|
642 |
|
644 |
* Change the post updated message for notification post type.
|
645 |
*
|
646 |
* @since 1.0
|
647 |
+
*
|
648 |
+
* @param $messages
|
649 |
+
*
|
650 |
+
* @return mixed
|
651 |
*/
|
652 |
public function post_updated_messages( $messages ) {
|
653 |
+
$messages[ self::POST_TYPE ] = array_fill( 0, 11, esc_html__( 'Notification saved.', 'bnfw' ) );
|
654 |
|
655 |
return $messages;
|
656 |
}
|
659 |
* Render submit div meta box.
|
660 |
*
|
661 |
* @since 1.0
|
662 |
+
*
|
663 |
+
* @param $post
|
664 |
*/
|
665 |
public function render_submitdiv( $post ) {
|
666 |
global $post;
|
667 |
+
?>
|
668 |
+
<div class="submitbox" id="submitpost">
|
669 |
|
670 |
+
<?php // Hidden submit button early on so that the browser chooses the right button when form is submitted with Return key ?>
|
671 |
+
<div style="display:none;">
|
672 |
+
<?php submit_button( esc_html__( 'Save' ), 'button', 'save' ); ?>
|
673 |
+
</div>
|
674 |
|
675 |
+
<?php // Always publish. ?>
|
676 |
+
<div class="disable-notification-checkbox" style="padding: 5px 0 10px 0;">
|
677 |
+
<input type="hidden" name="post_status" id="hidden_post_status" value="publish">
|
678 |
|
679 |
+
<?php
|
680 |
+
$setting = $this->read_settings( $post->ID );
|
681 |
+
?>
|
682 |
+
<label>
|
683 |
+
<input type="checkbox" name="disabled"
|
684 |
+
value="true" <?php checked( $setting['disabled'], 'true', true ); ?>><?php esc_html_e( 'Disable Notification', 'bnfw' ); ?>
|
685 |
+
</label>
|
686 |
+
|
687 |
+
<br>
|
688 |
+
<br>
|
689 |
+
|
690 |
+
<?php if ( 'publish' == $post->post_status ) { ?>
|
691 |
+
<input type="hidden" name="send-test-email" id="send-test-email" value="false">
|
692 |
+
<input name="test-email" type="submit" class="button button-secondary button-large" id="test-email"
|
693 |
+
value="<?php esc_attr_e( 'Send Me a Test Email', 'bnfw' ); ?>">
|
694 |
+
<?php } ?>
|
695 |
+
|
696 |
+
</div>
|
697 |
+
|
698 |
+
<div id="major-publishing-actions">
|
699 |
+
|
700 |
+
<div id="delete-action">
|
701 |
+
<?php
|
702 |
+
if ( ! EMPTY_TRASH_DAYS ) {
|
703 |
+
$delete_text = esc_html__( 'Delete Permanently', 'bnfw' );
|
704 |
+
} else {
|
705 |
+
$delete_text = esc_html__( 'Move to Trash', 'bnfw' );
|
706 |
+
}
|
707 |
+
?>
|
708 |
+
<a class="submitdelete deletion"
|
709 |
+
href="<?php echo esc_url( get_delete_post_link( $post->ID ) ); ?>"><?php echo esc_html( $delete_text ); ?></a>
|
710 |
+
</div>
|
711 |
+
|
712 |
+
<div id="publishing-action">
|
713 |
+
<span class="spinner"></span>
|
714 |
+
<input name="original_publish" type="hidden" id="original_publish"
|
715 |
+
value="<?php esc_attr_e( 'Save', 'bnfw' ); ?>">
|
716 |
+
<input name="save" type="submit" class="button button-primary button-large" id="publish"
|
717 |
+
accesskey="p" value="<?php esc_attr_e( 'Save', 'bnfw' ); ?>">
|
718 |
+
</div>
|
719 |
+
<div class="clear"></div>
|
720 |
+
|
721 |
+
</div>
|
722 |
+
<!-- #major-publishing-actions -->
|
723 |
+
|
724 |
+
<div class="clear"></div>
|
725 |
+
</div>
|
726 |
+
<!-- #submitpost -->
|
727 |
+
<?php
|
728 |
}
|
729 |
|
730 |
/**
|
731 |
* Get notifications based on type.
|
732 |
*
|
733 |
* @since 1.0
|
734 |
+
*
|
735 |
* @param array|string $types
|
736 |
+
* @param bool $exclude_disabled (optional) Whether to exclude disabled notifications or not. True by default.
|
737 |
+
*
|
738 |
* @return array WP_Post objects
|
739 |
*/
|
740 |
public function get_notifications( $types, $exclude_disabled = true ) {
|
743 |
}
|
744 |
|
745 |
$args = array(
|
746 |
+
'post_type' => self::POST_TYPE,
|
747 |
'meta_query' => array(
|
748 |
array(
|
749 |
'key' => self::META_KEY_PREFIX . 'notification',
|
762 |
}
|
763 |
|
764 |
$wp_query = new WP_Query();
|
765 |
+
$posts = $wp_query->query( $args );
|
766 |
+
|
767 |
return $posts;
|
768 |
}
|
769 |
|
772 |
*
|
773 |
* @since 1.1
|
774 |
*
|
775 |
+
* @param string $type Notification Type.
|
776 |
+
* @param bool $exclude_disabled (optional) Whether to exclude disabled notifications or not. True by default.
|
777 |
+
*
|
778 |
* @return bool True if present, False otherwise
|
779 |
*/
|
780 |
public function notification_exists( $type, $exclude_disabled = true ) {
|
790 |
/**
|
791 |
* Custom columns for this post type.
|
792 |
*
|
793 |
+
* @since 1.0
|
794 |
* @filter manage_{post_type}_posts_columns
|
795 |
+
*
|
796 |
+
* @param array $columns
|
797 |
+
*
|
798 |
* @return array
|
799 |
*/
|
800 |
public function columns_header( $columns ) {
|
801 |
+
$columns['type'] = esc_html__( 'Notification Type', 'bnfw' );
|
802 |
+
$columns['disabled'] = esc_html__( 'Enabled?', 'bnfw' );
|
803 |
+
$columns['subject'] = esc_html__( 'Subject', 'bnfw' );
|
804 |
+
$columns['users'] = esc_html__( 'User Roles / Users', 'bnfw' );
|
805 |
|
806 |
return $columns;
|
807 |
}
|
809 |
/**
|
810 |
* Custom column appears in each row.
|
811 |
*
|
812 |
+
* @since 1.0
|
813 |
* @action manage_{post_type}_posts_custom_column
|
814 |
+
*
|
815 |
+
* @param string $column Column name
|
816 |
+
* @param int $post_id Post ID
|
817 |
*/
|
818 |
public function custom_column_row( $column, $post_id ) {
|
819 |
$setting = $this->read_settings( $post_id );
|
820 |
switch ( $column ) {
|
821 |
case 'disabled':
|
822 |
if ( 'true' != $setting['disabled'] ) {
|
823 |
+
printf( '<span class="dashicons dashicons-yes"></span>' );
|
824 |
}
|
825 |
break;
|
826 |
case 'type':
|
831 |
break;
|
832 |
case 'users':
|
833 |
if ( 'true' === $setting['only-post-author'] ) {
|
834 |
+
echo esc_html__( 'Author only', 'bnfw' );
|
835 |
} else {
|
836 |
$users = $this->get_names_from_users( $setting['users'] );
|
837 |
echo implode( ', ', $users );
|
844 |
*
|
845 |
* @since 1.3.9
|
846 |
*
|
847 |
+
* @param string $column Column name
|
848 |
+
* @param int $post_id Post ID
|
849 |
*/
|
850 |
do_action( 'bnfw_notification_table_column', $column, $post_id );
|
851 |
}
|
856 |
* @since 1.2
|
857 |
*/
|
858 |
private function get_names_from_users( $users ) {
|
859 |
+
$email_list = array();
|
860 |
+
$user_ids = array();
|
861 |
+
$user_roles = array();
|
862 |
$names_from_user_ids = array();
|
863 |
|
864 |
foreach ( $users as $user ) {
|
882 |
/**
|
883 |
* Get name of the notification based on slug.
|
884 |
*
|
885 |
+
* @param mixed $slug
|
886 |
+
*
|
887 |
* @return unknown
|
888 |
*/
|
889 |
private function get_notifications_name( $slug ) {
|
890 |
$name = '';
|
891 |
switch ( $slug ) {
|
892 |
case 'new-comment':
|
893 |
+
$name = esc_html__( 'New Comment', 'bnfw' );
|
894 |
break;
|
895 |
case 'new-trackback':
|
896 |
+
$name = esc_html__( 'New Trackback', 'bnfw' );
|
897 |
break;
|
898 |
case 'new-pingback':
|
899 |
+
$name = esc_html__( 'New Pingback', 'bnfw' );
|
900 |
break;
|
901 |
case 'reply-comment':
|
902 |
+
$name = esc_html__( 'Comment Reply', 'bnfw' );
|
903 |
break;
|
904 |
case 'user-password':
|
905 |
+
$name = esc_html__( 'Lost Password - For User', 'bnfw' );
|
906 |
break;
|
907 |
case 'admin-password':
|
908 |
+
$name = esc_html__( 'Lost Password - For Admin', 'bnfw' );
|
909 |
break;
|
910 |
case 'new-user':
|
911 |
+
$name = esc_html__( 'New User Registration - For User', 'bnfw' );
|
912 |
break;
|
913 |
case 'welcome-email':
|
914 |
+
$name = esc_html__( 'New User - Post-registration Email', 'bnfw' );
|
915 |
break;
|
916 |
case 'admin-user':
|
917 |
+
$name = esc_html__( 'New User Registration - For Admin', 'bnfw' );
|
918 |
break;
|
919 |
case 'user-role':
|
920 |
+
$name = esc_html__( 'User Role Changed - For User', 'bnfw' );
|
921 |
break;
|
922 |
case 'admin-role':
|
923 |
+
$name = esc_html__( 'User Role Changed - For Admin', 'bnfw' );
|
924 |
break;
|
925 |
case 'new-post':
|
926 |
+
$name = esc_html__( 'New Post Published', 'bnfw' );
|
927 |
break;
|
928 |
case 'update-post':
|
929 |
+
$name = esc_html__( 'Post Updated', 'bnfw' );
|
930 |
break;
|
931 |
case 'pending-post':
|
932 |
+
$name = esc_html__( 'Post Pending Review', 'bnfw' );
|
933 |
break;
|
934 |
case 'future-post':
|
935 |
+
$name = esc_html__( 'Post Scheduled', 'bnfw' );
|
936 |
break;
|
937 |
case 'newterm-category':
|
938 |
+
$name = esc_html__( 'New Category', 'bnfw' );
|
939 |
break;
|
940 |
case 'newterm-post_tag':
|
941 |
+
$name = esc_html__( 'New Tag', 'bnfw' );
|
942 |
break;
|
943 |
default:
|
944 |
+
$splited = explode( '-', $slug );
|
945 |
+
$label = $splited[1];
|
946 |
$post_obj = get_post_type_object( $splited[1] );
|
947 |
|
948 |
if ( null != $post_obj ) {
|
951 |
|
952 |
switch ( $splited[0] ) {
|
953 |
case 'new':
|
954 |
+
$name = esc_html__( 'New ', 'bnfw' ) . $label;
|
955 |
break;
|
956 |
case 'update':
|
957 |
+
$name = esc_html__( 'Updated ', 'bnfw' ) . $label;
|
958 |
break;
|
959 |
case 'pending':
|
960 |
+
$name = $label . esc_html__( ' Pending Review', 'bnfw' );
|
961 |
break;
|
962 |
case 'future':
|
963 |
+
$name = $label . esc_html__( ' Scheduled', 'bnfw' );
|
964 |
break;
|
965 |
case 'comment':
|
966 |
+
$name = $label . esc_html__( ' Comment', 'bnfw' );
|
967 |
break;
|
968 |
case 'commentreply':
|
969 |
+
$name = $label . esc_html__( ' Comment Reply', 'bnfw' );
|
970 |
break;
|
971 |
case 'newterm':
|
972 |
$tax = get_taxonomy( $splited[1] );
|
973 |
if ( ! $tax ) {
|
974 |
+
$name = esc_html__( 'New Term', 'bnfw' );
|
975 |
} else {
|
976 |
+
$name = esc_html__( 'New Term in ', 'bnfw' ) . $tax->labels->name;
|
977 |
}
|
978 |
break;
|
979 |
}
|
988 |
/**
|
989 |
* Custom row actions for this post type.
|
990 |
*
|
991 |
+
* @since 1.0
|
992 |
* @filter post_row_actions
|
993 |
+
*
|
994 |
+
* @param array $actions
|
995 |
+
*
|
996 |
* @return array
|
997 |
*/
|
998 |
public function custom_row_actions( $actions ) {
|
1010 |
* Find if a string starts with another string.
|
1011 |
*
|
1012 |
* @since 1.2
|
1013 |
+
*
|
1014 |
+
* @param $haystack
|
1015 |
+
* @param $needle
|
1016 |
+
*
|
1017 |
+
* @return bool
|
1018 |
*/
|
1019 |
public function starts_with( $haystack, $needle ) {
|
1020 |
// search backwards starting from haystack length characters from the end
|
1021 |
+
return '' === $needle || strrpos( $haystack, $needle, - strlen( $haystack ) ) !== false;
|
1022 |
}
|
1023 |
}
|
includes/engine/class-bnfw-engine.php
CHANGED
@@ -11,6 +11,8 @@ class BNFW_Engine {
|
|
11 |
* Send test email.
|
12 |
*
|
13 |
* @since 1.2
|
|
|
|
|
14 |
*/
|
15 |
public function send_test_email( $setting ) {
|
16 |
$subject = $setting['subject'];
|
@@ -120,21 +122,30 @@ class BNFW_Engine {
|
|
120 |
public function send_comment_reply_email( $setting, $comment, $parent_comment ) {
|
121 |
$comment_id = $comment->comment_ID;
|
122 |
|
123 |
-
|
124 |
-
|
|
|
|
|
|
|
|
|
125 |
|
126 |
-
$
|
127 |
-
|
128 |
-
$
|
129 |
-
}
|
130 |
|
131 |
-
|
132 |
-
|
133 |
-
|
|
|
|
|
|
|
|
|
|
|
134 |
|
135 |
-
|
136 |
-
|
137 |
-
|
|
|
138 |
}
|
139 |
|
140 |
/**
|
@@ -361,9 +372,11 @@ class BNFW_Engine {
|
|
361 |
* Handle comment shortcodes.
|
362 |
*
|
363 |
* @since 1.0
|
364 |
-
*
|
365 |
-
* @param
|
366 |
-
* @
|
|
|
|
|
367 |
*/
|
368 |
private function comment_shortcodes( $message, $comment_id ) {
|
369 |
$comment = get_comment( $comment_id );
|
@@ -392,9 +405,11 @@ class BNFW_Engine {
|
|
392 |
* Handle user shortcodes.
|
393 |
*
|
394 |
* @since 1.0
|
395 |
-
*
|
396 |
-
* @param
|
397 |
-
* @
|
|
|
|
|
398 |
*/
|
399 |
public function user_shortcodes( $message, $user_id ) {
|
400 |
$user_info = get_userdata( $user_id );
|
@@ -413,9 +428,9 @@ class BNFW_Engine {
|
|
413 |
$message = str_replace( '[user_lastname]', $user_info->user_lastname, $message );
|
414 |
$message = str_replace( '[nickname]', $user_info->nickname, $message );
|
415 |
$message = str_replace( '[user_description]', $user_info->user_description, $message );
|
416 |
-
$message = str_replace( '[user_avatar]', get_avatar_url( $user_id), $message );
|
417 |
-
$message = str_replace( '[user_avatar]', get_avatar_url( $user_id), $message );
|
418 |
-
$message = str_replace( '[commenter_avatar]', get_avatar_url( $user_id), $message );
|
419 |
|
420 |
if ( is_array( $user_info->wp_capabilities ) ) {
|
421 |
$message = str_replace( '[wp_capabilities]', implode( ',', $user_info->wp_capabilities ), $message );
|
@@ -430,6 +445,7 @@ class BNFW_Engine {
|
|
430 |
*
|
431 |
* @access private
|
432 |
* @since 1.1
|
|
|
433 |
* @param string $message
|
434 |
* @param string $taxonomy
|
435 |
* @param int $term_id
|
@@ -513,11 +529,13 @@ class BNFW_Engine {
|
|
513 |
* Get emails from users.
|
514 |
*
|
515 |
* @since 1.2
|
516 |
-
*
|
517 |
-
* @param
|
|
|
|
|
|
|
518 |
*/
|
519 |
public function get_emails_from_users( $users, $exclude = null ) {
|
520 |
-
$email_list = array();
|
521 |
$user_ids = array();
|
522 |
$user_roles = array();
|
523 |
|
@@ -547,8 +565,10 @@ class BNFW_Engine {
|
|
547 |
* Get user emails by user ids.
|
548 |
*
|
549 |
* @since 1.0
|
550 |
-
*
|
551 |
-
* @
|
|
|
|
|
552 |
*/
|
553 |
private function get_emails_from_id( $user_ids ) {
|
554 |
$email_list = array();
|
@@ -577,10 +597,12 @@ class BNFW_Engine {
|
|
577 |
$email_list = array();
|
578 |
foreach ( $roles as $role ) {
|
579 |
$role_name = $this->get_role_name_by_label( $role );
|
580 |
-
$users = get_users(
|
|
|
581 |
'role' => $role_name,
|
582 |
'fields' => array( 'user_email', 'ID' ),
|
583 |
-
)
|
|
|
584 |
|
585 |
foreach ( $users as $user ) {
|
586 |
if ( null != $exclude ) {
|
@@ -599,6 +621,11 @@ class BNFW_Engine {
|
|
599 |
* Find if a string starts with another string.
|
600 |
*
|
601 |
* @since 1.2
|
|
|
|
|
|
|
|
|
|
|
602 |
*/
|
603 |
private function starts_with( $haystack, $needle ) {
|
604 |
// search backwards starting from haystack length characters from the end
|
@@ -608,13 +635,14 @@ class BNFW_Engine {
|
|
608 |
/**
|
609 |
* Get User role name by label.
|
610 |
*
|
611 |
-
* @param mixed
|
612 |
-
*
|
|
|
613 |
*/
|
614 |
protected function get_role_name_by_label( $role_label ) {
|
615 |
global $wp_roles;
|
616 |
foreach ( $wp_roles->roles as $role_name => $role_info ) {
|
617 |
-
if ( $role_label == $role_info['name'] ) {
|
618 |
return $role_name;
|
619 |
}
|
620 |
}
|
11 |
* Send test email.
|
12 |
*
|
13 |
* @since 1.2
|
14 |
+
*
|
15 |
+
* @param array $setting
|
16 |
*/
|
17 |
public function send_test_email( $setting ) {
|
18 |
$subject = $setting['subject'];
|
122 |
public function send_comment_reply_email( $setting, $comment, $parent_comment ) {
|
123 |
$comment_id = $comment->comment_ID;
|
124 |
|
125 |
+
/**
|
126 |
+
* BNFW - Whether notification is disabled?
|
127 |
+
*
|
128 |
+
* @since 1.3.6
|
129 |
+
*/
|
130 |
+
$notification_disabled = apply_filters( 'bnfw_notification_disabled', false, $comment_id, $setting );
|
131 |
|
132 |
+
if ( ! $notification_disabled ) {
|
133 |
+
$subject = $this->handle_shortcodes( $setting['subject'], $setting['notification'], $comment_id );
|
134 |
+
$message = $this->handle_shortcodes( $setting['message'], $setting['notification'], $comment_id );
|
|
|
135 |
|
136 |
+
$headers = array();
|
137 |
+
if ( 'html' == $setting['email-formatting'] ) {
|
138 |
+
$headers[] = 'Content-type: text/html';
|
139 |
+
}
|
140 |
+
|
141 |
+
if ( 'true' != $setting['disable-autop'] && 'html' == $setting['email-formatting'] ) {
|
142 |
+
$message = wpautop( $message );
|
143 |
+
}
|
144 |
|
145 |
+
$subject = $this->handle_global_user_shortcodes( $subject, $parent_comment->comment_author_email );
|
146 |
+
$message = $this->handle_global_user_shortcodes( $message, $parent_comment->comment_author_email );
|
147 |
+
wp_mail( $parent_comment->comment_author_email, stripslashes( $subject ), $message, $headers );
|
148 |
+
}
|
149 |
}
|
150 |
|
151 |
/**
|
372 |
* Handle comment shortcodes.
|
373 |
*
|
374 |
* @since 1.0
|
375 |
+
*
|
376 |
+
* @param string $message String to be processed.
|
377 |
+
* @param int $comment_id Comment id.
|
378 |
+
*
|
379 |
+
* @return string Processed string.
|
380 |
*/
|
381 |
private function comment_shortcodes( $message, $comment_id ) {
|
382 |
$comment = get_comment( $comment_id );
|
405 |
* Handle user shortcodes.
|
406 |
*
|
407 |
* @since 1.0
|
408 |
+
*
|
409 |
+
* @param string $message String to be processed.
|
410 |
+
* @param int $user_id User id.
|
411 |
+
*
|
412 |
+
* @return string Processed string.
|
413 |
*/
|
414 |
public function user_shortcodes( $message, $user_id ) {
|
415 |
$user_info = get_userdata( $user_id );
|
428 |
$message = str_replace( '[user_lastname]', $user_info->user_lastname, $message );
|
429 |
$message = str_replace( '[nickname]', $user_info->nickname, $message );
|
430 |
$message = str_replace( '[user_description]', $user_info->user_description, $message );
|
431 |
+
$message = str_replace( '[user_avatar]', get_avatar_url( $user_id ), $message );
|
432 |
+
$message = str_replace( '[user_avatar]', get_avatar_url( $user_id ), $message );
|
433 |
+
$message = str_replace( '[commenter_avatar]', get_avatar_url( $user_id ), $message );
|
434 |
|
435 |
if ( is_array( $user_info->wp_capabilities ) ) {
|
436 |
$message = str_replace( '[wp_capabilities]', implode( ',', $user_info->wp_capabilities ), $message );
|
445 |
*
|
446 |
* @access private
|
447 |
* @since 1.1
|
448 |
+
*
|
449 |
* @param string $message
|
450 |
* @param string $taxonomy
|
451 |
* @param int $term_id
|
529 |
* Get emails from users.
|
530 |
*
|
531 |
* @since 1.2
|
532 |
+
*
|
533 |
+
* @param array $users Users Array
|
534 |
+
* @param int $exclude User id to exclude
|
535 |
+
*
|
536 |
+
* @return array
|
537 |
*/
|
538 |
public function get_emails_from_users( $users, $exclude = null ) {
|
|
|
539 |
$user_ids = array();
|
540 |
$user_roles = array();
|
541 |
|
565 |
* Get user emails by user ids.
|
566 |
*
|
567 |
* @since 1.0
|
568 |
+
*
|
569 |
+
* @param array $user_ids.
|
570 |
+
*
|
571 |
+
* @return array Emails.
|
572 |
*/
|
573 |
private function get_emails_from_id( $user_ids ) {
|
574 |
$email_list = array();
|
597 |
$email_list = array();
|
598 |
foreach ( $roles as $role ) {
|
599 |
$role_name = $this->get_role_name_by_label( $role );
|
600 |
+
$users = get_users(
|
601 |
+
array(
|
602 |
'role' => $role_name,
|
603 |
'fields' => array( 'user_email', 'ID' ),
|
604 |
+
)
|
605 |
+
);
|
606 |
|
607 |
foreach ( $users as $user ) {
|
608 |
if ( null != $exclude ) {
|
621 |
* Find if a string starts with another string.
|
622 |
*
|
623 |
* @since 1.2
|
624 |
+
*
|
625 |
+
* @param $haystack
|
626 |
+
* @param $needle
|
627 |
+
*
|
628 |
+
* @return bool
|
629 |
*/
|
630 |
private function starts_with( $haystack, $needle ) {
|
631 |
// search backwards starting from haystack length characters from the end
|
635 |
/**
|
636 |
* Get User role name by label.
|
637 |
*
|
638 |
+
* @param mixed $role_label
|
639 |
+
*
|
640 |
+
* @return int|string
|
641 |
*/
|
642 |
protected function get_role_name_by_label( $role_label ) {
|
643 |
global $wp_roles;
|
644 |
foreach ( $wp_roles->roles as $role_name => $role_info ) {
|
645 |
+
if ( $role_label == $role_info['name'] || $role_name == $role_label ) {
|
646 |
return $role_name;
|
647 |
}
|
648 |
}
|
includes/helpers/ajax-helpers.php
CHANGED
@@ -16,22 +16,22 @@ function bnfw_search_users() {
|
|
16 |
$roles_data = array();
|
17 |
$user_count = count_users();
|
18 |
$roles = $wp_roles->get_names();
|
19 |
-
foreach ( $roles as $
|
20 |
$count = 0;
|
21 |
-
if ( isset( $user_count['avail_roles'][
|
22 |
-
$count = $user_count['avail_roles'][
|
23 |
}
|
24 |
|
25 |
$roles_data[] = array(
|
26 |
-
'id' => 'role-' . $
|
27 |
-
'text' => $
|
28 |
);
|
29 |
}
|
30 |
|
31 |
$data = array(
|
32 |
array(
|
33 |
'id' => 1,
|
34 |
-
'text' =>
|
35 |
'children' => $roles_data,
|
36 |
),
|
37 |
);
|
@@ -54,7 +54,7 @@ function bnfw_search_users() {
|
|
54 |
|
55 |
$data[] = array(
|
56 |
'id' => 2,
|
57 |
-
'text' =>
|
58 |
'children' => $user_data,
|
59 |
);
|
60 |
|
16 |
$roles_data = array();
|
17 |
$user_count = count_users();
|
18 |
$roles = $wp_roles->get_names();
|
19 |
+
foreach ( $roles as $role_slug => $role_name ) {
|
20 |
$count = 0;
|
21 |
+
if ( isset( $user_count['avail_roles'][ $role_slug ] ) ) {
|
22 |
+
$count = $user_count['avail_roles'][ $role_slug ];
|
23 |
}
|
24 |
|
25 |
$roles_data[] = array(
|
26 |
+
'id' => 'role-' . $role_slug,
|
27 |
+
'text' => $role_name . ' (' . $count . ' Users)',
|
28 |
);
|
29 |
}
|
30 |
|
31 |
$data = array(
|
32 |
array(
|
33 |
'id' => 1,
|
34 |
+
'text' => esc_html__( 'User Roles', 'bnfw' ),
|
35 |
'children' => $roles_data,
|
36 |
),
|
37 |
);
|
54 |
|
55 |
$data[] = array(
|
56 |
'id' => 2,
|
57 |
+
'text' => esc_html__( 'Users', 'bnfw' ),
|
58 |
'children' => $user_data,
|
59 |
);
|
60 |
|
includes/helpers/helpers.php
CHANGED
@@ -26,6 +26,8 @@ function bnfw_get_user_select_class() {
|
|
26 |
* Render users dropdown.
|
27 |
*
|
28 |
* @since 1.3.6
|
|
|
|
|
29 |
*/
|
30 |
function bnfw_render_users_dropdown( $selected_users ) {
|
31 |
global $wp_roles;
|
@@ -36,13 +38,20 @@ function bnfw_render_users_dropdown( $selected_users ) {
|
|
36 |
<?php
|
37 |
$roles = $wp_roles->get_names();
|
38 |
|
39 |
-
foreach ( $roles as $
|
40 |
-
$selected = selected( true, in_array( 'role-' . $
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
$count = 0;
|
42 |
-
if ( isset( $user_count['avail_roles'][
|
43 |
-
$count = $user_count['avail_roles'][
|
44 |
}
|
45 |
-
echo '<option value="role-', $
|
46 |
}
|
47 |
?>
|
48 |
</optgroup>
|
@@ -66,7 +75,7 @@ function bnfw_render_users_dropdown( $selected_users ) {
|
|
66 |
|
67 |
foreach ( $users as $user ) {
|
68 |
$selected = selected( true, in_array( $user->ID, $selected_users ), false );
|
69 |
-
echo '<option value="', $user->ID, '" ', $selected, '>', $user->user_login, '</option>';
|
70 |
}
|
71 |
}
|
72 |
|
26 |
* Render users dropdown.
|
27 |
*
|
28 |
* @since 1.3.6
|
29 |
+
*
|
30 |
+
* @param $selected_users
|
31 |
*/
|
32 |
function bnfw_render_users_dropdown( $selected_users ) {
|
33 |
global $wp_roles;
|
38 |
<?php
|
39 |
$roles = $wp_roles->get_names();
|
40 |
|
41 |
+
foreach ( $roles as $role_slug => $role_name ) {
|
42 |
+
$selected = selected( true, in_array( 'role-' . $role_slug, $selected_users ), false );
|
43 |
+
|
44 |
+
// Compatibility code, which will be eventually removed.
|
45 |
+
$selected_old = selected( true, in_array( 'role-' . $role_name, $selected_users ), false );
|
46 |
+
if ( ! empty( $selected_old ) ) {
|
47 |
+
$selected = $selected_old;
|
48 |
+
}
|
49 |
+
|
50 |
$count = 0;
|
51 |
+
if ( isset( $user_count['avail_roles'][ $role_slug ] ) ) {
|
52 |
+
$count = $user_count['avail_roles'][ $role_slug ];
|
53 |
}
|
54 |
+
echo '<option value="role-', esc_attr( $role_slug ), '" ', $selected, '>', esc_html( $role_name ), ' (', $count, ' Users)', '</option>';
|
55 |
}
|
56 |
?>
|
57 |
</optgroup>
|
75 |
|
76 |
foreach ( $users as $user ) {
|
77 |
$selected = selected( true, in_array( $user->ID, $selected_users ), false );
|
78 |
+
echo '<option value="', esc_attr( $user->ID ), '" ', $selected, '>', esc_html( $user->user_login ), '</option>';
|
79 |
}
|
80 |
}
|
81 |
|
includes/import.php
CHANGED
@@ -1,14 +1,22 @@
|
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
* Import notification from old plugin.
|
4 |
*
|
5 |
* @since 1.0
|
6 |
*/
|
7 |
-
|
8 |
class BNFW_Import {
|
9 |
-
const EMAIL_OPTION
|
10 |
const SETTING_OPTION = 'bnfw_settings';
|
11 |
-
private $events
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
/**
|
14 |
* Import notification from old plugin.
|
@@ -26,7 +34,7 @@ class BNFW_Import {
|
|
26 |
$event_array = explode( '-', $event );
|
27 |
if ( 2 == count( $event_array ) ) {
|
28 |
if ( in_array( $event_array[0], $this->events ) && in_array( $event_array[1], array_keys( $roles ) ) ) {
|
29 |
-
$event_array[1] = $roles[$event_array[1]];
|
30 |
$this->insert_notification( $event_array );
|
31 |
}
|
32 |
}
|
@@ -47,20 +55,21 @@ class BNFW_Import {
|
|
47 |
if ( get_option( self::EMAIL_OPTION ) && get_option( self::SETTING_OPTION ) ) {
|
48 |
return true;
|
49 |
}
|
|
|
50 |
return false;
|
51 |
}
|
52 |
|
53 |
/**
|
54 |
* Insert notification.
|
55 |
*
|
56 |
-
* @param mixed
|
57 |
*/
|
58 |
private function insert_notification( $event ) {
|
59 |
$post = array(
|
60 |
-
'post_title'
|
61 |
-
'post_type'
|
62 |
'post_content' => '',
|
63 |
-
'post_status'
|
64 |
);
|
65 |
|
66 |
$post_id = wp_insert_post( $post );
|
@@ -83,7 +92,8 @@ class BNFW_Import {
|
|
83 |
/**
|
84 |
* Map old notification type to new notification type.
|
85 |
*
|
86 |
-
* @param mixed
|
|
|
87 |
* @return unknown
|
88 |
*/
|
89 |
private function map_notification( $event_name ) {
|
@@ -116,6 +126,7 @@ class BNFW_Import {
|
|
116 |
* Map content from old plugin.
|
117 |
*
|
118 |
* @param unknown $event_name
|
|
|
119 |
* @return unknown
|
120 |
*/
|
121 |
private function map_notification_content( $event_name ) {
|
@@ -123,7 +134,8 @@ class BNFW_Import {
|
|
123 |
if ( ! isset( $this->content_map ) ) {
|
124 |
$this->parse_content();
|
125 |
}
|
126 |
-
|
|
|
127 |
}
|
128 |
|
129 |
/**
|
@@ -137,7 +149,7 @@ class BNFW_Import {
|
|
137 |
foreach ( $old_content as $key => $value ) {
|
138 |
$key_array = explode( '-', $key );
|
139 |
if ( 3 == count( $key_array ) ) {
|
140 |
-
$content_map[$key_array[2]][$key_array[1]] = $value;
|
141 |
}
|
142 |
}
|
143 |
$this->content_map = $content_map;
|
@@ -153,4 +165,5 @@ class BNFW_Import {
|
|
153 |
delete_option( self::SETTING_OPTION );
|
154 |
}
|
155 |
}
|
|
|
156 |
?>
|
1 |
<?php
|
2 |
+
|
3 |
/**
|
4 |
* Import notification from old plugin.
|
5 |
*
|
6 |
* @since 1.0
|
7 |
*/
|
|
|
8 |
class BNFW_Import {
|
9 |
+
const EMAIL_OPTION = 'bnfw_custom_email_settings';
|
10 |
const SETTING_OPTION = 'bnfw_settings';
|
11 |
+
private $events = array(
|
12 |
+
'create_term',
|
13 |
+
'publish_post',
|
14 |
+
'comment_post',
|
15 |
+
'user_register',
|
16 |
+
'trackback_post',
|
17 |
+
'pingback_post',
|
18 |
+
'lostpassword_post',
|
19 |
+
);
|
20 |
|
21 |
/**
|
22 |
* Import notification from old plugin.
|
34 |
$event_array = explode( '-', $event );
|
35 |
if ( 2 == count( $event_array ) ) {
|
36 |
if ( in_array( $event_array[0], $this->events ) && in_array( $event_array[1], array_keys( $roles ) ) ) {
|
37 |
+
$event_array[1] = $roles[ $event_array[1] ];
|
38 |
$this->insert_notification( $event_array );
|
39 |
}
|
40 |
}
|
55 |
if ( get_option( self::EMAIL_OPTION ) && get_option( self::SETTING_OPTION ) ) {
|
56 |
return true;
|
57 |
}
|
58 |
+
|
59 |
return false;
|
60 |
}
|
61 |
|
62 |
/**
|
63 |
* Insert notification.
|
64 |
*
|
65 |
+
* @param mixed $event
|
66 |
*/
|
67 |
private function insert_notification( $event ) {
|
68 |
$post = array(
|
69 |
+
'post_title' => $event[0] . esc_html__( ' for ', 'bnfw' ) . $event[1] . esc_html__( ' (Auto Imported)', 'bnfw' ),
|
70 |
+
'post_type' => BNFW_Notification::POST_TYPE,
|
71 |
'post_content' => '',
|
72 |
+
'post_status' => 'publish',
|
73 |
);
|
74 |
|
75 |
$post_id = wp_insert_post( $post );
|
92 |
/**
|
93 |
* Map old notification type to new notification type.
|
94 |
*
|
95 |
+
* @param mixed $event_name
|
96 |
+
*
|
97 |
* @return unknown
|
98 |
*/
|
99 |
private function map_notification( $event_name ) {
|
126 |
* Map content from old plugin.
|
127 |
*
|
128 |
* @param unknown $event_name
|
129 |
+
*
|
130 |
* @return unknown
|
131 |
*/
|
132 |
private function map_notification_content( $event_name ) {
|
134 |
if ( ! isset( $this->content_map ) ) {
|
135 |
$this->parse_content();
|
136 |
}
|
137 |
+
|
138 |
+
return $this->content_map[ $event_name ];
|
139 |
}
|
140 |
|
141 |
/**
|
149 |
foreach ( $old_content as $key => $value ) {
|
150 |
$key_array = explode( '-', $key );
|
151 |
if ( 3 == count( $key_array ) ) {
|
152 |
+
$content_map[ $key_array[2] ][ $key_array[1] ] = $value;
|
153 |
}
|
154 |
}
|
155 |
$this->content_map = $content_map;
|
165 |
delete_option( self::SETTING_OPTION );
|
166 |
}
|
167 |
}
|
168 |
+
|
169 |
?>
|
includes/license/class-bnfw-license-setting.php
CHANGED
@@ -15,13 +15,14 @@ defined( 'ABSPATH' ) || exit; // Exit if accessed directly
|
|
15 |
function bnfw_add_license_page() {
|
16 |
add_submenu_page(
|
17 |
'edit.php?post_type=bnfw_notification',
|
18 |
-
|
19 |
-
|
20 |
'manage_options',
|
21 |
'bnfw-license',
|
22 |
'bnfw_render_license_page'
|
23 |
);
|
24 |
}
|
|
|
25 |
add_action( 'admin_menu', 'bnfw_add_license_page', 11 );
|
26 |
|
27 |
/**
|
@@ -33,26 +34,25 @@ function bnfw_render_license_page() {
|
|
33 |
$settings = apply_filters( 'bnfw_settings_licenses', array() );
|
34 |
ob_start(); ?>
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
<h2><?php _e( 'BNFW Add-on Licenses', 'bnfw' ); ?></h2>
|
39 |
|
40 |
-
|
41 |
<?php
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
?>
|
52 |
-
|
53 |
-
|
54 |
|
55 |
-
|
56 |
}
|
57 |
|
58 |
function bnfw_license_settings() {
|
@@ -62,7 +62,7 @@ function bnfw_license_settings() {
|
|
62 |
|
63 |
add_settings_section(
|
64 |
'bnfw_license_section', // Section ID
|
65 |
-
|
66 |
'__return_false', // Name of function that renders a description of the settings section
|
67 |
'bnfw-license' // Page to show on
|
68 |
);
|
@@ -76,20 +76,20 @@ function bnfw_license_settings() {
|
|
76 |
'bnfw-license',
|
77 |
'bnfw_license_section',
|
78 |
array(
|
79 |
-
'id' => isset( $option['id'] )
|
80 |
-
'desc' => ! empty( $option['desc'] )
|
81 |
-
'name' => isset( $option['name'] )
|
82 |
-
'size' => isset( $option['size'] )
|
83 |
-
'options' => isset( $option['options'] )
|
84 |
-
'std' => isset( $option['std'] )
|
85 |
-
'min' => isset( $option['min'] )
|
86 |
-
'max' => isset( $option['max'] )
|
87 |
-
'step' => isset( $option['step'] )
|
88 |
-
'chosen' => isset( $option['chosen'] )
|
89 |
'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : null,
|
90 |
'allow_blank' => isset( $option['allow_blank'] ) ? $option['allow_blank'] : true,
|
91 |
-
'readonly' => isset( $option['readonly'] )
|
92 |
-
'faux' => isset( $option['faux'] )
|
93 |
)
|
94 |
);
|
95 |
}
|
@@ -100,6 +100,7 @@ function bnfw_license_settings() {
|
|
100 |
);
|
101 |
}
|
102 |
}
|
|
|
103 |
add_action( 'admin_init', 'bnfw_license_settings', 11 );
|
104 |
|
105 |
/**
|
@@ -117,13 +118,13 @@ function bnfw_license_key_callback( $args ) {
|
|
117 |
}
|
118 |
|
119 |
$size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
|
120 |
-
$html = '<input type="text" class="' . $size . '-text" id="bnfw_licenses[' . $args['id'] . ']" name="bnfw_licenses[' . $args['id'] . ']" value="' . esc_attr( $value ) . '"
|
121 |
|
122 |
if ( 'valid' == get_option( $args['options']['is_valid_license_option'] ) ) {
|
123 |
-
$html .= '<input type="submit" class="button-secondary" name="' . $args['id'] . '_deactivate" value="' .
|
124 |
}
|
125 |
|
126 |
-
$html .= '<label for="bnfw_licenses[' . $args['id'] . ']"> '
|
127 |
|
128 |
echo $html;
|
129 |
}
|
15 |
function bnfw_add_license_page() {
|
16 |
add_submenu_page(
|
17 |
'edit.php?post_type=bnfw_notification',
|
18 |
+
esc_html__( 'Add-on Licenses', 'bnfw' ),
|
19 |
+
esc_html__( 'Add-on Licenses', 'bnfw' ),
|
20 |
'manage_options',
|
21 |
'bnfw-license',
|
22 |
'bnfw_render_license_page'
|
23 |
);
|
24 |
}
|
25 |
+
|
26 |
add_action( 'admin_menu', 'bnfw_add_license_page', 11 );
|
27 |
|
28 |
/**
|
34 |
$settings = apply_filters( 'bnfw_settings_licenses', array() );
|
35 |
ob_start(); ?>
|
36 |
|
37 |
+
<div class="wrap">
|
38 |
+
<h2><?php esc_html_e( 'BNFW Add-on Licenses', 'bnfw' ); ?></h2>
|
|
|
39 |
|
40 |
+
<form method="post" action="options.php" class="bnfw-form">
|
41 |
<?php
|
42 |
+
settings_errors();
|
43 |
+
settings_fields( 'bnfw-license-settings' );
|
44 |
+
do_settings_sections( 'bnfw-license' );
|
45 |
+
|
46 |
+
if ( ! empty( $settings ) ) {
|
47 |
+
submit_button( esc_html__( 'Save License', 'bnfw' ) );
|
48 |
+
} else {
|
49 |
+
esc_html_e( '<br>You have no BNFW Add-ons installed yet. You can buy add-ons from the <a href="https://betternotificationsforwp.com/store/?utm_source=WP%20Admin%20Submenu%20Item%20-%20"Add-on%20Licenses"&utm_medium=referral" target="_blank">Store</a>.', 'bnfw' );
|
50 |
+
}
|
51 |
?>
|
52 |
+
</form>
|
53 |
+
</div>
|
54 |
|
55 |
+
<?php echo ob_get_clean();
|
56 |
}
|
57 |
|
58 |
function bnfw_license_settings() {
|
62 |
|
63 |
add_settings_section(
|
64 |
'bnfw_license_section', // Section ID
|
65 |
+
esc_html__( '', 'bnfw' ), // Title above settings section
|
66 |
'__return_false', // Name of function that renders a description of the settings section
|
67 |
'bnfw-license' // Page to show on
|
68 |
);
|
76 |
'bnfw-license',
|
77 |
'bnfw_license_section',
|
78 |
array(
|
79 |
+
'id' => isset( $option['id'] ) ? $option['id'] : null,
|
80 |
+
'desc' => ! empty( $option['desc'] ) ? $option['desc'] : '',
|
81 |
+
'name' => isset( $option['name'] ) ? $option['name'] : null,
|
82 |
+
'size' => isset( $option['size'] ) ? $option['size'] : null,
|
83 |
+
'options' => isset( $option['options'] ) ? $option['options'] : '',
|
84 |
+
'std' => isset( $option['std'] ) ? $option['std'] : '',
|
85 |
+
'min' => isset( $option['min'] ) ? $option['min'] : null,
|
86 |
+
'max' => isset( $option['max'] ) ? $option['max'] : null,
|
87 |
+
'step' => isset( $option['step'] ) ? $option['step'] : null,
|
88 |
+
'chosen' => isset( $option['chosen'] ) ? $option['chosen'] : null,
|
89 |
'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : null,
|
90 |
'allow_blank' => isset( $option['allow_blank'] ) ? $option['allow_blank'] : true,
|
91 |
+
'readonly' => isset( $option['readonly'] ) ? $option['readonly'] : false,
|
92 |
+
'faux' => isset( $option['faux'] ) ? $option['faux'] : false,
|
93 |
)
|
94 |
);
|
95 |
}
|
100 |
);
|
101 |
}
|
102 |
}
|
103 |
+
|
104 |
add_action( 'admin_init', 'bnfw_license_settings', 11 );
|
105 |
|
106 |
/**
|
118 |
}
|
119 |
|
120 |
$size = isset( $args['size'] ) && ! is_null( $args['size'] ) ? $args['size'] : 'regular';
|
121 |
+
$html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="bnfw_licenses[' . $args['id'] . ']" name="bnfw_licenses[' . $args['id'] . ']" value="' . esc_attr( $value ) . '">';
|
122 |
|
123 |
if ( 'valid' == get_option( $args['options']['is_valid_license_option'] ) ) {
|
124 |
+
$html .= '<input type="submit" class="button-secondary" name="' . $args['id'] . '_deactivate" value="' . esc_attr__( 'Deactivate License', 'bnfw' ) . '">';
|
125 |
}
|
126 |
|
127 |
+
$html .= '<label for="bnfw_licenses[' . $args['id'] . ']"> ' . esc_html( $args['desc'] ) . '</label>';
|
128 |
|
129 |
echo $html;
|
130 |
}
|
includes/license/class-bnfw-license.php
CHANGED
@@ -22,12 +22,12 @@ class BNFW_License {
|
|
22 |
/**
|
23 |
* Class constructor
|
24 |
*
|
25 |
-
* @param string
|
26 |
-
* @param string
|
27 |
-
* @param string
|
28 |
-
* @param string
|
29 |
-
* @param string
|
30 |
-
* @param string
|
31 |
*/
|
32 |
function __construct( $_file, $_item_name, $_version, $_author, $_optname = null, $_api_url = null ) {
|
33 |
$bnfw_options = get_option( 'bnfw_licenses' );
|
@@ -77,7 +77,7 @@ class BNFW_License {
|
|
77 |
'version' => $this->version,
|
78 |
'license' => $this->license,
|
79 |
'item_name' => $this->item_name,
|
80 |
-
'author' => $this->author
|
81 |
)
|
82 |
);
|
83 |
}
|
@@ -86,14 +86,16 @@ class BNFW_License {
|
|
86 |
* Add license field to settings
|
87 |
*
|
88 |
* @access public
|
89 |
-
*
|
|
|
|
|
90 |
* @return array
|
91 |
*/
|
92 |
public function settings( $settings ) {
|
93 |
$bnfw_license_settings = array(
|
94 |
array(
|
95 |
'id' => $this->item_shortname . '_license_key',
|
96 |
-
'name' => sprintf(
|
97 |
'desc' => '',
|
98 |
'type' => 'license_key',
|
99 |
'options' => array( 'is_valid_license_option' => $this->item_shortname . '_license_active' ),
|
@@ -111,14 +113,17 @@ class BNFW_License {
|
|
111 |
* @return void
|
112 |
*/
|
113 |
public function activate_license() {
|
114 |
-
if ( ! isset( $_POST['bnfw_licenses'] ) )
|
115 |
return;
|
|
|
116 |
|
117 |
-
if ( ! isset( $_POST['bnfw_licenses'][ $this->item_shortname . '_license_key' ] ) )
|
118 |
return;
|
|
|
119 |
|
120 |
-
if ( 'valid' == get_option( $this->item_shortname . '_license_active' ) )
|
121 |
return;
|
|
|
122 |
|
123 |
$license = sanitize_text_field( $_POST['bnfw_licenses'][ $this->item_shortname . '_license_key' ] );
|
124 |
|
@@ -135,13 +140,14 @@ class BNFW_License {
|
|
135 |
array(
|
136 |
'timeout' => 15,
|
137 |
'body' => $api_params,
|
138 |
-
'sslverify' => false
|
139 |
)
|
140 |
);
|
141 |
|
142 |
// Make sure there are no errors
|
143 |
-
if ( is_wp_error( $response ) )
|
144 |
return;
|
|
|
145 |
|
146 |
// Decode license data
|
147 |
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
|
@@ -156,11 +162,13 @@ class BNFW_License {
|
|
156 |
* @return void
|
157 |
*/
|
158 |
public function deactivate_license() {
|
159 |
-
if ( ! isset( $_POST['bnfw_licenses'] ) )
|
160 |
return;
|
|
|
161 |
|
162 |
-
if ( ! isset( $_POST['bnfw_licenses'][ $this->item_shortname . '_license_key' ] ) )
|
163 |
return;
|
|
|
164 |
|
165 |
// Run on deactivate button press
|
166 |
if ( isset( $_POST[ $this->item_shortname . '_license_key_deactivate' ] ) ) {
|
@@ -177,19 +185,21 @@ class BNFW_License {
|
|
177 |
esc_url_raw( add_query_arg( $api_params, $this->api_url ) ),
|
178 |
array(
|
179 |
'timeout' => 15,
|
180 |
-
'sslverify' => false
|
181 |
)
|
182 |
);
|
183 |
|
184 |
// Make sure there are no errors
|
185 |
-
if ( is_wp_error( $response ) )
|
186 |
return;
|
|
|
187 |
|
188 |
// Decode the license data
|
189 |
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
|
190 |
|
191 |
-
if ( $license_data->license
|
192 |
delete_option( $this->item_shortname . '_license_active' );
|
|
|
193 |
}
|
194 |
}
|
195 |
}
|
22 |
/**
|
23 |
* Class constructor
|
24 |
*
|
25 |
+
* @param string $_file
|
26 |
+
* @param string $_item_name
|
27 |
+
* @param string $_version
|
28 |
+
* @param string $_author
|
29 |
+
* @param string $_optname
|
30 |
+
* @param string $_api_url
|
31 |
*/
|
32 |
function __construct( $_file, $_item_name, $_version, $_author, $_optname = null, $_api_url = null ) {
|
33 |
$bnfw_options = get_option( 'bnfw_licenses' );
|
77 |
'version' => $this->version,
|
78 |
'license' => $this->license,
|
79 |
'item_name' => $this->item_name,
|
80 |
+
'author' => $this->author,
|
81 |
)
|
82 |
);
|
83 |
}
|
86 |
* Add license field to settings
|
87 |
*
|
88 |
* @access public
|
89 |
+
*
|
90 |
+
* @param array $settings
|
91 |
+
*
|
92 |
* @return array
|
93 |
*/
|
94 |
public function settings( $settings ) {
|
95 |
$bnfw_license_settings = array(
|
96 |
array(
|
97 |
'id' => $this->item_shortname . '_license_key',
|
98 |
+
'name' => sprintf( esc_html__( '%1$s License Key', 'bnfw' ), $this->item_name ),
|
99 |
'desc' => '',
|
100 |
'type' => 'license_key',
|
101 |
'options' => array( 'is_valid_license_option' => $this->item_shortname . '_license_active' ),
|
113 |
* @return void
|
114 |
*/
|
115 |
public function activate_license() {
|
116 |
+
if ( ! isset( $_POST['bnfw_licenses'] ) ) {
|
117 |
return;
|
118 |
+
}
|
119 |
|
120 |
+
if ( ! isset( $_POST['bnfw_licenses'][ $this->item_shortname . '_license_key' ] ) ) {
|
121 |
return;
|
122 |
+
}
|
123 |
|
124 |
+
if ( 'valid' == get_option( $this->item_shortname . '_license_active' ) ) {
|
125 |
return;
|
126 |
+
}
|
127 |
|
128 |
$license = sanitize_text_field( $_POST['bnfw_licenses'][ $this->item_shortname . '_license_key' ] );
|
129 |
|
140 |
array(
|
141 |
'timeout' => 15,
|
142 |
'body' => $api_params,
|
143 |
+
'sslverify' => false,
|
144 |
)
|
145 |
);
|
146 |
|
147 |
// Make sure there are no errors
|
148 |
+
if ( is_wp_error( $response ) ) {
|
149 |
return;
|
150 |
+
}
|
151 |
|
152 |
// Decode license data
|
153 |
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
|
162 |
* @return void
|
163 |
*/
|
164 |
public function deactivate_license() {
|
165 |
+
if ( ! isset( $_POST['bnfw_licenses'] ) ) {
|
166 |
return;
|
167 |
+
}
|
168 |
|
169 |
+
if ( ! isset( $_POST['bnfw_licenses'][ $this->item_shortname . '_license_key' ] ) ) {
|
170 |
return;
|
171 |
+
}
|
172 |
|
173 |
// Run on deactivate button press
|
174 |
if ( isset( $_POST[ $this->item_shortname . '_license_key_deactivate' ] ) ) {
|
185 |
esc_url_raw( add_query_arg( $api_params, $this->api_url ) ),
|
186 |
array(
|
187 |
'timeout' => 15,
|
188 |
+
'sslverify' => false,
|
189 |
)
|
190 |
);
|
191 |
|
192 |
// Make sure there are no errors
|
193 |
+
if ( is_wp_error( $response ) ) {
|
194 |
return;
|
195 |
+
}
|
196 |
|
197 |
// Decode the license data
|
198 |
$license_data = json_decode( wp_remote_retrieve_body( $response ) );
|
199 |
|
200 |
+
if ( 'deactivated' == $license_data->license ) {
|
201 |
delete_option( $this->item_shortname . '_license_active' );
|
202 |
+
}
|
203 |
}
|
204 |
}
|
205 |
}
|
includes/overrides.php
CHANGED
@@ -36,14 +36,14 @@ if ( ! function_exists( 'wp_new_user_notification' ) ) {
|
|
36 |
|
37 |
// The blogname option is escaped with esc_html on the way into the database in sanitize_option
|
38 |
// we want to reverse this for the plain text arena of emails.
|
39 |
-
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
|
40 |
|
41 |
if ( ! $bnfw->notifier->notification_exists( 'admin-user', false ) ) {
|
42 |
-
$message
|
43 |
-
$message .= sprintf(
|
44 |
-
$message .= sprintf(
|
45 |
|
46 |
-
@wp_mail(get_option('admin_email'), sprintf(
|
47 |
}
|
48 |
|
49 |
if ( 'admin' === $notify || empty( $notify ) ) {
|
@@ -66,18 +66,18 @@ if ( ! function_exists( 'wp_new_user_notification' ) ) {
|
|
66 |
|
67 |
if ( $bnfw->notifier->notification_exists( 'new-user', false ) ) {
|
68 |
$notifications = $bnfw->notifier->get_notifications( 'new-user' );
|
69 |
-
$password_url
|
70 |
foreach ( $notifications as $notification ) {
|
71 |
$bnfw->engine->send_registration_email( $bnfw->notifier->read_settings( $notification->ID ), $user, $password_url );
|
72 |
}
|
73 |
} else {
|
74 |
-
$message = sprintf(
|
75 |
-
$message .=
|
76 |
-
$message .= '<' . network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user->user_login), 'login') . ">\r\n\r\n";
|
77 |
|
78 |
$message .= wp_login_url() . "\r\n";
|
79 |
|
80 |
-
wp_mail($user->user_email, sprintf(
|
81 |
}
|
82 |
} else {
|
83 |
|
@@ -89,11 +89,11 @@ if ( ! function_exists( 'wp_new_user_notification' ) ) {
|
|
89 |
$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
|
90 |
|
91 |
if ( ! $bnfw->notifier->notification_exists( 'admin-user', false ) ) {
|
92 |
-
$message
|
93 |
-
$message .= sprintf(
|
94 |
-
$message .= sprintf(
|
95 |
|
96 |
-
@wp_mail( get_option( 'admin_email' ), sprintf(
|
97 |
}
|
98 |
|
99 |
if ( empty( $plaintext_pass ) ) {
|
@@ -106,11 +106,11 @@ if ( ! function_exists( 'wp_new_user_notification' ) ) {
|
|
106 |
$bnfw->engine->send_registration_email( $bnfw->notifier->read_settings( $notification->ID ), $user, $plaintext_pass );
|
107 |
}
|
108 |
} else {
|
109 |
-
$message
|
110 |
-
$message .= sprintf(
|
111 |
$message .= wp_login_url() . "\r\n";
|
112 |
|
113 |
-
wp_mail( $user->user_email, sprintf(
|
114 |
}
|
115 |
}
|
116 |
}
|
36 |
|
37 |
// The blogname option is escaped with esc_html on the way into the database in sanitize_option
|
38 |
// we want to reverse this for the plain text arena of emails.
|
39 |
+
$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
|
40 |
|
41 |
if ( ! $bnfw->notifier->notification_exists( 'admin-user', false ) ) {
|
42 |
+
$message = sprintf( esc_html__( 'New user registration on your site %s:' ), $blogname ) . "\r\n\r\n";
|
43 |
+
$message .= sprintf( esc_html__( 'Username: %s' ), $user->user_login ) . "\r\n\r\n";
|
44 |
+
$message .= sprintf( esc_html__( 'E-mail: %s' ), $user->user_email ) . "\r\n";
|
45 |
|
46 |
+
@wp_mail( get_option( 'admin_email' ), sprintf( esc_html__( '[%s] New User Registration' ), $blogname ), $message );
|
47 |
}
|
48 |
|
49 |
if ( 'admin' === $notify || empty( $notify ) ) {
|
66 |
|
67 |
if ( $bnfw->notifier->notification_exists( 'new-user', false ) ) {
|
68 |
$notifications = $bnfw->notifier->get_notifications( 'new-user' );
|
69 |
+
$password_url = network_site_url( 'wp-login.php?action=rp&key=' . $key . '&login=' . rawurlencode( $user->user_login ), 'login' );
|
70 |
foreach ( $notifications as $notification ) {
|
71 |
$bnfw->engine->send_registration_email( $bnfw->notifier->read_settings( $notification->ID ), $user, $password_url );
|
72 |
}
|
73 |
} else {
|
74 |
+
$message = sprintf( esc_html__( 'Username: %s' ), $user->user_login ) . "\r\n\r\n";
|
75 |
+
$message .= esc_html__( 'To set your password, visit the following address:' ) . "\r\n\r\n";
|
76 |
+
$message .= '<' . network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $user->user_login ), 'login' ) . ">\r\n\r\n";
|
77 |
|
78 |
$message .= wp_login_url() . "\r\n";
|
79 |
|
80 |
+
wp_mail( $user->user_email, sprintf( esc_html__( '[%s] Your username and password info' ), $blogname ), $message );
|
81 |
}
|
82 |
} else {
|
83 |
|
89 |
$blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
|
90 |
|
91 |
if ( ! $bnfw->notifier->notification_exists( 'admin-user', false ) ) {
|
92 |
+
$message = sprintf( esc_html__( 'New user registration on your site %s:' ), $blogname ) . "\r\n\r\n";
|
93 |
+
$message .= sprintf( esc_html__( 'Username: %s' ), $user->user_login ) . "\r\n\r\n";
|
94 |
+
$message .= sprintf( esc_html__( 'E-mail: %s' ), $user->user_email ) . "\r\n";
|
95 |
|
96 |
+
@wp_mail( get_option( 'admin_email' ), sprintf( esc_html__( '[%s] New User Registration' ), $blogname ), $message );
|
97 |
}
|
98 |
|
99 |
if ( empty( $plaintext_pass ) ) {
|
106 |
$bnfw->engine->send_registration_email( $bnfw->notifier->read_settings( $notification->ID ), $user, $plaintext_pass );
|
107 |
}
|
108 |
} else {
|
109 |
+
$message = sprintf( esc_html__( 'Username: %s' ), $user->user_login ) . "\r\n";
|
110 |
+
$message .= sprintf( esc_html__( 'Password: %s' ), $plaintext_pass ) . "\r\n";
|
111 |
$message .= wp_login_url() . "\r\n";
|
112 |
|
113 |
+
wp_mail( $user->user_email, sprintf( esc_html__( '[%s] Your username and password' ), $blogname ), $message );
|
114 |
}
|
115 |
}
|
116 |
}
|
includes/tmp.php
DELETED
@@ -1,43 +0,0 @@
|
|
1 |
-
<tr valign="top" id="toggle-fields">
|
2 |
-
<th>
|
3 |
-
<?php esc_attr_e( 'Additional Email Fields', 'bnfw' ); ?>
|
4 |
-
</th>
|
5 |
-
<td>
|
6 |
-
<input type="checkbox" id="show-fields" name="show-fields" value="true" <?php checked( $setting['show-fields'], 'true', true ); ?>>
|
7 |
-
<?php esc_html_e( 'Show additional email fields', 'bnfw' ); ?>
|
8 |
-
</td>
|
9 |
-
</tr>
|
10 |
-
|
11 |
-
<tr valign="top" id="email">
|
12 |
-
<th scope="row">
|
13 |
-
<?php _e( 'From Name and Email', 'bnfw' ); ?>
|
14 |
-
</th>
|
15 |
-
<td>
|
16 |
-
<input type="text" name="from-name" value="<?php echo $setting['from-name']; ?>" placeholder="Site Name" style="width:37%">
|
17 |
-
<input type="email" name="from-email" value="<?php echo $setting['from-email']; ?>" placeholder="Admin Email" style="width:37%">
|
18 |
-
</td>
|
19 |
-
</tr>
|
20 |
-
|
21 |
-
<tr valign="top" id="cc">
|
22 |
-
<th scope="row">
|
23 |
-
<?php _e( 'CC', 'bnfw' ); ?>
|
24 |
-
</th>
|
25 |
-
|
26 |
-
<td>
|
27 |
-
<?php $this->render_roles_dropdown( 'cc-roles', $setting['cc-roles'] ); ?>
|
28 |
-
<input type="email" name="cc-email" value="<?php echo $setting['cc-email']; ?>" placeholder="Additional email addresses" style="width:50%;">
|
29 |
-
</td>
|
30 |
-
</tr>
|
31 |
-
|
32 |
-
<tr valign="top" id="bcc">
|
33 |
-
<th scope="row">
|
34 |
-
<?php _e( 'BCC', 'bnfw' ); ?>
|
35 |
-
</th>
|
36 |
-
|
37 |
-
<td>
|
38 |
-
<?php $this->render_roles_dropdown( 'bcc-roles', $setting['bcc-roles'] ); ?>
|
39 |
-
<input type="email" name="bcc-email" value="<?php echo $setting['bcc-email']; ?>" placeholder="Additional email addresses" style="width:50%;">
|
40 |
-
</td>
|
41 |
-
</tr>
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
languages/bnfw-de_DE.po
CHANGED
@@ -73,7 +73,7 @@ msgstr "Nur Text"
|
|
73 |
#: includes/admin/class-bnfw-notification.php:48
|
74 |
#: includes/admin/class-bnfw-notification.php:49
|
75 |
msgid "Notifications"
|
76 |
-
msgstr "
|
77 |
|
78 |
#: includes/admin/class-bnfw-notification.php:46
|
79 |
msgid "Notification"
|
73 |
#: includes/admin/class-bnfw-notification.php:48
|
74 |
#: includes/admin/class-bnfw-notification.php:49
|
75 |
msgid "Notifications"
|
76 |
+
msgstr "Notifications"
|
77 |
|
78 |
#: includes/admin/class-bnfw-notification.php:46
|
79 |
msgid "Notification"
|