Skip to content

Commit 90133d4

Browse files
authored
Merge pull request #688 from ProgressPlanner/filip/v19/adjust-terms-task-description
V1.9 - Improve description for "Update term description" and "Delete term" interactive tasks
2 parents 486ee5a + 36e1fc4 commit 90133d4

4 files changed

Lines changed: 81 additions & 23 deletions

File tree

assets/js/recommendations/remove-terms-without-posts.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
taxonomyElement: popover.querySelector(
4444
'#prpl-delete-term-taxonomy'
4545
),
46+
taxonomyNameElement: popover.querySelector(
47+
'#prpl-delete-term-taxonomy-name'
48+
),
4649
termIdField: popover.querySelector( '#prpl-delete-term-id' ),
4750
taxonomyField: popover.querySelector( '#prpl-delete-taxonomy' ),
4851
};
@@ -82,6 +85,9 @@
8285
taxonomy: this.decodeHtmlEntities(
8386
event.detail.target_taxonomy
8487
),
88+
taxonomyName: this.decodeHtmlEntities(
89+
event.detail.target_taxonomy_name
90+
),
8591
termName: this.decodeHtmlEntities(
8692
event.detail.target_term_name
8793
),
@@ -97,19 +103,27 @@
97103
this.currentTermData.termId,
98104
this.currentTermData.taxonomy,
99105
this.currentTermData.termName,
106+
this.currentTermData.taxonomyName,
100107
this.decodeHtmlEntities( event.detail.post_title )
101108
);
102109
}
103110

104111
/**
105112
* Update the popover content.
106113
*
107-
* @param {string} termId The term ID.
108-
* @param {string} taxonomy The taxonomy.
109-
* @param {string} termName The term name.
110-
* @param {string} postTitle The post title.
114+
* @param {string} termId The term ID.
115+
* @param {string} taxonomy The taxonomy.
116+
* @param {string} termName The term name.
117+
* @param {string} taxonomyName The taxonomy name.
118+
* @param {string} postTitle The post title.
111119
*/
112-
updatePopoverContent( termId, taxonomy, termName, postTitle ) {
120+
updatePopoverContent(
121+
termId,
122+
taxonomy,
123+
termName,
124+
taxonomyName,
125+
postTitle
126+
) {
113127
if ( this.elements.popoverTitle ) {
114128
this.elements.popoverTitle.textContent = postTitle;
115129
}
@@ -122,6 +136,10 @@
122136
this.elements.taxonomyElement.textContent = taxonomy;
123137
}
124138

139+
if ( this.elements.taxonomyNameElement ) {
140+
this.elements.taxonomyNameElement.textContent = taxonomyName;
141+
}
142+
125143
if ( this.elements.termIdField ) {
126144
this.elements.termIdField.value = termId;
127145
}

assets/js/recommendations/update-term-description.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
taxonomyElement: popover.querySelector(
4545
'#prpl-update-term-taxonomy'
4646
),
47+
taxonomyNameElement: popover.querySelector(
48+
'#prpl-update-term-taxonomy-name'
49+
),
4750
termIdField: popover.querySelector( '#prpl-update-term-id' ),
4851
taxonomyField: popover.querySelector( '#prpl-update-taxonomy' ),
4952
descriptionField: popover.querySelector(
@@ -86,6 +89,9 @@
8689
taxonomy: this.decodeHtmlEntities(
8790
event.detail.target_taxonomy
8891
),
92+
taxonomyName: this.decodeHtmlEntities(
93+
event.detail.target_taxonomy_name
94+
),
8995
termName: this.decodeHtmlEntities(
9096
event.detail.target_term_name
9197
),
@@ -101,19 +107,27 @@
101107
this.currentTermData.termId,
102108
this.currentTermData.taxonomy,
103109
this.currentTermData.termName,
110+
this.currentTermData.taxonomyName,
104111
this.decodeHtmlEntities( event.detail.post_title )
105112
);
106113
}
107114

