-
-
Save benheu/cf9eb925b0e17e6dbd6c to your computer and use it in GitHub Desktop.
<?php | |
/** | |
* | |
* @param string $tag_value | |
* @param int $user_id mailpoet's subscriber id | |
* @return type | |
*/ | |
function mailpoet_shortcodes_custom_filter( $tag_value , $user_id ) { | |
// run this code only for my custom tag [custom:my_custom_tag] | |
if ($tag_value === 'my_custom_tag') { | |
// get the wpuser_id of that subscriber | |
$model_user = WYSIJA::get('user','model'); | |
$subscriber_data = (array)$model_user->getOne(array( 'wpuser_id' ) , array( 'user_id' => $user_id)); | |
// get the wp-user data based on the wp-user id | |
$wpuser_data = get_userdata( $subscriber_data['wpuser_id'] ); | |
// return the key you want | |
$replacement = $wpuser_data->last_name; | |
} | |
if ($tag_value === 'blog_name') { | |
$replacement = get_bloginfo('name'); | |
} | |
return $replacement; | |
} | |
// filter registration allowing the two parameters $tag_value and $user_id to be passed | |
add_filter('wysija_shortcodes', 'mailpoet_shortcodes_custom_filter', 10 , 2); |
I dont retrieve the last name, is it compatible with the latest wysija mail poet plugin? thank you
I am adding several posts to my MailPoet newsletter and from a shortcode I need to gather the specific post content. Is there any WYSIJA:get for this?
Thanks
@fmarzocca what do you mean by gather the specific post content.
thanks for the example!
however, im struggling to get the users custom fields data of mailpoet.
something like $wpuser_data->field_2 wont work.
any idea?
Did anybody managed to read out the custom fields? I searched and tried a lot but couldn't find any solution.
Thanks in advance for any hint!
I have been trying a lot, but still no success. Any help would be great? Am I the only one customizing Mailpoet? ;-)
I solved the problem with a workaround:
I read out the data directly from the MySQL-database without using the Mailpoet-API:
// Make variable global to get access to DB
global $wpdb;
// Get ZIP of subscribers:
// cf_2 is the name of the custom field -> replace by the name of your field
foreach( $wpdb->get_results("SELECT cf_2 FROM wp_wysija_user WHERE user_id ='".$user_id."'") as $key => $row) {
$zip = $row->cf_2;
}
I hope this helps other users of Mailpoet.
I understand the approach, so that's good. However, I am having a problem within the shortcode establishing the '$user_id' value that is being used in the SQL WHERE clause. Does it come into the shortcode as a parameter value, or is it established in some other manner?
Also, is it correct to make a distinction between '$user_id' and 'subscriber id'?
I have tried many things to establish either the $user_id value or the subscriber value within the shortcode, but have not been able to make it work.
Where should we put this code? under functions.php of theme?