Plugin Directory

Changeset 2052716


Ignore:
Timestamp:
03/18/2019 02:33:17 PM (7 years ago)
Author:
danillonunes
Message:

Add option to load donations count

Location:
makemydonation-imo/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • makemydonation-imo/trunk/mmdimo.php

    r2052712 r2052716  
    5252add_shortcode( 'mmdimo_donation_link', 'shortcode_mmdimo_donation_link' );
    5353add_shortcode( 'mmdimo_donation_url', 'shortcode_mmdimo_donation_url' );
     54add_shortcode( 'mmdimo_donations_count', 'shortcode_mmdimo_donations_count' );
    5455add_shortcode( 'mmdimo_donation_charity:name', 'shortcode_mmdimo_donation_charity_name' );
    5556add_shortcode( 'mmdimo_donation_charity:ein', 'shortcode_mmdimo_donation_charity_ein' );
  • makemydonation-imo/trunk/template.php

    r2052714 r2052716  
    11<?php
    22
    3 function the_mmdimo_donation_link( $before = '', $after = '', $echo = true, $content = NULL, $title = NULL, $target = NULL, $ein = NULL ) {
    4   $donation_link = get_the_mmdimo_donation_link(0, $content, $title, $target, $ein);
     3function the_mmdimo_donation_link( $before = '', $after = '', $echo = true, $content = NULL, $title = NULL, $target = NULL, $ein = NULL, $display_count = FALSE ) {
     4  $donation_link = get_the_mmdimo_donation_link(0, $content, $title, $target, $ein, $display_count);
    55
    66  if ( strlen($donation_link) == 0 ) {
     
    1818}
    1919
    20 function get_the_mmdimo_donation_link( $post = 0, $content = NULL, $title = NULL, $target = NULL, $ein = NULL ) {
     20function get_the_mmdimo_donation_link( $post = 0, $content = NULL, $title = NULL, $target = NULL, $ein = NULL, $display_count = FALSE ) {
    2121  $url = get_the_mmdimo_donation_url( $post, $ein );
    2222  $post = get_post( $post );
     23  $id = isset( $post->ID ) ? $post->ID : 0;
    2324
    2425  if ( is_null($content) ) {
    2526    $content = 'Donate';
    2627  }
     28
     29  if ( $display_count ) {
     30    $count = get_the_mmdimo_donations_count( $id );
     31
     32    if ( $count ) {
     33      $content .=  ' (' . $count . ')';
     34    }
     35  }
     36
    2737  if ( is_null($title) ) {
    2838    $title = 'Make My Donation in Memory of ' . $post->post_title;
     
    5060  $target = isset($attr['target'] ) ? $attr['target'] : NULL;
    5161  $ein = isset($attr['ein'] ) ? $attr['ein'] : NULL;
     62  $display_count = isset($attr['display_count'] ) && $attr['display_count'] ? TRUE : FALSE;
    5263
    5364  if (!$content) {
     
    5566  }
    5667
    57   return get_the_mmdimo_donation_link(0, $content, $title, $target, $ein);
     68  return get_the_mmdimo_donation_link(0, $content, $title, $target, $ein, $display_count);
    5869}
    5970
     
    121132}
    122133
     134function the_mmdimo_donations_count( $before = '', $after = '', $echo = true, $content = NULL ) {
     135  $donations_count = get_the_mmdimo_donations_count(0, $content);
     136
     137  if ( strlen($donations_count) == 0 ) {
     138    return;
     139  }
     140
     141  $donations_count = $before . $donations_count . $after;
     142
     143  if ( $echo ) {
     144    echo $donations_count;
     145  }
     146  else {
     147    return $donations_count;
     148  }
     149}
     150
     151function get_the_mmdimo_donations_count( $post = 0, $content = NULL ) {
     152  $post = get_post( $post );
     153  $id = isset( $post->ID ) ? $post->ID : 0;
     154  $mmdimo_case = get_post_meta( $id, 'mmdimo_case', TRUE );
     155
     156  require_once( MMDIMO_PLUGIN_DIR . '/api.php' );
     157  $donations_count = mmdimo_api_case_donations_load($mmdimo_case['id'], TRUE);
     158
     159  if ( $post->ID && $donations_count['total'] ) {
     160    $count =  sprintf(_n( '%s donation', '%s donations', $donations_count['total'], 'mmdimo' ), $donations_count['total']);
     161
     162    $content = '<span class="mmdimo-donation-count">' . $count . '</span>';
     163
     164    return apply_filters( 'get_the_mmdimo_donations_count', $content, $post, $donations_count );
     165  }
     166
     167  return '';
     168}
     169
     170function shortcode_mmdimo_donations_count( $content = NULL ) {
     171  if (!$content) {
     172    $content = NULL;
     173  }
     174
     175  return get_the_mmdimo_donations_count(0, $content);
     176}
     177
    123178function the_mmdimo_donation_charity_name( $before = '', $after = '', $echo = TRUE ) {
    124179  $charity_name = get_the_mmdimo_donation_charity_name();
Note: See TracChangeset for help on using the changeset viewer.