This repository has been archived by the owner on Jul 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rcp-hollerbox.php
134 lines (102 loc) · 2.66 KB
/
rcp-hollerbox.php
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
/**
* Plugin Name: RCP + Holler Box
* Description: Custom plugin to show/hide Holler Box by status in RCP.
* Author: 79mplus
* Author URI: https://www.79mplus.com
* Version: 1.2
* Text Domain: rcp-hollerbox
* Domain Path: /languages
*/
/**
* if accessed directly, exit.
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if( ! class_exists( 'Mplus_HollerBox' ) ) :
class Mplus_HollerBox {
public static $_instance;
public $plugin_name;
public function __construct() {
self::defines();
self::includes();
self::hooks();
}
/**
* Define constants
*/
public function defines(){
define( 'MP_Holler', __FILE__ );
$this->plugin_name = 'rcp-hollerbox';
}
/**
* Includes files
*/
public function includes(){
require_once dirname( MP_Holler ) . '/includes/helper-functions.php';
}
/**
* Hooks
*/
public function hooks(){
add_action( 'rcp_metabox_additional_options_before', array( $this, 'admin_restriction_box' ) );
add_action( 'save_post', array( $this, 'save_admin_restriction_box' ) );
add_filter( 'hwp_display_notification', array( $this, 'mplus_rcp_admin_check' ), 5, 3 );
}
/**
* Checking with RCP
*/
public function mplus_rcp_admin_check($show_it, $box_id, $post_id){
if(rcp_user_can_access( get_current_user_id( ), $box_id ) && admin_check($box_id)){
return $show_it;
}else{
return false;
}
}
/**
* Adding admin restriction checkbox
*/
public function admin_restriction_box(){
global $post;
$hide_in_admin = get_post_meta(get_the_ID(), 'rcp_hide_from_admin', true);
?>
<p>
<label for="rcp-hide-in-admin">
<input type="checkbox" name="rcp_hide_from_admin" id="rcp-hide-in-admin" value="1"<?php checked( true, $hide_in_admin ); ?>/>
<?php _e( 'Hide this content from Admin.', 'rcp-hollerbox' ); ?>
</label>
</p>
<?php
}
/**
* Saving admin restriction checkbox
*/
public function save_admin_restriction_box($post_id){
$hide_in_admin = isset( $_POST['rcp_hide_from_admin'] );
if ( $hide_in_admin ) {
update_post_meta( $post_id, 'rcp_hide_from_admin', $hide_in_admin );
} else {
delete_post_meta( $post_id, 'rcp_hide_from_admin' );
}
}
/**
* Cloning is forbidden.
*/
private function __clone() { }
/**
* Unserializing instances of this class is forbidden.
*/
private function __wakeup() { }
/**
* Instantiate the plugin
*/
public static function instance() {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
}
endif;
Mplus_HollerBox::instance();