Skip to content

Commit

Permalink
Merge pull request #49 from Emilia-Capital/develop
Browse files Browse the repository at this point in the history
v0.9.4
  • Loading branch information
jdevalk authored Jul 8, 2024
2 parents e8f49d8 + 5b8e25d commit c81b85b
Show file tree
Hide file tree
Showing 19 changed files with 328 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/playground.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ jobs:
with:
message: |
**Test on Playground**
[Test this pull request on the Playground](https://playground.wordpress.net/#{"landingPage":"/wp-admin/edit-tags.php?taxonomy=post_tag","features":{"networking":true},"steps":[{"step":"defineWpConfigConsts","consts":{"IS_PLAYGROUND_PREVIEW":true}},{"step":"login","username":"admin","password":"password"},{"step":"installPlugin","pluginZipFile":{"resource":"url","url":"https://bypass-cors.altha.workers.dev/${{ github.server_url }}/${{ github.repository }}/archive/${{ github.sha }}.zip"},"options":{"activate":true}}]}) or [download the zip](${{ github.server_url }}/${{ github.repository }}/archive/${{ github.sha }}.zip)
[Test this pull request on the Playground](https://playground.wordpress.net/#{"landingPage":"/wp-admin/admin.php?page=progress-planner","features":{"networking":true},"steps":[{"step":"defineWpConfigConsts","consts":{"IS_PLAYGROUND_PREVIEW":true}},{"step":"login","username":"admin","password":"password"},{"step":"installPlugin","pluginZipFile":{"resource":"url","url":"https://bypass-cors.altha.workers.dev/${{ github.server_url }}/${{ github.repository }}/archive/${{ github.sha }}.zip"},"options":{"activate":true}}]}) or [download the zip](${{ github.server_url }}/${{ github.repository }}/archive/${{ github.sha }}.zip)
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

## What does this plugin do?

This post explains what Progress Planner does and how to use it: [What does Progress Planner do?](https://progressplanner.com/what-does-progress-planner-do/).
This post explains what Progress Planner does and how to use it: [What does Progress Planner do?](https://prpl.fyi/explainer).

## How to install Progress Planner

You can find [installation instructions here](https://progressplanner.com/install/).
You can find [installation instructions here](https://prpl.fyi/install).

## Branches on this repository

Expand Down
27 changes: 26 additions & 1 deletion assets/css/admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ button.prpl-info-icon {
height: 100px;
}

.prpl-header-right {
display: flex;
gap: var(--prpl-padding);
align-items: center;
}

/*------------------------------------*\
Charts container.
\*------------------------------------*/
Expand Down Expand Up @@ -978,7 +984,7 @@ button.prpl-info-icon {
/*------------------------------------*\
Dashboard widget styles.
\*------------------------------------*/
#progress_planner_dashboard_widget_score .prpl-dashboard-widget {
#progress_planner_dashboard_widget_score .prpl-dashboard-widget.show-badges {
display: grid;
grid-template-columns: 1fr 1px 140px;
grid-gap: calc(var(--prpl-gap) / 2);
Expand Down Expand Up @@ -1088,3 +1094,22 @@ button.prpl-info-icon {
#prpl-dashboard-widget-todo-header p, #todo-list li {
font-size: 14px;
}

/*------------------------------------*\
Settings popup.
\*------------------------------------*/
#prpl-settings-form label {
display: block;
}

#prpl-settings-form p {
max-width: 42em;
}

#prpl-settings-form h3 {
font-size: 1.15em;
}

#prpl-settings-form button.button-primary {
margin-top: 1em;
}
21 changes: 21 additions & 0 deletions assets/js/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
document.getElementById( 'prpl-settings-form' ).addEventListener( 'submit', function( event ) {
event.preventDefault();
const form = new FormData( this );
const data = form.getAll( 'prpl-settings-post-types-include[]' );

// Save the options.
progressPlannerAjaxRequest( {
url: progressPlanner.ajaxUrl,
data: {
action: 'progress_planner_save_cpt_settings',
_ajax_nonce: progressPlanner.nonce,
include_post_types: data,
},
successAction: () => {
window.location.reload();
},
} );

document.getElementById( 'submit-include-post-types' ).disabled = true;
document.getElementById( 'submit-include-post-types' ).innerHTML = progressPlanner.l10n.saving;
} );
14 changes: 8 additions & 6 deletions classes/activities/class-content-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ class Content_Helpers {
* @return string[]
*/
public static function get_post_types_names() {
$post_types = \get_post_types( [ 'public' => true ] );
$post_types = \array_filter( $post_types, 'is_post_type_viewable' );
unset( $post_types['attachment'] );
unset( $post_types['elementor_library'] ); // Elementor templates are not a post type we want to track.

return array_keys( $post_types );
$default = [ 'post', 'page' ];
$include_post_types = \array_filter(
Settings::get( [ 'include_post_types' ], $default ),
function ( $post_type ) {
return $post_type && \post_type_exists( $post_type ) && is_post_type_viewable( $post_type );
}
);
return empty( $include_post_types ) ? $default : \array_values( $include_post_types );
}

/**
Expand Down
38 changes: 29 additions & 9 deletions classes/admin/class-dashboard-widget-score.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,24 @@ protected function get_title() {
*/
public function render_widget() {
Page::enqueue_styles();

$show_badges = (
$this->get_badge_details( 'content' )['progress']['progress'] ||
$this->get_badge_details( 'streak' )['progress']['progress']
);
?>
<div class="prpl-dashboard-widget">
<div class="prpl-dashboard-widget<?php echo ( $show_badges ) ? ' show-badges' : ''; ?>">
<div class="prpl-score-gauge">
<?php \Progress_Planner\Widgets\Website_Activity_Score::print_score_gauge( '#ffffff', '<p>' . \esc_html__( 'Website activity score', 'progress-planner' ) . '</p>' ); ?>
</div>

<div class="grid-separator"></div>

<div class="prpl-badges">
<h3><?php \esc_html_e( 'Next badges', 'progress-planner' ); ?></h3>
<?php $this->the_badge( 'content' ); ?>
<?php $this->the_badge( 'streak' ); ?>
</div>
<?php if ( $show_badges ) : ?>
<div class="grid-separator"></div>
<div class="prpl-badges">
<h3><?php \esc_html_e( 'Next badges', 'progress-planner' ); ?></h3>
<?php $this->the_badge( 'content' ); ?>
<?php $this->the_badge( 'streak' ); ?>
</div>
<?php endif; ?>
</div>

<div class="prpl-dashboard-widget-latest-activities">
Expand Down Expand Up @@ -121,6 +126,9 @@ public function render_widget() {
*/
protected function the_badge( $category = 'content' ) {
$details = $this->get_badge_details( $category );
if ( 100 <= (int) $details['progress']['progress'] ) {
return;
}
?>
<div class="prpl-badges-columns-wrapper">
<div class="prpl-badge-wrapper">
Expand Down Expand Up @@ -152,6 +160,15 @@ class="prpl-badge-gauge"
* @return array
*/
public function get_badge_details( $category = 'content' ) {
static $cached = [
'content' => false,
'streak' => false,
];

if ( $cached[ $category ] ) {
return $cached[ $category ];
}

$result = [];
$badges = [
'content' => [ 'wonderful-writer', 'bold-blogger', 'awesome-author' ],
Expand All @@ -175,6 +192,9 @@ public function get_badge_details( $category = 'content' ) {
if ( $result['progress']['progress'] > 75 ) {
$result['color'] = 'var(--prpl-color-accent-green)';
}

$cached[ $category ] = $result;

return $result;
}
}
38 changes: 38 additions & 0 deletions classes/admin/class-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public function __construct() {
private function register_hooks() {
\add_action( 'admin_menu', [ $this, 'add_page' ] );
\add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
\add_action( 'wp_ajax_progress_planner_save_cpt_settings', [ $this, 'save_cpt_settings' ] );
}

/**
Expand Down Expand Up @@ -187,6 +188,15 @@ public static function register_scripts() {
true
);

// Register the admin script for the settings popup.
\wp_register_script(
'progress-planner-settings',
PROGRESS_PLANNER_URL . '/assets/js/settings.js',
[ 'progress-planner-ajax' ],
filemtime( PROGRESS_PLANNER_DIR . '/assets/js/settings.js' ),
true
);

// Register the admin script for the page.
\wp_register_script(
'progress-planner-admin',
Expand Down Expand Up @@ -214,6 +224,15 @@ public static function register_scripts() {
// Localize the scripts.
\wp_localize_script( 'progress-planner-onboard', 'progressPlanner', $localize_data );
\wp_localize_script( 'progress-planner-admin', 'progressPlanner', $localize_data );
$localize_data_settings = array_merge(
$localize_data,
[
'l10n' => [
'saving' => \esc_html__( 'Saving...', 'progress-planner' ),
],
]
);
\wp_localize_script( 'progress-planner-settings', 'progressPlanner', $localize_data_settings );
\wp_localize_script(
'progress-planner-todo',
'progressPlannerTodo',
Expand All @@ -240,6 +259,7 @@ public static function enqueue_scripts() {
\wp_enqueue_script( 'progress-planner-onboard' );
\wp_enqueue_script( 'progress-planner-admin' );
\wp_enqueue_script( 'progress-planner-todo' );
\wp_enqueue_script( 'progress-planner-settings' );
}

/**
Expand All @@ -255,4 +275,22 @@ public static function enqueue_styles() {
filemtime( PROGRESS_PLANNER_DIR . '/assets/css/admin.css' )
);
}

/**
* Save the post types settings.
*
* @return void
*/
public function save_cpt_settings() {
\check_ajax_referer( 'progress_planner', 'nonce', false );
$include_post_types = isset( $_POST['include_post_types'] ) ? \sanitize_text_field( \wp_unslash( $_POST['include_post_types'] ) ) : 'post,page';
$include_post_types = \explode( ',', $include_post_types );
\Progress_Planner\Settings::set( 'include_post_types', $include_post_types );

\wp_send_json_success(
[
'message' => \esc_html__( 'Settings saved.', 'progress-planner' ),
]
);
}
}
9 changes: 9 additions & 0 deletions classes/badges/class-badge.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ public function register_badge() {
);
}

/**
* Get the badge ID.
*
* @return string
*/
public function get_id() {
return $this->id;
}

/**
* Get the badge name.
*
Expand Down
7 changes: 5 additions & 2 deletions classes/class-badges.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class Badges {
* @return void
*/
public static function register_badge( $badge_id, $args ) {
if ( ! isset( $args['id'] ) ) {
$args['id'] = $badge_id;
}
self::$badges[ $badge_id ] = $args;
}

Expand Down Expand Up @@ -92,7 +95,7 @@ public static function get_latest_completed_badge() {
$badge_progress = self::get_badge_progress( $badge_id );

// Skip if the badge is not completed.
if ( 100 !== $badge_progress['progress'] ) {
if ( 100 > (int) $badge_progress['progress'] ) {
continue;
}

Expand All @@ -111,7 +114,7 @@ public static function get_latest_completed_badge() {
}

// Compare dates.
if ( \DateTime::createFromFormat( 'Y-m-d H:i:s', $settings[ $badge_id ]['date'] )->format( 'U' ) > \DateTime::createFromFormat( 'Y-m-d H:i:s', $latest_date )->format( 'U' ) ) {
if ( \DateTime::createFromFormat( 'Y-m-d H:i:s', $settings[ $badge_id ]['date'] )->format( 'U' ) >= \DateTime::createFromFormat( 'Y-m-d H:i:s', $latest_date )->format( 'U' ) ) {
$latest_date = $settings[ $badge_id ]['date'];
$latest_id = $badge_id;
}
Expand Down
10 changes: 5 additions & 5 deletions classes/class-onboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static function the_form() {
printf(
/* translators: %s: progressplanner.com link */
\esc_html__( 'We would love to send you awesome emails with your progress stats. Please enter your name and email below and submit the form. You\'ll create an account on %1$s:', 'progress-planner' ),
'<a href="https://progressplanner.com" target="_blank">progressplanner.com</a>'
'<a href="https://prpl.fyi/home" target="_blank">progressplanner.com</a>'
)
?>
</div>
Expand Down Expand Up @@ -114,10 +114,10 @@ class="prpl-input"
<span class="prpl-label-content">
<?php
printf(
/* translators: %1$s: progressplanner.com link. %2$s: Link to https://progressplanner.com/onboarding-details/ with text "Learn more." */
/* translators: %1$s: progressplanner.com link. %2$s: Link with text "Learn more." */
\esc_html__( 'Create an account on %1$s, and subscribe to emails. %2$s', 'progress-planner' ),
'<a href="https://progressplanner.com" target="_blank">progressplanner.com</a>',
'<a href="https://progressplanner.com/onboarding-details/" target="_blank">' . \esc_html__( 'Learn more.', 'progress-planner' ) . '</a>'
'<a href="https://prpl.fyi/home" target="_blank">progressplanner.com</a>',
'<a href="https://prpl.fyi/onboarding" target="_blank">' . \esc_html__( 'Learn more.', 'progress-planner' ) . '</a>'
);
?>
</span>
Expand Down Expand Up @@ -149,7 +149,7 @@ class="button button-primary"
<p id="prpl-account-created-message" style="display:none;">
<?php
// translators: %s: progressplanner.com link.
printf( \esc_html__( 'Success! We created an account for you on %s so we can email you every week.', 'progress-planner' ), '<a href="https://progressplanner.com/">ProgressPlanner.com</a>' );
printf( \esc_html__( 'Success! We created an account for you on %s so we can email you every week.', 'progress-planner' ), '<a href="https://prpl.fyi/home">ProgressPlanner.com</a>' );
?>
</p>
<div id="progress-planner-scan-progress" style="display:none;">
Expand Down
14 changes: 12 additions & 2 deletions classes/popups/class-popup.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,28 @@ public function __construct() {
}

/**
* Render the widget content.
* Render the triggering button.
*
* @return void
*/
public function render() {
public function render_button() {
?>
<!-- The triggering button. -->
<button class="prpl-info-icon" popovertarget="prpl-popover-<?php echo \esc_attr( $this->id ); ?>">
<span class="dashicons dashicons-info-outline"></span>
<span class="screen-reader-text"><?php \esc_html_e( 'More info', 'progress-planner' ); ?>
</button>
<?php
}

/**
* Render the widget content.
*
* @return void
*/
public function render() {
?>
<?php $this->render_button(); ?>
<div id="prpl-popover-<?php echo \esc_attr( $this->id ); ?>" class="prpl-popover" popover>
<!-- The content. -->
<?php $this->the_content(); ?>
Expand Down
Loading

0 comments on commit c81b85b

Please sign in to comment.