微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

原文地址:https://www.jb51.cc/php/139558.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