Motors WordPress plugin add car data to Post to Google My Business plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
/** | |
* @return array Variable => Replacement | |
*/ | |
public function variables(){ | |
$years = get_the_terms($this->listing_id, 'ca-year'); | |
$year = is_array($years) ? $years[0]->name : ''; | |
return [ | |
'%motors_price%' => get_post_meta($this->listing_id, 'price', true), | |
'%motors_sale_price%' => get_post_meta($this->listing_id, 'sale_price', true), | |
'%motors_seller_notes%' => get_post_meta($this->listing_id, 'stm_seller_notes', true), | |
'%motors_car_year%' => $year | |
]; | |
} | |
} | |
} | |
function pgmb_motors_variables($decorators, $parent_post_id, $location){ | |
if('listings' !== get_post_type($parent_post_id) || !class_exists('PGMB_Motors_Variables')){ | |
return $decorators; | |
} | |
$decorators[] = new PGMB_Motors_Variables($parent_post_id); | |
return $decorators; | |
} | |
add_filter('mbp_placeholder_decorators', 'pgmb_motors_variables', 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment