-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathclass-tutsplus-post-notice-editor.php
More file actions
59 lines (41 loc) · 1.21 KB
/
class-tutsplus-post-notice-editor.php
File metadata and controls
59 lines (41 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
class TutsPlus_Post_Notice_Editor {
public function initialize() {
add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) );
add_action( 'save_post', array( $this, 'save_post_notice' ) );
}
public function add_meta_box() {
add_meta_box(
'tutsplus-post-notice',
'Post Notice',
array( $this, 'post_notice_display' ),
'post',
'normal',
'high'
);
}
public function post_notice_display() {
require_once(
plugin_dir_path( __FILE__ ) . 'views/tutsplus-post-notice-editor.php'
);
}
public function save_post_notice( $post_id ) {
if ( ! $this->user_can_save( $post_id ) ) {
return;
}
$post_notice = $_POST[ 'tutsplus-post-notice-editor' ];
$post_notice = stripslashes( strip_tags( $post_notice ) );
update_post_meta( $post_id, 'tutsplus-post-notice', $post_notice );
}
public function user_can_save( $post_id ) {
$is_valid_nonce =
( isset( $_POST['tutsplus-post-notice-nonce'] ) ) &&
wp_verify_nonce(
$_POST[ 'tutsplus-post-notice-nonce' ],
'tutsplus-post-notice-save'
);
$is_autosave = wp_is_post_autosave( $post_id );
$is_revision = wp_is_post_revision( $post_id );
return ! ( $is_autosave || $is_revision ) && $is_valid_nonce;
}
}