| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Plugins Condition | |
| 3 | + * Plugins Condition & Site Check | |
| 4 | 4 | * |
| 5 | 5 | * @package Plugins Condition |
| 6 | 6 | * @subpackage PluginsCondition Main Functions |
| 7 | 7 | /* |
| @@ -48,8 +48,9 @@ | ||
| 48 | 48 | add_filter( 'cron_schedules', array( $this, 'plugins_condition_add_intervals' ) ); |
| 49 | 49 | add_action( 'plugins_condition_notify_cron', array( $this, 'plugins_condition_notify_wp_cron' ) ); |
| 50 | 50 | add_action( 'plugins_condition_notify_cron_start', array( $this, 'notify_cron_start' ) ); |
| 51 | 51 | add_action( 'plugins_condition_notify_cron_stop', array( $this, 'notify_cron_stop' ) ); |
| 52 | + add_action( 'plugins_condition_notify_cron_now', array( $this, 'single_cron_run' ) ); | |
| 52 | 53 | register_activation_hook( plugin_dir_path( __DIR__ ) . 'pluginscondition.php', array( $this, 'notify_cron_start' ) ); |
| 53 | 54 | register_deactivation_hook( plugin_dir_path( __DIR__ ) . 'pluginscondition.php', array( $this, 'notify_cron_stop' ) ); |
| 54 | 55 | } |
| 55 | 56 | |
| @@ -79,15 +80,11 @@ | ||
| 79 | 80 | $notify_interval_str = 'plc_' . strval( get_option( 'plg_cond_notify_interval', 30 ) ) . 'days'; |
| 80 | 81 | wp_schedule_event( time() + $notify_interval_int, $notify_interval_str, 'plugins_condition_notify_cron' ); |
| 81 | 82 | } |
| 82 | 83 | |
| 83 | - if ( function_exists( 'wp_date' ) ) { | |
| 84 | - $current = wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ); | |
| 85 | - } else { | |
| 86 | - $current = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ); | |
| 87 | - } | |
| 84 | + $current = wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ); | |
| 88 | 85 | |
| 89 | - update_option( 'plg_cond_update_date_time', 'Plugins Condition ' . __( 'Last updated', 'plugins-condition' ) . ' : ' . $current ); | |
| 86 | + update_option( 'plg_cond_update_date_time', 'Plugins Condition & Site Check ' . __( 'Last updated', 'plugins-condition' ) . ' : ' . $current ); | |
| 90 | 87 | |
| 91 | 88 | return $links; |
| 92 | 89 | } |
| 93 | 90 | |
| @@ -106,15 +103,11 @@ | ||
| 106 | 103 | foreach ( $plugins as $file => $plugin ) { |
| 107 | 104 | list( $html_ver, $html_date ) = $this->main_func( $file, false ); |
| 108 | 105 | } |
| 109 | 106 | |
| 110 | - if ( function_exists( 'wp_date' ) ) { | |
| 111 | - $current = wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ); | |
| 112 | - } else { | |
| 113 | - $current = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ); | |
| 114 | - } | |
| 107 | + $current = wp_date( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ); | |
| 115 | 108 | |
| 116 | - update_option( 'plg_cond_update_date_time', 'Plugins Condition ' . __( 'Last updated', 'plugins-condition' ) . ' : ' . $current ); | |
| 109 | + update_option( 'plg_cond_update_date_time', 'Plugins Condition & Site Check ' . __( 'Last updated', 'plugins-condition' ) . ' : ' . $current ); | |
| 117 | 110 | } |
| 118 | 111 | |
| 119 | 112 | /** ================================================== |
| 120 | 113 | * Cron Start |
| @@ -151,13 +144,13 @@ | ||
| 151 | 144 | */ |
| 152 | 145 | public function plugins_condition_notify_wp_cron() { |
| 153 | 146 | |
| 154 | 147 | $adminmail = get_option( 'admin_email' ); |
| 155 | - $subject = 'Plugins Condition - ' . get_option( 'blogname' ); | |
| 148 | + $subject = 'Plugins Condition & Site Check - ' . get_option( 'blogname' ); | |
| 156 | 149 | |
| 157 | 150 | $plcaution = $this->plugins_condition_caution(); |
| 158 | 151 | /* translators: interval days */ |
| 159 | - $content = '<blockquote>' . sprintf( __( 'This email is delivered every %1$s days to the administrator by Plugins Condition.', 'plugins-condition' ), get_option( 'plg_cond_notify_interval', 30 ) ) . '</blockquote>'; | |
| 152 | + $content = '<blockquote>' . sprintf( __( 'This email is delivered every %1$s days to the administrator by Plugins Condition & Site Check.', 'plugins-condition' ), get_option( 'plg_cond_notify_interval', 30 ) ) . '</blockquote>'; | |
| 160 | 153 | $content .= '<strong>' . get_option( 'plg_cond_update_date_time' ) . '</strong>' . $plcaution; |
| 161 | 154 | |
| 162 | 155 | /* Mail Use HTML-Mails */ |
| 163 | 156 | add_filter( 'wp_mail_content_type', array( $this, 'set_html_content_type' ) ); |
| @@ -229,8 +222,24 @@ | ||
| 229 | 222 | wp_clear_scheduled_hook( 'plugins_condition_notify_cron' ); |
| 230 | 223 | } |
| 231 | 224 | |
| 232 | 225 | /** ================================================== |
| 226 | + * Notify Single Cron Run | |
| 227 | + * | |
| 228 | + * @since 2.01 | |
| 229 | + */ | |
| 230 | + public function single_cron_run() { | |
| 231 | + | |
| 232 | + wp_schedule_single_event( | |
| 233 | + time(), | |
| 234 | + 'plugins_condition_notify_cron', | |
| 235 | + array( 'plc_now' ), | |
| 236 | + ); | |
| 237 | + | |
| 238 | + spawn_cron(); | |
| 239 | + } | |
| 240 | + | |
| 241 | + /** ================================================== | |
| 233 | 242 | * Main |
| 234 | 243 | * |
| 235 | 244 | * @param string $file file. |
| 236 | 245 | * @param bool $installed_plugin installed_plugin. |
| @@ -409,9 +418,9 @@ | ||
| 409 | 418 | ?> |
| 410 | 419 | <h3> |
| 411 | 420 | <?php |
| 412 | 421 | /* translators: %s: Installed Plugins */ |
| 413 | - echo wp_kses_post( sprintf( __( 'Please read %s for the latest information.', 'plugins-condition' ), $installed_plugin_html ) ); | |
| 422 | + echo wp_kses_post( sprintf( __( 'To update the "Plugin Information," please load your %s.', 'plugins-condition' ), $installed_plugin_html ) ); | |
| 414 | 423 | ?> |
| 415 | 424 | </h3> |
| 416 | 425 | <?php |
| 417 | 426 | echo wp_kses_post( $plcaution ); |
| @@ -439,9 +448,11 @@ | ||
| 439 | 448 | if ( ! function_exists( 'get_plugins' ) ) { |
| 440 | 449 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 441 | 450 | } |
| 442 | 451 | $plugins = get_plugins(); |
| 443 | - $plcaution = null; | |
| 452 | + $plcaution = '<hr />'; | |
| 453 | + $plcaution .= '<strong>' . __( 'Plugin Information', 'plugins-condition' ) . '</strong>'; | |
| 454 | +; | |
| 444 | 455 | if ( ! empty( $wp_options ) ) { |
| 445 | 456 | foreach ( $wp_options as $wp_option ) { |
| 446 | 457 | $option_names[] = $wp_option->option_name; |
| 447 | 458 | } |
| @@ -460,8 +471,11 @@ | ||
| 460 | 471 | } |
| 461 | 472 | } |
| 462 | 473 | } |
| 463 | 474 | |
| 475 | + $plcaution .= $this->users_list(); | |
| 476 | + $plcaution .= $this->wp_content_check(); | |
| 477 | + | |
| 464 | 478 | return $plcaution; |
| 465 | 479 | } |
| 466 | 480 | |
| 467 | 481 | /** ================================================== |
| @@ -495,7 +509,92 @@ | ||
| 495 | 509 | } |
| 496 | 510 | |
| 497 | 511 | return $plugin_name; |
| 498 | 512 | } |
| 499 | -} | |
| 500 | 513 | |
| 514 | + /** ================================================== | |
| 515 | + * User's List | |
| 516 | + * | |
| 517 | + * @return string $html html for user's list. | |
| 518 | + * @since 2.00 | |
| 519 | + */ | |
| 520 | + private function users_list() { | |
| 501 | 521 | |
| 522 | + $users = get_users(); | |
| 523 | + | |
| 524 | + global $wp_roles; | |
| 525 | + | |
| 526 | + $html = '<hr />'; | |
| 527 | + $html .= '<strong>' . __( 'User Information', 'plugins-condition' ) . '</strong>'; | |
| 528 | + $html .= '<ul style="margin-top: 0;">'; | |
| 529 | + foreach ( $users as $user ) { | |
| 530 | + /* Get roles */ | |
| 531 | + $role_names = array(); | |
| 532 | + if ( ! empty( $user->roles ) && is_array( $user->roles ) ) { | |
| 533 | + foreach ( $user->roles as $role_slug ) { | |
| 534 | + if ( isset( $wp_roles->roles[ $role_slug ] ) ) { | |
| 535 | + $role_names[] = translate_user_role( $wp_roles->roles[ $role_slug ]['name'] ); | |
| 536 | + } | |
| 537 | + } | |
| 538 | + } | |
| 539 | + if ( ! empty( $role_names ) ) { | |
| 540 | + $display_roles = __( 'Role', 'plugins-condition' ) . ' : ' . implode( ', ', $role_names ); | |
| 541 | + } else { | |
| 542 | + $display_roles = __( 'No role', 'plugins-condition' ); | |
| 543 | + } | |
| 544 | + | |
| 545 | + /* Get regiterd date time */ | |
| 546 | + $registered_time = wp_date( 'Y-n-j H:i', strtotime( $user->user_registered ) ); | |
| 547 | + | |
| 548 | + $html.= '<li>' . esc_html( $user->user_login ) . ' (' . esc_html( $user->user_email ) . ')</li><ul style="list-style-type: disc; padding-left: 20px;"><li>' . esc_html( $display_roles ) . '</li><li>' . __( 'Date and Time of Registration', 'plugins-condition' ) . ' : ' . esc_html( $registered_time ) . '</li></ul>'; | |
| 549 | + } | |
| 550 | + $html.= '</ul>'; | |
| 551 | + | |
| 552 | + return $html; | |
| 553 | + } | |
| 554 | + | |
| 555 | + /** ================================================== | |
| 556 | + * Check list for wp-content | |
| 557 | + * | |
| 558 | + * @return string $html html for wp-content check list. | |
| 559 | + * @since 2.00 | |
| 560 | + */ | |
| 561 | + private function wp_content_check() { | |
| 562 | + | |
| 563 | + $upload_dir = wp_upload_dir(); | |
| 564 | + | |
| 565 | + $filetype = wp_check_filetype( $wp_content_dir . '/index.php' ); | |
| 566 | + $file_size = size_format( filesize( $file_path ) ); | |
| 567 | + $modified_date = wp_date( 'Y-m-d H:i:s', filemtime( $file_path ) ); | |
| 568 | + | |
| 569 | + $content_php_files = glob( WP_CONTENT_DIR . '/*.php' ); | |
| 570 | + $uploads_php_files = glob( $upload_dir['basedir'] . '/*.php'); | |
| 571 | + | |
| 572 | + $all_php_files = array_merge( | |
| 573 | + $content_php_files ?: [], | |
| 574 | + $uploads_php_files ?: [] | |
| 575 | + ); | |
| 576 | + | |
| 577 | + $html = '<hr />'; | |
| 578 | + $html .= '<strong>' . __( 'wp-content Information', 'plugins-condition' ) . '</strong>'; | |
| 579 | + $html .= '<ul style="margin-top: 0;">'; | |
| 580 | + | |
| 581 | + if ( ! empty( $all_php_files ) ) { | |
| 582 | + foreach ( $all_php_files as $file_path ) { | |
| 583 | + if ( str_contains( $file_path, 'wp-content/uploads' ) ) { | |
| 584 | + $folder = 'wp-content/uploads'; | |
| 585 | + } else { | |
| 586 | + $folder = 'wp-content'; | |
| 587 | + } | |
| 588 | + $filename = wp_basename( $file_path ); | |
| 589 | + $file_size = size_format( filesize( $file_path ) ); | |
| 590 | + $modified_date = wp_date( 'Y-m-d H:i:s', filemtime( $file_path ) ); | |
| 591 | + $html .= '<li>' . esc_html( $folder . '/' . $filename ) . '</li><ul style="list-style-type: disc; padding-left: 20px;"><li>' . esc_html__( 'Last updated', 'plugins-condition' ) . ' : ' . $modified_date . '</li><li>' . esc_html__( 'Size', 'plugins-condition' ) . ' : ' . $file_size . '</li></ul>'; | |
| 592 | + } | |
| 593 | + } else { | |
| 594 | + $html .= esc_html__( 'No PHP files were found in the "wp-content" or "wp-content/uploads" directories.', 'plugins-condition' ); | |
| 595 | + } | |
| 596 | + $html.= '</ul>'; | |
| 597 | + | |
| 598 | + return $html; | |
| 599 | + } | |
| 600 | +} | |