pingback

The timeline below displays how wordpress function pingback has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Pings back the links found in a post.
 *
 * @since 0.71
 * @since 4.7.0 `$post` can be a WP_Post object.
 *
 * @param string      $content Post content to check for links. If empty will retrieve from post.
 * @param int|WP_Post $post    Post ID or object.
 */
function pingback($content, $post)
{
    require_once ABSPATH . WPINC . '/class-IXR.php';
    require_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';
    // Original code by Mort (http://mort.mine.nu:8080).
    $post_links = array();
    $post = get_post($post);
    if (!$post) {
        return;
    }
    $pung = get_pung($post);
    if (empty($content)) {
        $content = $post->post_content;
    }
    /*
     * Step 1.
     * Parsing the post, external links (if any) are stored in the $post_links array.
     */
    $post_links_temp = wp_extract_urls($content);
    /*
     * Step 2.
     * Walking through the links array.
     * First we get rid of links pointing to sites, not to specific files.
     * Example:
     * http://dummy-weblog.org
     * http://dummy-weblog.org/
     * http://dummy-weblog.org/post.php
     * We don't wanna ping first and second types, even if they have a valid <link/>.
     */
    foreach ((array) $post_links_temp as $link_test) {
        // If we haven't pung it already and it isn't a link to itself.
        if (!in_array($link_test, $pung, true) && url_to_postid($link_test) != $post->ID && !is_local_attachment($link_test)) {
            $test = parse_url($link_test);
            if ($test) {
                if (isset($test['query'])) {
                    $post_links[] = $link_test;
                } elseif (isset($test['path']) && '/' !== $test['path'] && '' !== $test['path']) {
                    $post_links[] = $link_test;
                }
            }
        }
    }
    $post_links = array_unique($post_links);
    /**
     * Fires just before pinging back links found in a post.
     *
     * @since 2.0.0
     *
     * @param string[] $post_links Array of link URLs to be checked (passed by reference).
     * @param string[] $pung       Array of link URLs already pinged (passed by reference).
     * @param int      $post_id    The post ID.
     */
    do_action_ref_array('pre_ping', array(&$post_links, &$pung, $post->ID));
    foreach ((array) $post_links as $pagelinkedto) {
        $pingback_server_url = discover_pingback_server_uri($pagelinkedto);
        if ($pingback_server_url) {
            if (function_exists('set_time_limit')) {
                set_time_limit(60);
            }
            // Now, the RPC call.
            $pagelinkedfrom = get_permalink($post);
            // Using a timeout of 3 seconds should be enough to cover slow servers.
            $client = new WP_HTTP_IXR_Client($pingback_server_url);
            $client->timeout = 3;
            /**
             * Filters the user agent sent when pinging-back a URL.
             *
             * @since 2.9.0
             *
             * @param string $concat_useragent    The user agent concatenated with ' -- WordPress/'
             *                                    and the WordPress version.
             * @param string $useragent           The useragent.
             * @param string $pingback_server_url The server URL being linked to.
             * @param string $pagelinkedto        URL of page linked to.
             * @param string $pagelinkedfrom      URL of page linked from.
             */
            $client->useragent = apply_filters('pingback_useragent', $client->useragent . ' -- WordPress/' . get_bloginfo('version'), $client->useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom);
            // When set to true, this outputs debug messages by itself.
            $client->debug = false;
            if ($client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto) || isset($client->error->code) && 48 == $client->error->code) {
                // Already registered.
                add_ping($post, $pagelinkedto);
            }
        }
    }
}

WordPress Version: 6.2

/**
 * Pings back the links found in a post.
 *
 * @since 0.71
 * @since 4.7.0 `$post` can be a WP_Post object.
 *
 * @param string      $content Post content to check for links. If empty will retrieve from post.
 * @param int|WP_Post $post    Post ID or object.
 */
function pingback($content, $post)
{
    include_once ABSPATH . WPINC . '/class-IXR.php';
    include_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';
    // Original code by Mort (http://mort.mine.nu:8080).
    $post_links = array();
    $post = get_post($post);
    if (!$post) {
        return;
    }
    $pung = get_pung($post);
    if (empty($content)) {
        $content = $post->post_content;
    }
    /*
     * Step 1.
     * Parsing the post, external links (if any) are stored in the $post_links array.
     */
    $post_links_temp = wp_extract_urls($content);
    /*
     * Step 2.
     * Walking through the links array.
     * First we get rid of links pointing to sites, not to specific files.
     * Example:
     * http://dummy-weblog.org
     * http://dummy-weblog.org/
     * http://dummy-weblog.org/post.php
     * We don't wanna ping first and second types, even if they have a valid <link/>.
     */
    foreach ((array) $post_links_temp as $link_test) {
        // If we haven't pung it already and it isn't a link to itself.
        if (!in_array($link_test, $pung, true) && url_to_postid($link_test) != $post->ID && !is_local_attachment($link_test)) {
            $test = parse_url($link_test);
            if ($test) {
                if (isset($test['query'])) {
                    $post_links[] = $link_test;
                } elseif (isset($test['path']) && '/' !== $test['path'] && '' !== $test['path']) {
                    $post_links[] = $link_test;
                }
            }
        }
    }
    $post_links = array_unique($post_links);
    /**
     * Fires just before pinging back links found in a post.
     *
     * @since 2.0.0
     *
     * @param string[] $post_links Array of link URLs to be checked (passed by reference).
     * @param string[] $pung       Array of link URLs already pinged (passed by reference).
     * @param int      $post_id    The post ID.
     */
    do_action_ref_array('pre_ping', array(&$post_links, &$pung, $post->ID));
    foreach ((array) $post_links as $pagelinkedto) {
        $pingback_server_url = discover_pingback_server_uri($pagelinkedto);
        if ($pingback_server_url) {
            if (function_exists('set_time_limit')) {
                set_time_limit(60);
            }
            // Now, the RPC call.
            $pagelinkedfrom = get_permalink($post);
            // Using a timeout of 3 seconds should be enough to cover slow servers.
            $client = new WP_HTTP_IXR_Client($pingback_server_url);
            $client->timeout = 3;
            /**
             * Filters the user agent sent when pinging-back a URL.
             *
             * @since 2.9.0
             *
             * @param string $concat_useragent    The user agent concatenated with ' -- WordPress/'
             *                                    and the WordPress version.
             * @param string $useragent           The useragent.
             * @param string $pingback_server_url The server URL being linked to.
             * @param string $pagelinkedto        URL of page linked to.
             * @param string $pagelinkedfrom      URL of page linked from.
             */
            $client->useragent = apply_filters('pingback_useragent', $client->useragent . ' -- WordPress/' . get_bloginfo('version'), $client->useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom);
            // When set to true, this outputs debug messages by itself.
            $client->debug = false;
            if ($client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto) || isset($client->error->code) && 48 == $client->error->code) {
                // Already registered.
                add_ping($post, $pagelinkedto);
            }
        }
    }
}