108115
/**
109116
* Update the popover content.
110117
*
111-
* @param {string} termId The term ID.
112-
* @param {string} taxonomy The taxonomy.
113-
* @param {string} termName The term name.
114-
* @param {string} postTitle The post title.
118+
* @param {string} termId The term ID.
119+
* @param {string} taxonomy The taxonomy.
120+
* @param {string} termName The term name.
121+
* @param {string} taxonomyName The taxonomy name.
122+
* @param {string} postTitle The post title.
115123
*/
116-
updatePopoverContent( termId, taxonomy, termName, postTitle ) {
124+
updatePopoverContent(
125+
termId,
126+
taxonomy,
127+
termName,
128+
taxonomyName,
129+
postTitle
130+
) {
117131
if ( this.elements.popoverTitle ) {
118132
this.elements.popoverTitle.textContent = postTitle;
119133
}
@@ -126,6 +140,10 @@
126140
this.elements.taxonomyElement.textContent = taxonomy;
127141
}
128142

143+
if ( this.elements.taxonomyNameElement ) {
144+
this.elements.taxonomyNameElement.textContent = taxonomyName;
145+
}
146+
129147
if ( this.elements.termIdField ) {
130148
this.elements.termIdField.value = termId;
131149
}

classes/suggested-tasks/providers/class-remove-terms-without-posts.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ public function add_task_actions( $data = [], $actions = [] ) {
349349

350350
$task_details = $this->get_task_details( $task_data );
351351

352+
$taxonomy = \get_taxonomy( $term->taxonomy );
353+
352354
$actions[] = [
353355
'priority' => 10,
354356
'html' => \sprintf(
@@ -360,10 +362,11 @@ public function add_task_actions( $data = [], $actions = [] ) {
360362
\htmlspecialchars(
361363
\wp_json_encode(
362364
[
363-
'post_title' => $task_details['post_title'],
364-
'target_term_id' => $task_data['target_term_id'],
365-
'target_taxonomy' => $task_data['target_taxonomy'],
366-
'target_term_name' => $task_data['target_term_name'],
365+
'post_title' => $task_details['post_title'],
366+
'target_term_id' => $task_data['target_term_id'],
367+
'target_taxonomy' => $task_data['target_taxonomy'],
368+
'target_taxonomy_name' => $taxonomy ? $taxonomy->label : '',
369+
'target_term_name' => $task_data['target_term_name'],
367370
]
368371
),
369372
ENT_QUOTES,
@@ -401,14 +404,23 @@ public function print_popover_form_contents() {
401404
<span id="prpl-delete-term-name"></span>
402405
</p>
403406
<p style="margin: 5px 0 0 0; font-size: 12px; color: #646970;">
404-
<span id="prpl-delete-term-taxonomy"></span>
407+
<?php
408+
printf(
409+
/* translators: %1$s: The taxonomy name, %2$s: The term slug */
410+
\esc_html__( 'You are deleting the term which belongs to the "%1$s" (slug "%2$s").', 'progress-planner' ),
411+
'<span id="prpl-delete-term-taxonomy-name"></span>',
412+
'<span id="prpl-delete-term-taxonomy"></span>'
413+
);
414+
?>
405415
</p>
406416
</div>
407417
<input type="hidden" name="term_id" id="prpl-delete-term-id" value="">
408418
<input type="hidden" name="taxonomy" id="prpl-delete-taxonomy" value="">
409-
<button type="submit" class="prpl-button prpl-button-primary" id="prpl-delete-term-button">
410-
<?php \esc_html_e( 'Delete term', 'progress-planner' ); ?>
411-
</button>
419+
<div class="prpl-steps-nav-wrapper">
420+
<button type="submit" class="prpl-button prpl-button-primary" id="prpl-delete-term-button">
421+
<?php \esc_html_e( 'Delete term', 'progress-planner' ); ?>
422+
</button>
423+
</div>
412424
<?php
413425
}
414426

classes/suggested-tasks/providers/class-update-term-description.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,8 @@ public function add_task_actions( $data = [], $actions = [] ) {
333333

334334
$task_details = $this->get_task_details( $task_data );
335335

336+
$taxonomy = \get_taxonomy( $term->taxonomy );
337+
336338
$actions[] = [
337339
'priority' => 10,
338340
'html' => \sprintf(
@@ -344,10 +346,11 @@ public function add_task_actions( $data = [], $actions = [] ) {
344346
\htmlspecialchars(
345347
\wp_json_encode(
346348
[
347-
'post_title' => $task_details['post_title'],
348-
'target_term_id' => $task_data['target_term_id'],
349-
'target_taxonomy' => $task_data['target_taxonomy'],
350-
'target_term_name' => $task_data['target_term_name'],
349+
'post_title' => $task_details['post_title'],
350+
'target_term_id' => $task_data['target_term_id'],
351+
'target_taxonomy' => $task_data['target_taxonomy'],
352+
'target_taxonomy_name' => $taxonomy ? $taxonomy->label : '',
353+
'target_term_name' => $task_data['target_term_name'],
351354
]
352355
),
353356
ENT_QUOTES,
@@ -385,7 +388,14 @@ public function print_popover_form_contents() {
385388
<span id="prpl-update-term-name"></span>
386389
</p>
387390
<p style="margin: 0 0 10px 0; font-size: 12px; color: #646970;">
388-
<span id="prpl-update-term-taxonomy"></span>
391+
<?php
392+
printf(
393+
/* translators: %1$s: The taxonomy name, %2$s: The term slug */
394+
\esc_html__( 'You are updating the term which belongs to the "%1$s" (slug "%2$s").', 'progress-planner' ),
395+
'<span id="prpl-update-term-taxonomy-name"></span>',
396+
'<span id="prpl-update-term-taxonomy"></span>'
397+
);
398+
?>
389399
</p>
390400
</div>
391401
<textarea

0 commit comments

Comments
 (0)