Skip to content

Commit

Permalink
#232 include_sections attribute for ptc_asana_project shortcode
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleBlanchette committed Sep 27, 2024
1 parent a5a09b0 commit 62c6f05
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
5 changes: 3 additions & 2 deletions docs/_docs/shortcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ Only "list" layout is displayed in the free version of Completionist. Additional
| Attribute | Value Type | Required? | Description |
| ------------------ | ---------------------------- | ------------------------------------------------------------ | ------------------------------------------------------------ |
| `src` | URL | **Required** | The Asana project link.<br /><br />When viewing a project in Asana, copy the URL in the web browser address bar (eg. `https://app.asana.com/0/12345729186/12345167991`) or the URL from clicking "Copy project link" in the project's detail dropdown. |
| `exclude_sections` | CSV (Comma-Separated Values) | *Optional.* Default "" (empty) to display all sections within the Asana project. | A comma-separated list of the names of the Asana project sections to exclude from display.<br /><br />Note that HTML entities are encoded to keep compatibility with the WordPress Block Editor. For example, `exclude_sections="Design &amp; Development"` will exclude project sections named `Design & Development`. |
| `include_sections` | CSV (Comma-Separated Values) | *Optional.* Default "" (empty) to include all sections within the Asana project. | A comma-separated list of the names of the Asana project sections to include for display. All non-matching sections will be excluded. Included sections may be excluded by `exclude_sections` if specified.<br /><br />Note that HTML entities are encoded to keep compatibility with the WordPress Block Editor. For example, `include_sections="Design &amp; Development"` will include project sections named `Design & Development`. |
| `exclude_sections` | CSV (Comma-Separated Values) | *Optional.* Default "" (empty) to display all sections within the Asana project. | A comma-separated list of the names of the Asana project sections to exclude from display. Applies *after* `include_sections` to guarantee the specified sections are excluded.<br /><br />Note that HTML entities are encoded to keep compatibility with the WordPress Block Editor. For example, `exclude_sections="Design &amp; Development"` will exclude project sections named `Design & Development`. |
| `show_name` | Boolean (true/false) | *Optional.* Default "true". | Set to "false" to hide the project's name. |
| `show_description` | Boolean (true/false) | *Optional.* Default "true". | Set to "false" to hide the project's description. |
| `show_status` | Boolean (true/false) | *Optional.* Default "true". | Set to "false" to hide the project's current status update and completion status. |
Expand Down Expand Up @@ -64,7 +65,7 @@ Only "list" layout is displayed in the free version of Completionist. Additional
### Quick Copy (with default values)

```
[ptc_asana_project src="<ASANA_PROJECT_URL>" layout="list" auth_user="" exclude_sections="" show_name="true" show_description="true" show_status="true" show_modified="true" show_due="true" show_tasks_description="true" show_tasks_assignee="true" show_tasks_subtasks="true" show_tasks_completed="true" show_tasks_due="true" show_tasks_attachments="true" show_tasks_tags="true" show_tasks_comments="false" sort_tasks_by="" /]
[ptc_asana_project src="<ASANA_PROJECT_URL>" layout="list" auth_user="" include_sections="" exclude_sections="" show_name="true" show_description="true" show_status="true" show_modified="true" show_due="true" show_tasks_description="true" show_tasks_assignee="true" show_tasks_subtasks="true" show_tasks_completed="true" show_tasks_due="true" show_tasks_attachments="true" show_tasks_tags="true" show_tasks_comments="false" sort_tasks_by="" /]
```

_**\*\*Remember** to change the `src` attribute value to the URL of the Asana project that you'd like to display!_
Expand Down
23 changes: 21 additions & 2 deletions src/includes/class-asana-interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ public static function get_project_data(
$default_args = apply_filters(
'ptc_completionist_project_default_args',
array(
'include_sections' => '',
'exclude_sections' => '',
'show_gids' => true,
'show_name' => true,
Expand Down Expand Up @@ -778,16 +779,34 @@ public static function get_project_data(
$args
);

// Parse included project section names.
if ( ! empty( $args['include_sections'] ) ) {
$include_section_names = explode( ',', $args['include_sections'] );
if (
! empty( $include_section_names ) &&
is_array( $include_section_names )
) {
$include_section_names = array_map( 'trim', $include_section_names );
$keep_sections = array();
foreach ( $project->sections as $i => &$section ) {
if ( in_array( trim( $section->name ), $include_section_names, true ) ) {
// Keep section if name is in include list.
$keep_sections[] = $section;
}
}
$project->sections = $keep_sections;
}
}

// Parse excluded project section names.
$exclude_section_names = array();
if ( ! empty( $args['exclude_sections'] ) ) {
$exclude_section_names = explode( ',', $args['exclude_sections'] );
if (
! empty( $exclude_section_names ) &&
is_array( $exclude_section_names )
) {
$exclude_section_names = array_map( 'trim', $exclude_section_names );
$keep_sections = array();
$keep_sections = array();
foreach ( $project->sections as $i => &$section ) {
if ( ! in_array( trim( $section->name ), $exclude_section_names, true ) ) {
// Keep section if name is not in exclude list.
Expand Down
2 changes: 2 additions & 0 deletions src/public/class-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Shortcodes {
'src' => '', // Required.
'layout' => '',
'auth_user' => '',
'include_sections' => '',
'exclude_sections' => '',
'show_name' => 'true',
'show_description' => 'true',
Expand Down Expand Up @@ -328,6 +329,7 @@ public static function get_ptc_asana_project(

$atts['src'] = (string) esc_url_raw( $atts['src'] );
$atts['auth_user'] = (int) $atts['auth_user'];
$atts['include_sections'] = html_entity_decode( $atts['include_sections'], ENT_QUOTES | ENT_HTML5 );
$atts['exclude_sections'] = html_entity_decode( $atts['exclude_sections'], ENT_QUOTES | ENT_HTML5 );

// Prepare shortcode.
Expand Down

0 comments on commit 62c6f05

Please sign in to comment.