These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /* |
||
3 | Plugin Name: Post Promoter Pro |
||
4 | Plugin URI: https://postpromoterpro.com |
||
5 | Description: Maximize your social media presence on Twitter, Facebook, and LinkedIn. |
||
6 | Version: 2.3.17 |
||
7 | Author: Post Promoter Pro |
||
8 | Author URI: https://postpromoterpro.com |
||
9 | License: GPLv2 |
||
10 | */ |
||
11 | |||
12 | define( 'PPP_PATH', plugin_dir_path( __FILE__ ) ); |
||
13 | define( 'PPP_VERSION', '2.3.17' ); |
||
14 | define( 'PPP_FILE', plugin_basename( __FILE__ ) ); |
||
15 | define( 'PPP_URL', plugins_url( '/', PPP_FILE ) ); |
||
16 | |||
17 | define( 'PPP_STORE_URL', 'https://postpromoterpro.com' ); |
||
18 | define( 'PPP_PLUGIN_NAME', 'Post Promoter Pro' ); |
||
19 | if( !class_exists( 'EDD_SL_Plugin_Updater' ) ) { |
||
20 | // load our custom updater |
||
21 | include( PPP_PATH . '/includes/EDD_SL_Plugin_Updater.php' ); |
||
22 | } |
||
23 | |||
24 | class PostPromoterPro { |
||
25 | private static $ppp_instance; |
||
26 | |||
27 | private function __construct() { |
||
28 | add_action( 'init', array( $this, 'ppp_loaddomain' ), 1 ); |
||
29 | |||
30 | if ( ! is_callable( 'curl_init' ) ) { |
||
31 | add_action( 'admin_notices', array( $this, 'no_curl' ) ); |
||
32 | } else { |
||
33 | global $ppp_options, $ppp_social_settings, $ppp_share_settings; |
||
34 | |||
35 | include PPP_PATH . '/includes/general-functions.php'; |
||
36 | include PPP_PATH . '/includes/share-functions.php'; |
||
37 | include PPP_PATH . '/includes/cron-functions.php'; |
||
38 | include PPP_PATH . '/includes/filters.php'; |
||
39 | include PPP_PATH . '/includes/libs/social-loader.php'; |
||
40 | |||
41 | if( ! class_exists( 'WP_Logging' ) ) { |
||
42 | include PPP_PATH . '/includes/libs/class-wp-logging.php'; |
||
43 | } |
||
44 | |||
45 | if ( is_admin() ) { |
||
46 | include PPP_PATH . '/includes/admin/upgrades.php'; |
||
47 | include PPP_PATH . '/includes/admin/do-upgrades.php'; |
||
48 | include PPP_PATH . '/includes/admin/actions.php'; |
||
49 | include PPP_PATH . '/includes/admin/admin-pages.php'; |
||
50 | include PPP_PATH . '/includes/admin/admin-ajax.php'; |
||
51 | include PPP_PATH . '/includes/admin/meta-boxes.php'; |
||
52 | include PPP_PATH . '/includes/admin/welcome.php'; |
||
53 | include PPP_PATH . '/includes/admin/dashboard.php'; |
||
54 | } |
||
55 | |||
56 | $ppp_options = get_option( 'ppp_options' ); |
||
57 | $ppp_social_settings = get_option( 'ppp_social_settings' ); |
||
58 | $ppp_share_settings = get_option( 'ppp_share_settings' ); |
||
59 | |||
60 | // Do some leg work on the social settings for Issue #257 |
||
61 | if ( is_array( $ppp_share_settings ) && ! array_key_exists( 'share_on_publish', $ppp_share_settings ) ) { |
||
62 | $tw_share_on_publish = ! empty( $ppp_share_settings['twitter']['share_on_publish'] ) ? true : false; |
||
63 | $fb_share_on_publish = ! empty( $ppp_share_settings['facebook']['share_on_publish'] ) ? true : false; |
||
64 | $li_share_on_publish = ! empty( $ppp_share_settings['linkedin']['share_on_publish'] ) ? true : false; |
||
65 | |||
66 | unset( |
||
67 | $ppp_share_settings['twitter']['share_on_publish'], |
||
68 | $ppp_share_settings['facebook']['share_on_publish'], |
||
69 | $ppp_share_settings['linkedin']['share_on_publish'] |
||
70 | ); |
||
71 | |||
72 | $post_types = ppp_supported_post_types(); |
||
73 | foreach ( $post_types as $key => $post_type ) { |
||
74 | $ppp_share_settings['share_on_publish'][ $key ]['twitter'] = $tw_share_on_publish; |
||
75 | $ppp_share_settings['share_on_publish'][ $key ]['facebook'] = $fb_share_on_publish; |
||
76 | $ppp_share_settings['share_on_publish'][ $key ]['linkedin'] = $li_share_on_publish; |
||
77 | } |
||
78 | |||
79 | update_option( 'ppp_share_settings', $ppp_share_settings ); |
||
80 | } |
||
81 | |||
82 | $this->hooks(); |
||
83 | } |
||
84 | |||
85 | } |
||
86 | |||
87 | /** |
||
88 | * Get the singleton instance of our plugin |
||
89 | * @return class The Instance |
||
90 | * @access public |
||
91 | */ |
||
92 | 1 | public static function getInstance() { |
|
93 | 1 | if ( !self::$ppp_instance ) { |
|
94 | self::$ppp_instance = new PostPromoterPro(); |
||
95 | } |
||
96 | |||
97 | 1 | return self::$ppp_instance; |
|
98 | } |
||
99 | |||
100 | /** |
||
101 | * Nag if cURL is disabled |
||
102 | * @return void |
||
103 | */ |
||
104 | public function no_curl() { |
||
105 | ?> |
||
106 | <div class="no-curl"> |
||
107 | <p><?php _e( 'Post Promoter Pro requires cURL to be enabled. Please enable it to continue using the plugin.', 'ppp-txt' ); ?></p> |
||
108 | </div> |
||
109 | <?php |
||
110 | } |
||
111 | |||
112 | private function hooks() { |
||
113 | if ( is_admin() ) { |
||
114 | add_action( 'admin_init', array( $this, 'ppp_register_settings' ) ); |
||
115 | add_action( 'admin_init', 'ppp_upgrade_plugin', 1 ); |
||
116 | |||
117 | // Handle licenses |
||
118 | add_action( 'admin_init', array( $this, 'plugin_updater' ) ); |
||
119 | add_action( 'admin_init', array( $this, 'activate_license' ) ); |
||
120 | add_action( 'admin_init', array( $this, 'deactivate_license' ) ); |
||
121 | |||
122 | add_action( 'admin_menu', array( $this, 'ppp_setup_admin_menu' ), 1000, 0 ); |
||
123 | add_filter( 'plugin_action_links', array( $this, 'plugin_settings_links' ), 10, 2 ); |
||
124 | add_action( 'admin_enqueue_scripts', array( $this, 'load_custom_scripts' ), 99 ); |
||
125 | add_action( 'admin_enqueue_scripts', array( $this, 'load_styles' ), 99999 ); |
||
126 | add_action( 'wp_trash_post', 'ppp_remove_scheduled_shares', 10, 1 ); |
||
127 | |||
128 | if ( ppp_is_dev_or_staging() ) { |
||
129 | add_action( 'admin_notices', array( $this, 'local_site_nag' ) ); |
||
130 | } |
||
131 | } |
||
132 | |||
133 | add_action( 'init', array( $this, 'get_actions' ) ); |
||
134 | add_action( 'wp_insert_post', 'ppp_schedule_share', 99, 2); |
||
135 | add_action( 'transition_post_status', 'ppp_share_on_publish', 99, 3); |
||
136 | add_action( 'init', 'ppp_add_image_sizes' ); |
||
137 | add_filter( 'wp_log_types', array( $this, 'register_log_type' ), 10, 1 ); |
||
138 | } |
||
139 | |||
140 | /** |
||
141 | * Queue up the JavaScript file for the admin page, only on our admin page |
||
142 | * @param string $hook The current page in the admin |
||
143 | * @return void |
||
144 | * @access public |
||
145 | */ |
||
146 | public function load_custom_scripts( $hook ) { |
||
147 | |||
148 | $allowed_pages = array( |
||
149 | 'toplevel_page_ppp-options', |
||
150 | 'post-promoter_page_ppp-social-settings', |
||
151 | 'post-new.php', |
||
152 | 'post.php', |
||
153 | 'post-promoter_page_ppp-schedule-info', |
||
154 | ); |
||
155 | |||
156 | $allowed_pages = apply_filters( 'ppp_admin_scripts_pages', $allowed_pages, $hook ); |
||
157 | |||
158 | if ( ! in_array( $hook, $allowed_pages ) ) { |
||
159 | return; |
||
160 | } |
||
161 | |||
162 | wp_enqueue_script( 'jquery-ui-core' ); |
||
163 | wp_enqueue_script( 'jquery-ui-datepicker' ); |
||
164 | |||
165 | $jquery_ui_timepicker_path = PPP_URL . 'includes/scripts/libs/jquery-ui-timepicker-addon.js'; |
||
166 | wp_enqueue_script( 'ppp_timepicker_js', $jquery_ui_timepicker_path , array( 'jquery', 'jquery-ui-core' ), PPP_VERSION, true ); |
||
167 | wp_enqueue_script( 'ppp_core_custom_js', PPP_URL.'includes/scripts/js/ppp_custom.js', 'jquery', PPP_VERSION, true ); |
||
168 | |||
169 | } |
||
170 | |||
171 | public function load_styles() { |
||
172 | |||
173 | global $wp_styles; |
||
174 | |||
175 | // List of people who make it impossible to override their jQuery UI as it's in their core CSS...so only |
||
176 | // load ours if they don't exist |
||
177 | if ( ! wp_style_is( 'ot-admin-css' ) && ! wp_style_is( 'jquery-ui-css' ) ) { |
||
178 | wp_enqueue_style( 'jquery-ui-css', '//ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/flick/jquery-ui.css' ); |
||
179 | } |
||
180 | |||
181 | wp_register_style( 'ppp_admin_css', PPP_URL . 'includes/scripts/css/admin-style.css', false, PPP_VERSION ); |
||
182 | wp_enqueue_style( 'ppp_admin_css' ); |
||
183 | |||
184 | $sources = array_map( 'basename', (array) wp_list_pluck( $wp_styles->registered, 'src' ) ); |
||
185 | if ( ! in_array( 'font-awesome.css', $sources ) || in_array( 'font-awesome.min.css', $sources ) ) { |
||
186 | wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css', false, null ); |
||
187 | wp_enqueue_style( 'font-awesome' ); |
||
188 | } |
||
189 | |||
190 | } |
||
191 | |||
192 | /** |
||
193 | * Adds the Settings and Post Promoter Pro Link to the Settings page list |
||
194 | * @param array $links The current list of links |
||
195 | * @param string $file The plugin file |
||
196 | * @return array The new list of links, with our additional ones added |
||
197 | * @access public |
||
198 | */ |
||
199 | public function plugin_settings_links( $links, $file ) { |
||
200 | if ( $file != PPP_FILE ) { |
||
201 | return $links; |
||
202 | } |
||
203 | |||
204 | $settings_link = sprintf( '<a href="%s">%s</a>', admin_url( 'admin.php?page=ppp-options' ), __( 'Settings', 'ppp-txt' ) ); |
||
205 | |||
206 | array_unshift( $links, $settings_link ); |
||
207 | |||
208 | return $links; |
||
209 | } |
||
210 | |||
211 | /** |
||
212 | * Returns the capability (or role) required to manage the plugin. |
||
213 | * |
||
214 | * @return string A WordPress capability or role name. |
||
215 | */ |
||
216 | 1 | public static function get_manage_capability() { |
|
217 | 1 | return apply_filters( 'ppp_manage_role', 'manage_options' ); |
|
218 | } |
||
219 | |||
220 | /** |
||
221 | * Add the Pushover Notifications item to the Settings menu |
||
222 | * @return void |
||
223 | * @access public |
||
224 | */ |
||
225 | public function ppp_setup_admin_menu() { |
||
226 | $capability = self::get_manage_capability(); |
||
227 | |||
228 | add_menu_page( |
||
229 | __( 'Post Promoter', 'ppp-txt' ), |
||
230 | __( 'Post Promoter', 'ppp-txt' ), |
||
231 | $capability, |
||
232 | 'ppp-options', |
||
233 | 'ppp_admin_page' |
||
234 | ); |
||
235 | |||
236 | add_submenu_page( |
||
237 | 'ppp-options', |
||
238 | __( 'Social Settings', 'ppp-txt' ), |
||
239 | __( 'Social Settings', 'ppp-txt' ), |
||
240 | $capability, |
||
241 | 'ppp-social-settings', |
||
242 | 'ppp_display_social' |
||
243 | ); |
||
244 | |||
245 | add_submenu_page( |
||
246 | 'ppp-options', |
||
247 | __( 'Schedule', 'ppp-txt' ), |
||
248 | __( 'Schedule', 'ppp-txt' ), |
||
249 | $capability, |
||
250 | 'ppp-schedule-info', |
||
251 | 'ppp_display_schedule' |
||
252 | ); |
||
253 | |||
254 | add_submenu_page( |
||
255 | 'ppp-options', |
||
256 | __( 'System Info', 'ppp-txt' ), |
||
257 | __( 'System Info', 'ppp-txt' ), |
||
258 | $capability, |
||
259 | 'ppp-system-info', |
||
260 | 'ppp_display_sysinfo' |
||
261 | ); |
||
262 | |||
263 | add_submenu_page( |
||
264 | null, |
||
265 | __( 'PPP Upgrades', 'ppp-txt' ), |
||
266 | __( 'PPP Upgrades', 'ppp-txt' ), |
||
267 | $capability, |
||
268 | 'ppp-upgrades', |
||
269 | 'ppp_upgrades_screen' |
||
270 | ); |
||
271 | |||
272 | } |
||
273 | |||
274 | /** |
||
275 | * Register/Whitelist our settings on the settings page, allow extensions and other plugins to hook into this |
||
276 | * @return void |
||
277 | * @access public |
||
278 | */ |
||
279 | public function ppp_register_settings() { |
||
280 | register_setting( 'ppp-options', 'ppp_options' ); |
||
281 | register_setting( 'ppp-options', '_ppp_license_key', array( $this, 'ppp_sanitize_license' ) ); |
||
282 | |||
283 | register_setting( 'ppp-social-settings', 'ppp_social_settings' ); |
||
284 | register_setting( 'ppp-share-settings', 'ppp_share_settings' ); |
||
285 | do_action( 'ppp_register_additional_settings' ); |
||
286 | } |
||
287 | |||
288 | /** |
||
289 | * Load the Text Domain for i18n |
||
290 | * @return void |
||
291 | * @access public |
||
292 | */ |
||
293 | public function ppp_loaddomain() { |
||
294 | load_plugin_textdomain( 'ppp-txt', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); |
||
295 | } |
||
296 | |||
297 | /** |
||
298 | * Sets up the EDD SL Plugin updated class |
||
299 | * @return void |
||
300 | */ |
||
301 | public function plugin_updater() { |
||
302 | global $ppp_options; |
||
303 | if ( defined( 'NO_AUTO_UPDATE' ) && true === NO_AUTO_UPDATE ) { |
||
304 | return; |
||
305 | } |
||
306 | |||
307 | $license_key = trim( get_option( '_ppp_license_key' ) ); |
||
308 | |||
309 | if ( empty( $license_key ) ) { |
||
310 | add_action( 'admin_notices', array( $this, 'no_license_nag' ) ); |
||
311 | return; |
||
312 | } |
||
313 | |||
314 | // setup the updater |
||
315 | $edd_updater = new EDD_SL_Plugin_Updater( PPP_STORE_URL, __FILE__, array( |
||
0 ignored issues
–
show
|
|||
316 | 'version' => PPP_VERSION, // current version number |
||
317 | 'license' => $license_key, // license key (used get_option above to retrieve from DB) |
||
318 | 'item_name' => PPP_PLUGIN_NAME, // name of this plugin |
||
319 | 'author' => 'Post Promoter Pro', // author of this plugin |
||
320 | 'beta' => ! empty( $ppp_options['enable_betas'] ) ? true : false, // If we should install beta versions |
||
321 | ) |
||
322 | ); |
||
323 | } |
||
324 | |||
325 | /** |
||
326 | * If no license key is saved, show a notice |
||
327 | * @return void |
||
328 | */ |
||
329 | public function no_license_nag() { |
||
330 | ?> |
||
331 | <div class="updated"> |
||
332 | <p> |
||
333 | <?php printf( |
||
334 | __( 'Post Promoter Pro requires your license key to work, please <a href="%s">enter it now</a>.', 'ppp-txt' ), |
||
335 | admin_url( 'admin.php?page=ppp-options' ) |
||
336 | ); |
||
337 | ?> |
||
338 | </p> |
||
339 | </div> |
||
340 | <?php |
||
341 | } |
||
342 | |||
343 | /** |
||
344 | * If site is detected as local, show notice |
||
345 | * @return void |
||
346 | */ |
||
347 | public function local_site_nag() { |
||
348 | ?> |
||
349 | <div class="updated dismissible"> |
||
350 | <p> |
||
351 | <?php |
||
352 | _e( 'Post Promoter Pro has detected a development or staging site. To prevent unintended social media posts, sharing has been disabled.', 'ppp-txt' ); |
||
353 | ?> |
||
354 | </p> |
||
355 | </div> |
||
356 | <?php |
||
357 | } |
||
358 | |||
359 | /** |
||
360 | * Deactivates the license key |
||
361 | * @return void |
||
362 | */ |
||
363 | public function deactivate_license() { |
||
364 | // listen for our activate button to be clicked |
||
365 | if( isset( $_POST['ppp_license_deactivate'] ) ) { |
||
366 | |||
367 | // run a quick security check |
||
368 | if( ! check_admin_referer( 'ppp_deactivate_nonce', 'ppp_deactivate_nonce' ) ) { |
||
369 | return; |
||
370 | } |
||
371 | // get out if we didn't click the Activate button |
||
372 | |||
373 | // retrieve the license from the database |
||
374 | $license = trim( get_option( '_ppp_license_key' ) ); |
||
375 | |||
376 | |||
377 | // data to send in our API request |
||
378 | $api_params = array( |
||
379 | 'edd_action'=> 'deactivate_license', |
||
380 | 'license' => $license, |
||
381 | 'item_name' => urlencode( PPP_PLUGIN_NAME ) // the name of our product in EDD |
||
382 | ); |
||
383 | |||
384 | // Call the custom API. |
||
385 | $response = wp_remote_get( add_query_arg( $api_params, PPP_STORE_URL ), array( 'timeout' => 15, 'sslverify' => false ) ); |
||
386 | |||
387 | // make sure the response came back okay |
||
388 | if ( is_wp_error( $response ) ) { |
||
389 | return false; |
||
390 | } |
||
391 | |||
392 | // decode the license data |
||
393 | $license_data = json_decode( wp_remote_retrieve_body( $response ) ); |
||
394 | |||
395 | // $license_data->license will be either "deactivated" or "failed" |
||
396 | if( $license_data->license == 'deactivated' ) { |
||
397 | delete_option( '_ppp_license_key_status' ); |
||
398 | } |
||
399 | |||
400 | } |
||
401 | } |
||
402 | |||
403 | /** |
||
404 | * Activates the license key provided |
||
405 | * @return void |
||
406 | */ |
||
407 | public function activate_license() { |
||
408 | // listen for our activate button to be clicked |
||
409 | if( isset( $_POST['ppp_license_activate'] ) ) { |
||
410 | |||
411 | // run a quick security check |
||
412 | if( ! check_admin_referer( 'ppp_activate_nonce', 'ppp_activate_nonce' ) ) { |
||
413 | return; |
||
414 | } |
||
415 | // get out if we didn't click the Activate button |
||
416 | |||
417 | // retrieve the license from the database |
||
418 | $license = trim( get_option( '_ppp_license_key' ) ); |
||
419 | |||
420 | |||
421 | // data to send in our API request |
||
422 | $api_params = array( |
||
423 | 'edd_action' => 'activate_license', |
||
424 | 'license' => $license, |
||
425 | 'item_name' => urlencode( PPP_PLUGIN_NAME ), |
||
426 | ); |
||
427 | |||
428 | // Call the custom API. |
||
429 | $response = wp_remote_get( add_query_arg( $api_params, PPP_STORE_URL ), array( 'timeout' => 15, 'sslverify' => false ) ); |
||
430 | |||
431 | // make sure the response came back okay |
||
432 | if ( is_wp_error( $response ) ) { |
||
433 | return false; |
||
434 | } |
||
435 | |||
436 | // decode the license data |
||
437 | $license_data = json_decode( wp_remote_retrieve_body( $response ) ); |
||
438 | |||
439 | // $license_data->license will be either "active" or "inactive" |
||
440 | |||
441 | update_option( '_ppp_license_key_status', $license_data->license ); |
||
442 | |||
443 | } |
||
444 | } |
||
445 | |||
446 | /** |
||
447 | * Sanatize the liscense key being provided |
||
448 | * @param string $new The License key provided |
||
449 | * @return string Sanitized license key |
||
450 | */ |
||
451 | public function ppp_sanitize_license( $new ) { |
||
452 | $old = get_option( '_ppp_license_key' ); |
||
453 | if( $old && $old != $new ) { |
||
454 | delete_option( '_ppp_license_key_status' ); // new license has been entered, so must reactivate |
||
455 | } |
||
456 | return $new; |
||
457 | } |
||
458 | |||
459 | /** |
||
460 | * Hook to listen for our actions |
||
461 | * |
||
462 | * @return void |
||
463 | */ |
||
464 | public function get_actions() { |
||
465 | if ( isset( $_GET['ppp_action'] ) ) { |
||
466 | do_action( 'ppp_' . $_GET['ppp_action'], $_GET ); |
||
467 | } |
||
468 | } |
||
469 | |||
470 | /** |
||
471 | * Register our log type for when items are shared |
||
472 | * |
||
473 | * @since 2.3 |
||
474 | * @param array $log_types Array of log types |
||
475 | * @return array |
||
476 | */ |
||
477 | public function register_log_type( $log_types ) { |
||
0 ignored issues
–
show
|
|||
478 | $types[] = 'ppp_share'; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$types was never initialized. Although not strictly required by PHP, it is generally a good practice to add $types = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
479 | return $types; |
||
480 | } |
||
481 | |||
482 | } |
||
483 | |||
484 | /** |
||
485 | * Load and access the one true instance of Post Promoter Pro |
||
486 | * |
||
487 | * @return object The Post_Promoter_Pro instance |
||
488 | */ |
||
489 | function post_promoter_pro() { |
||
490 | 1 | return PostPromoterPro::getInstance(); |
|
491 | } |
||
492 | add_action( 'plugins_loaded', 'post_promoter_pro' ); |
||
493 | |||
494 | /** |
||
495 | * On activation, setup the default options |
||
496 | * @return void |
||
497 | */ |
||
498 | function post_promoter_pro_activation_setup() { |
||
499 | // If the settings already exist, don't do this |
||
500 | if ( get_option( 'ppp_options' ) ) { |
||
501 | return; |
||
502 | } |
||
503 | |||
504 | $default_settings['post_types']['post'] = '1'; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$default_settings was never initialized. Although not strictly required by PHP, it is generally a good practice to add $default_settings = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
505 | update_option( 'ppp_options', $default_settings ); |
||
506 | |||
507 | $default_share_settings['share_on_publish'] = array( |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$default_share_settings was never initialized. Although not strictly required by PHP, it is generally a good practice to add $default_share_settings = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
508 | 'post' => array( |
||
509 | 'twitter' => 1, |
||
510 | 'facebook' => 1, |
||
511 | 'linkedin' => 1, |
||
512 | ), |
||
513 | ); |
||
514 | update_option( 'ppp_share_settings', $default_share_settings ); |
||
515 | |||
516 | update_option( 'ppp_completed_upgrades', array( 'upgrade_post_meta' ) ); |
||
517 | } |
||
518 | register_activation_hook( PPP_FILE, 'post_promoter_pro_activation_setup' ); |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.