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

前端之家收集整理的这篇文章主要介绍了php – 如何在WordPress中调试save_post操作?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一些自定义后期元生成,并准备添加到帖子的元.我知道如何执行此操作,但在POST数据发送后,save_post会导致重定向.这意味着我被重定向到仪表板,并且无法访问我的POST数据 – 因此我无法轻松调试.

目前使用的东西如下:

  1. add_action('save_post','something_process');
  2. function something_process() {
  3. if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
  4. print_r($_POST);
  5. }

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

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

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

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

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

  1. @ini_set('display_errors',0);
  2. define( 'WP_DEBUG',true ); // Turn debugging ON
  3. define( 'WP_DEBUG_DISPLAY',false ); // Turn forced display OFF
  4. define( 'WP_DEBUG_LOG',true ); // Turn logging to wp-content/debug.log ON
  5. define( 'WP_POST_REVISIONS',false); // Disables revision functionality

猜你在找的PHP相关文章