Skip to content

Commit a6710c2

Browse files
authored
Merge branch 'develop' into ari/detect-domain-changes
2 parents 7530adc + 707f951 commit a6710c2

2 files changed

Lines changed: 38 additions & 3 deletions

File tree

assets/js/web-components/prpl-badge-progress-bar.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ customElements.define(
1717
* Observed attributes, defined the attributes that will trigger the attributeChangedCallback.
1818
*/
1919
static get observedAttributes() {
20-
return [ 'data-badge-id', 'data-points', 'data-max-points' ];
20+
return [
21+
'data-badge-id',
22+
'data-points',
23+
'data-max-points',
24+
'data-branding-id',
25+
];
2126
}
2227

2328
/**
@@ -32,6 +37,9 @@ customElements.define(
3237
maxPoints: parseInt(
3338
this.getAttribute( 'data-max-points' ) || 10
3439
),
40+
brandingId: parseInt(
41+
this.getAttribute( 'data-branding-id' ) || 0
42+
),
3543
};
3644
}
3745

@@ -70,6 +78,10 @@ customElements.define(
7078
* Get the progress percent.
7179
*/
7280
get progressPercent() {
81+
// Prevent division by zero.
82+
if ( 0 === this.maxPoints ) {
83+
return 0;
84+
}
7385
return ( this.points / this.maxPoints ) * 100;
7486
}
7587

@@ -98,8 +110,14 @@ customElements.define(
98110
// Convert kebab-case to camelCase
99111
.replace( /-([a-z])/g, ( _, chr ) => chr.toUpperCase() );
100112

101-
// Update state.
102-
this.state[ camelCaseName ] = newVal;
113+
// Update state with proper type conversion.
114+
this.state[ camelCaseName ] = [
115+
'points',
116+
'maxPoints',
117+
'brandingId',
118+
].includes( camelCaseName )
119+
? parseInt( newVal || 0 )
120+
: newVal;
103121

104122
// Update progress.
105123
this.updateProgress();

classes/utils/class-playground.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function __construct() {
2020
\add_action( 'plugins_loaded', [ $this, 'enable_debug_tools' ], 1 );
2121
\add_filter( 'progress_planner_tasks_show_ui', '__return_true' );
2222
\add_action( 'admin_footer', [ $this, 'inject_playground_js_patch' ] );
23+
\add_action( 'init', [ $this, 'disable_upgrade_tasks_popover' ], 101 );
2324
}
2425

2526
/**
@@ -54,6 +55,22 @@ public function register_hooks() {
5455
\progress_planner()->get_settings()->set( 'activation_date', ( new \DateTime() )->modify( '-2 months' )->format( 'Y-m-d' ) );
5556
}
5657

58+
/**
59+
* Disable the upgrade tasks popover.
60+
*
61+
* @return void
62+
*/
63+
public function disable_upgrade_tasks_popover() {
64+
// This will make the plugin think it was activated, so the upgrade tasks popover will not be shown.
65+
$onboard_task_provider_ids = \apply_filters( 'prpl_onboarding_task_providers', [] );
66+
67+
// Update 'progress_planner_previous_version_task_providers' option.
68+
\update_option( 'progress_planner_previous_version_task_providers', \array_unique( $onboard_task_provider_ids ), SORT_REGULAR );
69+
70+
// Clear the upgrade popover task provider IDs, this are the 'newly' added task providers, so the upgrade tasks popover will not be shown.
71+
\update_option( 'progress_planner_upgrade_popover_task_provider_ids', [] );
72+
}
73+
5774
/**
5875
* Enable debug tools.
5976
*

0 commit comments

Comments
 (0)