: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* The class provides utility functions related to WordPress.
* @author Advanced Ads <info@wpadvancedads.com>
namespace AdvancedAds\Utilities;
use AdvancedAds\Framework\Utilities\Params;
defined( 'ABSPATH' ) || exit;
* Get the current action selected from the bulk actions dropdown.
* @return string|false The action name or False if no action was selected
public static function current_action() {
$action = Params::request( 'action' );
if ( '-1' !== $action ) {
return sanitize_key( $action );
$action = Params::request( 'action2' );
if ( '-1' !== $action ) {
return sanitize_key( $action );
* Returns whether the current user has the specified capability.
* @param string $capability Capability name.
public static function user_can( $capability = 'manage_options' ): bool {
// Admins can do everything.
if ( current_user_can( 'manage_options' ) ) {
apply_filters( 'advanced-ads-capability', $capability )
* Returns the capability needed to perform an action
* @param string $capability A capability to check, can be internal to Advanced Ads.
public static function user_cap( $capability = 'manage_options' ) {
// Admins can do everything.
if ( current_user_can( 'manage_options' ) ) {
return apply_filters( 'advanced-ads-capability', $capability );
* @param string $part Part of domain.
public static function get_site_domain( $part = 'host' ): string {
$domain = wp_parse_url( home_url( '/' ), PHP_URL_HOST );
if ( 'name' === $part ) {
$domain = explode( '.', $domain );
$domain = count( $domain ) > 2 ? $domain[1] : $domain[0];
* Returns true if the current request is a REST request.
public static function is_rest_request(): bool {
$request = Params::server( 'REQUEST_URI' );
if ( empty( $request ) ) {
return false !== strpos( $request, trailingslashit( rest_get_url_prefix() ) );
* Returns true if a REST request has an Advanced Ads endpoint.
public static function is_gutenberg_writing_request(): bool {
$rest_route = $wp->query_vars['rest_route'] ?? '';
$is_writing = in_array( Params::server( 'REQUEST_METHOD' ), [ 'POST', 'PUT' ], true );
$is_gutenberg = strpos( $rest_route, '/wp/v2/posts' ) !== false || strpos( $rest_route, '/wp/v2/pages' ) !== false;
return $is_gutenberg && $is_writing;
* Unserializes data only if it was serialized.
* @link https://patchstack.com/articles/unauthenticated-php-object-injection-in-flatsome-theme-3-17-5/
* @param string $data Data that might be unserialized.
* @return mixed Unserialized data can be any type.
public static function maybe_unserialize( $data ) {
if ( is_serialized( $data ) ) { // Don't attempt to unserialize data that wasn't serialized going in.
return @unserialize( trim( $data ), [ 'allowed_classes' => false ] ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.PHP.DiscouragedPHPFunctions.serialize_unserialize