WordPress Version: 6.1

/**
 * Pings back the links found in a post.
 *
 * @since 0.71
 * @since 4.7.0 `$post` can be a WP_Post object.
 *
 * @param string      $content Post content to check for links. If empty will retrieve from post.
 * @param int|WP_Post $post    Post ID or object.
 */
function pingback($content, $post)
{
    include_once ABSPATH . WPINC . '/class-IXR.php';
    include_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';
    // Original code by Mort (http://mort.mine.nu:8080).
    $post_links = array();
    $post = get_post($post);
    if (!$post) {
        return;
    }
    $pung = get_pung($post);
    if (empty($content)) {
        $content = $post->post_content;
    }
    /*
     * Step 1.
     * Parsing the post, external links (if any) are stored in the $post_links array.
     */
    $post_links_temp = wp_extract_urls($content);
    /*
     * Step 2.
     * Walking through the links array.
     * First we get rid of links pointing to sites, not to specific files.
     * Example:
     * http://dummy-weblog.org
     * http://dummy-weblog.org/
     * http://dummy-weblog.org/post.php
     * We don't wanna ping first and second types, even if they have a valid <link/>.
     */
    foreach ((array) $post_links_temp as $link_test) {
        // If we haven't pung it already and it isn't a link to itself.
        if (!in_array($link_test, $pung, true) && url_to_postid($link_test) != $post->ID && !is_local_attachment($link_test)) {
            $test = parse_url($link_test);
            if ($test) {
                if (isset($test['query'])) {
                    $post_links[] = $link_test;
                } elseif (isset($test['path']) && '/' !== $test['path'] && '' !== $test['path']) {
                    $post_links[] = $link_test;
                }
            }
        }
    }
    $post_links = array_unique($post_links);
    /**
     * Fires just before pinging back links found in a post.
     *
     * @since 2.0.0
     *
     * @param string[] $post_links Array of link URLs to be checked (passed by reference).
     * @param string[] $pung       Array of link URLs already pinged (passed by reference).
     * @param int      $post_id    The post ID.
     */
    do_action_ref_array('pre_ping', array(&$post_links, &$pung, $post->ID));
    foreach ((array) $post_links as $pagelinkedto) {
        $pingback_server_url = discover_pingback_server_uri($pagelinkedto);
        if ($pingback_server_url) {
            set_time_limit(60);
            // Now, the RPC call.
            $pagelinkedfrom = get_permalink($post);
            // Using a timeout of 3 seconds should be enough to cover slow servers.
            $client = new WP_HTTP_IXR_Client($pingback_server_url);
            $client->timeout = 3;
            /**
             * Filters the user agent sent when pinging-back a URL.
             *
             * @since 2.9.0
             *
             * @param string $concat_useragent    The user agent concatenated with ' -- WordPress/'
             *                                    and the WordPress version.
             * @param string $useragent           The useragent.
             * @param string $pingback_server_url The server URL being linked to.
             * @param string $pagelinkedto        URL of page linked to.
             * @param string $pagelinkedfrom      URL of page linked from.
             */
            $client->useragent = apply_filters('pingback_useragent', $client->useragent . ' -- WordPress/' . get_bloginfo('version'), $client->useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom);
            // When set to true, this outputs debug messages by itself.
            $client->debug = false;
            if ($client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto) || isset($client->error->code) && 48 == $client->error->code) {
                // Already registered.
                add_ping($post, $pagelinkedto);
            }
        }
    }
}

WordPress Version: 5.5

/**
 * Pings back the links found in a post.
 *
 * @since 0.71
 * @since 4.7.0 `$post_id` can be a WP_Post object.
 *
 * @param string      $content Post content to check for links. If empty will retrieve from post.
 * @param int|WP_Post $post_id Post Object or ID.
 */
function pingback($content, $post_id)
{
    include_once ABSPATH . WPINC . '/class-IXR.php';
    include_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';
    // Original code by Mort (http://mort.mine.nu:8080).
    $post_links = array();
    $post = get_post($post_id);
    if (!$post) {
        return;
    }
    $pung = get_pung($post);
    if (empty($content)) {
        $content = $post->post_content;
    }
    /*
     * Step 1.
     * Parsing the post, external links (if any) are stored in the $post_links array.
     */
    $post_links_temp = wp_extract_urls($content);
    /*
     * Step 2.
     * Walking through the links array.
     * First we get rid of links pointing to sites, not to specific files.
     * Example:
     * http://dummy-weblog.org
     * http://dummy-weblog.org/
     * http://dummy-weblog.org/post.php
     * We don't wanna ping first and second types, even if they have a valid <link/>.
     */
    foreach ((array) $post_links_temp as $link_test) {
        // If we haven't pung it already and it isn't a link to itself.
        if (!in_array($link_test, $pung, true) && url_to_postid($link_test) != $post->ID && !is_local_attachment($link_test)) {
            $test = parse_url($link_test);
            if ($test) {
                if (isset($test['query'])) {
                    $post_links[] = $link_test;
                } elseif (isset($test['path']) && '/' !== $test['path'] && '' !== $test['path']) {
                    $post_links[] = $link_test;
                }
            }
        }
    }
    $post_links = array_unique($post_links);
    /**
     * Fires just before pinging back links found in a post.
     *
     * @since 2.0.0
     *
     * @param string[] $post_links Array of link URLs to be checked (passed by reference).
     * @param string[] $pung       Array of link URLs already pinged (passed by reference).
     * @param int      $post_ID    The post ID.
     */
    do_action_ref_array('pre_ping', array(&$post_links, &$pung, $post->ID));
    foreach ((array) $post_links as $pagelinkedto) {
        $pingback_server_url = discover_pingback_server_uri($pagelinkedto);
        if ($pingback_server_url) {
            set_time_limit(60);
            // Now, the RPC call.
            $pagelinkedfrom = get_permalink($post);
            // Using a timeout of 3 seconds should be enough to cover slow servers.
            $client = new WP_HTTP_IXR_Client($pingback_server_url);
            $client->timeout = 3;
            /**
             * Filters the user agent sent when pinging-back a URL.
             *
             * @since 2.9.0
             *
             * @param string $concat_useragent    The user agent concatenated with ' -- WordPress/'
             *                                    and the WordPress version.
             * @param string $useragent           The useragent.
             * @param string $pingback_server_url The server URL being linked to.
             * @param string $pagelinkedto        URL of page linked to.
             * @param string $pagelinkedfrom      URL of page linked from.
             */
            $client->useragent = apply_filters('pingback_useragent', $client->useragent . ' -- WordPress/' . get_bloginfo('version'), $client->useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom);
            // When set to true, this outputs debug messages by itself.
            $client->debug = false;
            if ($client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto) || isset($client->error->code) && 48 == $client->error->code) {
                // Already registered.
                add_ping($post, $pagelinkedto);
            }
        }
    }
}

WordPress Version: 5.4

/**
 * Pings back the links found in a post.
 *
 * @since 0.71
 * @since 4.7.0 `$post_id` can be a WP_Post object.
 *
 * @param string $content Post content to check for links. If empty will retrieve from post.
 * @param int|WP_Post $post_id Post Object or ID.
 */
function pingback($content, $post_id)
{
    include_once ABSPATH . WPINC . '/class-IXR.php';
    include_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';
    // Original code by Mort (http://mort.mine.nu:8080).
    $post_links = array();
    $post = get_post($post_id);
    if (!$post) {
        return;
    }
    $pung = get_pung($post);
    if (empty($content)) {
        $content = $post->post_content;
    }
    /*
     * Step 1.
     * Parsing the post, external links (if any) are stored in the $post_links array.
     */
    $post_links_temp = wp_extract_urls($content);
    /*
     * Step 2.
     * Walking through the links array.
     * First we get rid of links pointing to sites, not to specific files.
     * Example:
     * http://dummy-weblog.org
     * http://dummy-weblog.org/
     * http://dummy-weblog.org/post.php
     * We don't wanna ping first and second types, even if they have a valid <link/>.
     */
    foreach ((array) $post_links_temp as $link_test) {
        // If we haven't pung it already and it isn't a link to itself.
        if (!in_array($link_test, $pung) && url_to_postid($link_test) != $post->ID && !is_local_attachment($link_test)) {
            $test = @parse_url($link_test);
            if ($test) {
                if (isset($test['query'])) {
                    $post_links[] = $link_test;
                } elseif (isset($test['path']) && '/' !== $test['path'] && '' !== $test['path']) {
                    $post_links[] = $link_test;
                }
            }
        }
    }
    $post_links = array_unique($post_links);
    /**
     * Fires just before pinging back links found in a post.
     *
     * @since 2.0.0
     *
     * @param string[] $post_links Array of link URLs to be checked (passed by reference).
     * @param string[] $pung       Array of link URLs already pinged (passed by reference).
     * @param int      $post_ID    The post ID.
     */
    do_action_ref_array('pre_ping', array(&$post_links, &$pung, $post->ID));
    foreach ((array) $post_links as $pagelinkedto) {
        $pingback_server_url = discover_pingback_server_uri($pagelinkedto);
        if ($pingback_server_url) {
            set_time_limit(60);
            // Now, the RPC call.
            $pagelinkedfrom = get_permalink($post);
            // Using a timeout of 3 seconds should be enough to cover slow servers.
            $client = new WP_HTTP_IXR_Client($pingback_server_url);
            $client->timeout = 3;
            /**
             * Filters the user agent sent when pinging-back a URL.
             *
             * @since 2.9.0
             *
             * @param string $concat_useragent    The user agent concatenated with ' -- WordPress/'
             *                                    and the WordPress version.
             * @param string $useragent           The useragent.
             * @param string $pingback_server_url The server URL being linked to.
             * @param string $pagelinkedto        URL of page linked to.
             * @param string $pagelinkedfrom      URL of page linked from.
             */
            $client->useragent = apply_filters('pingback_useragent', $client->useragent . ' -- WordPress/' . get_bloginfo('version'), $client->useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom);
            // When set to true, this outputs debug messages by itself.
            $client->debug = false;
            if ($client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto) || isset($client->error->code) && 48 == $client->error->code) {
                // Already registered.
                add_ping($post, $pagelinkedto);
            }
        }
    }
}

