Using WordPress ‘pingback_ping_source_uri()’ PHP function

The pingback_ping_source_uri() WordPress PHP function validates the pingback’s Source URI using the default filter.

Usage

apply_filters('pingback_ping_source_uri', $source_uri);

Parameters

  • $source_uri (string) – The Source URI that needs to be validated.

More information

See WordPress Developer Resources: pingback_ping_source_uri

Examples

Validate a Source URI

This example demonstrates how to validate a Source URI using the pingback_ping_source_uri() function.

function validate_source_uri($source_uri) {
    return apply_filters('pingback_ping_source_uri', $source_uri);
}

$source_uri = 'https://example.com';
$validated_uri = validate_source_uri($source_uri);

// Output: Validated URI
echo 'Validated URI: ' . $validated_uri;

Hook a Custom Validation Function

This example demonstrates how to hook a custom function to the pingback_ping_source_uri filter.

function custom_ping_source_uri_validation($source_uri) {
    // Custom validation logic
    return $source_uri;
}

add_filter('pingback_ping_source_uri', 'custom_ping_source_uri_validation', 10, 1);

Sanitize the Source URI

This example demonstrates how to sanitize the Source URI using the pingback_ping_source_uri filter.

function sanitize_source_uri($source_uri) {
    return esc_url($source_uri);
}

add_filter('pingback_ping_source_uri', 'sanitize_source_uri', 10, 1);

Block Specific Domains

This example demonstrates how to block specific domains using the pingback_ping_source_uri filter.

function block_specific_domains($source_uri) {
    $blocked_domains = array('blockeddomain.com', 'anotherblockeddomain.com');

    foreach ($blocked_domains as $domain) {
        if (strpos($source_uri, $domain) !== false) {
            return false;
        }
    }

    return $source_uri;
}

add_filter('pingback_ping_source_uri', 'block_specific_domains', 10, 1);

Restrict Pingbacks to Specific Post Types

This example demonstrates how to restrict pingbacks to specific post types using the pingback_ping_source_uri filter.

function restrict_pingbacks_to_post_types($source_uri) {
    global $post;

    $allowed_post_types = array('post', 'custom_post_type');

    if (in_array($post->post_type, $allowed_post_types)) {
        return $source_uri;
    }

    return false;
}

add_filter('pingback_ping_source_uri', 'restrict_pingbacks_to_post_types', 10, 1);