Skip to content

Instantly share code, notes, and snippets.

@Alimir
Created June 20, 2022 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alimir/c05e35c968d27c62627b826cd0b4a279 to your computer and use it in GitHub Desktop.
Save Alimir/c05e35c968d27c62627b826cd0b4a279 to your computer and use it in GitHub Desktop.
Add wp ulike block in the card builder (wpgridbuilder plugin)
<?php
function register_wp_ulike_block( $blocks ) {
$blocks['custom_field_image_block'] = [
'name' => 'WP ULike Button',
'render_callback' => 'render_wp_ulike_block',
];
return $blocks;
}
add_filter( 'wp_grid_builder/blocks', 'register_wp_ulike_block' );
function render_wp_ulike_block() {
// Object can be a post, term or user.
$object = wpgb_get_object();
// If this is not a post (you may change this condition for user or term).
if ( ! isset( $object->post_type ) ) {
return;
}
echo wp_ulike( 'put', array(
'id' => $object->ID
) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment