Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Adds a multitude of data variables from the WP Download Manager plugin to the Post to Google My Business plugin
<?php
/*
This code snippet adds various info about downloads from the WP Download Manager plugin to Post to Google My Business
%wpdm_access%
%wpdm_download_count%
%wpdm_view_count%
%wpdm_version%
%wpdm_link_label%
%wpdm_quota%
%wpdm_download_limit_per_user%
%wpdm_package_size%
%wpdm_package_size_b%
%wpdm_individual_file_download%
%wpdm_template%
%wpdm_page_template%
%wpdm_password_lock%
%wpdm_password%
%wpdm_password_usage_limit%
%wpdm_email_lock%
%wpdm_tweet_lock%
%wpdm_facebook_lock%
%wpdm_googleplus_lock%
%wpdm_files%
%wpdm_fileinfo%
%wpdm_package_dir%
%wpdm_publish_date%
%wpdm_expire_date%
%wpdm_icon%
%wpdm_base_price%
%wpdm_sales_price%
%wpdm_variation%
*/
class PGMB_WP_Download_Manager_Variables implements \PGMB\Placeholders\VariableInterface {
private $download_id;
public function __construct($download_id){
$this->download_id = $download_id;
}
/**
* @return array Variable => Replacement
*/
public function variables(){
if(!function_exists('wpdm_get_package')){ return []; }
$package_details = wpdm_get_package($this->download_id);
$variables = [];
foreach($package_details as $key => $data){
$variables["%wpdm_{$key}%"] = $data;
}
return $variables;
}
}
function pgmb_wpdm_variables($decorators, $parent_post_id, $location){
$decorators[] = new PGMB_WP_Download_Manager_Variables($parent_post_id);
return $decorators;
}
add_filter('mbp_placeholder_decorators', 'pgmb_wpdm_variables', 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment