我有一些自定义后期元生成,并准备添加到帖子的元.我知道如何执行此操作,但在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