返回
<?php /** * Plugin name: CloudLinux SmartAdvice * Plugin URI: https://www.cloudlinux.com * Description: AccelerateWP helps to solve performance issues of your website. It includes Optimization Modules that can be activated for WP sites easily. * Version: 0.1-5 * Requires at least: 5.0.0 * Requires PHP: 5.6 * Author: CloudLinux * Author URI: https://www.cloudlinux.com * Licence: CloudLinux Commercial License * * Copyright 2022 CloudLinux */ use CloudLinux\SmartAdvice\App\Plugin; use CloudLinux\SmartAdvice\App\Cli\Commands; if ( ! defined( 'WPINC' ) ) { die; } if ( getenv( 'CL_SMART_ADVICE_DISABLED' ) ) { return; } if ( ! function_exists( 'cl_smart_advice_basedir_check' ) ) { if ( ! function_exists( 'cl_smart_advice_basedir_notice' ) ) { /** * Add error notice. * * @return void */ function cl_smart_advice_basedir_notice() { $transient_name = 'cl_smart_advice_disable_basedir_notice_' . get_current_user_id(); if ( 1 === (int) get_transient( $transient_name ) ) { return; } if ( isset( $_GET['cl-smart-advice-dismiss'] ) && 'dismiss_basedir_notices' === $_GET['cl-smart-advice-dismiss'] && isset( $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ) ) ) { set_transient( $transient_name, '1' ); } else { echo ' <div class="notice notice-error is-dismissible"> <form action="' . esc_attr( admin_url() ) . '" method="GET"> <p> <strong>SmartAdvice</strong><br> SmartAdvice is currently unable to function properly due to a misconfiguration. We recommend reaching out to your hosting provider for assistance.<br><br> To resolve this issue, the following value should be appended to the PHP open_basedir setting (be sure to include the colon): <pre>:/opt/alt/php-xray/</pre> For more detailed information about the SmartAdvice plugin please refer to our <a href="https://docs.cloudlinux.com/user-docs/user-docs-shared-cloudlinux/#overview" target="_blank">documentation</a>.<br><br> <button type="submit" class="button button-link">Dismiss this notice</button> </p> <button type="submit" class="notice-dismiss"> <span class="screen-reader-text">Dismiss this notice.</span> </button> <input type="hidden" name="cl-smart-advice-dismiss" value="dismiss_basedir_notices"> <input type="hidden" name="_wpnonce" value="' . esc_attr( wp_create_nonce() ) . '"> </form> </div>'; } } } /** * Check PHP ini open_basedir setting restriction * * @param bool $open_basedir PHP open_basedir value for testing. * * @return bool */ function cl_smart_advice_basedir_check( $open_basedir = false ) { if ( ! $open_basedir ) { $open_basedir = ini_get( 'open_basedir' ); } if ( empty( $open_basedir ) ) { return true; } $paths_to_check = array( '/opt', '/opt/', '/opt/alt', '/opt/alt/', '/opt/alt/php-xray', '/opt/alt/php-xray/', ); $open_basedir_parts = explode( PATH_SEPARATOR, $open_basedir ); $found_paths = array_intersect( $open_basedir_parts, $paths_to_check ); if ( empty( $found_paths ) ) { // open_basedir restriction in effect. add_action( 'admin_notices', 'cl_smart_advice_basedir_notice' ); return false; } return true; } if ( ! cl_smart_advice_basedir_check() ) { return; } } define( 'CL_SMART_ADVICE_SLUG', 'cl-smart-advice' ); // @phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged if ( @is_readable( '/opt/alt/php-xray/php/smart-advice-plugin' ) ) { define( 'CL_SMART_ADVICE_PATH', '/opt/alt/php-xray/php/smart-advice-plugin' ); } else { define( 'CL_SMART_ADVICE_PATH', dirname( __FILE__ ) ); } define( 'CL_SMART_ADVICE_VERSION', '0.1-5' ); define( 'CL_SMART_ADVICE_XRAY_RELEASE', '0.6-2.el8' ); define( 'CL_SMART_ADVICE_FOLDER_PATH', CL_SMART_ADVICE_PATH . '/cl-smart-advice' ); define( 'CL_SMART_ADVICE_SYMLINK_FILE_PATH', WPMU_PLUGIN_DIR . '/' . basename( __FILE__ ) ); spl_autoload_register( function ( $class ) { $namespace = 'CloudLinux\\SmartAdvice\\'; if ( preg_match( '#^' . preg_quote( $namespace, '/' ) . '#', $class ) ) { $path = CL_SMART_ADVICE_FOLDER_PATH; $name = str_replace( $namespace, '', $class ); $file = preg_replace( '#\\\\#', '/', $name ) . '.php'; $path .= '/' . $file; // @phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged if ( @file_exists( $path ) ) { include_once $path; } } } ); try { if ( ! class_exists( Plugin::class ) ) { return; } if ( defined( 'WP_CLI' ) && WP_CLI ) { // @phpstan-ignore-next-line WP_CLI::add_command( 'smart-advice', Commands::class ); } Plugin::instance()->init(); } catch ( \Exception $e ) { do_action( 'cl_smart_advice_set_error', E_WARNING, 'Init plugin failed: ' . $e->getMessage(), __FILE__, __LINE__ ); }
保存