$message,
'class' => $class,
'is_dismissible' => (bool) $is_dismissible,
);
}
/**
* Display all notices.
*
* @since 1.0.0
* @since 1.5.0 Allow the notice to be dismissible, remove the id attribute, which is not unique.
*/
public static function display_admin_notices() {
foreach ( (array) self::$admin_notices as $notice ) :
$dismissible = $notice['is_dismissible'] ? 'is-dismissible' : '';
?>
` for non-HTML tags.
*
* @since 1.5.0
*
* @param string $value String we want to sanitize.
*
* @return string
*/
public static function sanitize_value( $value ) {
// Remove HTML tags.
$filtered = wp_strip_all_tags( $value, false );
// Remove multi-lines/tabs.
$filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered );
// Remove whitespaces.
$filtered = trim( $filtered );
// Remove octets.
$found = false;
while ( preg_match( '/%[a-f0-9]{2}/i', $filtered, $match ) ) {
$filtered = str_replace( $match[0], '', $filtered );
$found = true;
}
if ( $found ) {
// Strip out the whitespace that may now exist after removing the octets.
$filtered = trim( preg_replace( '/ +/', ' ', $filtered ) );
}
return $filtered;
}
/**
* Get default email address.
*
* This is the same code as used in WP core for getting the default email address.
*
* @see https://github.com/WordPress/WordPress/blob/master/wp-includes/pluggable.php#L332
*
* @since 2.2.0
* @since 2.3.0 In WP 5.5 the core code changed and is now using `network_home_url`.
*
* @return string
*/
public static function get_default_email() {
if ( version_compare( get_bloginfo( 'version' ), '5.5-alpha', '<' ) ) {
$sitename = strtolower( $_SERVER['SERVER_NAME'] ); // phpcs:ignore
} else {
$sitename = wp_parse_url( network_home_url(), PHP_URL_HOST );
}
if ( 'www.' === substr( $sitename, 0, 4 ) ) {
$sitename = substr( $sitename, 4 );
}
return 'wordpress@' . $sitename;
}
/**
* Wrapper for the WP `admin_url` method that should be used in the plugin.
*
* We can filter into it, to maybe call `network_admin_url` for multisite support.
*
* @since 2.2.0
*
* @param string $path Optional path relative to the admin URL.
* @param string $scheme The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl().
* 'http' or 'https' can be passed to force those schemes.
*
* @return string Admin URL link with optional path appended.
*/
public static function admin_url( $path = '', $scheme = 'admin' ) {
return apply_filters( 'wp_mail_smtp_admin_url', \admin_url( $path, $scheme ), $path, $scheme );
}
/**
* Check if the global plugin option in a multisite should be used.
* If the global plugin option "multisite" is set and true.
*
* @since 2.2.0
*
* @return bool
*/
public static function use_global_plugin_settings() {
if ( ! is_multisite() ) {
return false;
}
$main_site_options = get_blog_option( get_main_site_id(), Options::META_KEY, [] );
return ! empty( $main_site_options['general']['network_wide'] );
}
}