Skip to content

Instantly share code, notes, and snippets.

@Kuzmanov
Kuzmanov / functions.php
Created December 1, 2016 13:40
Register custom bulk action
<?php
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;
}
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' ) {
@Kuzmanov
Kuzmanov / functions.php
Last active December 1, 2016 13:41
Add video header support in WordPress 4.7
<?php
add_theme_support( 'custom-header', array(
'video' => true,
) );
?>
@Kuzmanov
Kuzmanov / filter-get-all-posts-json.php
Created May 12, 2016 07:57
Modifying WP API JSON response
<?php
function get_all_posts( $data, $post, $context ) {
return [
'id' => $data->data['id'],
'title' => $data->data['title']['rendered'],
'link' => $data->data['link'],
];
}
add_filter( 'rest_prepare_post', 'get_all_posts', 10, 3 );
?>
@Kuzmanov
Kuzmanov / remove-featured-image-id-json.php
Last active May 12, 2016 07:58
Remove Featured Image ID from the WP API JSON response
@Kuzmanov
Kuzmanov / include-post-featured-image-in-json.php
Last active May 12, 2016 07:58
Include post's featured image URL in the WP API JSON response
<?php
function post_fetured_image_json( $data, $post, $context ) {
$featured_image_id = $data->data['featured_media']; // get featured image id
$featured_image_url = wp_get_attachment_image_src( $featured_image_id, 'original' ); // get url of the original size
if( $featured_image_url ) {
$data->data['featured_image_url'] = $featured_image_url[0];
}
return $data;
@Kuzmanov
Kuzmanov / wp-api-add-custom-meta-field.php
Last active May 12, 2016 07:58
Including custom meta field in the WP API JSON response
<?php
function filter_post_json( $data, $post, $context ) {
$source = get_post_meta( $post->ID, '_source', true ); // get the value from the meta field
if( $source ) { // include it in the response if not empty
$data->data['custom_meta'] = array( 'source' => $source );
}
return $data;
}
@Kuzmanov
Kuzmanov / adding-login-logout-link-specific-menu.php
Created November 26, 2015 14:12
Extending the WordPress Nav Menu
@Kuzmanov
Kuzmanov / adding-login-logout-link.php
Created November 26, 2015 14:06
Extending the WordPress Nav Menu