-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ohryan/update-to-blocks
- Loading branch information
Showing
20 changed files
with
31,792 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"name": "ohryan-historian/historian-block", | ||
"version": "0.1.0", | ||
"title": "Historian Block", | ||
"category": "widgets", | ||
"icon": "calendar-alt", | ||
"description": "Historian surfaces old blog posts on your dashboard and as a sidebar widget.", | ||
"supports": { | ||
"html": false | ||
}, | ||
"attributes": { | ||
"title": { | ||
"type": "string", | ||
"source": "html", | ||
"selector": "h3", | ||
"default": "This week in history" | ||
} | ||
}, | ||
"textdomain": "ohryan-historian", | ||
"editorScript": "file:./index.js", | ||
"editorStyle": "file:./index.css", | ||
"style": "file:./style-index.css" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php return array('dependencies' => array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-element', 'wp-url'), 'version' => '767ee09a92d7feb25772'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.wp-block-create-block-starter-block{border:1px dotted red} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.wp-block-create-block-starter-block{background-color:#21759b;color:#fff;padding:2px} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
namespace Ohryan\Historian; | ||
use \WP_Query; | ||
|
||
class Historian { | ||
|
||
|
||
/** | ||
* Get all posts by week. | ||
* | ||
* @return WP_Query | ||
*/ | ||
private function get_posts_for_this_week_of_the_year() { | ||
return new WP_Query(array( | ||
'posts_per_page' => 25, // @todo perhaps make this configurable | ||
'post_status' => 'publish', | ||
'w' => date('W'), | ||
'date_query' => array( 'before' => date( 'Y-m-d 00:00' ),) | ||
)); | ||
|
||
} | ||
|
||
|
||
/** | ||
* Group posts by year. | ||
* | ||
* @param WP_Query $posts | ||
* | ||
* @return array | ||
*/ | ||
private function group_posts_by_year($posts) { | ||
|
||
$output = array(); | ||
|
||
if ( $posts->have_posts() ) { | ||
while ( $posts->have_posts() ) { | ||
$posts->the_post(); | ||
|
||
$post_year = get_the_date('Y'); | ||
$output[$post_year][] = array( | ||
'permalink' => get_the_permalink(), | ||
'title' => get_the_title(), | ||
); | ||
} | ||
} | ||
|
||
return $output; | ||
} | ||
|
||
/** | ||
* Output the widget. | ||
* | ||
* @return void | ||
*/ | ||
public function display_legacy_widget() { | ||
echo $this->get_widget_content(); | ||
} | ||
|
||
public function get_widget_content(){ | ||
$output = ''; | ||
$posts = $this->get_posts_for_this_week_of_the_year(); | ||
$posts_by_year = $this->group_posts_by_year( $posts ); | ||
|
||
foreach ( $posts_by_year as $year => $posts ) { | ||
$output .= "<h4>$year</h4>"; | ||
$output .= '<ul>'; | ||
array_walk($posts, function($post) use (&$output) { | ||
$output .= "<li><a href='{$post['permalink']}'>{$post['title']}</a></li>"; | ||
}); | ||
$output .= '</ul>'; | ||
} | ||
|
||
return $output; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/* | ||
Plugin Name: Historian Block | ||
Plugin URI: https://github.com/ohryan/RetroPosts | ||
Description: Historian Block provides a "this day in history" for your blog. | ||
Version: 2.0 | ||
Author: Ryan Neudorf | ||
Author URI: http://ohryan.ca/ | ||
Text Domain: ohryan-historian | ||
License: GPLv2 or later | ||
*/ | ||
namespace Ohryan\Historian; | ||
|
||
require_once 'classes/Historian-class.php'; | ||
require_once 'classes/HistorianWidget-class.php'; | ||
|
||
function historian_add_dashboard_widgets() { | ||
wp_add_dashboard_widget( | ||
'retroposts_dashboard_widget', | ||
'Historian', | ||
__NAMESPACE__.'\\historian_dashboard_widget_display' | ||
); | ||
} | ||
|
||
add_action( 'wp_dashboard_setup', __NAMESPACE__.'\\historian_add_dashboard_widgets' ); | ||
|
||
function historian_dashboard_widget_display() { | ||
$h = new Historian(); | ||
$h->display_legacy_widget(); | ||
} | ||
|
||
add_action('widgets_init', function(){ return register_widget(__NAMESPACE__."\\HistorianWidget"); }); | ||
|
||
function historian_block_render_callback($attributes, $content, $block) { | ||
return $content . (new Historian())->get_widget_content(); | ||
} | ||
|
||
function historian_block_init() { | ||
register_block_type( | ||
__DIR__ . '/build', | ||
array( | ||
'render_callback' => __NAMESPACE__ . "\\historian_block_render_callback" | ||
) | ||
); | ||
} | ||
|
||
add_action( 'init', __NAMESPACE__ . "\\historian_block_init" ); |
Oops, something went wrong.