-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecomail-newsletter.php
188 lines (160 loc) · 5.34 KB
/
ecomail-newsletter.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
181
182
183
184
185
186
187
188
<?php
/*
Plugin Name: Ecomail Newsletter
Plugin URI: https://github.com/adam-laita/ecomail-newsletter/
Description: Ecomail Newsletter plugin.
Version: 1.0.0
Author: Daniel Koch, Adam Laita
Author URI: https://github.com/adam-laita/ecomail-newsletter/
License: GPL3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
Text Domain: klen
Domain Path: /languages
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
// Path, directory & basename
define( 'KLEN_PATH_DIR', plugin_dir_path( __FILE__ ) );
define( 'KLEN_PATH_URL', plugin_dir_url( __FILE__ ) );
define( 'KLEN_BASENAME', plugin_basename( __FILE__ ) );
class KLEN_Ecomail {
/**
* Plugin meta
*
* @var string
*/
public $plugin_meta;
/**
*
*/
public function __construct() {
$this->actions();
$this->includePluginFiles();
$this->registerSettingsFields();
}
/**
* List all actions of the plugin
*
* @return void
*/
private function actions() {
add_action( 'wp_enqueue_scripts', array( $this, 'registerFrontendScripts' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'registerAdminScripts' ) );
add_action( 'admin_menu', array( $this, 'createAdminPage' ) );
add_action( 'admin_init', array( $this, 'languageTextdomain' ) );
add_filter( 'plugin_action_links', array( $this, 'addSettingsLink' ), 10, 2 );
}
/**
* Adds textdomain for translations.
*
* @return void
*/
public function languageTextdomain() {
load_plugin_textdomain( 'klen', false, dirname( KLEN_BASENAME ) . '/languages' );
}
/**
* @return void
*/
private function includePluginFiles() {
require_once KLEN_PATH_DIR . '/admin/settings/labels.php';
require_once KLEN_PATH_DIR . '/admin/settings/appearance.php';
require_once KLEN_PATH_DIR . '/admin/settings/main.php';
require_once KLEN_PATH_DIR . '/includes/request.php';
require_once KLEN_PATH_DIR . '/includes/shortcode.php';
require_once KLEN_PATH_DIR . '/includes/translations.php';
}
/**
* Register all frontend scripts used in plugin
*
* @return void
*/
public function registerFrontendScripts() {
if ( ! function_exists( 'get_plugin_data' ) ) {
require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
}
$plugin_meta = get_plugin_data( __FILE__ );
// Styles for Ecomail form
wp_register_style( 'klen_form', KLEN_PATH_URL . '/assets/css/klen-form.css', null, $plugin_meta['Version'], 'all' );
// Scripts for Ecomail form
wp_register_script( 'klen_form', KLEN_PATH_URL . '/assets/js/klen-form.js', null, $plugin_meta['Version'], true );
}
/**
* Register all admin scripts used in plugin
*
* @return void
*/
public function registerAdminScripts() {
$plugin_meta = get_plugin_data( __FILE__ );
$style = get_option( 'klen_appearance_style' );
if ( empty( $style ) || $style == 'default' ) {
// Styles for Ecomail form
wp_enqueue_style( 'klen_form', KLEN_PATH_URL . '/assets/css/klen-form.css', null, $plugin_meta['Version'], 'all' );
}
$current_admin_page = get_current_screen();
if ( $current_admin_page->base == 'settings_page_klen_admin_page' ) {
// Styles for admin
wp_enqueue_style( 'klen_admin', KLEN_PATH_URL . '/assets/css/klen-admin.css', null, $plugin_meta['Version'], 'all' );
}
// Scripts for Ecomail form
wp_enqueue_script( 'klen_form', KLEN_PATH_URL . '/assets/js/klen-form.js', null, $plugin_meta['Version'], true );
}
/**
* Create admin menu page
*
* @return void
*/
public function createAdminPage() {
add_submenu_page(
'options-general.php',
__( 'Ecomail Newsletter', 'klen' ),
__( 'Ecomail Newsletter', 'klen' ),
'manage_options',
'klen_admin_page',
array( $this, 'adminPageTemplate' )
);
}
/**
* Admin menu page labels callback
*
* @return void
*/
public function adminPageTemplate() {
require_once KLEN_PATH_DIR . '/admin/settings/template.php';
}
public function registerSettingsFields() {
// Register a new settings main tab
register_setting( 'klen_main', 'klen_api_key' );
register_setting( 'klen_main', 'klen_list_id' );
register_setting( 'klen_main', 'klen_subscribers_count' );
// Register a new settings labels tab
register_setting( 'klen_labels', 'klen_labels_title' );
register_setting( 'klen_labels', 'klen_labels_desc' );
register_setting( 'klen_labels', 'klen_labels_label' );
register_setting( 'klen_labels', 'klen_labels_placeholder' );
register_setting( 'klen_labels', 'klen_labels_checkbox' );
register_setting( 'klen_labels', 'klen_labels_button' );
register_setting( 'klen_labels', 'klen_labels_success' );
register_setting( 'klen_labels', 'klen_labels_error' );
register_setting( 'klen_labels', 'klen_labels_warning' );
// Register a new settings appearance tab
register_setting( 'klen_appearance', 'klen_appearance_style' );
}
/**
* Add a settings link to the plugin listing page.
*
* @param array $actions Plugin action links.
* @param string $plugin_file Plugin file path.
*
* @return array Modified plugin action links.
*/
public function addSettingsLink( $actions, $plugin_file ) {
// Add the settings link only for your plugin
if ( plugin_basename( __FILE__ ) === $plugin_file ) {
$settings_link = '<a href="' . esc_url( admin_url( 'options-general.php?page=klen_admin_page' ) ) . '">' . __( 'Settings', 'klen' ) . '</a>';
array_push( $actions, $settings_link );
}
return $actions;
}
}
new KLEN_Ecomail();