WordPress Version: 5.3

/**
 * Pings back the links found in a post.
 *
 * @since 0.71
 * @since 4.7.0 `$post_id` can be a WP_Post object.
 *
 * @param string $content Post content to check for links. If empty will retrieve from post.
 * @param int|WP_Post $post_id Post Object or ID.
 */
function pingback($content, $post_id)
{
    include_once ABSPATH . WPINC . '/class-IXR.php';
    include_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';
    // original code by Mort (http://mort.mine.nu:8080)
    $post_links = array();
    $post = get_post($post_id);
    if (!$post) {
        return;
    }
    $pung = get_pung($post);
    if (empty($content)) {
        $content = $post->post_content;
    }
    // Step 1
    // Parsing the post, external links (if any) are stored in the $post_links array
    $post_links_temp = wp_extract_urls($content);
    // Step 2.
    // Walking thru the links array
    // first we get rid of links pointing to sites, not to specific files
    // Example:
    // http://dummy-weblog.org
    // http://dummy-weblog.org/
    // http://dummy-weblog.org/post.php
    // We don't wanna ping first and second types, even if they have a valid <link/>
    foreach ((array) $post_links_temp as $link_test) {
        if (!in_array($link_test, $pung) && url_to_postid($link_test) != $post->ID && !is_local_attachment($link_test)) {
            // Also, let's never ping local attachments.
            $test = @parse_url($link_test);
            if ($test) {
                if (isset($test['query'])) {
                    $post_links[] = $link_test;
                } elseif (isset($test['path']) && $test['path'] != '/' && $test['path'] != '') {
                    $post_links[] = $link_test;
                }
            }
        }
    }
    $post_links = array_unique($post_links);
    /**
     * Fires just before pinging back links found in a post.
     *
     * @since 2.0.0
     *
     * @param string[] $post_links Array of link URLs to be checked (passed by reference).
     * @param string[] $pung       Array of link URLs already pinged (passed by reference).
     * @param int      $post_ID    The post ID.
     */
    do_action_ref_array('pre_ping', array(&$post_links, &$pung, $post->ID));
    foreach ((array) $post_links as $pagelinkedto) {
        $pingback_server_url = discover_pingback_server_uri($pagelinkedto);
        if ($pingback_server_url) {
            set_time_limit(60);
            // Now, the RPC call
            $pagelinkedfrom = get_permalink($post);
            // using a timeout of 3 seconds should be enough to cover slow servers
            $client = new WP_HTTP_IXR_Client($pingback_server_url);
            $client->timeout = 3;
            /**
             * Filters the user agent sent when pinging-back a URL.
             *
             * @since 2.9.0
             *
             * @param string $concat_useragent    The user agent concatenated with ' -- WordPress/'
             *                                    and the WordPress version.
             * @param string $useragent           The useragent.
             * @param string $pingback_server_url The server URL being linked to.
             * @param string $pagelinkedto        URL of page linked to.
             * @param string $pagelinkedfrom      URL of page linked from.
             */
            $client->useragent = apply_filters('pingback_useragent', $client->useragent . ' -- WordPress/' . get_bloginfo('version'), $client->useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom);
            // when set to true, this outputs debug messages by itself
            $client->debug = false;
            if ($client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto) || isset($client->error->code) && 48 == $client->error->code) {
                // Already registered
                add_ping($post, $pagelinkedto);
            }
        }
    }
}

WordPress Version: 5.1

/**
 * Pings back the links found in a post.
 *
 * @since 0.71
 * @since 4.7.0 `$post_id` can be a WP_Post object.
 *
 * @param string $content Post content to check for links. If empty will retrieve from post.
 * @param int|WP_Post $post_id Post Object or ID.
 */
function pingback($content, $post_id)
{
    include_once ABSPATH . WPINC . '/class-IXR.php';
    include_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';
    // original code by Mort (http://mort.mine.nu:8080)
    $post_links = array();
    $post = get_post($post_id);
    if (!$post) {
        return;
    }
    $pung = get_pung($post);
    if (empty($content)) {
        $content = $post->post_content;
    }
    // Step 1
    // Parsing the post, external links (if any) are stored in the $post_links array
    $post_links_temp = wp_extract_urls($content);
    // Step 2.
    // Walking thru the links array
    // first we get rid of links pointing to sites, not to specific files
    // Example:
    // http://dummy-weblog.org
    // http://dummy-weblog.org/
    // http://dummy-weblog.org/post.php
    // We don't wanna ping first and second types, even if they have a valid <link/>
    foreach ((array) $post_links_temp as $link_test) {
        if (!in_array($link_test, $pung) && url_to_postid($link_test) != $post->ID && !is_local_attachment($link_test)) {
            // Also, let's never ping local attachments.
            if ($test = @parse_url($link_test)) {
                if (isset($test['query'])) {
                    $post_links[] = $link_test;
                } elseif (isset($test['path']) && $test['path'] != '/' && $test['path'] != '') {
                    $post_links[] = $link_test;
                }
            }
        }
    }
    $post_links = array_unique($post_links);
    /**
     * Fires just before pinging back links found in a post.
     *
     * @since 2.0.0
     *
     * @param string[] $post_links Array of link URLs to be checked (passed by reference).
     * @param string[] $pung       Array of link URLs already pinged (passed by reference).
     * @param int      $post_ID    The post ID.
     */
    do_action_ref_array('pre_ping', array(&$post_links, &$pung, $post->ID));
    foreach ((array) $post_links as $pagelinkedto) {
        $pingback_server_url = discover_pingback_server_uri($pagelinkedto);
        if ($pingback_server_url) {
            @set_time_limit(60);
            // Now, the RPC call
            $pagelinkedfrom = get_permalink($post);
            // using a timeout of 3 seconds should be enough to cover slow servers
            $client = new WP_HTTP_IXR_Client($pingback_server_url);
            $client->timeout = 3;
            /**
             * Filters the user agent sent when pinging-back a URL.
             *
             * @since 2.9.0
             *
             * @param string $concat_useragent    The user agent concatenated with ' -- WordPress/'
             *                                    and the WordPress version.
             * @param string $useragent           The useragent.
             * @param string $pingback_server_url The server URL being linked to.
             * @param string $pagelinkedto        URL of page linked to.
             * @param string $pagelinkedfrom      URL of page linked from.
             */
            $client->useragent = apply_filters('pingback_useragent', $client->useragent . ' -- WordPress/' . get_bloginfo('version'), $client->useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom);
            // when set to true, this outputs debug messages by itself
            $client->debug = false;
            if ($client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto) || isset($client->error->code) && 48 == $client->error->code) {
                // Already registered
                add_ping($post, $pagelinkedto);
            }
        }
    }
}

