PluginProbe
Edit Flow / 0.9.9
Edit Flow v0.9.9
0.11.1 0.11.0 0.7.2 0.7.3 0.7.4 0.7.5 0.7.6 0.8 0.8.1 0.8.2 0.9 0.9.1 0.9.2 0.9.3 0.9.4 0.9.5 0.9.6 0.9.7 0.9.8 0.9.9 trunk 0.1.5 0.10.0 0.10.1 0.10.2 All 44 releases
edit-flow / modules / dashboard / widgets / dashboard-notepad.php

dashboard-notepad.php in Edit Flow 0.9.9, at modules/dashboard/widgets/dashboard-notepad.php

111 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * A notepad for the dashboard
4 */
5
6 class EF_Dashboard_Notepad_Widget {
7
8 const notepad_post_type = 'dashboard-note';
9
10 public $edit_cap = 'edit_others_posts';
11
12 function __construct() {
13 // Silence is golden
14 }
15
16 public function init() {
17
18 register_post_type( self::notepad_post_type, array(
19 'rewrite' => false,
20 'label' => __( 'Dashboard Note', 'edit-flow' )
21 )
22 );
23
24 $this->edit_cap = apply_filters( 'ef_dashboard_notepad_edit_cap', $this->edit_cap );
25
26 add_action( 'admin_init', array( $this, 'handle_notepad_update' ) );
27 }
28
29 /**
30 * Handle a dashboard note being created or updated
31 *
32 * @since 0.8
33 */
34 public function handle_notepad_update() {
35 global $pagenow;
36
37 if ( 'index.php' !== $pagenow || empty( $_POST['action'] ) || 'dashboard-notepad' !== $_POST['action'] ) {
38 return;
39 }
40
41 check_admin_referer( 'dashboard-notepad' );
42
43 if ( ! current_user_can( $this->edit_cap ) ) {
44 wp_die( EditFlow()->dashboard->messages['invalid-permissions'] );
45 }
46
47 $note_data = array(
48 'post_content' => isset( $_POST['note'] ) ? wp_filter_nohtml_kses( $_POST['note'] ) : '',
49 'post_type' => self::notepad_post_type,
50 'post_status' => 'draft',
51 'post_author' => get_current_user_id(),
52 );
53
54 $existing_notepad = isset( $_POST['notepad-id'] ) ? get_post( absint( $_POST['notepad-id'] ) ) : null;
55 if ( isset( $existing_notepad->post_type ) && self::notepad_post_type === $existing_notepad->post_type ) {
56 $note_data['ID'] = $existing_notepad->ID;
57 }
58
59 wp_insert_post( $note_data );
60 }
61
62 /**
63 * Notepad Widget
64 * Editors can leave notes in the dashboard for authors and contributors
65 *
66 * @since 0.8
67 */
68 public function notepad_widget() {
69
70 $args = array(
71 'posts_per_page' => 1,
72 'post_status' => 'draft',
73 'post_type' => self::notepad_post_type,
74 );
75 $posts = get_posts( $args );
76 $current_note = ( ! empty( $posts[0]->post_content ) ) ? $posts[0]->post_content : '';
77 $current_id = ( ! empty( $posts[0]->ID ) ) ? $posts[0]->ID : 0;
78 $current_post = ( ! empty( $posts[0] ) ) ? $posts[0] : false;
79
80 if ( $current_post )
81 $last_updated = '<span id="dashboard-notepad-last-updated">' . sprintf( __( '%1$s last updated on %2$s', 'edit-flow' ), get_user_by( 'id', $current_post->post_author )->display_name, get_the_modified_time( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $current_post ) ) . '</span>';
82 else
83 $last_updated = '';
84
85 if ( current_user_can( $this->edit_cap ) ) {
86 echo '<form method="post" id="dashboard-notepad">';
87 echo '<input type="hidden" name="action" value="dashboard-notepad" />';
88 echo '<input type="hidden" name="notepad-id" value="' . esc_attr( $current_id ) . '" />';
89 echo '<textarea style="width:100%" rows="10" name="note">';
90 echo esc_textarea( trim( $current_note ) );
91 echo '</textarea>';
92 echo '<p class="submit">';
93 echo $last_updated;
94 echo '<span id="dashboard-notepad-submit-buttons">';
95 submit_button( __( 'Update Note', 'edit-flow' ), 'primary', 'update-note', false );
96 echo '</span>';
97 echo '<div style="clear:both;"></div>';
98 wp_nonce_field( 'dashboard-notepad' );
99 echo '</form>';
100 } else {
101 echo '<form id="dashboard-notepad">';
102 echo '<textarea style="width:100%" rows="10" name="note" disabled="disabled">';
103 echo esc_textarea( trim( $current_note ) );
104 echo '</textarea>';
105 echo $last_updated;
106 echo '</form>';
107 }
108 }
109
110 }
111