-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-job-manager-mail-applications.php
180 lines (154 loc) · 3.93 KB
/
wp-job-manager-mail-applications.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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
<?php namespace WP_Job_Manager_Mail_Applications;
/**
* Plugin Name: WP Job Manager - Mail Applications
* Description: Quick way to mail job application with stored maillist
* Version: 1.0.0
* Author: Nabeel Molham
* Author URI: https://nabeel.molham.me/
* Text Domain: wp-job-manager-mail-applications
* Domain Path: /languages
* License: GNU General Public License, version 3, http://www.gnu.org/licenses/gpl-3.0.en.html
*/
if ( ! defined( 'WPINC' ) ) {
// Exit if accessed directly
die();
}
/**
* Constants
*/
// plugin master file
define( 'WPJM_MA_MAIN_FILE', __FILE__ );
// plugin DIR
define( 'WPJM_MA_DIR', plugin_dir_path( WPJM_MA_MAIN_FILE ) );
// plugin URI
define( 'WPJM_MA_URI', plugin_dir_url( WPJM_MA_MAIN_FILE ) );
// localization text Domain
define( 'WPJM_MA_DOMAIN', 'wp-job-manager-mail-applications' );
require_once WPJM_MA_DIR . 'includes/classes/Singular.php';
require_once WPJM_MA_DIR . 'includes/helpers.php';
require_once WPJM_MA_DIR . 'includes/functions.php';
/**
* Plugin main component
*
* @package WP_Job_Manager_Mail_Applications
*/
class Plugin extends Singular {
/**
* Plugin version
*
* @var string
*/
public $version = '1.0.0';
/**
* Backend
*
* @var Backend
*/
public $backend;
/**
* Backend
*
* @var Frontend
*/
public $frontend;
/**
* Backend
*
* @var Ajax_Handler
*/
public $ajax;
/**
* Initialization
*
* @return void
*/
protected function init() {
// load language files
add_action( 'plugins_loaded', [ &$this, 'load_language' ] );
// autoloader register
spl_autoload_register( [ &$this, 'autoloader' ] );
// modules
$this->ajax = Ajax_Handler::get_instance();
$this->backend = Backend::get_instance();
$this->frontend = Frontend::get_instance();
// plugin loaded hook
do_action_ref_array( 'wpjm_ma_loaded', [ &$this ] );
}
/**
* Load view template
*
* @param string $view_name
* @param array $args ( optional )
*
* @return void
*/
public function load_view( $view_name, $args = null ) {
// build view file path
$__view_name = $view_name;
$__template_path = WPJM_MA_DIR . 'views/' . $__view_name . '.php';
if ( ! file_exists( $__template_path ) ) {
// file not found!
wp_die( sprintf( __( 'Template <code>%s</code> File not found, calculated path: <code>%s</code>', WPJM_MA_DOMAIN ), $__view_name, $__template_path ) );
}
// clear vars
unset( $view_name );
if ( ! empty( $args ) ) {
// extract passed args into variables
extract( $args, EXTR_OVERWRITE );
}
/**
* Before loading template hook
*
* @param string $__template_path
* @param string $__view_name
*/
do_action_ref_array( 'wpjm_ma_load_template_before', [ &$__template_path, $__view_name, $args ] );
/**
* Loading template file path filter
*
* @param string $__template_path
* @param string $__view_name
*
* @return string
*/
require apply_filters( 'wpjm_ma_load_template_path', $__template_path, $__view_name, $args );
/**
* After loading template hook
*
* @param string $__template_path
* @param string $__view_name
*/
do_action( 'wpjm_ma_load_template_after', $__template_path, $__view_name, $args );
}
/**
* Language file loading
*
* @return void
*/
public function load_language() {
load_plugin_textdomain( WPJM_MA_DOMAIN, false, dirname( plugin_basename( WPJM_MA_MAIN_FILE ) ) . '/languages' );
}
/**
* System classes loader
*
* @param $class_name
*
* @return void
*/
public function autoloader( $class_name ) {
if ( strpos( $class_name, __NAMESPACE__ ) === false ) {
// skip non related classes
return;
}
$class_path = WPJM_MA_DIR . 'includes' . DIRECTORY_SEPARATOR . 'classes' . str_replace( [
__NAMESPACE__,
'\\',
], [ '', DIRECTORY_SEPARATOR ], $class_name ) . '.php';
if ( file_exists( $class_path ) ) {
// load class file if found
require_once $class_path;
}
}
}
// boot up the system
wp_job_manager_mail_applications();