summaryrefslogtreecommitdiff
path: root/Postman/Postman-Email-Log/PostmanEmailLogPostType.php
blob: cf297db222a8b9b0a0f450afb9a6dd5c68175fea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}
if (! class_exists ( 'PostmanEmailLogPostType' )) {
	
	/**
	 * This class creates the Custom Post Type for Email Logs and handles writing these posts.
	 *
	 * @author jasonhendriks
	 */
	class PostmanEmailLogPostType {
		
		// constants
		const POSTMAN_CUSTOM_POST_TYPE_SLUG = 'postman_sent_mail';
		
		/**
		 * Behavior to run on the WordPress 'init' action
		 */
		public static function automaticallyCreatePostType() {
			add_action ( 'init', array (
					new PostmanEmailLogPostType (),
					'create_post_type' 
			) );
		}
		
		/**
		 * Create a custom post type
		 * Callback function - must be public scope
		 *
		 * register_post_type should only be invoked through the 'init' action.
		 * It will not work if called before 'init', and aspects of the newly
		 * created or modified post type will work incorrectly if called later.
		 *
		 * https://codex.wordpress.org/Function_Reference/register_post_type
		 */
		public static function create_post_type() {
			register_post_type ( self::POSTMAN_CUSTOM_POST_TYPE_SLUG, array (
					'labels' => array (
							'name' => _x ( 'Sent Emails', 'The group of Emails that have been delivered', 'post-smtp' ),
							'singular_name' => _x ( 'Sent Email', 'An Email that has been delivered', 'post-smtp' ) 
					),
					'capability_type' => '',
					'capabilities' => array () 
			) );
			$logger = new PostmanLogger ( 'PostmanEmailLogPostType' );
			$logger->trace ( 'Created post type: ' . self::POSTMAN_CUSTOM_POST_TYPE_SLUG );
		}
	}
}