$coupons = get_posts($args);
foreach ($coupons as $coupon) {
$custom = get_post_custom($coupon->ID);
+ if ($custom['glm_coupons_member'][0]) {
+ $member_data = $this->_getMemberData($custom['glm_coupons_member'][0]);
+ }
$coupon->end = false;
$coupon->glm_coupons_startdate = $custom['glm_coupons_startdate'][0];
$coupon->glm_coupons_enddate = $custom['glm_coupons_enddate'][0];
$coupon->glm_coupons_expdate = $custom['glm_coupons_expdate'][0];
- $coupon->glm_coupons_url = $custom['glm_coupons_url'][0];
+ $coupon->glm_coupons_url = preg_replace('/http:\/\//i', '', $coupon->glm_coupons_url);
+ $coupon->glm_coupons_member = ($member_data['member_name']) ? $member_data['member_name'] : '';
+ $coupon->glm_coupons_address = ($member_data['address']) ? $member_data['address'] : '';
$coupon->glm_coupons_thumb = get_the_post_thumbnail($coupon->ID, 'thumbnail', array('class' => 'aligncenter'));
$post_categories = wp_get_object_terms(
$coupon->ID,
return;
}
+ private function _getMemberData($id)
+ {
+ global $wpdb;
+ $data = array();
+ if (!filter_var($id, FILTER_VALIDATE_INT)) {
+ return false;
+ }
+ if ( !defined( 'GLM_MEMBERS_PLUGIN_DB_PREFIX' ) ) {
+ return false;
+ } else {
+ $sql = "
+ SELECT m.member_name, addr1,c.name as city,state,zip
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info m
+ LEFT OUTER JOIN " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "cities c ON (c.id = m.city)
+ WHERE m.id = {$id}";
+ $results = $wpdb->get_results($sql, ARRAY_A);
+ if ($results[0]) {
+ $address = array();
+ if ($results[0]['addr1']) {
+ $address[] = $results[0]['addr1'];
+ }
+ if ($results[0]['city']) {
+ $address[] = $results[0]['city'];
+ }
+ if ($results[0]['state']) {
+ $address[] = $results[0]['state'];
+ }
+ if ($results[0]['zip']) {
+ $address[] = $results[0]['zip'];
+ }
+ $data = array(
+ 'member_name' => $results[0]['member_name'],
+ 'address' => implode(',', $address)
+ );
+ }
+ return $data;
+ }
+ }
}
*/
public function __construct($path)
{
-// global $typenow;
$this->pluginDirName = $path;
add_action('init', array($this, 'addPostTypes'));
add_action('init', array($this, 'createCouponTaxonomy'));
add_action('restrict_manage_posts',
array($this, 'taxonomy_filter_restrict_manage_posts'));
add_filter('parse_query', array($this, 'couponFilter'));
-// var_dump($typenow);
-// add_filter('user_row_actions', array($this, 'remove_row_actions'));
}
// Filter the request to just give posts for the given taxonomy, if applicable.
function taxonomy_filter_restrict_manage_posts()
{
global $typenow;
-// var_dump($typenow);
if ($typenow == GLM_COUPON_POST_TYPE) {
$filters = get_object_taxonomies(GLM_COUPON_POST_TYPE);
'hide_empty' => true
));
}
- }
-
-
-
+ }
}
function taxonomy_filter_post_type_request($query)
global $pagenow, $typenow;
if ('edit.php' == $pagenow && $typenow == GLM_COUPON_POST_TYPE) {
$filters = get_object_taxonomies(GLM_COUPON_POST_TYPE);
-// var_dump($filters);
foreach ($filters as $tax_slug) {
$var = &$query->query_vars[$tax_slug];
-// var_dump($var);
-// var_dump($tax_slug);
if (isset($var)) {
$term = get_term_by('id', $var, $tax_slug);
var_dump($term);
if (isset($qv[GLM_COUPON_TAX_CATEGORIES]) && $qv[GLM_COUPON_TAX_CATEGORIES] != 0) {
$term = get_term_by('id', $qv[GLM_COUPON_TAX_CATEGORIES], GLM_COUPON_TAX_CATEGORIES);
$qv[GLM_COUPON_TAX_CATEGORIES] = $term->slug;
-
if (isset($query->tax_query)) {
$tax_query =& $query->tax_query;
$queries =& $tax_query->queries;
-// echo '<pre>'.print_r($queries, true).'</pre>';
foreach ($queries as $key => &$qs) {
if ($qs['taxonomy'] == GLM_COUPON_TAX_CATEGORIES) {
$qs['terms'][$key] = $term->slug;
}
}
- if ($qv['post_type'] == GLM_COUPON_POST_TYPE) {
-// echo '<pre>'.print_r($qv, true).'</pre>';
- }
-// echo '<pre>'.print_r($query, true).'</pre>';
}
-
return $query;
}
}
$clean_ed = date('D, M d, Y', $meta_ed);
$clean_ex = date('D, M d, Y', $meta_ex);
- $glm_coupon_url = (isset($glm_coupon_url))
- ? $glm_coupon_url
+ $glm_coupons_url = (isset($custom['glm_coupons_url']))
+ ? $custom['glm_coupons_url'][0]
+ : '';
+
+ // if they have member db plugin get a list of the members
+ $glm_coupons_member = (isset($custom['glm_coupons_member']))
+ ? $custom['glm_coupons_member'][0]
: '';
+
+ $memberList = $this->_getMemberList();
+
include $this->pluginDirName . 'views/admin/coupon_meta.php';
}
+ private function _getMemberList()
+ {
+ global $wpdb;
+ $members = array();
+ if ( !defined( 'GLM_MEMBERS_PLUGIN_DB_PREFIX' ) ) {
+ return false;
+ } else {
+ $sql = "
+ SELECT id,member_name as name
+ FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "member_info
+ WHERE status = 10
+ ORDER BY member_name";
+ $results = $wpdb->get_results($sql, ARRAY_A);
+ foreach ($results as $row) {
+ $members[] = $row;
+ }
+ }
+ return $members;
+ }
+
/**
* Save the coupon meta data
*
update_post_meta($post->ID, 'glm_coupons_expdate', $updateexpd);
update_post_meta($post->ID, 'glm_coupons_url', $_POST['glm_coupons_url']);
+
+ update_post_meta($post->ID, 'glm_coupons_member', $_POST['glm_coupons_member']);
}
/**
'menu_name' => 'Coupons'
);
$args = array(
-// 'label' => __('Coupons'),
'labels' => $labels,
'description' => 'Stores Coupons and Coupon data',
'public' => true,
'can_export' => true,
'menu_position' => 21,
- 'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'author'),
+ 'supports' => array('title', 'editor', 'thumbnail', 'author'),
'has_archive' => true,
'menu_icon' => 'dashicons-products',
'capability_type' => 'post',
<div class="<?php if ($coupon->end){ echo ' end';}?> coupon-item">
<div class="coupon-select"><label><input type="checkbox" name="coupon-id-<?php echo $coupon->ID;?>"> Select this coupon</label></div>
<div class="coupon-item-wrap">
+ <?php if ($coupon->glm_coupons_member) : ?>
+ <h3><?php echo $coupon->glm_coupons_member;?></h3>
+ <?php endif;?>
<h3><?php echo $coupon->post_title;?></h3>
<?php if ($coupon->glm_coupons_thumb) : ?>
<?php echo $coupon->glm_coupons_thumb;?>
<?php endif;?>
<div class="coupon-descr"><?php echo $coupon->post_content;?></div>
<?php if ($coupon->glm_coupons_url) :?>
- <div class="coupon-url"><a href="<?php echo date('F d,Y', $coupon->glm_coupons_url);?>">Web Site</a></div>
+ <div class="coupon-url"><a target="_blank" href="http://<?php echo $coupon->glm_coupons_url;?>">Web Site</a></div>
<?php endif;?>
<div class="coupon-expires">Expires: <?php echo date('m/d/Y', $coupon->glm_coupons_expdate);?></div>
</div>