ピンバック/トラックバックを完全にオフにする方法はありますか?


13

の下にトラックバック/ピンバックをオフにするオプションがありますSettings > Discussion

しかし、X-PingbackWordPressが送信するヘッダーを削除し、trackbackエンドポイントを完全に削除したいと思います。

これを行う方法はありますか?

回答:


12
<?php
/*
Plugin Name: [RPC] XMLRPCless Blog
Plugin URI: http://earnestodev.com/
Description: Disable XMLRPC advertising/functionality blog-wide.
Version: 0.0.7
Author: EarnestoDev
Author URI: http://earnestodev.com/
*/
// Disable X-Pingback HTTP Header.
add_filter('wp_headers', function($headers, $wp_query){
    if(isset($headers['X-Pingback'])){
        // Drop X-Pingback
        unset($headers['X-Pingback']);
    }
    return $headers;
}, 11, 2);
// Disable XMLRPC by hijacking and blocking the option.
add_filter('pre_option_enable_xmlrpc', function($state){
    return '0'; // return $state; // To leave XMLRPC intact and drop just Pingback
});
// Remove rsd_link from filters (<link rel="EditURI" />).
add_action('wp', function(){
    remove_action('wp_head', 'rsd_link');
}, 9);
// Hijack pingback_url for get_bloginfo (<link rel="pingback" />).
add_filter('bloginfo_url', function($output, $property){
    return ($property == 'pingback_url') ? null : $output;
}, 11, 2);
// Just disable pingback.ping functionality while leaving XMLRPC intact?
add_action('xmlrpc_call', function($method){
    if($method != 'pingback.ping') return;
    wp_die(
        'Pingback functionality is disabled on this Blog.',
        'Pingback Disabled!',
        array('response' => 403)
    );
});
?>

/ wp-content / pluginsまたは/ wp-content / mu-plugins (自動アクティベーション用)のプラグインにこれ​​を使用します。またはfunctions.php

おもしろいのは、WordPress Remote Publishing Libraryを販売し、XMLRPCを無効にするコードを提供したことです:) 評判が悪い。


return '0'期待どおりに動作しません。文字列'0'はtrueを返します。 add_filter( 'pre_option_enable_xmlrpc', '__return_false' );
chrisguitarguy

1
var_dump((bool) '0');
EarnestoDev

get_optionとpre_option_ *ハイジャックの仕組みをご覧ください。__return_false ...の場合、無視され、通常どおり処理が再開されます。何も返さないでください=== false。コードを参照してください。
EarnestoDev

3
助けてくれてありがとう。書き換えルールを無効にするためにもう1つ追加しました:gist.github.com/1309433
chrisguitarguy

5

@EarnestoDevにはすばらしい答えがありましたが、最近のxml-rcpの悪用以来、少し時代遅れになっています

私はそれへのすべての可能なアクセスをブロックすると思う更新されたバージョンを作りました。ただし、XML-RPCのpingback / trackback機能を利用するプラグインがいくつかあり、それらを使用している場合は問題が発生する可能性があることに注意してください。

  • WordPressモバイルアプリ
  • JetPack LibSyn(ポッドキャスト用)
  • BuddyPressの一部
  • Windows Liveライター
  • IFTTT
  • いくつかのギャラリープラグイン

以下が更新されたバージョンです。ダウンロードするには、プラグインファイルにコピーするか、mu-pluginsにドロップインするか、githubにダウンロードします。

<?php
/*
Plugin Name:        BYE BYE Pingback
Plugin URI:         https://github.com/Wordpress-Development/bye-bye-pingback/
Description:        Banishment of wordpress pingback
Version:            1.0.0
Author:             bryanwillis
Author URI:         https://github.com/bryanwillis/
*/

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
    die;
}

/**
 * Htaccess directive block xmlrcp for extra security.
 * Here are some rewrite examples:
 *   404 - RewriteRule xmlrpc\.php$ - [R=404,L]
 *   301 - RewriteRule ^xmlrpc\.php$ index.php [R=301]
 * If you want custom 404 make sure your server is finding it by also adding this 'ErrorDocument 404 /index.php?error=404' or 'ErrorDocument 404 /wordpress/index.php?error=404' for sites in subdirectory.
 */ 
