generated from alleyinteractive/create-wordpress-plugin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplugin.php
137 lines (124 loc) · 3.81 KB
/
plugin.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
<?php
/**
* Plugin Name: Newsletter Builder
* Plugin URI: https://github.com/alleyinteractive/wp-newsletter-builder
* Description: Interface to manage email newsletters
* Version: 0.5.0
* Author: Alley Interactive
* Author URI: https://github.com/alleyinteractive/wp-newsletter-builder
* Requires at least: 6.2
* Tested up to: 6.5.2
*
* Text Domain: wp-newsletter-builder
* Domain Path: /languages/
*
* @package wp-newsletter-builder
*/
namespace WP_Newsletter_Builder;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Root directory to this plugin.
*/
define( 'WP_NEWSLETTER_BUILDER_DIR', __DIR__ );
// Check if Composer is installed (remove if Composer is not required for your plugin).
if ( ! file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
\add_action(
'admin_notices',
function () {
?>
<div class="notice notice-error">
<p><?php esc_html_e( 'Composer is not installed and wp-newsletter-builder cannot load. Try using a `*-built` branch if the plugin is being loaded as a submodule.', 'wp-newsletter-builder' ); ?></p>
</div>
<?php
}
);
return;
}
// Load Composer dependencies.
require_once __DIR__ . '/vendor/autoload.php';
// Load the plugin's main files.
require_once __DIR__ . '/src/assets.php';
require_once __DIR__ . '/src/meta.php';
require_once __DIR__ . '/src/utils.php';
require_once __DIR__ . '/block-filters/button/index.php';
require_once __DIR__ . '/block-filters/heading/index.php';
require_once __DIR__ . '/block-filters/image/index.php';
require_once __DIR__ . '/block-filters/latest-posts/index.php';
require_once __DIR__ . '/block-filters/list/index.php';
require_once __DIR__ . '/block-filters/paragraph/index.php';
require_once __DIR__ . '/block-filters/separator/index.php';
require_once __DIR__ . '/plugins/newsletter-from-post/index.php';
require_once __DIR__ . '/plugins/newsletter-status/index.php';
require_once __DIR__ . '/plugins/newsletter-template-styles/index.php';
require_once __DIR__ . '/plugins/pre-publish-checks/index.php';
/* class files get loaded by the autoloader */
global $newsletter_builder_email_provider;
/**
* Instantiate the plugin.
*/
function main(): void {
new Ads();
new Block_Modifications();
new Email_Types();
new Settings();
new Media();
new WP_Newsletter_Builder();
new Rest_API_Endpoints();
new Rest_API_Fields();
new Rest_API_Query();
// Find selected email provider and instantiate it.
$selected_email_provider = apply_filters( 'wp_newsletter_builder_selected_provider', '' );
// Check if provider has been selected and exists.
if ( empty( $selected_email_provider ) || ! class_exists( $selected_email_provider ) ) {
\add_action(
'admin_notices',
function () {
wp_admin_notice(
// translators: %s is the filter name.
sprintf(
/* translators: %s is the WordPress filter name */
esc_html__(
'No email provider selected for WP Newsletter Builder. Use the %s filter to specify one.',
'wp-newsletter-builder'
),
'<code>wp_newsletter_builder_selected_provider</code>'
),
[
'type' => 'error',
'dismissible' => false,
]
);
}
);
return;
}
global $newsletter_builder_email_provider;
$provider = new $selected_email_provider();
$newsletter_builder_email_provider = new $provider();
if ( $newsletter_builder_email_provider instanceof Email_Providers\Email_Provider ) {
$newsletter_builder_email_provider->setup();
} else {
\add_action(
'admin_notices',
function () use ( $selected_email_provider ) {
wp_admin_notice(
sprintf(
// translators: %s is the email provider class name.
esc_html__(
'The selected email provider %s is not supported.',
'wp-newsletter-builder'
),
$selected_email_provider
),
[
'type' => 'error',
'dismissible' => false,
]
);
}
);
}
}
main();