CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Installing CiviCRM »
  • WordPress Installations (Moderators: Kurund Jalmi, Coleman Watts) »
  • Custom tokens in Wordpress
Pages: [1]

Author Topic: Custom tokens in Wordpress  (Read 621 times)

divemasterza

  • I’m new here
  • *
  • Posts: 15
  • Karma: 0
  • CiviCRM version: 4.4+
  • CMS version: WP
  • MySQL version: 5.6
  • PHP version: 5.4
Custom tokens in Wordpress
February 06, 2014, 03:38:45 am
I am having issues with a custom token.

1) In system settings --> directory I pointed to my civicrmHooks.php directory
2) The token description appears in the modal pop window and is being added to the content (email in this instance)
3) Mail is sent but the token is replaced with null (or not populated)

The code I have used is from colemanw blog post - and the token I am implementing is a simple today's date (That should really be integrated into the codebase)
Code: [Select]
<?php

 
// function to add today's date custom token

function wordpress_civicrm_tokens(&$tokens) {
  
$tokens['date'] = array(
    
'date.date_short' => 'Today\'s Date: mm/dd/yyyy',
    
'date.date_med' => 'Today\'s Date: Mon d yyyy',
    
'date.date_long' => 'Today\'s Date: Month dth, yyyy',
  );
}

function 
wordpress_civicrm_tokenValues(&$values, $cids, $job = null, $tokens = array(), $context = null) {
  
// Date tokens
  
if (!empty($tokens['date'])) {
    
$date = array(
      
'date.date_short' => date('m/d/Y'),
      
'date.date_med' => date('M j Y'),
      
'date.date_long' => date('F jS, Y'),
    );
    foreach (
$cids as $cid) {
      
$values[$cid] = empty($values[$cid]) ? $date : $values[$cid] + $date;
    }
  }
}
?>

Anyone has any insights why this does not work as expected?
« Last Edit: February 06, 2014, 04:34:32 am by divemasterza »

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Custom tokens in Wordpress
February 06, 2014, 10:52:44 am
Your code looks correct.
It may be related to this bug: http://issues.civicrm.org/jira/browse/CRM-14095
Which is fixed in today's 4.4 release.
Try asking your question on the new CiviCRM help site.

divemasterza

  • I’m new here
  • *
  • Posts: 15
  • Karma: 0
  • CiviCRM version: 4.4+
  • CMS version: WP
  • MySQL version: 5.6
  • PHP version: 5.4
Re: Custom tokens in Wordpress
February 06, 2014, 10:03:34 pm
Thank you!

I can confirm that after upgrade this has been fixed

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Installing CiviCRM »
  • WordPress Installations (Moderators: Kurund Jalmi, Coleman Watts) »
  • Custom tokens in Wordpress

This forum was archived on 2017-11-26.