add_filter('mod_rewrite_rules', 'noxmlrpc_mod_rewrite_rules'); // should we put this inside wp_loaded or activation hook
function noxmlrpc_mod_rewrite_rules($rules) {
  $insert = "RewriteRule xmlrpc\.php$ - [F,L]";
  $rules = preg_replace('!RewriteRule!', "$insert\n\nRewriteRule", $rules, 1);
  return $rules;
}

register_activation_hook(__FILE__, 'noxmlrpc_htaccess_activate');
function noxmlrpc_htaccess_activate() {
  flush_rewrite_rules(true);
}

register_deactivation_hook(__FILE__, 'noxmlrpc_htaccess_deactivate');
function noxmlrpc_htaccess_deactivate() {
  remove_filter('mod_rewrite_rules', 'noxmlrpc_mod_rewrite_rules');
  flush_rewrite_rules(true);
}


// Remove rsd_link from filters- link rel="EditURI"
add_action('wp', function(){
    remove_action('wp_head', 'rsd_link');
}, 9);


// Remove pingback from head (link rel="pingback")
if (!is_admin()) {      
    function link_rel_buffer_callback($buffer) {
        $buffer = preg_replace('/(<link.*?rel=("|\')pingback("|\').*?href=("|\')(.*?)("|\')(.*?)?\/?>|<link.*?href=("|\')(.*?)("|\').*?rel=("|\')pingback("|\')(.*?)?\/?>)/i', '', $buffer);
                return $buffer;
    }
    function link_rel_buffer_start() {
        ob_start("link_rel_buffer_callback");
    }
    function link_rel_buffer_end() {
        ob_flush();
    }
    add_action('template_redirect', 'link_rel_buffer_start', -1);
    add_action('get_header', 'link_rel_buffer_start');
    add_action('wp_head', 'link_rel_buffer_end', 999);
}


// Return pingback_url empty (<link rel="pingback" href>).
add_filter('bloginfo_url', function($output, $property){
    return ($property == 'pingback_url') ? null : $output;
}, 11, 2);


// Disable xmlrcp/pingback
add_filter( 'xmlrpc_enabled', '__return_false' );
add_filter( 'pre_update_option_enable_xmlrpc', '__return_false' );
add_filter( 'pre_option_enable_xmlrpc', '__return_zero' );

// Disable trackbacks
add_filter( 'rewrite_rules_array', function( $rules ) {
    foreach( $rules as $rule => $rewrite ) {
        if( preg_match( '/trackback\/\?\$$/i', $rule ) ) {
            unset( $rules[$rule] );
        }
    }
    return $rules;
});


// Disable X-Pingback HTTP Header.
add_filter('wp_headers', function($headers, $wp_query){
    if(isset($headers['X-Pingback'])){
        unset($headers['X-Pingback']);
    }
    return $headers;
}, 11, 2);


add_filter( 'xmlrpc_methods', function($methods){
    unset( $methods['pingback.ping'] );
    unset( $methods['pingback.extensions.getPingbacks'] );
    unset( $methods['wp.getUsersBlogs'] ); // Block brute force discovery of existing users
    unset( $methods['system.multicall'] );
    unset( $methods['system.listMethods'] );
    unset( $methods['system.getCapabilities'] );
    return $methods;
});


// Just disable pingback.ping functionality while leaving XMLRPC intact?
add_action('xmlrpc_call', function($method){
    if($method != 'pingback.ping') return;
    wp_die(
        'This site does not have pingback.',
        'Pingback not Enabled!',
        array('response' => 403)
    );
});


また、既存のPingbackをすべて閉じる場合は、次の手順を実行します。

1)phpmyadminを開き、SQLセクションに移動します。

sql

2)次を入力します。

UPDATE wp_posts SET ping_status="closed";

3)既存のすべてのピンバックを閉じる必要があります

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.