Skip to content

WIP POC - Try adding dashboard widgets #228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions classes/admin/class-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ 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' ] );
\add_action( 'wp_dashboard_setup', [ $this, 'add_dashboard_widgets' ] );
}

/**
Expand Down Expand Up @@ -192,4 +193,19 @@ public function save_cpt_settings() {
]
);
}

/**
* Add dashboard widgets.
*
* @return void
*/
public function add_dashboard_widgets() {
foreach ( $this->get_widgets() as $widget ) {
\wp_add_dashboard_widget(
$widget->get_id(),
$widget->get_title(),
[ $widget, 'render' ]
);
}
}
}
9 changes: 9 additions & 0 deletions classes/class-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ public function get_id() {
return $this->id;
}

/**
* Get the widget title.
*
* @return string
*/
public function get_title() {
return '';
}

/**
* Get the widget range.
*
Expand Down
9 changes: 9 additions & 0 deletions classes/widgets/class-activity-scores.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ final class Activity_Scores extends Widget {
*/
protected $id = 'activity-scores';

/**
* The title.
*
* @return string
*/
public function get_title() {
return \esc_html__( 'Your website activity score', 'progress-planner' );
}

/**
* The color callback.
*
Expand Down
9 changes: 9 additions & 0 deletions classes/widgets/class-badge-streak.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ final class Badge_Streak extends Widget {
*/
protected $id = 'badge-streak';

/**
* The title.
*
* @return string
*/
public function get_title() {
return \esc_html__( 'Your streak badges', 'progress-planner' );
}

/**
* Get the badge.
*
Expand Down
9 changes: 9 additions & 0 deletions classes/widgets/class-challenge.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ final class Challenge extends \Progress_Planner\Widget {
*/
protected $id = 'challenge';

/**
* The title.
*
* @return string
*/
public function get_title() {
return \esc_html__( 'Your challenge', 'progress-planner' );
}

/**
* Get the feed from the blog.
*
Expand Down
9 changes: 9 additions & 0 deletions classes/widgets/class-latest-badge.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ final class Latest_Badge extends Widget {
*/
public $endpoint;

/**
* The title.
*
* @return string
*/
public function get_title() {
return \esc_html__( 'Latest new badge!', 'progress-planner' );
}

/**
* Constructor.
*/
Expand Down
9 changes: 9 additions & 0 deletions classes/widgets/class-published-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ final class Published_Content extends Widget {
*/
protected $id = 'published-content';

/**
* The title.
*
* @return string
*/
public function get_title() {
return \esc_html__( 'Published content', 'progress-planner' );
}

/**
* Get stats for posts, by post-type.
*
Expand Down
9 changes: 9 additions & 0 deletions classes/widgets/class-suggested-tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ final class Suggested_Tasks extends Widget {
*/
protected $id = 'suggested-tasks';

/**
* The title.
*
* @return string
*/
public function get_title() {
return \esc_html__( 'Suggested tasks', 'progress-planner' );
}

/**
* Get the score.
*
Expand Down
9 changes: 9 additions & 0 deletions classes/widgets/class-todo.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ final class ToDo extends Widget {
*/
protected $id = 'todo';

/**
* The title.
*
* @return string
*/
public function get_title() {
return \esc_html__( 'ToDo list', 'progress-planner' );
}

/**
* Print the widget content.
*
Expand Down
9 changes: 9 additions & 0 deletions classes/widgets/class-whats-new.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ final class Whats_New extends Widget {
*/
protected $id = 'whats-new';

/**
* The title.
*
* @return string
*/
public function get_title() {
return \esc_html__( 'What\'s new', 'progress-planner' );
}

/**
* Get the feed from the blog.
*
Expand Down
Loading