' . esc_html( (string) wp_parse_url( Config::delivery_url(), PHP_URL_HOST ) ) . '',
'sranywhere'
)
);
}
$text = $found
/* translators: %s: plugin names, such as "LiteSpeed Cache, Complianz". */
? sprintf( __( 'Found: %s. SR Anywhere\'s scripts mark themselves for these tools, so there is nothing to set.', 'sr-anywhere' ), implode( ', ', array_unique( $found ) ) )
: __( 'No caching, optimizing or consent plugin was found that needs a setting for SR Anywhere.', 'sr-anywhere' );
return self::result( 'sranywhere_optimizers', 'good', __( 'Optimizers leave SR Anywhere\'s scripts alone', 'sr-anywhere' ), $text );
}
/**
* Our section in Site Health → Info (WordPress' own "Copy site info" takes it along). No key, no token, no e-mail.
*
* @param array $info The sections so far.
* @return array
*/
public static function info( $info ) {
$fields = array();
foreach ( self::facts( false ) as $key => $fact ) {
$fields[ $key ] = array(
'label' => $fact[0],
'value' => $fact[1],
'debug' => $fact[2] ?? $fact[1], // what WordPress' "Copy site info" takes: in English
);
}
$info['sr-anywhere'] = array(
'label' => __( 'SR Anywhere', 'sr-anywhere' ),
'fields' => $fields,
);
return $info;
}
/**
* The text "Copy diagnostics" puts on the clipboard, for SR Anywhere's Help: one fact a line. Its labels stay in
* English for the support team, whatever the site's language.
*
* @return string
*/
public static function diagnostics() {
$lines = array();
foreach ( self::facts( true ) as $key => $fact ) {
$lines[] = $key . ': ' . ( $fact[2] ?? $fact[1] );
}
return implode( "\n", $lines );
}
/**
* What the site runs: [ label, value, the value in English if it differs ] by key. With the site's basics (WordPress,
* PHP, theme) for the diagnostics; Site Health shows those in its own sections.
*
* @param bool $basics Whether to include WordPress, PHP, the environment, the theme and the builders.
* @return array
*/
private static function facts( $basics ) {
$none = array( __( 'none found', 'sr-anywhere' ), 'none found' );
$facts = array( 'sr-anywhere' => array( __( 'Version', 'sr-anywhere' ), SRANYWHERE_VERSION ) );
$connection = Connection::get();
if ( $basics ) {
$theme = wp_get_theme();
$parent = $theme->parent();
$facts['wordpress'] = array( __( 'WordPress', 'sr-anywhere' ), get_bloginfo( 'version' ) . ( is_multisite() ? ' (multisite)' : '' ) );
$facts['php'] = array( __( 'PHP', 'sr-anywhere' ), PHP_VERSION );
$facts['env'] = array( __( 'Environment', 'sr-anywhere' ), wp_get_environment_type() );
$facts['theme'] = array(
__( 'Theme', 'sr-anywhere' ),
$theme->get( 'Name' ) . ' ' . $theme->get( 'Version' ) . ( $parent ? ' (child of ' . $parent->get( 'Name' ) . ' ' . $parent->get( 'Version' ) . ')' : '' ) . ( wp_is_block_theme() ? ', block theme' : '' ),
);
$builders = self::active( self::BUILDERS );
if ( isset( self::BUILDER_THEMES[ $theme->get_template() ] ) ) {
$builders[ 'theme:' . $theme->get_template() ] = self::BUILDER_THEMES[ $theme->get_template() ];
}
$facts['builders'] = self::fact( __( 'Page builders', 'sr-anywhere' ), $builders ? self::with_versions( $builders ) : $none );
}
$facts['connection'] = array(
__( 'Connection', 'sr-anywhere' ),
$connection ? $connection->state() . ( $connection->is_oauth() ? ' (OAuth)' : ' (key)' ) : Connection::DISCONNECTED,
);
if ( $connection ) {
$facts['account'] = array( __( 'Account', 'sr-anywhere' ), '' !== $connection->account_id() ? $connection->account_id() : '-' );
$facts['site'] = array( __( 'Connected for', 'sr-anywhere' ), '' !== $connection->site() ? $connection->site() : '-' );
}
$facts['modules'] = array( __( 'Known modules', 'sr-anywhere' ), (string) count( Placeable::all() ) );
$changed = Config::api_url() . ', ' . Config::delivery_url() . ', ' . Config::start_url();
$facts['service'] = self::fact(
__( 'Service', 'sr-anywhere' ),
Config::API === Config::api_url() && Config::DELIVERY === Config::delivery_url() && Config::delivery_url() === Config::start_url()
? array( __( 'default', 'sr-anywhere' ), 'default' )
/* translators: %s: the service's addresses. */
: array( sprintf( __( 'changed in wp-config.php: %s', 'sr-anywhere' ), $changed ), 'changed in wp-config.php: ' . $changed )
);
$optimizers = self::active( self::OPTIMIZERS );
$consent = self::active( self::CONSENT );
$facts['optimizers'] = self::fact( __( 'Optimizers', 'sr-anywhere' ), $optimizers ? self::with_versions( $optimizers ) : $none );
$facts['consent'] = self::fact( __( 'Consent tools', 'sr-anywhere' ), $consent ? self::with_versions( $consent ) : $none );
$facts['cloudflare'] = self::fact( __( 'Cloudflare in front', 'sr-anywhere' ), isset( $_SERVER['HTTP_CF_RAY'] ) ? array( __( 'yes', 'sr-anywhere' ), 'yes' ) : array( __( 'no', 'sr-anywhere' ), 'no' ) );
$classic = array( __( 'not active', 'sr-anywhere' ), 'not active' );
if ( Settings::classic_active() ) {
$version = defined( 'RS_REVISION' ) ? (string) RS_REVISION : '?';
$classic = Settings::classic_outdated()
/* translators: 1: the Slider Revolution version found, 2: the version that runs both side by side. */
? array( sprintf( __( '%1$s (older than %2$s)', 'sr-anywhere' ), $version, Settings::CLASSIC_FIXED ), $version . ' (older than ' . Settings::CLASSIC_FIXED . ')' )
: $version;
}
$facts['classic'] = self::fact( __( 'Slider Revolution', 'sr-anywhere' ), $classic );
return $facts;
}
/**
* A fact: its label, its value, and the value in English when the shown one is translated.
*
* @param string $label The label.
* @param string|array $value The value, or [ translated, English ].
* @return array
*/
private static function fact( $label, $value ) {
return is_array( $value ) ? array( $label, $value[0], $value[1] ) : array( $label, $value );
}
/**
* Whether the delivery answers the server: a module's start, as the cache fetches it (it never counts a view).
* True without a known module, as there is nothing to fetch then.
*
* @return bool
*/
private static function delivery_reachable() {
$keys = array_values( array_filter( Placeable::all(), array( Keys::class, 'is_embed_key' ) ) );
$keys = array_values( array_diff( $keys, array_filter( $keys, array( Keys::class, 'is_group_key' ) ) ) );
if ( ! $keys ) {
return true;
}
$host = (string) wp_parse_url( home_url(), PHP_URL_HOST );
$response = wp_remote_get(
Config::start_url() . '/i/' . rawurlencode( $keys[0] ) . '/start.json?host=' . rawurlencode( $host ),
array(
'timeout' => 5,
'redirection' => 0,
)
);
return ! is_wp_error( $response ) && in_array( (int) wp_remote_retrieve_response_code( $response ), array( 200, 404 ), true );
}
/**
* The active plugins among a list, by folder: [ folder => name ].
*
* @param array $known Names by plugin folder.
* @return array
*/
private static function active( array $known ) {
$active = (array) get_option( 'active_plugins', array() );
if ( is_multisite() ) {
$active = array_merge( $active, array_keys( (array) get_site_option( 'active_sitewide_plugins', array() ) ) );
}
$found = array();
foreach ( $active as $file ) {
$folder = dirname( (string) $file );
if ( isset( $known[ $folder ] ) ) {
$found[ $folder ] = $known[ $folder ];
}
}
return $found;
}
/**
* "LiteSpeed Cache 7.6, Complianz 7.4": names with the installed versions.
*
* @param array $found Names by plugin folder (or by "theme:' . wp_kses( $description, array( 'code' => array() ) ) . '
', 'actions' => '' === $action ? '' : '', 'test' => $test, ); } }