-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgm-mailchimp-form.php
104 lines (88 loc) · 2.47 KB
/
gm-mailchimp-form.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
<?php
namespace GMMailchimpForm;
/**
* Plugin Name: Gm Mailchimp Form
* Description: This plugin allows you to display a Block for newsletter form subscription.
* Requires at least: 5.7
* Requires PHP: 7.0
* Version: 0.1.0
* Author: Faramaz Patrick <[email protected]>
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: gm-mailchimp-form
*
* @package goodmotion
*/
require_once( dirname( __FILE__ ) . '/includes/rest.php' );
require_once(dirname(__FILE__) . '/includes/config_panel.php');
require_once(dirname(__FILE__) . '/includes/token.php');
require_once( dirname( __FILE__ ) . '/includes/form.php' );
$PLUGIN_NAME = 'gm-mailchimp-form';
$VERSION = '0.0.1';
/**
* Load the plugin text domain for translation.
*
*/ function load_textdomain()
{
load_plugin_textdomain(
'gm-mailchimp-form',
false,
basename(dirname(__FILE__)) . '/languages'
);
}
/**
* load translations
*/
function set_script_translations()
{
wp_set_script_translations('gm-mailchimp-form', 'gm-mailchimp-form', plugin_dir_path(__FILE__) . 'languages');
}
add_action('init', __NAMESPACE__ . '\load_textdomain');
add_action('init', __NAMESPACE__ . '\set_script_translations');
/**
* block registration
*/
function block_init()
{
register_block_type_from_metadata(__DIR__, [
"render_callback" => __NAMESPACE__ . '\Includes\render_callback',
]);
}
add_action('init', __NAMESPACE__ . '\block_init');
/**
* add api endpoint
*/
add_action(
'rest_api_init',
function () {
register_rest_route('gm_mailchimp_form', '/action', array(
'methods' => 'POST',
'permission_callback' => '__return_true',
'callback' => 'GMMailchimpForm\Includes\form_callback'
));
}
);
/**
* add api endpoint
*/
add_action(
'rest_api_init',
function () {
register_rest_route('gm_mailchimp_form', '/getToken', array(
'methods' => 'GET',
'permission_callback' => '__return_true',
'callback' => 'GMMailchimpForm\Includes\get_token_request'
));
}
);
/**
* add script if block is in content
*/
add_action('wp_enqueue_scripts', function () use ($PLUGIN_NAME, $VERSION) {
$id = get_the_ID();
if (has_block('goodmotion/block-gm-mailchimp-form', $id)) {
// add script only if shortcode is used
$path = plugins_url() . '/' . $PLUGIN_NAME;
wp_enqueue_script($PLUGIN_NAME, $path . '/assets/scripts.js', array(), $VERSION, true);
}
});