Ján Bočínec
Entrepreneur and inglourious basterd
Ján Bočínec, Webikon
@johnnypea
<?php
/*
Template Name: Full-width layout
Template Post Type: post, page, product
*/
// … your code here
get_theme_file_uri()
//{$type}_template_hierarchy
add_filter( 'category_template_hierarchy', function( array $templates ) {
$format = get_term_meta( get_queried_object_id(), 'format', true );
if ( $format ) {
$new = "category-format-{$format}.php";
$pos = array_search( 'category.php', $templates );
array_splice( $templates, $pos, 0, $new );
}
return $templates;
} );
//An option in the dropdown
add_filter( 'bulk_actions-edit-post', 'register_my_bulk_actions' );
function register_my_bulk_actions($bulk_actions) {
$bulk_actions['email_to_eric'] = __( 'Email to Eric', 'email_to_eric');
return $bulk_actions;
}
//Handling the form submission
add_filter( 'handle_bulk_actions-edit-post', 'my_bulk_action_handler', 10, 3 );
function my_bulk_action_handler( $redirect_to, $doaction, $post_ids ) {
if ( $doaction !== 'email_to_eric' ) {
return $redirect_to;
}
foreach ( $post_ids as $post_id ) {
// Perform action for each post.
}
$redirect_to = add_query_arg( 'bulk_emailed_posts', count( $post_ids ), $redirect_to );
return $redirect_to;
}
(register_meta)
register_setting( 'general', 'blog_visibility', array(
'show_in_rest' => array(
'schema' => array(
'enum' => array( 'private', 'public' )
),
),
'type' => 'string',
'default' => 'public',
))
add_action('after_setup_theme', function () {
add_theme_support('starter-content', [
'posts' => [
'home',
'about' => [
'post_content' => file_get_contents(
get_template_directory_uri() . 'content/pages/about.html'
)
],
'contact',
'blog'
]
]);
});
https://developer.wordpress.org/rest-api/
(JavaScript Object Notation)
By Ján Bočínec