forked from humanmade/P2-By-Email
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp2-by-email.php
120 lines (91 loc) · 3.08 KB
/
p2-by-email.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/*
Plugin Name: P2 By Email
Version: 1.1-alpha
Description: For those who like to interact with P2 by email.
Author: danielbachhuber, humanmade
Author URI: http://hmn.md/
Plugin URI: http://wordpress.org/extend/plugins/p2-by-email/
Text Domain: p2-by-email
Domain Path: /languages
*/
class P2_By_Email {
private $data;
private static $instance;
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new P2_By_Email;
self::$instance->setup_globals();
self::$instance->includes();
self::$instance->setup_actions();
}
return self::$instance;
}
private function __construct() {
/** Prevent the class from being loaded more than once **/
}
public function __isset( $key ) {
return isset( $this->data[$key] );
}
public function __get( $key ) {
return isset( $this->data[$key] ) ? $this->data[$key] : null;
}
public function __set( $key, $value ) {
$this->data[$key] = $value;
}
private function setup_globals() {
$this->file = __FILE__;
$this->basename = apply_filters( 'p2be_plugin_basenname', plugin_basename( $this->file ) );
$this->plugin_dir = apply_filters( 'p2be_plugin_dir_path', plugin_dir_path( $this->file ) );
$this->plugin_url = apply_filters( 'p2be_plugin_dir_url', plugin_dir_url ( $this->file ) );
$this->extend = new stdClass();
}
private function includes() {
require_once( $this->plugin_dir . 'inc/class-p2be-emails.php' );
require_once( $this->plugin_dir . 'inc/class-p2be-email-replies.php' );
require_once( $this->plugin_dir . 'inc/class-p2be-settings.php' );
require_once( $this->plugin_dir . 'inc/what-the-email/what-the-email.php' );
if ( defined('WP_CLI') && WP_CLI )
require_once( $this->plugin_dir . 'inc/class-p2be-wp-cli.php' );
}
private function setup_actions() {
do_action_ref_array( 'p2be_after_setup_actions', array( &$this ) );
}
protected function get_following_post( $post_id ) {
return wp_list_pluck( get_users(), 'user_login' );
}
protected function get_template( $template, $vars = array() ) {
$template_path = dirname( __FILE__ ) . '/templates/' . $template . '.php';
ob_start();
if ( file_exists( $template_path ) ) {
extract( $vars );
include $template_path;
}
return wpautop( ob_get_clean() );
}
/**
* Get a default From name for this site
*/
protected function get_default_from_name() {
return apply_filters( 'p2be_emails_from_name', get_bloginfo( 'name' ) );
}
/**
* Get a default From email address for this domain
*/
protected function get_default_from_address() {
return apply_filters( 'p2be_emails_from_address', $this->get_domain_email_address( 'noreply' ) );
}
/**
* Get a fake email address for this domain
*
* @param string $mailbox A fake mailbox
* @return string $email_address A fake email address at this domain
*/
protected function get_domain_email_address( $mailbox ) {
return $mailbox . '@' . parse_url( home_url(), PHP_URL_HOST );
}
}
function P2_By_Email() {
return P2_By_Email::get_instance();
}
add_action( 'plugins_loaded', 'P2_By_Email' );