WordPress Version: 4.9

/**
 * Pings back the links found in a post.
 *
 * @since 0.71
 * @since 4.7.0 $post_id can be a WP_Post object.
 *
 * @param string $content Post content to check for links. If empty will retrieve from post.
 * @param int|WP_Post $post_id Post Object or ID.
 */
function pingback($content, $post_id)
{
    include_once ABSPATH . WPINC . '/class-IXR.php';
    include_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';
    // original code by Mort (http://mort.mine.nu:8080)
    $post_links = array();
    $post = get_post($post_id);
    if (!$post) {
        return;
    }
    $pung = get_pung($post);
    if (empty($content)) {
        $content = $post->post_content;
    }
    // Step 1
    // Parsing the post, external links (if any) are stored in the $post_links array
    $post_links_temp = wp_extract_urls($content);
    // Step 2.
    // Walking thru the links array
    // first we get rid of links pointing to sites, not to specific files
    // Example:
    // http://dummy-weblog.org
    // http://dummy-weblog.org/
    // http://dummy-weblog.org/post.php
    // We don't wanna ping first and second types, even if they have a valid <link/>
    foreach ((array) $post_links_temp as $link_test) {
        if (!in_array($link_test, $pung) && url_to_postid($link_test) != $post->ID && !is_local_attachment($link_test)) {
            // Also, let's never ping local attachments.
            if ($test = @parse_url($link_test)) {
                if (isset($test['query'])) {
                    $post_links[] = $link_test;
                } elseif (isset($test['path']) && $test['path'] != '/' && $test['path'] != '') {
                    $post_links[] = $link_test;
                }
            }
        }
    }
    $post_links = array_unique($post_links);
    /**
     * Fires just before pinging back links found in a post.
     *
     * @since 2.0.0
     *
     * @param array $post_links An array of post links to be checked (passed by reference).
     * @param array $pung       Whether a link has already been pinged (passed by reference).
     * @param int   $post_ID    The post ID.
     */
    do_action_ref_array('pre_ping', array(&$post_links, &$pung, $post->ID));
    foreach ((array) $post_links as $pagelinkedto) {
        $pingback_server_url = discover_pingback_server_uri($pagelinkedto);
        if ($pingback_server_url) {
            @set_time_limit(60);
            // Now, the RPC call
            $pagelinkedfrom = get_permalink($post);
            // using a timeout of 3 seconds should be enough to cover slow servers
            $client = new WP_HTTP_IXR_Client($pingback_server_url);
            $client->timeout = 3;
            /**
             * Filters the user agent sent when pinging-back a URL.
             *
             * @since 2.9.0
             *
             * @param string $concat_useragent    The user agent concatenated with ' -- WordPress/'
             *                                    and the WordPress version.
             * @param string $useragent           The useragent.
             * @param string $pingback_server_url The server URL being linked to.
             * @param string $pagelinkedto        URL of page linked to.
             * @param string $pagelinkedfrom      URL of page linked from.
             */
            $client->useragent = apply_filters('pingback_useragent', $client->useragent . ' -- WordPress/' . get_bloginfo('version'), $client->useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom);
            // when set to true, this outputs debug messages by itself
            $client->debug = false;
            if ($client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto) || isset($client->error->code) && 48 == $client->error->code) {
                // Already registered
                add_ping($post, $pagelinkedto);
            }
        }
    }
}

WordPress Version: 4.7

/**
 * Pings back the links found in a post.
 *
 * @since 0.71
 * @since 4.7.0 $post_id can be a WP_Post object.
 *
 * @param string $content Post content to check for links. If empty will retrieve from post.
 * @param int|WP_Post $post_id Post Object or ID.
 */
