Last active
November 29, 2016 16:26
-
-
Save danielpataki/251cd71ebc2d065c1ea3 to your computer and use it in GitHub Desktop.
Goal Tracker
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
add_action( 'admin_enqueue_scripts', 'gt_post_list_style' ); | |
function gt_post_list_style() { | |
$screen = get_current_screen(); | |
if( 'edit-post' == $screen->id ) { | |
wp_enqueue_style( 'gt-post-list-style', get_stylesheet_directory_uri() . '/post-list.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
<?php | |
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' ); | |
function theme_enqueue_styles() { | |
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.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
$glasses = get_field( 'glasses_today', 3727 ); | |
if( !empty( $glasses ) ) { | |
echo "<span class='glasses'>".$glasses." glasses</span>"; | |
} |
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
function get_habit_status() { | |
global $post; | |
$habit_status = get_category_by_slug( 'habit-status' ); | |
if( empty( $habit_status ) ) { | |
return false; | |
} | |
$habit_statuses = get_categories(array( | |
"child_of" => $habit_status->term_id | |
)); | |
if( empty( $habit_statuses ) ) { | |
return false; | |
} | |
$habit_status_ids = array(); | |
$habit_list = array(); | |
foreach( $habit_statuses as $status ) { | |
$habit_list[$status->term_id] = $status; | |
$habit_status_ids[] = $status->term_id; | |
} | |
$categories = wp_get_post_categories( $post->ID ); | |
if( empty( $categories ) ) { | |
return false; | |
} | |
$shared = array_intersect( $categories, $habit_status_ids ); | |
if( empty( $shared ) ) { | |
return false; | |
} | |
$status_id = array_shift( $shared ); | |
return $habit_list[$status_id]; | |
} |
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
.glasses { | |
margin-right:1em; | |
} |
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
$habit_status = get_habit_status(); | |
if( !empty( $habit_status ) ) { | |
echo "<span class='habit-status-indicator " . $habit_status->slug . "'></span>"; | |
} |
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
.habit-status-indicator { | |
display:inline-block; | |
width:20px; | |
height:20px; | |
border-radius:40px; | |
position:absolute; | |
left:2.5%; | |
} | |
.habit-status-indicator.complete { | |
background: #3eeb4e; | |
} | |
.habit-status-indicator.incomplete { | |
background: #e66e6e; | |
} |
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
.fixed .column-categories { | |
width: 30%; | |
} |
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
include( "gt-stats.class.php" ); | |
add_action( 'widgets_init', 'gt_stat_widget_init' ); | |
function gt_stat_widget_init() { | |
register_widget( 'GT_Stats' ); | |
} |
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
add_filter('manage_post_posts_columns', 'gt_post_columns'); | |
function gt_post_columns( $defaults ) { | |
$defaults['habit_status'] = 'Habit Status'; | |
unset( $defaults['author'], $defaults['tags'], $defaults['comments'] ); | |
return $defaults; | |
} |
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
add_filter( 'the_category_list', 'gt_category_filter', 10, 2 ); | |
function gt_category_filter( $categories, $post_id ) { | |
$habit_status = get_category_by_slug( 'habit-status' ); | |
if( !empty( $habit_status ) ) { | |
foreach( $categories as $i => $category ) { | |
if( $category->parent == $habit_status->term_id ) { | |
unset( $categories[$i] ); | |
} | |
} | |
} | |
return $categories; | |
} |
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
/* | |
Theme Name: Goal Tracker | |
Theme URI: http://danielpataki.com | |
Description: A little goal tracking application built in WordPress. A child theme of Twenty Fifteen. | |
Author: Daniel Pataki | |
Author URI: http://danielpataki.com | |
Template: twentyfifteen | |
Version: 1.0.0 | |
License: GNU General Public License v2 or later | |
License URI: http://www.gnu.org/licenses/gpl-2.0.html | |
Text Domain: twentysixteen-chirstmas-edition | |
*/ |
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
function twentyfifteen_entry_meta() { | |
if ( is_sticky() && is_home() && ! is_paged() ) { | |
printf( '<span class="sticky-post">%s</span>', __( 'Featured', 'twentyfifteen' ) ); | |
} | |
$format = get_post_format(); | |
if ( current_theme_supports( 'post-formats', $format ) ) { | |
printf( '<span class="entry-format">%1$s<a href="%2$s">%3$s</a></span>', | |
sprintf( '<span class="screen-reader-text">%s </span>', _x( 'Format', 'Used before post format.', 'twentyfifteen' ) ), | |
esc_url( get_post_format_link( $format ) ), | |
get_post_format_string( $format ) | |
); | |
} | |
if ( in_array( get_post_type(), array( 'post', 'attachment' ) ) ) { | |
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>'; | |
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { | |
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>'; | |
} | |
$time_string = sprintf( $time_string, | |
esc_attr( get_the_date( 'c' ) ), | |
get_the_date(), | |
esc_attr( get_the_modified_date( 'c' ) ), | |
get_the_modified_date() | |
); | |
printf( '<span class="posted-on"><span class="screen-reader-text">%1$s </span><a href="%2$s" rel="bookmark">%3$s</a></span>', | |
_x( 'Posted on', 'Used before publish date.', 'twentyfifteen' ), | |
esc_url( get_permalink() ), | |
$time_string | |
); | |
} | |
if ( 'post' == get_post_type() ) { | |
if ( is_singular() || is_multi_author() ) { | |
printf( '<span class="byline"><span class="author vcard"><span class="screen-reader-text">%1$s </span><a class="url fn n" href="%2$s">%3$s</a></span></span>', | |
_x( 'Author', 'Used before post author name.', 'twentyfifteen' ), | |
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), | |
get_the_author() | |
); | |
} | |
$categories_list = get_the_category_list( _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfifteen' ) ); | |
if ( $categories_list && twentyfifteen_categorized_blog() ) { | |
printf( '<span class="cat-links"><span class="screen-reader-text">%1$s </span>%2$s</span>', | |
_x( 'Categories', 'Used before category names.', 'twentyfifteen' ), | |
$categories_list | |
); | |
} | |
$tags_list = get_the_tag_list( '', _x( ', ', 'Used between list items, there is a space after the comma.', 'twentyfifteen' ) ); | |
if ( $tags_list ) { | |
printf( '<span class="tags-links"><span class="screen-reader-text">%1$s </span>%2$s</span>', | |
_x( 'Tags', 'Used before tag names.', 'twentyfifteen' ), | |
$tags_list | |
); | |
} | |
} | |
if ( is_attachment() && wp_attachment_is_image() ) { | |
// Retrieve attachment metadata. | |
$metadata = wp_get_attachment_metadata(); | |
printf( '<span class="full-size-link"><span class="screen-reader-text">%1$s </span><a href="%2$s">%3$s × %4$s</a></span>', | |
_x( 'Full size', 'Used before full size attachment link.', 'twentyfifteen' ), | |
esc_url( wp_get_attachment_url() ), | |
$metadata['width'], | |
$metadata['height'] | |
); | |
} | |
} |
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
<?php | |
class GT_Stats extends WP_Widget | |
{ | |
public function __construct() | |
{ | |
$widget_details = array( | |
'classname' => 'gt_stats', | |
'description' => 'A small statistics widget for my goals' | |
); | |
parent::__construct( 'gt_stats', 'Goal Stats', $widget_details ); | |
} | |
public function form( $instance ) { | |
} | |
public function widget( $args, $instance ) { | |
} | |
} |
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
class GT_Stats extends WP_Widget | |
{ | |
public function __construct() | |
{ | |
$widget_details = array( | |
'classname' => 'gt_stats', | |
'description' => 'A small statistics widget for my goals' | |
); | |
parent::__construct( 'gt_stats', 'Goal Stats', $widget_details ); | |
} | |
public function form( $instance ) { | |
$title = ''; | |
if( !empty( $instance['title'] ) ) { | |
$title = $instance['title']; | |
} | |
?> | |
<p> | |
<label for="<?php echo $this->get_field_name( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> | |
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" /> | |
</p> | |
<?php | |
} | |
public function widget( $args, $instance ) { | |
$habit_status = get_category_by_slug( 'habit-status' ); | |
if( empty( $habit_status ) ) { | |
return false; | |
} | |
$habit_statuses = get_categories(array( | |
"child_of" => $habit_status->term_id | |
)); | |
if( !empty( $habit_statuses ) ) { | |
echo $args['before_widget']; | |
echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title']; | |
echo "<ul>"; | |
foreach( $habit_statuses as $status ) { | |
echo "<li>" . $status->name . ": " . $status->count . "</li>"; | |
} | |
echo "</ul>"; | |
echo $args['after_widget']; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment