# taskbuilder/trunk/includes/replace_task_macro.php

Taskbuilder – Project Management &amp; Task Management Tool With Kanban Board, version trunk. 163 lines.

- Page: https://pluginprobe.com/plugins/taskbuilder/trunk/code/includes/replace_task_macro.php
- Raw: https://pluginprobe.com/plugins/taskbuilder/trunk/raw/includes/replace_task_macro.php
- Modified: 2026-08-26T12:08:58+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/taskbuilder/trunk/code/includes/replace_task_macro.php#L10-L20`.

```php
<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

global $current_user, $wppmfunction,$wpdb;
$current_user_data = get_userdata($current_user->ID);
$task_id = intval(sanitize_text_field($task_id));
$wppm_task_data = $wppmfunction->get_task($task_id);
$task_creator = $wppm_task_data['created_by'];
$task_creator_data = get_userdata($task_creator);
$task_creator_name = $task_creator_data->display_name;
$orderby_sql       = (sanitize_sql_orderby( "id DESC" ));
$wppm_task_comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wppm_task_comment where task_id=%d ORDER BY $orderby_sql LIMIT 1",$task_id));
$wppm_project_data = $wppmfunction->get_project($wppm_task_data['project']);
$auth_id           = sanitize_text_field($wppm_task_data['task_auth_code']);
$attachments = array();
if(!empty($wppm_task_comment)){
	$attachments = explode(',',$wppm_task_comment->attachment_ids);
}
preg_match_all("/{[^}]*}/" ,$str,$matches);
$matches = array_unique($matches[0]);
$flag =false;
$page_setting = get_option( 'wppm-page-settings' );
$view = $page_setting['task-url-page'];
foreach($matches as $match){
	switch($match){
		// Task ID
		case '{task_id}':
			$str = preg_replace('/{task_id}/', $task_id, $str);
			break;
		// Task Creator Name
		case '{task_creator_name}':
			$str = preg_replace('/{task_creator_name}/', $task_creator_name, $str);
			break;
		//Current User Name
		case '{user_name}':
			$str = preg_replace('/{user_name}/', sanitize_text_field($current_user_data->display_name), $str);
			break;
		// Task Name
		case '{task_name}':
			$str = preg_replace('/{task_name}/', sanitize_text_field($wppm_task_data['task_name']), $str);
			break;
		//Old Task Status
		case '{old_task_status}':
			$str = preg_replace('/{old_task_status}/', $this->get_old_task_status_name($task_id), $str);
			break;
		//New Task Status
		case '{new_task_status}':
			$str = preg_replace('/{new_task_status}/', $this->get_new_task_status_name(sanitize_text_field($wppm_task_data['status'])), $str);
			break;
		//New Task Status
		case '{task_status}':
			$str = preg_replace('/{task_status}/', $this->get_new_task_status_name(sanitize_text_field($wppm_task_data['status'])), $str);
			break;
		//Task Assigned Users
		case '{task_assigned_users}':
			$assigned_users = $this->get_task_assigned_users_names($task_id);
			$str = preg_replace('/{task_assigned_users}/', sanitize_text_field($assigned_users), $str);
			break;
		//Previously Assign Task Users
		case '{previously_assigned_task_users}':
			$previously_assigned_task_users = $this->get_task_previously_assigned_users_names($task_id);
			$str = preg_replace('/{previously_assigned_task_users}/', sanitize_text_field($previously_assigned_task_users), $str);
			break;
		// Task Start Date
		case '{task_start_date}':
			$str = preg_replace('/{task_start_date}/', sanitize_text_field($wppm_task_data['start_date']), $str);
			break;
		// Task End Date
		case '{task_end_date}':
			$str = preg_replace('/{task_end_date}/', sanitize_text_field($wppm_task_data['end_date']), $str);
			break;
		// Task Priority
		case '{task_priority}':
			$str = preg_replace('/{task_priority}/', $this->get_task_priority_name(sanitize_text_field($wppm_task_data['priority'])), $str);
			break;
		// Task Description
		case '{task_description}':
			$str = preg_replace('/{task_description}/', sanitize_text_field($wppm_task_data['description']), $str);
			break;
		// Date created
		case '{task_date_created}':
			$str = preg_replace('/{task_date_created}/', get_date_from_gmt(sanitize_text_field($wppm_task_data['date_created']) ), $str);
			break;
		// Project Name
		case '{project_name}':
			$str = preg_replace('/{project_name}/', sanitize_text_field($wppm_project_data['project_name']), $str);
		break;
		//Last comment user name
		case '{last_comment_user_name}':
			$str = preg_replace('/{last_comment_user_name}/', $this->get_last_comment_user_name($task_id), $str);
		break;
		//Project status
		case '{project_status}';
			$str = preg_replace('/{project_status}/', $this->get_new_project_status_name(sanitize_text_field($wppm_project_data['status'])), $str);
		break;
		// Project Category
		case '{project_category}';
		if(!empty($wppm_project_data['cat_id'])){
			$str = preg_replace('/{project_category}/', $this->get_project_category_name(sanitize_text_field($wppm_project_data['cat_id'])), $str);
		}else{
			$str = "";
		}
		break;
		// Project Name
		case '{project_name}':
			$str = preg_replace('/{project_name}/', (sanitize_text_field($wppm_project_data['project_name'])), $str);
		break;
		// Project Start Date
		case 'project_start_date':
			$str = preg_replace('/{project_start_date}/', (sanitize_text_field($wppm_project_data['start_date'])), $str);
		break;
		// Project End Date
		case '{project_end_date}':
			$str = preg_replace('/{project_end_date}/', (sanitize_text_field($wppm_project_data['end_date'])), $str);
		break;
		// Project Description
		case '{project_description}':
			$str = preg_replace('/{project_description}/', (sanitize_text_field($wppm_project_data['description'])), $str);
		break;
		// Project Assigned Users
		case '{project_assigned_users}':
			$assigned_users = $this->get_project_assigned_users_names($wppm_project_data['id']);
			$str = preg_replace('/{project_assigned_users}/', (sanitize_text_field($assigned_users)), $str);
		break;
		//Last comment body
		case '{comment_body}':
			$flag= true;
			$str = preg_replace('/{comment_body}/', $this->get_last_comment_body($task_id), $str);
		break;
		case '{task_url}':
			$task_url = '<a class="wppm_link" href="' . $this->get_task_url($task_id,$view) . '" target="_blank">' . $this->get_task_url($task_id,$view) . '</a>';
			$str = preg_replace('/{task_url}/', $task_url, $str);
		break;

	}
}
if($flag == true){
	if(!empty($attachments)){
		foreach($attachments as $attach_id){
			$upload_dir   = wp_upload_dir();
			$attach_id = absint($attach_id);
			$attachment = $wpdb->get_row($wpdb->prepare("select * from {$wpdb->prefix}wppm_attachments where id=%d",$attach_id));
			if(!empty($attachment)){
				$updated_time = sanitize_text_field($attachment->date_created);
				$time  = strtotime(sanitize_text_field($updated_time));
				$month = wp_date("m",$time);
				$year  = wp_date("Y",$time);
				$findStr = ".txt";
				$attachment_name = preg_replace('/' . $findStr . '/', "", sanitize_file_name($attachment->name), 1);
				$file_url = $upload_dir['basedir'] . '/wppm/'.'/'.$year.'/'.$month.'/'. $attachment_name;
				$download_url = home_url('/').'?wppm_attachment='.sanitize_text_field($attachment->id).'&tid='.sanitize_text_field($task_id).'&tac='.sanitize_text_field($auth_id);
				$attach_url[] = '<a style="text-decoration:none;" href="'.$download_url.'" target="_blank">'.sanitize_file_name($attachment->file_name).'</a>';
			}else{
				$attach_url= array();
			}
		}
		$str = $str.implode("<br>",$attach_url);
	}
	
}
$str = apply_filters('wppm_replace_task_macro',$str,$task_id);
```
