Completed
Branch master (8d1f99)
by
unknown
01:57
created

Auto_Load_Next_Post_Admin::sidebar_top()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Auto Load Next Post - Admin.
4
 *
5
 * @since    1.0.0
6
 * @version  1.6.0
7
 * @author   Sébastien Dumont
8
 * @category Admin
9
 * @package  Auto Load Next Post/Admin
10
 * @license  GPL-2.0+
11
 */
12
13
// Exit if accessed directly.
14
if ( ! defined( 'ABSPATH' ) ) {
15
	exit;
16
}
17
18
if ( ! class_exists( 'Auto_Load_Next_Post_Admin' ) ) {
19
20
	class Auto_Load_Next_Post_Admin {
21
22
		/**
23
		 * Constructor
24
		 *
25
		 * @access  public
26
		 * @since   1.0.0
27
		 * @version 1.4.10
28
		 */
29
		public function __construct() {
30
			// Include classes.
31
			add_action( 'admin_init', array( $this, 'includes' ), 10 );
32
33
			// Register scripts and styles for settings page.
34
			add_action( 'admin_enqueue_scripts', array( $this, 'admin_styles' ), 10 );
35
			add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ), 10 );
36
37
			// Add a message in the WP Privacy Policy Guide page.
38
			add_action( 'admin_init', array( $this, 'add_privacy_policy_guide_content' ) );
39
40
			// Add settings page.
41
			add_action( 'admin_menu', array( $this, 'admin_menu' ), 9 );
42
43
			// Filters
44
			add_filter( 'plugin_action_links_' . plugin_basename( AUTO_LOAD_NEXT_POST_FILE ), array( $this, 'plugin_action_links' ) );
45
			add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta'), 10, 3 );
46
			add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
47
			add_filter( 'update_footer', array( $this, 'update_footer'), 15 );
48
49
			// Add sidebar
50
			add_action( 'auto_load_next_post_sidebar', array( $this, 'sidebar_top' ), 0 );
51
			add_action( 'auto_load_next_post_sidebar', array( $this, 'upgrade_details' ), 1 );
52
			add_action( 'auto_load_next_post_sidebar', array( $this, 'sidebar_bottom' ), 999 );
53
		} // END __construct()
54
55
		/**
56
		 * Include any classes we need within admin.
57
		 *
58
		 * @access public
59
		 * @since  1.0.0
60
		 */
61
		public function includes() {
62
			// Classes we only need if the ajax is not-ajax
63
			if ( ! auto_load_next_post_is_ajax() ) {
64
				include( dirname( __FILE__ ) . '/class-alnp-admin-notices.php' ); // Plugin Notices
65
				include( dirname( __FILE__ ) . '/class-alnp-admin-help.php' ); // Plugin Help Tab
66
			}
67
68
			include_once( dirname( __FILE__ ) . '/class-alnp-extensions.php'); // Extensions.
69
		} // END includes()
70
71
		/**
72
		 * Register and enqueue stylesheets.
73
		 *
74
		 * @access public
75
		 * @since  1.5.0
76
		 * @global $wp_scripts
77
		 */
78
		public function admin_styles() {
79
			global $wp_scripts;
80
81
			$screen    = get_current_screen();
82
			$screen_id = $screen ? $screen->id : '';
0 ignored issues
show
Unused Code introduced by
$screen_id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
83
84
			Auto_Load_Next_Post::load_file( AUTO_LOAD_NEXT_POST_SLUG . '_admin', '/assets/css/admin/auto-load-next-post' . AUTO_LOAD_NEXT_POST_SCRIPT_MODE . '.css' );
85
86
			if ( $screen->id == 'settings_page_auto-load-next-post-settings' ) {
87
				// Select2 - Make sure that we remove other registered Select2 to prevent styling issues.
88
				if ( wp_script_is( 'select2', 'registered' ) ) {
89
					wp_dequeue_style( 'select2' );
90
					wp_deregister_style( 'select2' );
91
				}
92
93
				Auto_Load_Next_Post::load_file( 'select2', '/assets/css/libs/select2' . AUTO_LOAD_NEXT_POST_SCRIPT_MODE . '.css' );
94
			}
95
		} // END admin_styles()
96
97
		/**
98
		 * Registers and enqueue javascripts.
99
		 *
100
		 * @access  public
101
		 * @since   1.0.0
102
		 * @version 1.5.0
103
		 */
