Skip to content

Commit

Permalink
Merge pull request #26 from hofmannsven/master
Browse files Browse the repository at this point in the history
Proposal for restructured dashboard widget
  • Loading branch information
flymke committed Jun 3, 2014
2 parents 4a4b520 + 13bac0f commit adcb5d9
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 80 deletions.
5 changes: 4 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
Tags: mark, mark posts, highlight, highlight posts, status, post status, overview, post overview, featured, custom posts, featured posts, post, posts
Requires at least: 3.7
Tested up to: 3.9
Stable tag: 1.0.7
Stable tag: 1.0.8
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -83,6 +83,9 @@ Visit [Mark Posts on Github](https://github.com/flymke/mark-posts)

== Changelog ==

= 1.0.8 =
* Introducing the new Dashboard Widget

= 1.0.7 =
* Bugs fixed:
* Update marker count if posts get deleted
Expand Down
30 changes: 20 additions & 10 deletions admin/assets/css/dashboard.css
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
/* Mark Posts Dashboard Widget Styles */
#markers_right_now {

h3.mark_posts_headline {
padding: 0 2% 8px 2%;
}

.markers_right_now {
overflow: hidden;
padding: 0px;
margin: 0;
padding: 0;
margin: 0 0 17px 0;
}

#markers_right_now li {
width: 50%;
float: left;
margin-bottom: 10px;
.markers_right_now:last-child {
margin-bottom: 0;
}

#markers_right_now li span {
.markers_right_now li {
width: 46%;
float: left;
padding: 8px 1% 0 1%;
margin: 0;
}

.markers_right_now li a {
line-height: 1.4em;
font-size: 13px;
}

#markers_right_now li span:before {
.markers_right_now li a:before {
font: 400 20px/1 dashicons;
content: '\f159';
speak: none;
Expand All @@ -29,4 +39,4 @@
position: relative;
-webkit-font-smoothing: antialiased;
text-decoration: none !important;
}
}
43 changes: 37 additions & 6 deletions admin/class-mark-posts-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ private function __construct() {
*/
$plugin = Mark_Posts::get_instance();
$this->plugin_slug = $plugin->get_plugin_slug();
$get_mark_posts_setup = get_option( 'mark_posts_settings' );

// Load admin style sheet and JavaScript
add_action( 'admin_enqueue_scripts', array( $this, 'mark_posts_enqueue_admin_styles' ) );
Expand All @@ -55,8 +56,15 @@ private function __construct() {
// Add the options page and menu item
add_action( 'admin_menu', array( $this, 'mark_posts_add_plugin_admin_menu' ) );

// Add dashboard
add_action( 'wp_dashboard_setup', array( $this, 'mark_posts_dashboard_widget' ) );
/**
* Add dashboard
*
* @since 1.0.8
*/
$mark_posts_dashboard = $get_mark_posts_setup['mark_posts_dashboard'];
if ( !empty($mark_posts_dashboard) ) :
add_action( 'wp_dashboard_setup', array( $this, 'mark_posts_dashboard_widget' ) );
endif;

// Add an action link pointing to the options page
$plugin_basename = plugin_basename( plugin_dir_path( __DIR__ ) . $this->plugin_slug . '.php' );
Expand All @@ -76,6 +84,8 @@ private function __construct() {
add_action( 'save_post', array( $this, 'mark_posts_save_quick_edit' ), 10, 2 );
// Save action for bulk edit
add_action( 'wp_ajax_mark_posts_save_bulk_edit', array( $this, 'mark_posts_save_bulk_edit' ) );
// Trash action
add_action( 'trash_post', array( $this, 'mark_posts_trash' ), 1, 1 );
// Delete action
add_action( 'delete_post', array( $this, 'mark_posts_delete' ), 10 );

Expand All @@ -84,9 +94,7 @@ private function __construct() {
*
* @since 1.0.0
*/
$get_mark_posts_setup = get_option( 'mark_posts_settings' );
$mark_posts_posttypes = $get_mark_posts_setup['mark_posts_posttypes'];

foreach ( $mark_posts_posttypes as $post_type ) {
add_filter( 'manage_' . $post_type . '_posts_columns', array( $this, 'mark_posts_column_head' ), 10, 2 );
add_action( 'manage_' . $post_type . '_posts_custom_column', array( $this, 'mark_posts_column_content' ), 10, 2 );
Expand Down Expand Up @@ -223,7 +231,7 @@ public function mark_posts_custom_dashboard_styles() {
echo '<style>';

foreach ( $markers as $marker ) :
echo '.mark-posts-' . $marker->slug . ' span:before { color: ' . $marker->description . '} ';
echo '.mark-posts-' . $marker->slug . ' a:before { color: ' . $marker->description . '} ';
endforeach;

echo '</style>';
Expand Down Expand Up @@ -350,10 +358,13 @@ public function mark_posts_save( $post_id ) {
// Update taxonomy count
wp_update_term_count_now();

// Clear transient dashboard stats
delete_transient( 'marker_posts_stats' );

}

/**
* Update taxonomy count if posts get deleted
* Update taxonomy count if posts get permanently deleted
*
* @since 1.0.7
*
Expand All @@ -368,9 +379,23 @@ public function mark_posts_delete ( $post_id ) {
else :
wp_set_object_terms( $post_id, NULL, 'marker' ); // clear/remove all marker from post with $post_id
endif;
// Clear transient dashboard stats
delete_transient( 'marker_posts_stats' );
endif;
}

/**
* Update dashboard stats if posts get trashed
*
* @since 1.0.7
*
* @param $post_id ID of the post e.g. '1'
*/
public function mark_posts_trash ( $post_id ) {
// Clear transient dashboard stats
delete_transient( 'marker_posts_stats' );
}

/**
* Custom quick edit box
*
Expand Down Expand Up @@ -449,6 +474,9 @@ public function mark_posts_save_quick_edit( $post_id, $post ) {
else :
wp_set_object_terms( $post_id, NULL, 'marker' ); // clear/remove all marker from post with $post_id
endif;

// Clear transient dashboard stats
delete_transient( 'marker_posts_stats' );
endif;
endforeach;
}
Expand Down Expand Up @@ -481,6 +509,9 @@ public function mark_posts_save_bulk_edit() {
// update terms
$term = get_term( $_POST[$mark_field], 'marker' );
wp_set_object_terms( $post_id, $term->name, 'marker' );

// Clear transient dashboard stats
delete_transient( 'marker_posts_stats' );
}

}
Expand Down
51 changes: 46 additions & 5 deletions admin/views/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
* Create options
*
* @since 1.0.0
* @updated 1.0.8
*/
$default_marker_post_types = array( 'posts', 'pages' );
add_option( 'default_mark_posts_posttypes', $default_marker_post_types );
add_option( 'default_mark_posts_dashboard', array( 'dashboard') );

/**
* Declare default colors
Expand Down Expand Up @@ -51,8 +53,9 @@ function mark_posts_get_marker_terms() {
* Misc functions
*
* @since 1.0.0
* @updated 1.0.8
*/
function mark_posts_misc_funtions() {
function mark_posts_misc_functions() {

// mark all posts
if ( $_SERVER["REQUEST_METHOD"] == "GET" && ISSET( $_GET['mark-all-posts-term-id'] ) ) {
Expand Down Expand Up @@ -100,19 +103,34 @@ function mark_posts_validate_form() {

if ( $_SERVER["REQUEST_METHOD"] == "POST" && isset( $_POST['submit'] ) ) {

// update marker posttypes
// get marker posttypes
if ( ISSET( $_POST['markertypes'] ) ) {
$markertypes = $_POST['markertypes'];
} else {
$markertypes = array();
}

// update post type settings
$get_mark_posts_settings = get_option( 'mark_posts_settings' );
$set_mark_posts_settings = $markertypes;
$get_mark_posts_settings['mark_posts_posttypes'] = $set_mark_posts_settings;

update_option( 'mark_posts_settings', $get_mark_posts_settings );

// get marker dashboard
if ( ISSET( $_POST['markerdashboard'] ) ) {
$markerdashboard = $_POST['markerdashboard'];
} else {
$markerdashboard = array();
}

// update dashboard settings
$get_mark_posts_settings = get_option( 'mark_posts_settings' );
$set_mark_posts_settings = $markerdashboard;
$get_mark_posts_settings['mark_posts_dashboard'] = $set_mark_posts_settings;

update_option( 'mark_posts_settings', $get_mark_posts_settings );

// news markers
$markers = explode( ",", $_POST['markers'] );
$count_markers = count( mark_posts_get_marker_terms() );
Expand Down Expand Up @@ -160,6 +178,9 @@ function mark_posts_validate_form() {

echo mark_posts_display_settings_updated();

// Clear transient dashboard stats
delete_transient( 'marker_posts_stats' );

}
}

Expand Down Expand Up @@ -198,6 +219,20 @@ function mark_posts_get_all_types() {
}
}

/**
* Get dashboard widget setup
*
* @since 1.0.8
*/
function mark_posts_dashboard() {
$option = get_option( 'mark_posts_settings' );
echo '<p><input name="markerdashboard[]" type="checkbox" value="dashboard"';
if ( !empty( $option['mark_posts_dashboard'] ) ) :
echo ' checked="checked"';
endif;
echo ' /> ' . __('Dashboard Widget', 'mark-posts') . '</p>';
}

/**
* Display all settings
*
Expand Down Expand Up @@ -286,15 +321,21 @@ function mark_posts_show_settings() {
submit_button();
?>

<hr />
<h3 class="title"><?php _e( 'Enable/Disable Dashboard Widget', 'mark-posts' ); ?></h3>

<?php
mark_posts_dashboard();
submit_button();
?>

</form>

<?php } ?>

<div class="wrap">

<?php // screen_icon(); ?>

<?php mark_posts_misc_funtions() ?>
<?php mark_posts_misc_functions() ?>

<?php mark_posts_validate_form(); ?>

Expand Down
Loading

0 comments on commit adcb5d9

Please sign in to comment.