1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Auto Load Next Post - Admin. |
4
|
|
|
* |
5
|
|
|
* @class Auto_Load_Next_Post_Admin |
6
|
|
|
* @author Sébastien Dumont |
7
|
|
|
* @category Admin |
8
|
|
|
* @package Auto Load Next Post |
9
|
|
|
* @license GPL-2.0+ |
10
|
|
|
* @since 1.0.0 |
11
|
|
|
* @version 1.4.10 |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
// Exit if accessed directly. |
15
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
16
|
|
|
exit; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
if ( ! class_exists( 'Auto_Load_Next_Post_Admin' ) ) { |
20
|
|
|
|
21
|
|
|
class Auto_Load_Next_Post_Admin { |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Constructor |
25
|
|
|
* |
26
|
|
|
* @access public |
27
|
|
|
* @since 1.0.0 |
28
|
|
|
* @version 1.4.10 |
29
|
|
|
*/ |
30
|
|
|
public function __construct() { |
31
|
|
|
// Actions |
32
|
|
|
add_action( 'admin_init', array( $this, 'includes' ), 10 ); |
33
|
|
|
add_action( 'admin_init', array( $this, 'admin_scripts' ), 100 ); |
34
|
|
|
|
35
|
|
|
// Add settings page. |
36
|
|
|
add_action( 'admin_menu', array( $this, 'admin_menu' ), 9 ); |
37
|
|
|
|
38
|
|
|
// Filters |
39
|
|
|
add_filter( 'plugin_action_links_' . plugin_basename( AUTO_LOAD_NEXT_POST_FILE ), array( $this, 'plugin_action_links' ) ); |
40
|
|
|
add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta'), 10, 3 ); |
41
|
|
|
add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) ); |
42
|
|
|
add_filter( 'update_footer', array( $this, 'update_footer'), 15 ); |
43
|
|
|
} // END __construct() |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Include any classes we need within admin. |
47
|
|
|
* |
48
|
|
|
* @access public |
49
|
|
|
* @since 1.0.0 |
50
|
|
|
*/ |
51
|
|
|
public function includes() { |
52
|
|
|
// Classes we only need if the ajax is not-ajax |
53
|
|
|
if ( ! auto_load_next_post_is_ajax() ) { |
54
|
|
|
include( dirname( __FILE__ ) . '/class-auto-load-next-post-admin-notices.php' ); // Plugin Notices |
55
|
|
|
include( dirname( __FILE__ ) . '/class-auto-load-next-post-admin-help.php' ); // Plugin Help Tab |
56
|
|
|
} |
57
|
|
|
} // END includes() |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Registers and enqueues stylesheets and javascripts |
61
|
|
|
* for the administration panel. |
62
|
|
|
* |
63
|
|
|
* @access public |
64
|
|
|
* @since 1.0.0 |
65
|
|
|
*/ |
66
|
|
|
public function admin_scripts() { |
67
|
|
|
// Auto Load Next Post Main Javascript |
68
|
|
|
Auto_Load_Next_Post::load_file( AUTO_LOAD_NEXT_POST_SLUG . '_admin_script', '/assets/js/admin/auto-load-next-post' . AUTO_LOAD_NEXT_POST_SCRIPT_MODE . '.js', true, array('jquery'), AUTO_LOAD_NEXT_POST_VERSION ); |
69
|
|
|
|
70
|
|
|
// Chosen |
71
|
|
|
Auto_Load_Next_Post::load_file( 'chosen', '/assets/js/libs/chosen/chosen.jquery' . AUTO_LOAD_NEXT_POST_SCRIPT_MODE . '.js', true, array('jquery'), AUTO_LOAD_NEXT_POST_VERSION ); |
72
|
|
|
|
73
|
|
|
// TipTip |
74
|
|
|
Auto_Load_Next_Post::load_file( 'jquery-tiptip', '/assets/js/libs/jquery-tiptip/jquery.tipTip' . AUTO_LOAD_NEXT_POST_SCRIPT_MODE.'.js', true, array('jquery'), AUTO_LOAD_NEXT_POST_VERSION ); |
75
|
|
|
|
76
|
|
|
// Variables for Admin JavaScripts |
77
|
|
|
wp_localize_script( AUTO_LOAD_NEXT_POST_SLUG . '_admin_script', 'auto_load_next_post_admin_params', array( |
78
|
|
|
'i18n_nav_warning' => __( 'The changes you made will be lost if you navigate away from this page.', 'auto-load-next-post' ), |
79
|
|
|
)); |
80
|
|
|
|
81
|
|
|
// Stylesheets |
82
|
|
|
Auto_Load_Next_Post::load_file( AUTO_LOAD_NEXT_POST_SLUG . '_admin_style', '/assets/css/admin/auto-load-next-post' . AUTO_LOAD_NEXT_POST_SCRIPT_MODE . '.css' ); |
83
|
|
|
Auto_Load_Next_Post::load_file( AUTO_LOAD_NEXT_POST_SLUG.'_chosen_style', '/assets/css/libs/chosen' . AUTO_LOAD_NEXT_POST_SCRIPT_MODE.'.css' ); |
84
|
|
|
} // END admin_scripts() |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Add Auto Load Next Post to the settings menu. |
88
|
|
|
* |
89
|
|
|
* @access public |
90
|
|
|
* @since 1.0.0 |
91
|
|
|
* @version 1.4.10 |
92
|
|
|
*/ |
93
|
|
|
public function admin_menu() { |
94
|
|
|
$settings_page = add_options_page( |
95
|
|
|
sprintf( __( '%s Settings', 'auto-load-next-post' ), esc_html__( 'Auto Load Next Post', 'auto-load-next-post' ) ), |
96
|
|
|
esc_html__( 'Auto Load Next Post', 'auto-load-next-post' ), |
97
|
|
|
'manage_options', |
98
|
|
|
'auto-load-next-post-settings', |
99
|
|
|
array( $this, 'settings_page' ) |
100
|
|
|
); |
101
|
|
|
|
102
|
|
|
add_action( 'load-' . $settings_page, array( $this, 'settings_page_init' ) ); |
103
|
|
|
} // END admin_menu() |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Loads settings. |
107
|
|
|
* |
108
|
|
|
* @access public |
109
|
|
|
* @global string $current_tab |
110
|
|
|
* @global string $current_section |
111
|
|
|
*/ |
112
|
|
|
public function settings_page_init() { |
113
|
|
|
global $current_tab, $current_section; |
114
|
|
|
|
115
|
|
|
// Include settings pages. |
116
|
|
|
include_once( dirname( __FILE__ ) . '/class-auto-load-next-post-admin-settings.php' ); |
117
|
|
|
|
118
|
|
|
Auto_Load_Next_Post_Admin_Settings::get_settings_pages(); |
119
|
|
|
|
120
|
|
|
// Get current tab/section. |
121
|
|
|
$current_tab = empty( $_GET['tab'] ) ? 'general' : sanitize_title( wp_unslash( $_GET['tab'] ) ); |
122
|
|
|
$current_section = empty( $_REQUEST['section'] ) ? '' : sanitize_title( wp_unslash( $_REQUEST['section'] ) ); |
123
|
|
|
|
124
|
|
|
// Save settings if data has been posted. |
125
|
|
|
if ( apply_filters( '' !== $current_section ? "auto_load_next_post_save_settings_{$current_tab}_{$current_section}" : "auto_load_next_post_save_settings_{$current_tab}", ! empty( $_POST ) ) ) { |
126
|
|
|
Auto_Load_Next_Post_Admin_Settings::save(); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
// Add any posted messages. |
130
|
|
|
if ( ! empty( $_GET['auto_load_next_post_error'] ) ) { |
131
|
|
|
Auto_Load_Next_Post_Admin_Settings::add_error( wp_kses_post( wp_unslash( $_GET['auto_load_next_post_error'] ) ) ); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
if ( ! empty( $_GET['auto_load_next_post_message'] ) ) { |
135
|
|
|
Auto_Load_Next_Post_Admin_Settings::add_message( wp_kses_post( wp_unslash( $_GET['auto_load_next_post_message'] ) ) ); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
do_action( 'auto_load_next_post_settings_page_init' ); |
139
|
|
|
} // END settings_page_init() |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Initialize the Auto Load Next Post settings page. |
143
|
|
|
* |
144
|
|
|
* @access public |
145
|
|
|
* @since 1.0.0 |
146
|
|
|
*/ |
147
|
|
|
public function settings_page() { |
148
|
|
|
include_once( dirname( __FILE__ ) . '/class-auto-load-next-post-admin-settings.php' ); |
149
|
|
|
|
150
|
|
|
Auto_Load_Next_Post_Admin_Settings::output(); |
151
|
|
|
} // END settings_page() |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* Plugin action links. |
155
|
|
|
* |
156
|
|
|
* @access public |
157
|
|
|
* @since 1.0.0 |
158
|
|
|
* @version 1.4.10 |
159
|
|
|
* @param array $links |
160
|
|
|
* @return array $links |
161
|
|
|
*/ |
162
|
|
|
public function plugin_action_links( $links ) { |
163
|
|
|
$plugin_action_links = array(); |
164
|
|
|
|
165
|
|
|
if ( current_user_can( 'manage_options' ) ) { |
166
|
|
|
// Checks if Auto Load Next Post Pro has been installed. |
167
|
|
|
if ( ! is_alnp_pro_version_installed() ) { |
168
|
|
|
$plugin_action_links['go-pro'] = '<a href="' . esc_url( 'https://autoloadnextpost.com/pro/?utm_source=plugin&utm_medium=link&utm_campaign=plugins-page' ) . '" target="_blank" style="color:green; font-weight:bold;">' . __( 'Upgrade to Pro', 'auto-load-next-post' ) . '</a>'; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
$plugin_action_links['settings'] = '<a href="' . admin_url( 'options-general.php?page=auto-load-next-post-settings' ) . '">' . __( 'Settings', 'auto-load-next-post' ) . '</a>'; |
172
|
|
|
|
173
|
|
|
return array_merge( $plugin_action_links, $links ); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
return $links; |
177
|
|
|
} // END plugin_action_links() |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Plugin row meta links |
181
|
|
|
* |
182
|
|
|
* @access public |
183
|
|
|
* @since 1.0.0 |
184
|
|
|
* @version 1.4.10 |
185
|
|
|
* @param array $links Plugin Row Meta |
186
|
|
|
* @param string $file Plugin Base file |
187
|
|
|
* @param array $data Plugin Information |
188
|
|
|
* @return array $links |
189
|
|
|
*/ |
190
|
|
|
public function plugin_row_meta( $links, $file, $data ) { |
191
|
|
|
if ( $file == plugin_basename( AUTO_LOAD_NEXT_POST_FILE ) ) { |
192
|
|
|
$links[ 1 ] = sprintf( __( 'Developed By %s', 'auto-load-next-post' ), '<a href="' . $data[ 'AuthorURI' ] . '">' . $data[ 'Author' ] . '</a>' ); |
193
|
|
|
|
194
|
|
|
$row_meta = array( |
195
|
|
|
'docs' => '<a href="' . esc_url( 'https://autoloadnextpost.com/documentation/' ) . '" target="_blank">' . __( 'Documentation', 'auto-load-next-post' ) . '</a>', |
196
|
|
|
'community' => '<a href="' . esc_url( 'https://wordpress.org/support/plugin/auto-load-next-post' ) . '" target="_blank">' . __( 'Community Support', 'auto-load-next-post' ) . '</a>', |
197
|
|
|
'theme-support' => '<a href="' . esc_url( 'https://autoloadnextpost.com/product/theme-support/?utm_source=plugin&utm_medium=link&utm_campaign=plugins-page' ) . '" target="_blank">' . __( 'Theme Support', 'auto-load-next-post' ) . '</a>', |
198
|
|
|
); |
199
|
|
|
|
200
|
|
|
$links = array_merge( $links, $row_meta ); |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
return $links; |
204
|
|
|
} // END plugin_row_meta() |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Filters the admin footer text by placing simply thank you to those who |
208
|
|
|
* like and review the plugin on WordPress.org. |
209
|
|
|
* |
210
|
|
|
* @access public |
211
|
|
|
* @since 1.0.0 |
212
|
|
|
* @version 1.4.10 |
213
|
|
|
* @param string $text |
214
|
|
|
* @return string $text |
215
|
|
|
*/ |
216
|
|
|
public function admin_footer_text( $text ) { |
217
|
|
|
$current_screen = get_current_screen(); |
218
|
|
|
|
219
|
|
|
if ( isset( $current_screen->id ) && $current_screen->id == 'settings_page_auto-load-next-post-settings' ) { |
220
|
|
|
// Rating and Review |
221
|
|
|
return sprintf( |
222
|
|
|
/* translators: 1: Auto Load Next Post 2:: five stars */ |
223
|
|
|
__( 'If you like %1$s, please leave a %2$s rating. A huge thank you in advance!', 'auto-load-next-post' ), |
224
|
|
|
sprintf( '<strong>%1$s</strong>', esc_html__( 'Auto Load Next Post', 'auto-load-next-post' ) ), |
225
|
|
|
'<a href="https://wordpress.org/support/plugin/auto-load-next-post/reviews?rate=5#new-post" target="_blank" data-rated="' . esc_attr__( 'Thanks :)', 'auto-load-next-post' ) . '">★★★★★</a>' |
226
|
|
|
); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
return $text; |
230
|
|
|
} // END admin_footer_text() |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Filters the update footer by placing the version of the plugin |
234
|
|
|
* when viewing any of the plugins pages. |
235
|
|
|
* |
236
|
|
|
* @access public |
237
|
|
|
* @since 1.0.0 |
238
|
|
|
* @version 1.4.10 |
239
|
|
|
* @param string $text |
240
|
|
|
* @return string $text |
241
|
|
|
*/ |
242
|
|
|
public function update_footer( $text ) { |
243
|
|
|
$screen = get_current_screen(); |
244
|
|
|
|
245
|
|
|
if ( $screen->id == 'settings_page_auto-load-next-post-settings' ) { |
246
|
|
|
return '<p class="alignright">' . sprintf( __( '%s Version', 'auto-load-next-post' ), esc_html__( 'Auto Load Next Post', 'auto-load-next-post' ) ) . ' ' . esc_attr( AUTO_LOAD_NEXT_POST_VERSION ) . '</p>'; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
return $text; |
250
|
|
|
} // END update_footer() |
251
|
|
|
|
252
|
|
|
} // END class |
253
|
|
|
|
254
|
|
|
} // END if class exists |
255
|
|
|
|
256
|
|
|
return new Auto_Load_Next_Post_Admin(); |
257
|
|
|
|