PluginProbe
Post Lockdown / 2.1
Post Lockdown v2.1
trunk 1.0.0 1.0.1 1.1 1.1.1 2.0 2.0.1 2.0.2 2.0.3 2.1 3.0 3.0.1 3.0.13 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 4.0 4.0.2 4.0.3 4.0.4 4.0.5 4.1.0 All 26 releases
post-lockdown / classes / class-postlockdown-adminnotice.php

class-postlockdown-adminnotice.php in Post Lockdown 2.1, at classes/class-postlockdown-adminnotice.php

60 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class PostLockdown_AdminNotice {
4 /** Query arg used to determine if an admin notice should be displayed. */
5 const QUERY_ARG = 'plstatuschange';
6
7 private $plugin_path;
8
9 public function __construct( $plugin_path ) {
10 $this->plugin_path = $plugin_path;
11 add_action( 'admin_notices', array( $this, '_output_admin_notices' ) );
12 add_filter( 'removable_query_args', array( $this, '_remove_query_arg' ) );
13 }
14
15 /**
16 * Filter for the 'redirect_post_location' hook.
17 * @see PostLockdown::_prevent_status_change()
18 *
19 * @param string $location
20 * @return string
21 */
22 public function _add_query_arg( $location ) {
23 return add_query_arg( self::QUERY_ARG, 1, $location );
24 }
25
26 /**
27 * Filter for the 'removable_query_args' hook.
28 *
29 * Adds the plugin's query arg to the array of args
30 * removed by WordPress using the JavaScript History API.
31 * @param array $args Array of query args to be removed.
32 * @return array
33 */
34 public function _remove_query_arg( $args ) {
35 $args[] = self::QUERY_ARG;
36
37 return $args;
38 }
39
40 /**
41 * Callback for the 'admin_notices' hook.
42 *
43 * Outputs the plugin's admin notices if there are any.
44 */
45 public function _output_admin_notices() {
46 $notices = array();
47
48 if ( ! empty( $_GET[ self::QUERY_ARG ] ) ) {
49 $notices[] = array(
50 'class' => 'error',
51 'message' => __( 'This post is protected by Post Lockdown and must stay published.', 'postlockdown' ),
52 );
53 }
54
55 if ( ! empty( $notices ) ) {
56 include_once( $this->plugin_path . 'view/admin-notices.php' );
57 }
58 }
59 }
60