// Enable Debug logging to the /wp-content/debug.log file
define( 'WP_DEBUG_LOG', true );
function track_redirects_in_template() {
if ( did_action( 'wp_redirect' ) ) {
error_log( 'Redirect action triggered in template.' );
} else {
error_log( 'No redirect detected in template.' );
}
}
add_action( 'template_redirect', 'track_redirects_in_template' );
function check_is_singular_essay() {
if ( is_singular( 'my-cpt' ) ) {
error_log( 'My CPT post is being accessed.' );
global $post;
error_log( 'We are on: ' . $post->ID );
}
}
add_action( 'wp_head', 'check_is_singular_essay' );
error_log( 'Message | post type: ' . get_post_type() . ' | ' . get_the_title() );
global $wp_query;
error_log( 'Query Variables: ' . print_r( $wp_query->query_vars, true ) );
add_action( 'init', function() {
global $wp_rewrite;
error_log( print_r( $wp_rewrite->wp_rewrite_rules(), true ) );
} );
add_filter( 'request', function ( $query_vars ) {
error_log( 'Request Vars During Parse: ' . print_r( $query_vars, true ) );
return $query_vars;
} );
add_action( 'init', function () {
$query = new WP_Query([
'post_type' => 'my-cpt',
'posts_per_page' => -1,
]);
if ( $query->have_posts() ) {
error_log( 'CPT found: ' . $query->posts[0]->post_title );
} else {
error_log( 'No cpt posts found in query.' );
}
} );
add_action( 'init', function () {
$query = new WP_Query([
'post_type' => 'my-cpt',
'posts_per_page' => -1,
]);
if ( $query->have_posts() ) {
error_log( 'CPT found: ' . $query->posts[0]->post_title );
} else {
error_log( 'No cpt posts found in query.' );
}
} );
add_action( 'init', function () {
error_log( 'Registered Post Types: ' . print_r( get_post_types(), true ) );
} );
add_action( 'template_redirect', function() {
error_log( 'Current User Caps: ' . print_r( wp_get_current_user()->allcaps, true ) );
error_log( 'Current User Role: ' . implode( ', ', wp_get_current_user()->roles ) );
error_log(print_r(get_role('subscriber')->capabilities, true));
}
Författare: Erik
Erik har jobbat med webb professionellt sedan 2008. Från 2005 till 2008 studerades webb på ING/JTH och dessförinnan skapades webb på all fritid. Första sajten byggdes någon gång mellan 1996-1998.
Visa alla inlägg av Erik