: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Returns path to a plugin file.
* @param string $path File path relative to the plugin root directory.
* @return string Absolute file path.
function wpcf7_plugin_path( $path = '' ) {
return path_join( WPCF7_PLUGIN_DIR, trim( $path, '/' ) );
* Returns the URL to a plugin file.
* @param string $path File path relative to the plugin root directory.
function wpcf7_plugin_url( $path = '' ) {
$url = plugins_url( $path, WPCF7_PLUGIN );
and 'http:' == substr( $url, 0, 5 ) ) {
$url = 'https:' . substr( $url, 5 );
* Include a file under WPCF7_PLUGIN_MODULES_DIR.
* @param string $path File path relative to the module dir.
* @return bool True on success, false on failure.
function wpcf7_include_module_file( $path ) {
$dir = WPCF7_PLUGIN_MODULES_DIR;
if ( empty( $dir ) or ! is_dir( $dir ) ) {
$path = path_join( $dir, ltrim( $path, '/' ) );
if ( file_exists( $path ) ) {
* Retrieves uploads directory information.
* @param string|bool $type Optional. Type of output. Default false.
* @return array|string Information about the upload directory.
function wpcf7_upload_dir( $type = false ) {
$uploads = wp_get_upload_dir();
$uploads = apply_filters( 'wpcf7_upload_dir', array(
'dir' => $uploads['basedir'],
'url' => $uploads['baseurl'],
} if ( 'url' == $type ) {
* Verifies that a correct security nonce was used with time limit.
* @param string $nonce Nonce value that was used for verification.
* @param string $action Optional. Context to what is taking place.
* @return int|bool 1 if the nonce is generated between 0-12 hours ago,
* 2 if the nonce is generated between 12-24 hours ago.
* False if the nonce is invalid.
function wpcf7_verify_nonce( $nonce, $action = 'wp_rest' ) {
return wp_verify_nonce( $nonce, $action );
* Creates a cryptographic token tied to a specific action, user, user session,
* @param string $action Optional. Context to what is taking place.
* @return string The token.
function wpcf7_create_nonce( $action = 'wp_rest' ) {
return wp_create_nonce( $action );
* Converts multi-dimensional array to a flat array.
* @param mixed $input Array or item of array.
* @return array Flatten array.
function wpcf7_array_flatten( $input ) {
if ( ! is_array( $input ) ) {
foreach ( $input as $value ) {
$output = array_merge( $output, wpcf7_array_flatten( $value ) );
* Excludes unset or blank text values from the given array.
* @param array $input The array.
* @return array Array without blank text values.
function wpcf7_exclude_blank( $input ) {
$output = array_filter( $input,
return isset( $i ) && '' !== $i;
return array_values( $output );
* Creates a comma-separated list from a multi-dimensional array.
* @param mixed $input Array or item of array.
* @param string|array $options Optional. Output options.
* @return string Comma-separated list.
function wpcf7_flat_join( $input, $options = '' ) {
$options = wp_parse_args( $options, array(
$input = wpcf7_array_flatten( $input );
foreach ( (array) $input as $value ) {
if ( is_scalar( $value ) ) {
$output[] = trim( (string) $value );
return implode( $options['separator'], $output );
* Returns true if HTML5 is supported.
function wpcf7_support_html5() {
return (bool) wpcf7_apply_filters_deprecated(
* Returns true if HTML5 fallback is active.
function wpcf7_support_html5_fallback() {
return (bool) apply_filters( 'wpcf7_support_html5_fallback', false );
* Returns true if the Really Simple CAPTCHA plugin is used for contact forms.
function wpcf7_use_really_simple_captcha() {
return apply_filters( 'wpcf7_use_really_simple_captcha',
WPCF7_USE_REALLY_SIMPLE_CAPTCHA
* Returns true if config validation is active.
function wpcf7_validate_configuration() {
return apply_filters( 'wpcf7_validate_configuration',
WPCF7_VALIDATE_CONFIGURATION
* Returns true if wpcf7_autop() is applied.
function wpcf7_autop_or_not( $options = '' ) {
$options = wp_parse_args( $options, array(
return (bool) apply_filters( 'wpcf7_autop_or_not', WPCF7_AUTOP, $options );
* Returns true if JavaScript for this plugin is loaded.
function wpcf7_load_js() {
return apply_filters( 'wpcf7_load_js', WPCF7_LOAD_JS );
* Returns true if CSS for this plugin is loaded.
function wpcf7_load_css() {
return apply_filters( 'wpcf7_load_css', WPCF7_LOAD_CSS );
* Builds an HTML anchor element.
* @param string $url Link URL.
* @param string $anchor_text Anchor label text.
* @param string|array $atts Optional. HTML attributes.
* @return string Formatted anchor element.
function wpcf7_link( $url, $anchor_text, $atts = '' ) {
$atts = wp_parse_args( $atts, array(
$atts = array_merge( $atts, array(
'href' => esc_url( $url ),
wpcf7_format_atts( $atts ),
* Returns the current request URL.
function wpcf7_get_request_uri() {
static $request_uri = '';
if ( empty( $request_uri ) ) {
$request_uri = add_query_arg( array() );
$request_uri = '/' . ltrim( $request_uri, '/' );
return sanitize_url( $request_uri );
* Registers post types used for this plugin.
function wpcf7_register_post_types() {
if ( class_exists( 'WPCF7_ContactForm' ) ) {
WPCF7_ContactForm::register_post_type();
* Returns the version string of this plugin.
* @param string|array $options Optional. Output options.
* @return string Version string.
function wpcf7_version( $options = '' ) {
$options = wp_parse_args( $options, array(
if ( $options['only_major'] ) {
$options['limit'] = (int) $options['limit'];
$ver = strtr( $ver, '_-+', '...' );
$ver = preg_replace( '/[^0-9.]+/', ".$0.", $ver );
$ver = preg_replace( '/[.]+/', ".", $ver );
$ver = trim( $ver, '.' );
$ver = explode( '.', $ver );
if ( -1 < $options['limit'] ) {
$ver = array_slice( $ver, 0, $options['limit'] );
$ver = implode( '.', $ver );
* Returns array entries that match the given version.
* @param string $version The version to search for.
* @param array $input Search target array.
* @return array|bool Array of matched entries. False on failure.
function wpcf7_version_grep( $version, array $input ) {
$pattern = '/^' . preg_quote( (string) $version, '/' ) . '(?:\.|$)/';
return preg_grep( $pattern, $input );
* Returns an enctype attribute value.
* @param string $enctype Enctype value.
* @return string Enctype value. Empty if not a valid enctype.
function wpcf7_enctype_value( $enctype ) {
$enctype = trim( $enctype );
if ( empty( $enctype ) ) {
'application/x-www-form-urlencoded',
if ( in_array( $enctype, $valid_enctypes ) ) {
$pattern = '%^enctype="(' . implode( '|', $valid_enctypes ) . ')"$%';
if ( preg_match( $pattern, $enctype, $matches ) ) {
return $matches[1]; // for back-compat
* Removes directory recursively.
* @param string $dir Directory path.
* @return bool True on success, false on failure.
function wpcf7_rmdir_p( $dir ) {
if ( @unlink( $file ) ) {
if ( @chmod( $file, $stat['mode'] | 0200 ) ) { // add write for owner
if ( @unlink( $file ) ) {
@chmod( $file, $stat['mode'] );
if ( ! is_dir( $dir ) ) {
if ( $handle = opendir( $dir ) ) {
while ( false !== ( $file = readdir( $handle ) ) ) {
wpcf7_rmdir_p( path_join( $dir, $file ) );
if ( false !== ( $files = scandir( $dir ) )
and ! array_diff( $files, array( '.', '..' ) ) ) {
* Builds a URL-encoded query string.
* @link https://developer.wordpress.org/reference/functions/_http_build_query/
* @param array $data URL query parameters.
* @param string $key Optional. If specified, used to prefix key name.
* @return string Query string.
function wpcf7_build_query( $data, $key = '' ) {
foreach ( (array) $data as $k => $v ) {
$k = $key . '%5B' . $k . '%5D';
} elseif ( false === $v ) {
if ( is_array( $v ) or is_object( $v ) ) {
array_push( $ret, wpcf7_build_query( $v, $k ) );
array_push( $ret, $k . '=' . urlencode( $v ) );
return implode( $sep, $ret );
* Returns the number of code units in a string.
* @link http://www.w3.org/TR/html5/infrastructure.html#code-unit-length
* @param string $text Input string.
* @return int|bool The number of code units, or false if
* mb_convert_encoding is not available.
function wpcf7_count_code_units( $text ) {
if ( is_null( $use_mb ) ) {
$use_mb = function_exists( 'mb_convert_encoding' );
$text = str_replace( "\r\n", "\n", $text );
$encoding = mb_detect_encoding( $text, mb_detect_order(), true );
$text = mb_convert_encoding( $text, 'UTF-16', $encoding );
$text = mb_convert_encoding( $text, 'UTF-16', 'UTF-8' );
$byte_count = mb_strlen( $text, '8bit' );
return floor( $byte_count / 2 );