104
		public function admin_scripts() {
105
			$screen    = get_current_screen();
106
			$screen_id = $screen ? $screen->id : '';
0 ignored issues
show
Unused Code introduced by
$screen_id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
107
108
			if ( $screen->id == 'settings_page_auto-load-next-post-settings' ) {
109
				// Select2 - Make sure that we remove other registered Select2 to prevent plugin conflict issues.
110
				if ( wp_script_is( 'select2', 'registered' ) ) {
111
					wp_dequeue_script( 'select2' );
112
					wp_deregister_script( 'select2' );
113
				}
114
115
				// Load Select2
116
				Auto_Load_Next_Post::load_file( 'select2', '/assets/js/libs/select2' . AUTO_LOAD_NEXT_POST_SCRIPT_MODE . '.js', true, array( 'jquery' ), '4.0.5', true );
117
118
				// Load plugin settings.
119
				Auto_Load_Next_Post::load_file( AUTO_LOAD_NEXT_POST_SLUG . '_admin', '/assets/js/admin/settings' . AUTO_LOAD_NEXT_POST_SCRIPT_MODE . '.js', true, array( 'jquery' ), AUTO_LOAD_NEXT_POST_VERSION, true );
120
121
				// Variables for Admin JavaScripts
122
				wp_localize_script( AUTO_LOAD_NEXT_POST_SLUG . '_admin', 'alnp_settings_params', array(
123
					'is_rtl'           => is_rtl() ? 'rtl' : 'ltr',
124
					'i18n_nav_warning' => esc_html__( 'The changes you made will be lost if you navigate away from this page.', 'auto-load-next-post' ),
125
				) );
126
			}
127
		} // END admin_scripts()
128
129
		/**
130
		 * Add a message in the WP Privacy Policy Guide page.
131
		 *
132
		 * @access public
133
		 * @since  1.5.0
134
		 * @static
135
		 */
136
		public static function add_privacy_policy_guide_content() {
137
			if ( function_exists( 'wp_add_privacy_policy_content' ) ) {
138
				wp_add_privacy_policy_content( esc_html__( 'Auto Load Next Post', 'auto-load-next-post' ), self::get_privacy_policy_guide_message() );
139
			}
140
		} // END add_privacy_policy_guide_content()
141
142
		/**
143
		 * Message to add in the WP Privacy Policy Guide page.
144
		 *
145
		 * @access protected
146
		 * @since  1.5.0
147
		 * @static
148
		 * @return string
149
		 */
150
		protected static function get_privacy_policy_guide_message() {
151
			$content = '
152
				<div contenteditable="false">' .
153
					'<p class="wp-policy-help">' .
154
						sprintf( __( '%s does not collect, store or share any personal data.', 'auto-load-next-post' ), esc_html__( 'Auto Load Next Post', 'auto-load-next-post' ) ) .
155
					'</p>' .
156
				'</div>';
157
158
			return $content;
159
		} // END get_privacy_policy_guide_message()
160
161
		/**
162
		 * Add Auto Load Next Post to the settings menu.
163
		 *
164
		 * @access  public
165
		 * @since   1.0.0
166
		 * @version 1.4.10
167
		 */
168
		public function admin_menu() {
169
			$settings_page = add_options_page(
170
				sprintf( __( '%s Settings', 'auto-load-next-post' ), esc_html__( 'Auto Load Next Post', 'auto-load-next-post' ) ),
171
				esc_html__( 'Auto Load Next Post', 'auto-load-next-post' ),
172
				'manage_options',
173
				'auto-load-next-post-settings',
174
				array( $this, 'settings_page' )
175
			);
176
177
			add_action( 'load-' . $settings_page, array( $this, 'settings_page_init' ) );
178
		} // END admin_menu()
179
180
		/**
181
		 * Loads settings.
182
		 *
183
		 * @access public
184
		 * @since  1.0.0
185
		 * @global string $current_tab
186
		 * @global string $current_section
187
		 */
