Support » Plugins » [hack:] discover_pingback_server_uri() vs. large files

  • The following easy hack will stop WordPress from downloading external references which are not XML (like my script does with my 160 megs ISO images):

    Open wp-includes/comment-functions.php, search for // Try to connect to the server at $host, and add before:

    ////// SNIP ////////////
    // Try to connect to the server at $host
    $fp = @fsockopen($host, $port, $errno, $errstr, 2);
    if (!$fp) {
    // Couldn’t open a connection to $host;
    return false;

    // Send the HEAD request
    $request = “HEAD $path HTTP/1.0rnHost: $hostrnUser-Agent: WordPress-Verifier/$wp_version rnrn”;
    // ob_end_flush();
    fputs($fp, $request);

    // Let’s check for an X-Pingback header first
    while (!feof($fp)) {
    $line = fgets($fp, 512);
    if (trim($line) == ”) {
    $headers .= trim($line).”n”;
    $x_pingback_header_offset = strpos(strtolower($headers), $x_pingback_str);
    if ($x_pingback_header_offset) {
    // We got it!
    preg_match(‘#x-pingback: (.+)#is’, $headers, $matches);
    $pingback_server_url = trim($matches[1]);
    return $pingback_server_url;
    if(strpos(strtolower($headers), ‘content-type: ‘)) {
    preg_match(‘#content-type: (.+)#is’, $headers, $matches);
    $content_type = trim($matches[1]);

    if (preg_match(‘#(image|audio|video|model)/#is’, $content_type)) {
    // Not an (x)html, sgml, or xml page, no use going further
    return false;

    // Re-open the line
    ////// SNAP ////////////

    You may want to remove the checking code for a X-Pingback in the same loop some lines below because it is already done. 🙂

    Note: This hack is in ALPHA state and not tested enougth. It will work only in theory. So please feel free to test it. 🙂


  • The topic ‘[hack:] discover_pingback_server_uri() vs. large files’ is closed to new replies.