function pingback($content, $post_id)
{
    include_once ABSPATH . WPINC . '/class-IXR.php';
    include_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';
    // original code by Mort (http://mort.mine.nu:8080)
    $post_links = array();
    $post = get_post($post_id);
    if (!$post) {
        return;
    }
    $pung = get_pung($post);
    if (empty($content)) {
        $content = $post->post_content;
    }
    // Step 1
    // Parsing the post, external links (if any) are stored in the $post_links array
    $post_links_temp = wp_extract_urls($content);
    // Step 2.
    // Walking thru the links array
    // first we get rid of links pointing to sites, not to specific files
    // Example:
    // http://dummy-weblog.org
    // http://dummy-weblog.org/
    // http://dummy-weblog.org/post.php
    // We don't wanna ping first and second types, even if they have a valid <link/>
    foreach ((array) $post_links_temp as $link_test) {
        if (!in_array($link_test, $pung) && url_to_postid($link_test) != $post->ID && !is_local_attachment($link_test)) {
            // Also, let's never ping local attachments.
            if ($test = @parse_url($link_test)) {
                if (isset($test['query'])) {
                    $post_links[] = $link_test;
                } elseif (isset($test['path']) && $test['path'] != '/' && $test['path'] != '') {
                    $post_links[] = $link_test;
                }
            }
        }
    }
    $post_links = array_unique($post_links);
    /**
     * Fires just before pinging back links found in a post.
     *
     * @since 2.0.0
     *
     * @param array &$post_links An array of post links to be checked, passed by reference.
     * @param array &$pung       Whether a link has already been pinged, passed by reference.
     * @param int   $post_ID     The post ID.
     */
    do_action_ref_array('pre_ping', array(&$post_links, &$pung, $post->ID));
    foreach ((array) $post_links as $pagelinkedto) {
        $pingback_server_url = discover_pingback_server_uri($pagelinkedto);
        if ($pingback_server_url) {
            @set_time_limit(60);
            // Now, the RPC call
            $pagelinkedfrom = get_permalink($post);
            // using a timeout of 3 seconds should be enough to cover slow servers
            $client = new WP_HTTP_IXR_Client($pingback_server_url);
            $client->timeout = 3;
            /**
             * Filters the user agent sent when pinging-back a URL.
             *
             * @since 2.9.0
             *
             * @param string $concat_useragent    The user agent concatenated with ' -- WordPress/'
             *                                    and the WordPress version.
             * @param string $useragent           The useragent.
             * @param string $pingback_server_url The server URL being linked to.
             * @param string $pagelinkedto        URL of page linked to.
             * @param string $pagelinkedfrom      URL of page linked from.
             */
            $client->useragent = apply_filters('pingback_useragent', $client->useragent . ' -- WordPress/' . get_bloginfo('version'), $client->useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom);
            // when set to true, this outputs debug messages by itself
            $client->debug = false;
            if ($client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto) || isset($client->error->code) && 48 == $client->error->code) {
                // Already registered
                add_ping($post, $pagelinkedto);
            }
        }
    }
}

WordPress Version: 4.6

/**
 * Pings back the links found in a post.
 *
 * @since 0.71
 *
 * @global string $wp_version
 *
 * @param string $content Post content to check for links.
 * @param int $post_ID Post ID.
 */
function pingback($content, $post_ID)
{
    global $wp_version;
    include_once ABSPATH . WPINC . '/class-IXR.php';
    include_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';
    // original code by Mort (http://mort.mine.nu:8080)
    $post_links = array();
    $pung = get_pung($post_ID);
    // Step 1
    // Parsing the post, external links (if any) are stored in the $post_links array
    $post_links_temp = wp_extract_urls($content);
    // Step 2.
    // Walking thru the links array
    // first we get rid of links pointing to sites, not to specific files
    // Example:
    // http://dummy-weblog.org
    // http://dummy-weblog.org/
    // http://dummy-weblog.org/post.php
    // We don't wanna ping first and second types, even if they have a valid <link/>
    foreach ((array) $post_links_temp as $link_test) {
        if (!in_array($link_test, $pung) && url_to_postid($link_test) != $post_ID && !is_local_attachment($link_test)) {
            // Also, let's never ping local attachments.
            if ($test = @parse_url($link_test)) {
                if (isset($test['query'])) {
                    $post_links[] = $link_test;
                } elseif (isset($test['path']) && $test['path'] != '/' && $test['path'] != '') {
                    $post_links[] = $link_test;
                }
            }
        }
    }
    $post_links = array_unique($post_links);
    /**
     * Fires just before pinging back links found in a post.
     *
     * @since 2.0.0
     *
     * @param array &$post_links An array of post links to be checked, passed by reference.
     * @param array &$pung       Whether a link has already been pinged, passed by reference.
     * @param int   $post_ID     The post ID.
     */
    do_action_ref_array('pre_ping', array(&$post_links, &$pung, $post_ID));
    foreach ((array) $post_links as $pagelinkedto) {
        $pingback_server_url = discover_pingback_server_uri($pagelinkedto);
        if ($pingback_server_url) {
            @set_time_limit(60);
            // Now, the RPC call
            $pagelinkedfrom = get_permalink($post_ID);
            // using a timeout of 3 seconds should be enough to cover slow servers
            $client = new WP_HTTP_IXR_Client($pingback_server_url);
            $client->timeout = 3;
            /**
             * Filters the user agent sent when pinging-back a URL.
             *
             * @since 2.9.0
             *
             * @param string $concat_useragent    The user agent concatenated with ' -- WordPress/'
             *                                    and the WordPress version.
             * @param string $useragent           The useragent.
             * @param string $pingback_server_url The server URL being linked to.
             * @param string $pagelinkedto        URL of page linked to.
             * @param string $pagelinkedfrom      URL of page linked from.
             */
            $client->useragent = apply_filters('pingback_useragent', $client->useragent . ' -- WordPress/' . $wp_version, $client->useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom);
            // when set to true, this outputs debug messages by itself
            $client->debug = false;
            if ($client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto) || isset($client->error->code) && 48 == $client->error->code) {
                // Already registered
                add_ping($post_ID, $pagelinkedto);
            }
        }
    }
}

WordPress Version: 4.3

/**
 * Pings back the links found in a post.
 *
 * @since 0.71
 *
 * @global string $wp_version
 *
 * @param string $content Post content to check for links.
 * @param int $post_ID Post ID.
 */
