Completed
Branch codeclean (07bbe5)
by Sébastien
01:40
created
includes/admin/class-alnp-admin.php 1 patch
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -11,11 +11,11 @@  discard block
 block discarded – undo
11 11
  */
12 12
 
13 13
 // Exit if accessed directly.
14
-if ( ! defined( 'ABSPATH' ) ) {
14
+if ( ! defined('ABSPATH')) {
15 15
 	exit;
16 16
 }
17 17
 
18
-if ( ! class_exists( 'Auto_Load_Next_Post_Admin' ) ) {
18
+if ( ! class_exists('Auto_Load_Next_Post_Admin')) {
19 19
 
20 20
 	class Auto_Load_Next_Post_Admin {
21 21
 
@@ -28,23 +28,23 @@  discard block
 block discarded – undo
28 28
 		 */
29 29
 		public function __construct() {
30 30
 			// Include classes.
31
-			add_action( 'admin_init', array( $this, 'includes' ), 10 );
31
+			add_action('admin_init', array($this, 'includes'), 10);
32 32
 
33 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 );
34
+			add_action('admin_enqueue_scripts', array($this, 'admin_styles'), 10);
35
+			add_action('admin_enqueue_scripts', array($this, 'admin_scripts'), 10);
36 36
 
37 37
 			// Add a message in the WP Privacy Policy Guide page.
38
-			add_action( 'admin_init', array( $this, 'add_privacy_policy_guide_content' ) );
38
+			add_action('admin_init', array($this, 'add_privacy_policy_guide_content'));
39 39
 
40 40
 			// Add settings page.
41
-			add_action( 'admin_menu', array( $this, 'admin_menu' ), 9 );
41
+			add_action('admin_menu', array($this, 'admin_menu'), 9);
42 42
 
43 43
 			// Filters plugin row and admin footer.
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' ), 15, 1 );
47
-			add_filter( 'update_footer', array( $this, 'update_footer'), 15 );
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'), 15, 1);
47
+			add_filter('update_footer', array($this, 'update_footer'), 15);
48 48
 		} // END __construct()
49 49
 
50 50
 		/**
@@ -55,9 +55,9 @@  discard block
 block discarded – undo
55 55
 		 */
56 56
 		public function includes() {
57 57
 			// Classes we only need if the ajax is not-ajax
58
-			if ( ! auto_load_next_post_is_ajax() ) {
59
-				include( dirname( __FILE__ ) . '/class-alnp-admin-notices.php' ); // Plugin Notices
60
-				include( dirname( __FILE__ ) . '/class-alnp-admin-help.php' ); // Plugin Help Tab
58
+			if ( ! auto_load_next_post_is_ajax()) {
59
+				include(dirname(__FILE__).'/class-alnp-admin-notices.php'); // Plugin Notices
60
+				include(dirname(__FILE__).'/class-alnp-admin-help.php'); // Plugin Help Tab
61 61
 			}
62 62
 		} // END includes()
63 63
 
@@ -71,16 +71,16 @@  discard block
 block discarded – undo
71 71
 			$screen    = get_current_screen();
72 72
 			$screen_id = $screen ? $screen->id : '';
73 73
 
74
-			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' );
74
+			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');
75 75
 
76
-			if ( $screen_id == 'settings_page_auto-load-next-post-settings' ) {
76
+			if ($screen_id == 'settings_page_auto-load-next-post-settings') {
77 77
 				// Select2 - Make sure that we remove other registered Select2 to prevent styling issues.
78
-				if ( wp_script_is( 'select2', 'registered' ) ) {
79
-					wp_dequeue_style( 'select2' );
80
-					wp_deregister_style( 'select2' );
78
+				if (wp_script_is('select2', 'registered')) {
79
+					wp_dequeue_style('select2');
80
+					wp_deregister_style('select2');
81 81
 				}
82 82
 
83
-				Auto_Load_Next_Post::load_file( 'select2', '/assets/css/libs/select2' . AUTO_LOAD_NEXT_POST_SCRIPT_MODE . '.css' );
83
+				Auto_Load_Next_Post::load_file('select2', '/assets/css/libs/select2'.AUTO_LOAD_NEXT_POST_SCRIPT_MODE.'.css');
84 84
 			}
85 85
 		} // END admin_styles()
86 86
 
@@ -95,24 +95,24 @@  discard block
 block discarded – undo
95 95
 			$screen    = get_current_screen();
96 96
 			$screen_id = $screen ? $screen->id : '';
97 97
 
98
-			if ( $screen->id == 'settings_page_auto-load-next-post-settings' ) {
98
+			if ($screen->id == 'settings_page_auto-load-next-post-settings') {
99 99
 				// Select2 - Make sure that we remove other registered Select2 to prevent plugin conflict issues.
100
-				if ( wp_script_is( 'select2', 'registered' ) ) {
101
-					wp_dequeue_script( 'select2' );
102
-					wp_deregister_script( 'select2' );
100
+				if (wp_script_is('select2', 'registered')) {
101
+					wp_dequeue_script('select2');
102
+					wp_deregister_script('select2');
103 103
 				}
104 104
 
105 105
 				// Load Select2
106
-				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 );
106
+				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);
107 107
 
108 108
 				// Load plugin settings.
109
-				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 );
109
+				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);
110 110
 
111 111
 				// Variables for Admin JavaScripts
112
-				wp_localize_script( AUTO_LOAD_NEXT_POST_SLUG . '_admin', 'alnp_settings_params', array(
112
+				wp_localize_script(AUTO_LOAD_NEXT_POST_SLUG.'_admin', 'alnp_settings_params', array(
113 113
 					'is_rtl'           => is_rtl() ? 'rtl' : 'ltr',
114
-					'i18n_nav_warning' => esc_html__( 'The changes you made will be lost if you navigate away from this page.', 'auto-load-next-post' ),
115
-				) );
114
+					'i18n_nav_warning' => esc_html__('The changes you made will be lost if you navigate away from this page.', 'auto-load-next-post'),
115
+				));
116 116
 			}
117 117
 		} // END admin_scripts()
118 118
 
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
 		 * @static
125 125
 		 */
126 126
 		public static function add_privacy_policy_guide_content() {
127
-			if ( function_exists( 'wp_add_privacy_policy_content' ) ) {
128
-				wp_add_privacy_policy_content( esc_html__( 'Auto Load Next Post', 'auto-load-next-post' ), self::get_privacy_policy_guide_message() );
127
+			if (function_exists('wp_add_privacy_policy_content')) {
128
+				wp_add_privacy_policy_content(esc_html__('Auto Load Next Post', 'auto-load-next-post'), self::get_privacy_policy_guide_message());
129 129
 			}
130 130
 		} // END add_privacy_policy_guide_content()
131 131
 
@@ -140,9 +140,9 @@  discard block
 block discarded – undo
140 140
 		protected static function get_privacy_policy_guide_message() {
141 141
 			$content = '
142 142
 				<div contenteditable="false">' .
143
-					'<p class="wp-policy-help">' .
144
-						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' ) ) .
145
-					'</p>' .
143
+					'<p class="wp-policy-help">'.
144
+						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')).
145
+					'</p>'.
146 146
 				'</div>';
147 147
 
148 148
 			return $content;
@@ -157,14 +157,14 @@  discard block
 block discarded – undo
157 157
 		 */
158 158
 		public function admin_menu() {
159 159
 			$settings_page = add_options_page(
160
-				sprintf( __( '%s Settings', 'auto-load-next-post' ), esc_html__( 'Auto Load Next Post', 'auto-load-next-post' ) ),
161
-				esc_html__( 'Auto Load Next Post', 'auto-load-next-post' ),
160
+				sprintf(__('%s Settings', 'auto-load-next-post'), esc_html__('Auto Load Next Post', 'auto-load-next-post')),
161
+				esc_html__('Auto Load Next Post', 'auto-load-next-post'),
162 162
 				'manage_options',
163 163
 				'auto-load-next-post-settings',
164
-				array( $this, 'settings_page' )
164
+				array($this, 'settings_page')
165 165
 			);
166 166
 
167
-			add_action( 'load-' . $settings_page, array( $this, 'settings_page_init' ) );
167
+			add_action('load-'.$settings_page, array($this, 'settings_page_init'));
168 168
 		} // END admin_menu()
169 169
 
170 170
 		/**
@@ -179,29 +179,29 @@  discard block
 block discarded – undo
179 179
 			global $current_tab, $current_section;
180 180
 
181 181
 			// Include settings pages.
182
-			include_once( dirname( __FILE__ ) . '/class-alnp-admin-settings.php' );
182
+			include_once(dirname(__FILE__).'/class-alnp-admin-settings.php');
183 183
 
184 184
 			Auto_Load_Next_Post_Admin_Settings::get_settings_pages();
185 185
 
186 186
 			// Get current tab/section.
187
-			$current_tab     = empty( $_GET['tab'] ) ? 'theme-selectors' : sanitize_title( wp_unslash( $_GET['tab'] ) );
188
-			$current_section = empty( $_REQUEST['section'] ) ? '' : sanitize_title( wp_unslash( $_REQUEST['section'] ) );
187
+			$current_tab     = empty($_GET['tab']) ? 'theme-selectors' : sanitize_title(wp_unslash($_GET['tab']));
188
+			$current_section = empty($_REQUEST['section']) ? '' : sanitize_title(wp_unslash($_REQUEST['section']));
189 189
 
190 190
 			// Save settings if data has been posted.
191
-			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 ) ) ) {
191
+			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))) {
192 192
 				Auto_Load_Next_Post_Admin_Settings::save();
193 193
 			}
194 194
 
195 195
 			// Add any posted messages.
196
-			if ( ! empty( $_GET['auto_load_next_post_error'] ) ) {
197
-				Auto_Load_Next_Post_Admin_Settings::add_error( wp_kses_post( wp_unslash( $_GET['auto_load_next_post_error'] ) ) );
196
+			if ( ! empty($_GET['auto_load_next_post_error'])) {
197
+				Auto_Load_Next_Post_Admin_Settings::add_error(wp_kses_post(wp_unslash($_GET['auto_load_next_post_error'])));
198 198
 			}
199 199
 
200
-			if ( ! empty( $_GET['auto_load_next_post_message'] ) ) {
201
-				Auto_Load_Next_Post_Admin_Settings::add_message( wp_kses_post( wp_unslash( $_GET['auto_load_next_post_message'] ) ) );
200
+			if ( ! empty($_GET['auto_load_next_post_message'])) {
201
+				Auto_Load_Next_Post_Admin_Settings::add_message(wp_kses_post(wp_unslash($_GET['auto_load_next_post_message'])));
202 202
 			}
203 203
 
204
-			do_action( 'auto_load_next_post_settings_page_init' );
204
+			do_action('auto_load_next_post_settings_page_init');
205 205
 		} // END settings_page_init()
206 206
 
207 207
 		/**
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 		 * @since  1.0.0
212 212
 		 */
213 213
 		public function settings_page() {
214
-			include_once( dirname( __FILE__ ) . '/class-alnp-admin-settings.php' );
214
+			include_once(dirname(__FILE__).'/class-alnp-admin-settings.php');
215 215
 
216 216
 			Auto_Load_Next_Post_Admin_Settings::output();
217 217
 		} // END settings_page()
@@ -225,18 +225,18 @@  discard block
 block discarded – undo
225 225
 		 * @param   array $links
226 226
 		 * @return  array $links
227 227
 		 */
228
-		public function plugin_action_links( $links ) {
228
+		public function plugin_action_links($links) {
229 229
 			$plugin_action_links = array();
230 230
 
231
-			if ( current_user_can( 'manage_options' ) ) {
231
+			if (current_user_can('manage_options')) {
232 232
 				// Checks if Auto Load Next Post Pro has been installed.
233
-				if ( ! is_alnp_pro_version_installed() ) {
234
-					$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>';
233
+				if ( ! is_alnp_pro_version_installed()) {
234
+					$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>';
235 235
 				}
236 236
 
237
-				$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>';
237
+				$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>';
238 238
 
239
-				return array_merge( $plugin_action_links, $links );
239
+				return array_merge($plugin_action_links, $links);
240 240
 			}
241 241
 
242 242
 			return $links;
@@ -253,18 +253,18 @@  discard block
 block discarded – undo
253 253
 		 * @param   array  $data  Plugin Information
254 254
 		 * @return  array  $links
255 255
 		 */
256
-		public function plugin_row_meta( $links, $file, $data ) {
257
-			if ( $file == plugin_basename( AUTO_LOAD_NEXT_POST_FILE ) ) {
258
-				$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>' );
256
+		public function plugin_row_meta($links, $file, $data) {
257
+			if ($file == plugin_basename(AUTO_LOAD_NEXT_POST_FILE)) {
258
+				$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>');
259 259
 
260 260
 				$row_meta = array(
261
-					'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>',
262
-					'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>',
263
-					'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>',
264
-					'review' => '<a href="' . esc_url( AUTO_LOAD_NEXT_POST_REVIEW_URL ) . '" aria-label="' . esc_attr( __( 'Review Auto Load Next Post on WordPress.org', 'auto-load-next-post' ) ) . '" target="_blank">' . __( 'Leave a Review', 'auto-load-next-post' ) . '</a>',
261
+					'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>',
262
+					'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>',
263
+					'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>',
264
+					'review' => '<a href="'.esc_url(AUTO_LOAD_NEXT_POST_REVIEW_URL).'" aria-label="'.esc_attr(__('Review Auto Load Next Post on WordPress.org', 'auto-load-next-post')).'" target="_blank">'.__('Leave a Review', 'auto-load-next-post').'</a>',
265 265
 				);
266 266
 
267
-				$links = array_merge( $links, $row_meta );
267
+				$links = array_merge($links, $row_meta);
268 268
 			}
269 269
 
270 270
 			return $links;
@@ -280,16 +280,16 @@  discard block
 block discarded – undo
280 280
 		 * @param   string $text text to be rendered in the footer.
281 281
 		 * @return  string $text
282 282
 		 */
283
-		public function admin_footer_text( $text ) {
283
+		public function admin_footer_text($text) {
284 284
 			$current_screen = get_current_screen();
285 285
 
286
-			if ( isset( $current_screen->id ) && $current_screen->id == 'settings_page_auto-load-next-post-settings' ) {
286
+			if (isset($current_screen->id) && $current_screen->id == 'settings_page_auto-load-next-post-settings') {
287 287
 				// Rating and Review
288 288
 				$text = sprintf(
289 289
 					/* translators: 1: Auto Load Next Post 2:: five stars */
290
-					__( 'If you like %1$s, please leave a %2$s rating. A huge thank you in advance!', 'auto-load-next-post' ),
291
-					sprintf( '<strong>%1$s</strong>', esc_html__( 'Auto Load Next Post', 'auto-load-next-post' ) ),
292
-					'<a href="' . AUTO_LOAD_NEXT_POST_REVIEW_URL . '?rate=5#new-post" target="_blank" aria-label="' . esc_attr__( 'five star', 'auto-load-next-post' ) . '" data-rated="' . esc_attr__( 'Thanks :)', 'auto-load-next-post' ) . '">&#9733;&#9733;&#9733;&#9733;&#9733;</a>'
290
+					__('If you like %1$s, please leave a %2$s rating. A huge thank you in advance!', 'auto-load-next-post'),
291
+					sprintf('<strong>%1$s</strong>', esc_html__('Auto Load Next Post', 'auto-load-next-post')),
292
+					'<a href="'.AUTO_LOAD_NEXT_POST_REVIEW_URL.'?rate=5#new-post" target="_blank" aria-label="'.esc_attr__('five star', 'auto-load-next-post').'" data-rated="'.esc_attr__('Thanks :)', 'auto-load-next-post').'">&#9733;&#9733;&#9733;&#9733;&#9733;</a>'
293 293
 				);
294 294
 			}
295 295
 
@@ -306,11 +306,11 @@  discard block
 block discarded – undo
306 306
 		 * @param   string $text
307 307
 		 * @return  string $text
308 308
 		 */
309
-		public function update_footer( $text ) {
309
+		public function update_footer($text) {
310 310
 			$screen = get_current_screen();
311 311
 
312
-			if ( $screen->id == 'settings_page_auto-load-next-post-settings' ) {
313
-				return sprintf( __( '%s Version', 'auto-load-next-post' ), esc_html__( 'Auto Load Next Post', 'auto-load-next-post' ) ) . ' ' . esc_attr( AUTO_LOAD_NEXT_POST_VERSION );
312
+			if ($screen->id == 'settings_page_auto-load-next-post-settings') {
313
+				return sprintf(__('%s Version', 'auto-load-next-post'), esc_html__('Auto Load Next Post', 'auto-load-next-post')).' '.esc_attr(AUTO_LOAD_NEXT_POST_VERSION);
314 314
 			}
315 315
 
316 316
 			return $text;
Please login to merge, or discard this patch.