Using WordPress ‘get_pung’ PHP filter

The get_pung WordPress PHP filter allows you to modify the list of already-pinged URLs for a specific post.

Usage

add_filter('get_pung', 'your_custom_function');
function your_custom_function($pung) {
    // your custom code here
    return $pung;
}

Parameters

  • $pung (string[]): An array of URLs that have already been pinged for the given post.

More information

See WordPress Developer Resources: get_pung

Examples

Remove a specific URL from the list of already-pinged URLs

This code removes “https://example.com” from the list of already-pinged URLs.

add_filter('get_pung', 'remove_specific_url');
function remove_specific_url($pung) {
    $url_to_remove = 'https://example.com';
    $pung = array_diff($pung, array($url_to_remove));
    return $pung;
}

Clear the list of already-pinged URLs

This code clears the list of already-pinged URLs.

add_filter('get_pung', 'clear_pinged_urls');
function clear_pinged_urls($pung) {
    return array();
}

Add a URL to the list of already-pinged URLs

This code adds “https://example.com” to the list of already-pinged URLs.

add_filter('get_pung', 'add_url_to_pung');
function add_url_to_pung($pung) {
    $pung[] = 'https://example.com';
    return $pung;
}

Remove all non-HTTPS URLs from the list of already-pinged URLs

This code removes all non-HTTPS URLs from the list of already-pinged URLs.

add_filter('get_pung', 'remove_non_https_urls');
function remove_non_https_urls($pung) {
    $pung = array_filter($pung, function ($url) {
        return strpos($url, 'https://') === 0;
    });
    return $pung;
}

Log the list of already-pinged URLs

This code logs the list of already-pinged URLs in a text file.

add_filter('get_pung', 'log_pinged_urls');
function log_pinged_urls($pung) {
    $log_file = '/path/to/your/log/file.txt';
    $log_content = implode("\n", $pung);
    file_put_contents($log_file, $log_content, FILE_APPEND);
    return $pung;
}