-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-sendgrid-categories.php
49 lines (42 loc) · 1.99 KB
/
wp-sendgrid-categories.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/**
* Plugin Name: WP SendGrid Categories
* Description: Associates a category with emails that are sent through SendGrid
* Plugin URI: http://github.com/codeawhile/wp-sendgrid-categories/
* Author: CodeAwhile.com
* Author URI: http://codeawhile.com/
* Version: 1.0
*/
class WP_SendGrid_Categories {
const CATEGORY_SECTION_ID = 'wp-sendgrid-email-category';
public static function start() {
add_action( 'admin_init', array( __CLASS__, 'add_category_settings' ), 11 );
add_filter( 'wp_sendgrid_xsmtpapi', array( __CLASS__, 'add_category' ) );
}
public static function add_category_settings() {
if ( class_exists( 'WP_SendGrid_Settings' ) ) {
add_settings_section( self::CATEGORY_SECTION_ID, __( 'Email Category' ),
array( __CLASS__, 'show_section_description' ), WP_SendGrid_Settings::SETTINGS_PAGE_SLUG );
add_settings_field( self::CATEGORY_SECTION_ID . '-category', __( 'Email Category' ),
array( __CLASS__, 'display_category_field' ), WP_SendGrid_Settings::SETTINGS_PAGE_SLUG, self::CATEGORY_SECTION_ID );
}
}
public static function show_section_description() {
echo '<p>' . __( 'Configure a category to be added to all emails sent through WP SendGrid' ) . '</p>';
}
public static function display_category_field() {
$settings = WP_SendGrid_Settings::get_settings();
$category = isset( $settings['category'] ) ? $settings['category'] : '';
echo '<input type="text" name="' . esc_attr( WP_SendGrid_Settings::SETTINGS_OPTION_NAME . '[category]' )
. '" id="' . self::CATEGORY_SECTION_ID . '-category" value="' . $category . '"/>';
echo ' <span class="description">' . __( 'This category will be associated with all emails sent through SendGrid' ) . '</span>';
}
public static function add_category( $xsmtpapi ) {
$settings = WP_SendGrid_Settings::get_settings();
if ( !empty( $settings['category'] ) ) {
$xsmtpapi['category'] = $settings['category'];
}
return $xsmtpapi;
}
}
WP_SendGrid_Categories::start();