I’ve accomplished this many instances earlier than, nevertheless it stopped working and I am unable to work out why and have not discovered a solution to re-accomplish the identical job.
GOAL: intercept submitted values from $_POST/$_REQUEST earlier than saving/updating publish in DB. Particularly for processing each default WP meta/tax in addition to customized meta/tax.
QUESTION: How do I get the $_POST/$_REQUEST knowledge for ALL fields when a publish is created or up to date in WordPress. Every part that USED TO WORK not does. I would like $_POST & $_REQUEST knowledge in order that I can course of front-end kind submissions, admin panel submissions, and fast edits.
HOOKS TRIED:
Hooks ‘pre_post_update’ SHOULD work, however at all times returns empty array, or the generic a:1:{s:7:"_locale";s:4:"consumer";}
which can be a part of the wp-admin URL question string.
Hook ‘post_updated’ is after submission and does give previous/new values, however just for default WP meta/tax, not customized meta/tax, and it is after processing so no $_POST or $_REQUEST knowledge.
Hook ‘save_post’ is after saving, so not appropriate for the duty.
DUMP VARS:
For each single one among these hooks, I am saving a dump for every of those:
$post_id
$post_data
$_POST
$_GET
$_REQUEST
'php://enter'
SAMPLE CODE TRIED:
pre_post_update hook:
perform PPU_intercept_post_save($post_id, $post_data){
// handed vars first
file_put_contents('vardump.txt', serialize($post_id));
file_put_contents('vardump.txt', PHP_EOL.serialize($post_data), FILE_APPEND);
// relaxation knowledge second
$json_data = json_decode(file_get_contents('php://enter'), true);
file_put_contents('vardump.txt', PHP_EOL.serialize($json_data), FILE_APPEND);
// server vars final
file_put_contents('vardump.txt', PHP_EOL.serialize($_POST), FILE_APPEND);
file_put_contents('vardump.txt', PHP_EOL.serialize($_GET), FILE_APPEND);
file_put_contents('vardump.txt', PHP_EOL.serialize($_REQUEST), FILE_APPEND);
}
add_action( 'pre_post_update', 'PPU_intercept_post_save', 10, 2 );
end result:
// post_id
i:118;
// post_data
a:21:{s:11:"post_author";s:1:"1";s:9:"post_date";s:19:"2022-06-08 15:45:49";s:13:"post_date_gmt";s:19:"2022-06-08 20:45:49";s:12:"post_content";s:821:"SENSITIVE_REMOVED";s:21:"post_content_filtered";s:0:"";s:10:"post_title";s:21:"SENSITIVE_REMOVED";s:12:"post_excerpt";s:0:"";s:11:"post_status";s:7:"publish";s:9:"post_type";s:13:"SENSITIVE_REMOVED";s:14:"comment_status";s:4:"open";s:11:"ping_status";s:6:"closed";s:13:"post_password";s:0:"";s:9:"post_name";s:21:"SENSITIVE_REMOVED";s:7:"to_ping";s:0:"";s:6:"pinged";s:0:"";s:13:"post_modified";s:19:"2022-06-11 12:45:20";s:17:"post_modified_gmt";s:19:"2022-06-11 17:45:20";s:11:"post_parent";i:0;s:10:"menu_order";i:0;s:14:"post_mime_type";s:0:"";s:4:"guid";s:59:"SENSITIVE_REMOVED&p=118";}
// relaxation knowledge
a:2:{s:2:"id";i:118;s:7:"content material";s:821:"SENSITIVE_REMOVED";}
// POST
a:0:{}
// GET
a:1:{s:7:"_locale";s:4:"consumer";}
// REQUEST
a:1:{s:7:"_locale";s:4:"consumer";}
save_post hook:
perform SP_intercept_post_save( $post_id, $post_data, $replace ) {
// handed vars first
file_put_contents('vardump.txt', serialize($post_id));
file_put_contents('vardump.txt', PHP_EOL.serialize($post_data), FILE_APPEND);
file_put_contents('vardump.txt', PHP_EOL.serialize($replace), FILE_APPEND);
// relaxation knowledge second
$json_data = json_decode(file_get_contents('php://enter'), true);
file_put_contents('vardump.txt', PHP_EOL.serialize($json_data), FILE_APPEND);
// server vars final
file_put_contents('vardump.txt', PHP_EOL.serialize($_POST), FILE_APPEND);
file_put_contents('vardump.txt', PHP_EOL.serialize($_GET), FILE_APPEND);
file_put_contents('vardump.txt', PHP_EOL.serialize($_REQUEST), FILE_APPEND);
}
add_action( 'save_post', 'SP_intercept_post_save', 10, 3 );
end result:
// post_id
i:118;
// post_data
O:7:"WP_Post":24:{s:2:"ID";i:118;s:11:"post_author";s:1:"1";s:9:"post_date";s:19:"2022-06-08 15:45:49";s:13:"post_date_gmt";s:19:"2022-06-08 20:45:49";s:12:"post_content";s:821:"SENSITIVE_REMOVED";s:10:"post_title";s:21:"SENSITIVE_REMOVED";s:12:"post_excerpt";s:0:"";s:11:"post_status";s:7:"publish";s:14:"comment_status";s:4:"open";s:11:"ping_status";s:6:"closed";s:13:"post_password";s:0:"";s:9:"post_name";s:21:"SENSITIVE_REMOVED";s:7:"to_ping";s:0:"";s:6:"pinged";s:0:"";s:13:"post_modified";s:19:"2022-06-11 13:04:34";s:17:"post_modified_gmt";s:19:"2022-06-11 18:04:34";s:21:"post_content_filtered";s:0:"";s:11:"post_parent";i:0;s:4:"guid";s:59:"SENSITIVE_REMOVED&p=118";s:10:"menu_order";i:0;s:9:"post_type";s:13:"SENSITIVE_REMOVED";s:14:"post_mime_type";s:0:"";s:13:"comment_count";s:1:"0";s:6:"filter";s:3:"uncooked";}
// replace
b:1;
// relaxation knowledge
a:2:{s:2:"id";i:118;s:7:"content material";s:821:"SENSITIVE_REMOVED";}
// POST
a:0:{}
// GET
a:1:{s:7:"_locale";s:4:"consumer";}
// REQUEST
a:1:{s:7:"_locale";s:4:"consumer";}
post_updated hook:
perform PU_intercept_post_save($post_id, $post_after, $post_before){
// handed vars first
file_put_contents('vardump.txt', serialize($post_id));
file_put_contents('vardump.txt', PHP_EOL.serialize($post_after), FILE_APPEND);
file_put_contents('vardump.txt', PHP_EOL.serialize($post_before), FILE_APPEND);
// relaxation knowledge second
$json_data = json_decode(file_get_contents('php://enter'), true);
file_put_contents('vardump.txt', PHP_EOL.serialize($json_data), FILE_APPEND);
// server vars final
file_put_contents('vardump.txt', PHP_EOL.serialize($_POST), FILE_APPEND);
file_put_contents('vardump.txt', PHP_EOL.serialize($_GET), FILE_APPEND);
file_put_contents('vardump.txt', PHP_EOL.serialize($_REQUEST), FILE_APPEND);
}
add_action( 'post_updated', 'PU_intercept_post_save', 10, 3 );
end result:
// post_id
i:118;
// post_after
O:7:"WP_Post":24:{s:2:"ID";i:118;s:11:"post_author";s:1:"1";s:9:"post_date";s:19:"2022-06-08 15:45:49";s:13:"post_date_gmt";s:19:"2022-06-08 20:45:49";s:12:"post_content";s:821:"SENSITIVE_REMOVED";s:10:"post_title";s:21:"SENSITIVE_REMOVED";s:12:"post_excerpt";s:0:"";s:11:"post_status";s:7:"publish";s:14:"comment_status";s:4:"open";s:11:"ping_status";s:6:"closed";s:13:"post_password";s:0:"";s:9:"post_name";s:21:"SENSITIVE_REMOVED";s:7:"to_ping";s:0:"";s:6:"pinged";s:0:"";s:13:"post_modified";s:19:"2022-06-11 13:14:58";s:17:"post_modified_gmt";s:19:"2022-06-11 18:14:58";s:21:"post_content_filtered";s:0:"";s:11:"post_parent";i:0;s:4:"guid";s:59:"SENSITIVE_REMOVED&p=118";s:10:"menu_order";i:0;s:9:"post_type";s:13:"SENSITIVE_REMOVED";s:14:"post_mime_type";s:0:"";s:13:"comment_count";s:1:"0";s:6:"filter";s:3:"uncooked";}
// post_before
O:7:"WP_Post":24:{s:2:"ID";i:118;s:11:"post_author";s:1:"1";s:9:"post_date";s:19:"2022-06-08 15:45:49";s:13:"post_date_gmt";s:19:"2022-06-08 20:45:49";s:12:"post_content";s:821:"SENSITIVE_REMOVED";s:10:"post_title";s:21:"SENSITIVE_REMOVED";s:12:"post_excerpt";s:0:"";s:11:"post_status";s:7:"publish";s:14:"comment_status";s:4:"open";s:11:"ping_status";s:6:"closed";s:13:"post_password";s:0:"";s:9:"post_name";s:21:"SENSITIVE_REMOVED";s:7:"to_ping";s:0:"";s:6:"pinged";s:0:"";s:13:"post_modified";s:19:"2022-06-11 13:04:34";s:17:"post_modified_gmt";s:19:"2022-06-11 18:04:34";s:21:"post_content_filtered";s:0:"";s:11:"post_parent";i:0;s:4:"guid";s:59:"SENSITIVE_REMOVED&p=118";s:10:"menu_order";i:0;s:9:"post_type";s:13:"SENSITIVE_REMOVED";s:14:"post_mime_type";s:0:"";s:13:"comment_count";s:1:"0";s:6:"filter";s:3:"uncooked";}
// relaxation knowledge
a:2:{s:2:"id";i:118;s:7:"content material";s:821:"SENSITIVE_REMOVED";}
// POST
a:0:{}
// GET
a:1:{s:7:"_locale";s:4:"consumer";}
// REQUEST
a:1:{s:7:"_locale";s:4:"consumer";}