function pingback($content, $post_ID)
{
    global $wp_version;
    include_once ABSPATH . WPINC . '/class-IXR.php';
    include_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';
    // original code by Mort (http://mort.mine.nu:8080)
    $post_links = array();
    $pung = get_pung($post_ID);
    // Step 1
    // Parsing the post, external links (if any) are stored in the $post_links array
    $post_links_temp = wp_extract_urls($content);
    // Step 2.
    // Walking thru the links array
    // first we get rid of links pointing to sites, not to specific files
    // Example:
    // http://dummy-weblog.org
    // http://dummy-weblog.org/
    // http://dummy-weblog.org/post.php
    // We don't wanna ping first and second types, even if they have a valid <link/>
    foreach ((array) $post_links_temp as $link_test) {
        if (!in_array($link_test, $pung) && url_to_postid($link_test) != $post_ID && !is_local_attachment($link_test)) {
            // Also, let's never ping local attachments.
            if ($test = @parse_url($link_test)) {
                if (isset($test['query'])) {
                    $post_links[] = $link_test;
                } elseif (isset($test['path']) && $test['path'] != '/' && $test['path'] != '') {
                    $post_links[] = $link_test;
                }
            }
        }
    }
    $post_links = array_unique($post_links);
    /**
     * Fires just before pinging back links found in a post.
     *
     * @since 2.0.0
     *
     * @param array &$post_links An array of post links to be checked, passed by reference.
     * @param array &$pung       Whether a link has already been pinged, passed by reference.
     * @param int   $post_ID     The post ID.
     */
    do_action_ref_array('pre_ping', array(&$post_links, &$pung, $post_ID));
    foreach ((array) $post_links as $pagelinkedto) {
        $pingback_server_url = discover_pingback_server_uri($pagelinkedto);
        if ($pingback_server_url) {
            @set_time_limit(60);
            // Now, the RPC call
            $pagelinkedfrom = get_permalink($post_ID);
            // using a timeout of 3 seconds should be enough to cover slow servers
            $client = new WP_HTTP_IXR_Client($pingback_server_url);
            $client->timeout = 3;
            /**
             * Filter the user agent sent when pinging-back a URL.
             *
             * @since 2.9.0
             *
             * @param string $concat_useragent    The user agent concatenated with ' -- WordPress/'
             *                                    and the WordPress version.
             * @param string $useragent           The useragent.
             * @param string $pingback_server_url The server URL being linked to.
             * @param string $pagelinkedto        URL of page linked to.
             * @param string $pagelinkedfrom      URL of page linked from.
             */
            $client->useragent = apply_filters('pingback_useragent', $client->useragent . ' -- WordPress/' . $wp_version, $client->useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom);
            // when set to true, this outputs debug messages by itself
            $client->debug = false;
            if ($client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto) || isset($client->error->code) && 48 == $client->error->code) {
                // Already registered
                add_ping($post_ID, $pagelinkedto);
            }
        }
    }
}

WordPress Version: 4.1

/**
 * Pings back the links found in a post.
 *
 * @since 0.71
 * @uses $wp_version
 *
 * @param string $content Post content to check for links.
 * @param int $post_ID Post ID.
 */
function pingback($content, $post_ID)
{
    global $wp_version;
    include_once ABSPATH . WPINC . '/class-IXR.php';
    include_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';
    // original code by Mort (http://mort.mine.nu:8080)
    $post_links = array();
    $pung = get_pung($post_ID);
    // Step 1
    // Parsing the post, external links (if any) are stored in the $post_links array
    $post_links_temp = wp_extract_urls($content);
    // Step 2.
    // Walking thru the links array
    // first we get rid of links pointing to sites, not to specific files
    // Example:
    // http://dummy-weblog.org
    // http://dummy-weblog.org/
    // http://dummy-weblog.org/post.php
    // We don't wanna ping first and second types, even if they have a valid <link/>
    foreach ((array) $post_links_temp as $link_test) {
        if (!in_array($link_test, $pung) && url_to_postid($link_test) != $post_ID && !is_local_attachment($link_test)) {
            // Also, let's never ping local attachments.
            if ($test = @parse_url($link_test)) {
                if (isset($test['query'])) {
                    $post_links[] = $link_test;
                } elseif (isset($test['path']) && $test['path'] != '/' && $test['path'] != '') {
                    $post_links[] = $link_test;
                }
            }
        }
    }
    $post_links = array_unique($post_links);
    /**
     * Fires just before pinging back links found in a post.
     *
     * @since 2.0.0
     *
     * @param array &$post_links An array of post links to be checked, passed by reference.
     * @param array &$pung       Whether a link has already been pinged, passed by reference.
     * @param int   $post_ID     The post ID.
     */
    do_action_ref_array('pre_ping', array(&$post_links, &$pung, $post_ID));
    foreach ((array) $post_links as $pagelinkedto) {
        $pingback_server_url = discover_pingback_server_uri($pagelinkedto);
        if ($pingback_server_url) {
            @set_time_limit(60);
            // Now, the RPC call
            $pagelinkedfrom = get_permalink($post_ID);
            // using a timeout of 3 seconds should be enough to cover slow servers
            $client = new WP_HTTP_IXR_Client($pingback_server_url);
            $client->timeout = 3;
            /**
             * Filter the user agent sent when pinging-back a URL.
             *
             * @since 2.9.0
             *
             * @param string $concat_useragent    The user agent concatenated with ' -- WordPress/'
             *                                    and the WordPress version.
             * @param string $useragent           The useragent.
             * @param string $pingback_server_url The server URL being linked to.
             * @param string $pagelinkedto        URL of page linked to.
             * @param string $pagelinkedfrom      URL of page linked from.
             */
            $client->useragent = apply_filters('pingback_useragent', $client->useragent . ' -- WordPress/' . $wp_version, $client->useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom);
            // when set to true, this outputs debug messages by itself
            $client->debug = false;
            if ($client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto) || isset($client->error->code) && 48 == $client->error->code) {
                // Already registered
                add_ping($post_ID, $pagelinkedto);
            }
        }
    }
}

WordPress Version: 3.8

