-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompletionist-custom-fields.php
More file actions
73 lines (63 loc) · 1.85 KB
/
completionist-custom-fields.php
File metadata and controls
73 lines (63 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
* Plugin Name: Completionist - Custom Fields
* Description: Displays custom fields on project tasks in the [ptc_asana_project] shortcode. Requires Completionist v3.11.0 or later.
* Version: 0.1.0
* Requires PHP: 7.2
* Requires at least: 5.0.0
* Tested up to: 6.4.1
*/
namespace Completionist_Custom_Fields;
defined( 'ABSPATH' ) || die();
// Register code.
add_action(
'ptc_completionist_shortcode_enqueue_assets',
__NAMESPACE__ . '\enqueue_shortcode_assets',
10,
1
);
add_filter(
'ptc_completionist_project_task_fields',
__NAMESPACE__ . '\filter_project_task_fields',
10,
1
);
// Define functionality.
/**
* Enqueues custom shortcode assets.
*
* @link https://docs.purpleturtlecreative.com/completionist/shortcodes/customizations/#enqueueing-custom-assets
*
* @param string $shortcode_tag The shortcode tag being rendered.
*/
function enqueue_shortcode_assets( string $shortcode_tag ) {
if ( 'ptc_asana_project' === $shortcode_tag ) {
wp_enqueue_script(
'completionist-custom-fields',
plugins_url( '/script.js', __FILE__ ),
array( 'ptc-completionist-shortcode-asana-project' ),
filemtime( __DIR__ . '/script.js' ),
true
);
wp_enqueue_style(
'completionist-custom-fields',
plugins_url( '/styles.css', __FILE__ ),
array( 'ptc-completionist-shortcode-asana-project' ),
filemtime( __DIR__ . '/styles.css' ),
'all'
);
}
}
/**
* Adds custom fields data to Asana project tasks.
*
* @link https://developers.asana.com/reference/gettask See all
* supported Asana task fields in the HTTP 200 response.
*
* @param string $task_fields The ?opt_fields CSV string.
*
* @return string The modified ?opt_fields CSV string.
*/
function filter_project_task_fields( string $task_fields ) : string {
return $task_fields . ',custom_fields,custom_fields.name,custom_fields.display_value';
}