php – 如何在WordPress中调试save_post操作?

我有一些自定义后期元生成,并准备添加到帖子的元.我知道如何执行此操作,但在POST数据发送后,save_post会导致重定向.这意味着我被重定向到仪表板,并且无法访问我的POST数据 – 因此我无法轻松调试.

目前使用的东西如下:

add_action('save_post','something_process');
function something_process() {
   if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
   print_r($_POST);
}

有没有办法轻松调试这个?

对我来说,最好的方法是使用一个函数将值记录到wp-content / debug.log,从 http://fuelyourcoding.com/simple-debugging-with-wordpress提取
if(!function_exists('log_it')){
 function log_it( $message ) {
   if( WP_DEBUG === true ){
     if( is_array( $message ) || is_object( $message ) ){
       error_log( print_r( $message,true ) );
     } else {
       error_log( $message );
     }
   }
 }
}

然后在save_post钩子中使用这样的功能

log_it($_POST);
log_it('The value for ' . $custom_field . ' is ' . $_POST[$custom_field]);

确保wp-content / debug.log是可写的,并且您在wp-config.php中启用了调试:

@ini_set('display_errors',0);
define( 'WP_DEBUG',true );  // Turn debugging ON
define( 'WP_DEBUG_disPLAY',false ); // Turn forced display OFF
define( 'WP_DEBUG_LOG',true );  // Turn logging to wp-content/debug.log ON
define( 'WP_POST_REVISIONS',false); // disables revision functionality

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...