-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcivicrm-wp-mosaico.php
174 lines (125 loc) · 3.91 KB
/
civicrm-wp-mosaico.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
<?php /*
--------------------------------------------------------------------------------
Plugin Name: CiviCRM WordPress Mosaico Test
Plugin URI: https://github.com/christianwach/civicrm-wp-mosaico
Description: Overrides the Mosaico template.
Author: Christian Wach
Version: 0.1
Author URI: http://haystack.co.uk
Text Domain: civicrm-wp-mosaico
Domain Path: /languages
Depends: CiviCRM
--------------------------------------------------------------------------------
*/
// Set plugin version here.
define( 'CIVICRM_WP_MOSAICO_VERSION', '0.1' );
// Store reference to this file.
if ( ! defined( 'CIVICRM_WP_MOSAICO_FILE' ) ) {
define( 'CIVICRM_WP_MOSAICO_FILE', __FILE__ );
}
// Store URL to this plugin's directory.
if ( ! defined( 'CIVICRM_WP_MOSAICO_URL' ) ) {
define( 'CIVICRM_WP_MOSAICO_URL', plugin_dir_url( CIVICRM_WP_MOSAICO_FILE ) );
}
// Store PATH to this plugin's directory.
if ( ! defined( 'CIVICRM_WP_MOSAICO_PATH' ) ) {
define( 'CIVICRM_WP_MOSAICO_PATH', plugin_dir_path( CIVICRM_WP_MOSAICO_FILE ) );
}
/**
* CiviCRM WordPress Mosaico Class.
*
* A class that encapsulates this plugin's functionality.
*
* @since 0.1
*/
class CiviCRM_WP_Mosaico {
/**
* Initialises this object.
*
* @since 0.1
*/
public function __construct() {
// Register PHP and template directories.
add_action( 'civicrm_config', array( $this, 'register_directories' ), 10 );
}
/**
* Register directories that CiviCRM searches in.
*
* @since 0.1
*
* @param object $config The CiviCRM config object.
*/
public function register_directories( &$config ) {
Civi::service('dispatcher')->addListener(
'hook_civicrm_coreResourceList',
array( $this, 'register_php_directory' ),
-200
);
Civi::service('dispatcher')->addListener(
'hook_civicrm_coreResourceList',
array( $this, 'register_template_directory' ),
-200
);
}
/**
* Register directory that CiviCRM searches in for new PHP files.
*
* This only works with *new* PHP files. One cannot override existing PHP
* with this technique - instead, the file must be placed in the path:
* defined in $config->customPHPPathDir
*
* @since 0.1
*
* @param \Civi\Core\Event\GenericHookEvent $event The event object.
* @param str $hook The name of the hook currently being run.
*/
public function register_php_directory( $event, $hook ) {
// Kick out if no CiviCRM.
if ( ! civi_wp()->initialize() ) return;
// Define our custom path.
$custom_path = CIVICRM_WP_MOSAICO_PATH . 'civicrm_php';
// Add to include path.
$include_path = $custom_path . PATH_SEPARATOR . get_include_path();
set_include_path( $include_path );
}
/**
* Register directories that CiviCRM searches for template files.
*
* @since 0.1
*
* @param \Civi\Core\Event\GenericHookEvent $event The event object.
* @param str $hook The name of the hook currently being run.
*/
public function register_template_directory( $event, $hook ) {
// Define our custom path.
$custom_path = CIVICRM_WP_MOSAICO_PATH . 'civicrm_templates';
// Kick out if no CiviCRM.
if ( ! civi_wp()->initialize() ) return;
// Get template instance.
$template = CRM_Core_Smarty::singleton();
// Add our custom template directory.
$template->addTemplateDir( $custom_path );
// Register template directories.
$template_include_path = $custom_path . PATH_SEPARATOR . get_include_path();
set_include_path( $template_include_path );
}
} // Class ends.
/**
* Load plugin if not yet loaded and return reference.
*
* @since 0.1
*
* @return CiviCRM_WP_Mosaico $civicrm_wp_mosaico The plugin reference.
*/
function civicrm_wp_mosaico() {
// Declare as static.
static $civicrm_wp_mosaico;
// Instantiate plugin if not yet instantiated.
if ( ! isset( $civicrm_wp_mosaico ) ) {
$civicrm_wp_mosaico = new CiviCRM_WP_Mosaico();
}
// --<
return $civicrm_wp_mosaico;
}
// Load only when CiviCRM has loaded.
add_action( 'civicrm_instance_loaded', 'civicrm_wp_mosaico' );