Skip to content

Instantly share code, notes, and snippets.

Avatar

Koen koen12344

View GitHub Profile
@koen12344
koen12344 / pgmb_business_selector_full_height.php
Created Sep 22, 2022
Force the business selector to be 100% height
View pgmb_business_selector_full_height.php
<?php
add_action('admin_head', 'pgmb_increase_height');
function pgmb_increase_height() {
echo '<style>
.mbp-business-selector {
height:100% !important;
}
</style>';
}
View pgmb_calendarize_it_variables.php
<?php
function pgmb_add_calendarize_it_fields( $variables, $parent_post_id ) {
$event_start_date = get_post_meta( $parent_post_id, 'fc_start_datetime', true );
$event_end_date = get_post_meta( $parent_post_id, 'fc_end_datetime', true );
if ( ! $event_start_date || !$event_end_date ) {
return $variables;
}
$start_datetime = new \DateTime($event_start_date);
@koen12344
koen12344 / bulk-update-auto-post-template.php
Created Jul 15, 2022
Snippet to bulk change the auto-post template for a selection of posts
View bulk-update-auto-post-template.php
<?php
function pgmb_batch_update_templates(){
$product_ids = get_posts([
'post_type' => 'product',
'fields' => 'ids',
'numberposts' => '-1',
]);
foreach($product_ids as $product_id){
$product = wc_get_product($product_id);
View pgmb_event_date.php
<?php
function pgmb_add_event_fields( $variables, $parent_post_id ) {
$event_start_date = get_post_meta( $parent_post_id, 'WooCommerceEventsDateTimestamp', true );
$event_end_date = get_post_meta( $parent_post_id, 'WooCommerceEventsEndDateTimestamp', true );
if ( ! $event_start_date || !$event_end_date ) {
return $variables;
}
$start_datetime = new \DateTime();
@koen12344
koen12344 / hide_user_locations.php
Last active Jun 29, 2022
Hide specific locations from users in Post to GMB plugin
View hide_user_locations.php
<?php
/*
It is possible to limit the location list to specific locations (or a single location) using the mbp_business_selector_locations filter.
We can use it to filter out the locations that don't belong to the website or user.
The code loops through all locations and checks whether the location is within an array of allowed locations. If not, it is removed (hidden).
You can find the location ID by right clicking the location in the location selector, and pressing "Inspect Element": https://i.imgur.com/gWd5M9x.png
@koen12344
koen12344 / pgbm_woocommerce_variation_price_variables.php
Created Jun 8, 2022
Add price variables for WooCommerce variations
View pgbm_woocommerce_variation_price_variables.php
<?php
//Remove the <?php opening tag to get rid of the red exclamation mark in the Code Snippets plugin
if(interface_exists('\PGMB\Placeholders\VariableInterface')){
class PGMB_WC_Variation_Prices implements \PGMB\Placeholders\VariableInterface{
private $product;
public function __construct($parent_id) {
@koen12344
koen12344 / pgmb_content_img.php
Created May 17, 2022
Fetch image from html content
View pgmb_content_img.php
<?php
function pgmb_insert_content_img($localPost, $post_id, $is_autopost, $location){
if(
!class_exists('DOMDocument') ||
!class_exists('\PGMB\Google\MediaItem')
){ return $localPost; }
$form_fields = get_post_meta($post_id, 'mbp_form_fields', true);
View acf_custom_fields.php
<?php
function pgmb_add_acf_fields($variables, $parent_post_id){
//Check if the ACF get_fields function is actually available
if(!function_exists('get_fields')){ return $variables; }
$fields = get_fields($parent_post_id);
if($fields){
foreach($fields as $name => $value){
$variables["%acf_{$name}%"] = $value;
View pgmb_gravity_forms_advanced_post_creation.php
<?php
/**
Snippet to create GMB posts from the Advanced Post Creation plugin of Gravity Forms
**/
function pgmb_gf_create_post_advancedpostcreation($post_id, $feed, $entry, $form){
if(!class_exists('\PGMB\PostTypes\SubPost') || !class_exists('\PGMB\FormFields') || !class_exists('\PGMB\Vendor\WeDevsSettingsAPI')){
@koen12344
koen12344 / snippet_motors_car_data.php
Last active Mar 3, 2022
Motors WordPress plugin add car data to Post to Google My Business plugin
View snippet_motors_car_data.php
<?php
if(interface_exists('\PGMB\Placeholders\VariableInterface')){
class PGMB_Motors_Variables implements \PGMB\Placeholders\VariableInterface {
private $listing_id;
public function __construct($listing_id){
$this->listing_id = $listing_id;
}
/**