188
		public function settings_page_init() {
189
			global $current_tab, $current_section;
190
191
			// Include settings pages.
192
			include_once( dirname( __FILE__ ) . '/class-alnp-admin-settings.php' );
193
194
			Auto_Load_Next_Post_Admin_Settings::get_settings_pages();
195
196
			// Get current tab/section.
197
			$current_tab     = empty( $_GET['tab'] ) ? 'theme-selectors' : sanitize_title( wp_unslash( $_GET['tab'] ) );
198
			$current_section = empty( $_REQUEST['section'] ) ? '' : sanitize_title( wp_unslash( $_REQUEST['section'] ) );
199
200
			// Save settings if data has been posted.
201
			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 ) ) ) {
202
				Auto_Load_Next_Post_Admin_Settings::save();
203
			}
204
205
			// Add any posted messages.
206
			if ( ! empty( $_GET['auto_load_next_post_error'] ) ) {
207
				Auto_Load_Next_Post_Admin_Settings::add_error( wp_kses_post( wp_unslash( $_GET['auto_load_next_post_error'] ) ) );
208
			}
209
210
			if ( ! empty( $_GET['auto_load_next_post_message'] ) ) {
211
				Auto_Load_Next_Post_Admin_Settings::add_message( wp_kses_post( wp_unslash( $_GET['auto_load_next_post_message'] ) ) );
212
			}
213
214
			do_action( 'auto_load_next_post_settings_page_init' );
215
		} // END settings_page_init()
216
217
		/**
218
		 * Initialize the Auto Load Next Post settings page.
219
		 *
220
		 * @access public
221
		 * @since  1.0.0
222
		 */
223
		public function settings_page() {
224
			include_once( dirname( __FILE__ ) . '/class-alnp-admin-settings.php' );
225
226
			Auto_Load_Next_Post_Admin_Settings::output();
227
		} // END settings_page()
228
229
		/**
230
		 * Plugin action links.
231
		 *
232
		 * @access  public
233
		 * @since   1.0.0
234
		 * @version 1.4.10
235
		 * @param   array $links
236
		 * @return  array $links
237
		 */
238
		public function plugin_action_links( $links ) {
239
			$plugin_action_links = array();
240
241
			if ( current_user_can( 'manage_options' ) ) {
242
				// Checks if Auto Load Next Post Pro has been installed.
243
				if ( ! is_alnp_pro_version_installed() ) {
244
					$plugin_action_links['go-pro'] = '<a href="' . esc_url( AUTO_LOAD_NEXT_POST_STORE_URL . 'pro/?utm_source=plugin&utm_medium=link&utm_campaign=plugins-page' ) . '" aria-label="' . esc_attr__( 'Sign up for Auto Load Next Post Pro', 'auto-load-next-post' ) . '" target="_blank" style="color:green; font-weight:bold;">' . __( 'Sign up for Pro', 'auto-load-next-post' ) . '</a>';
245
				}
246
247
				$plugin_action_links['settings'] = '<a href="' . admin_url( 'options-general.php?page=auto-load-next-post-settings' ) . '" aria-label="' . esc_attr__( 'View Auto Load Next Post settings', 'auto-load-next-post' ) . '">' . __( 'Settings', 'auto-load-next-post' ) . '</a>';
248
249
				return array_merge( $plugin_action_links, $links );
250
			}
251
252
			return $links;
253
		} // END plugin_action_links()
254
255
		/**
256
		 * Plugin row meta links
257
		 *
258
		 * @access  public
259
		 * @since   1.0.0
260
		 * @version 1.5.0
261
		 * @param   array  $links Plugin Row Meta
262
		 * @param   string $file  Plugin Base file
263
		 * @param   array  $data  Plugin Information
264
		 * @return  array  $links
265
		 */
266
		public function plugin_row_meta( $links, $file, $data ) {
267
			if ( $file == plugin_basename( AUTO_LOAD_NEXT_POST_FILE ) ) {
268
				$links[ 1 ] = sprintf( __( 'Developed By %s', 'auto-load-next-post' ), '<a href="' . $data[ 'AuthorURI' ] . '" aria-label="' . esc_attr__( 'View the developers site', 'auto-load-next-post' ) . '">' . $data[ 'Author' ] . '</a>' );
269
270
				$row_meta = array(
271
					'docs' => '<a href="' . esc_url( AUTO_LOAD_NEXT_POST_STORE_URL . 'documentation/?utm_source=plugin&utm_medium=link&utm_campaign=plugins-page' ) . '" aria-label="' . esc_attr__( 'View Auto Load Next Post documentation', 'auto-load-next-post' ) . '" target="_blank">' . esc_attr__( 'Documentation', 'auto-load-next-post' ) . '</a>',
272
					'community' => '<a href="' . esc_url( 'https://wordpress.org/support/plugin/auto-load-next-post' ) . '" aria-label="' . esc_attr__( 'Get support from the community', 'auto-load-next-post' ). '" target="_blank">' . esc_attr__( 'Community Support', 'auto-load-next-post' ) . '</a>',
273
					'theme-support' => '<a href="' . esc_url( AUTO_LOAD_NEXT_POST_STORE_URL . 'product/theme-support/?utm_source=plugin&utm_medium=link&utm_campaign=plugins-page' ) . '" attr-label="' . esc_attr__( 'Get theme support', 'auto-load-next-post' ) . '" target="_blank">' . esc_attr__( 'Theme Support', 'auto-load-next-post' ) . '</a>',
274
				);
275
276
				$links = array_merge( $links, $row_meta );
277
			}
278
279
			return $links;
280
		} // END plugin_row_meta()
281
282
		/**
283
		 * Filters the admin footer text by placing simply thank you to those who
284
		 * like and review the plugin on WordPress.org.
285
		 *
286
		 * @access  public
287
		 * @since   1.0.0
288
		 * @version 1.4.10
289
		 * @param   string $text
290
		 * @return  string $text
291
		 */
292
		public function admin_footer_text( $text ) {
293
			$current_screen = get_current_screen();
294
295
			if ( isset( $current_screen->id ) && $current_screen->id == 'settings_page_auto-load-next-post-settings' ) {
296
				// Rating and Review
297
				return sprintf(
298
					/* translators: 1: Auto Load Next Post 2:: five stars */
299
					__( 'If you like %1$s, please leave a %2$s rating. A huge thank you in advance!', 'auto-load-next-post' ),
300
					sprintf( '<strong>%1$s</strong>', esc_html__( 'Auto Load Next Post', 'auto-load-next-post' ) ),
301
					'<a href="' . AUTO_LOAD_NEXT_POST_REVIEW_URL . '?rate=5#new-post" target="_blank" data-rated="' . esc_attr__( 'Thanks :)', 'auto-load-next-post' ) . '">&#9733;&#9733;&#9733;&#9733;&#9733;</a>'
302
				);
303
			}
304
305
			return $text;
306
		} // END admin_footer_text()
307
308
		/**
309
		 * Filters the update footer by placing the version of the plugin
310
		 * when viewing any of the plugins pages.
311
		 *
312
		 * @access  public
313
		 * @since   1.0.0
314
		 * @version 1.4.10
315
		 * @param   string $text
316
		 * @return  string $text
317
		 */
318
		public function update_footer( $text ) {
319
			$screen = get_current_screen();
320
321
			if ( $screen->id == 'settings_page_auto-load-next-post-settings' ) {
322
				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>';
323
			}
324
325
			return $text;
326
		} // END update_footer()
327
328
		/**
329
		 * Displays 
330
		 * 
331
		 * @access public
332
		 * @since  1.6.0
333
		 */
334
		public function sidebar_top() {
335
			include_once( dirname( __FILE__ ) . '/views/html-admin-sidebar-logo.php' );
336
337
			do_action( 'auto_load_next_post_sidebar_top' );
338
		} // END sidebar_top()
339
340
		/**
341
		 * Checks if Auto Load Next Post Pro is installed before 
342
		 * displaying upgrade details in the sidebar.
343
		 *
344
		 * @access public
345
		 * @since  1.6.0
346
		 */
347
		public function upgrade_details() {
348
			if ( ! is_alnp_pro_version_installed() ) {
349
				include_once( dirname( __FILE__ ) . '/views/html-admin-sidebar.php' );
350
			}
351
		} // END upgrade_details()
352
353
		/**
354
		 * Displays plugin credits at the bottom of the sidebar.
355
		 * 
356
		 * @access public
357
		 * @since  1.6.0
358
		 */
359
		public function sidebar_bottom() {
360
			do_action( 'auto_load_next_post_sidebar_bottom' );
361
362
			include_once( dirname( __FILE__ ) . '/views/html-admin-sidebar-credits.php' );
363
		} // END sidebar_bottom()
364
365
	} // END class
366
367
} // END if class exists
368
369
return new Auto_Load_Next_Post_Admin();
370