/**
 * Pings back the links found in a post.
 *
 * @since 0.71
 * @uses $wp_version
 * @uses IXR_Client
 *
 * @param string $content Post content to check for links.
 * @param int $post_ID Post ID.
 */
function pingback($content, $post_ID)
{
    global $wp_version;
    include_once ABSPATH . WPINC . '/class-IXR.php';
    include_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';
    // original code by Mort (http://mort.mine.nu:8080)
    $post_links = array();
    $pung = get_pung($post_ID);
    // Step 1
    // Parsing the post, external links (if any) are stored in the $post_links array
    $post_links_temp = wp_extract_urls($content);
    // Step 2.
    // Walking thru the links array
    // first we get rid of links pointing to sites, not to specific files
    // Example:
    // http://dummy-weblog.org
    // http://dummy-weblog.org/
    // http://dummy-weblog.org/post.php
    // We don't wanna ping first and second types, even if they have a valid <link/>
    foreach ((array) $post_links_temp as $link_test) {
        if (!in_array($link_test, $pung) && url_to_postid($link_test) != $post_ID && !is_local_attachment($link_test)) {
            // Also, let's never ping local attachments.
            if ($test = @parse_url($link_test)) {
                if (isset($test['query'])) {
                    $post_links[] = $link_test;
                } elseif (isset($test['path']) && $test['path'] != '/' && $test['path'] != '') {
                    $post_links[] = $link_test;
                }
            }
        }
    }
    $post_links = array_unique($post_links);
    /**
     * Fires just before pinging back links found in a post.
     *
     * @since 2.0.0
     *
     * @param array &$post_links An array of post links to be checked, passed by reference.
     * @param array &$pung       Whether a link has already been pinged, passed by reference.
     * @param int   $post_ID     The post ID.
     */
    do_action_ref_array('pre_ping', array(&$post_links, &$pung, $post_ID));
    foreach ((array) $post_links as $pagelinkedto) {
        $pingback_server_url = discover_pingback_server_uri($pagelinkedto);
        if ($pingback_server_url) {
            @set_time_limit(60);
            // Now, the RPC call
            $pagelinkedfrom = get_permalink($post_ID);
            // using a timeout of 3 seconds should be enough to cover slow servers
            $client = new WP_HTTP_IXR_Client($pingback_server_url);
            $client->timeout = 3;
            /**
             * Filter the user agent sent when pinging-back a URL.
             *
             * @since 2.9.0
             *
             * @param string $concat_useragent    The user agent concatenated with ' -- WordPress/'
             *                                    and the WordPress version.
             * @param string $useragent           The useragent.
             * @param string $pingback_server_url The server URL being linked to.
             * @param string $pagelinkedto        URL of page linked to.
             * @param string $pagelinkedfrom      URL of page linked from.
             */
            $client->useragent = apply_filters('pingback_useragent', $client->useragent . ' -- WordPress/' . $wp_version, $client->useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom);
            // when set to true, this outputs debug messages by itself
            $client->debug = false;
            if ($client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto) || isset($client->error->code) && 48 == $client->error->code) {
                // Already registered
                add_ping($post_ID, $pagelinkedto);
            }
        }
    }
}

WordPress Version: 3.7

/**
 * Pings back the links found in a post.
 *
 * @since 0.71
 * @uses $wp_version
 * @uses IXR_Client
 *
 * @param string $content Post content to check for links.
 * @param int $post_ID Post ID.
 */
function pingback($content, $post_ID)
{
    global $wp_version;
    include_once ABSPATH . WPINC . '/class-IXR.php';
    include_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php';
    // original code by Mort (http://mort.mine.nu:8080)
    $post_links = array();
    $pung = get_pung($post_ID);
    // Step 1
    // Parsing the post, external links (if any) are stored in the $post_links array
    $post_links_temp = wp_extract_urls($content);
    // Step 2.
    // Walking thru the links array
    // first we get rid of links pointing to sites, not to specific files
    // Example:
    // http://dummy-weblog.org
    // http://dummy-weblog.org/
    // http://dummy-weblog.org/post.php
    // We don't wanna ping first and second types, even if they have a valid <link/>
    foreach ((array) $post_links_temp as $link_test) {
        if (!in_array($link_test, $pung) && url_to_postid($link_test) != $post_ID && !is_local_attachment($link_test)) {
            // Also, let's never ping local attachments.
            if ($test = @parse_url($link_test)) {
                if (isset($test['query'])) {
                    $post_links[] = $link_test;
                } elseif (isset($test['path']) && $test['path'] != '/' && $test['path'] != '') {
                    $post_links[] = $link_test;
                }
            }
        }
    }
    $post_links = array_unique($post_links);
    do_action_ref_array('pre_ping', array(&$post_links, &$pung, $post_ID));
    foreach ((array) $post_links as $pagelinkedto) {
        $pingback_server_url = discover_pingback_server_uri($pagelinkedto);
        if ($pingback_server_url) {
            @set_time_limit(60);
            // Now, the RPC call
            $pagelinkedfrom = get_permalink($post_ID);
            // using a timeout of 3 seconds should be enough to cover slow servers
            $client = new WP_HTTP_IXR_Client($pingback_server_url);
            $client->timeout = 3;
            $client->useragent = apply_filters('pingback_useragent', $client->useragent . ' -- WordPress/' . $wp_version, $client->useragent, $pingback_server_url, $pagelinkedto, $pagelinkedfrom);
            // when set to true, this outputs debug messages by itself
            $client->debug = false;
            if ($client->query('pingback.ping', $pagelinkedfrom, $pagelinkedto) || isset($client->error->code) && 48 == $client->error->code) {
                // Already registered
                add_ping($post_ID, $pagelinkedto);
            }
        }
    }
}