| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
namespace JP\CC\Admin\Settings; |
| 5 |
|
| 6 |
use JP\CC\Helpers; |
| 7 |
use JP\CC\Options; |
| 8 |
use JP\CC\Conditions; |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
exit; |
| 12 |
} |
| 13 |
|
| 14 |
|
| 15 |
class Restrictions { |
| 16 |
|
| 17 |
public static function init() { |
| 18 |
add_action( 'jp_cc_restriction_editor', array( __CLASS__, 'restrictions_editor' ) ); |
| 19 |
} |
| 20 |
|
| 21 |
public static function restrictions_editor() { |
| 22 |
$restrictions = Options::get( 'restrictions', array() ); |
| 23 |
|
| 24 |
$restrictions = Helpers::object_to_array( $restrictions ); |
| 25 |
|
| 26 |
// Remove array keys. |
| 27 |
$restrictions = array_values( $restrictions ); |
| 28 |
?> |
| 29 |
<script type="text/javascript"> |
| 30 |
var jp_cc_restrictions = <?php echo json_encode( $restrictions ); ?>, |
| 31 |
jp_cc_conditions = <?php echo json_encode( Conditions::instance()->get_conditions() ); ?>, |
| 32 |
jp_cc_conditions_selectlist = <?php echo json_encode( Conditions::instance()->conditions_dropdown_list() ); ?>, |
| 33 |
jp_cc_restriction_fields = <?php echo json_encode( static::fields() ); ?>; |
| 34 |
</script> |
| 35 |
|
| 36 |
<button class="add_new_restriction button" type="button"><?php _e( 'Add a Restriction', 'content-control' ); ?></button> |
| 37 |
<div class="tablenav top"> |
| 38 |
<div class="alignleft actions bulkactions"> |
| 39 |
<label for="bulk-action-selector-top" class="screen-reader-text"><?php _e( 'Select bulk action', 'content-control' ); ?></label> |
| 40 |
<select id="bulk-action-selector-top"> |
| 41 |
<option value="-1"><?php _e( 'Bulk Actions', 'content-control' ); ?></option> |
| 42 |
<option value="trash"><?php _e( 'Move to Trash', 'content-control' ); ?></option> |
| 43 |
</select> |
| 44 |
<input type="button" class="button action" value="<?php _e( 'Apply', 'content-control' ); ?>" /> |
| 45 |
</div> |
| 46 |
<br class="clear"> |
| 47 |
</div> |
| 48 |
<table id="jp-cc-restrictions" class="wp-list-table widefat fixed striped posts"> |
| 49 |
<thead> |
| 50 |
<tr> |
| 51 |
<td id="cb" class="manage-column column-cb check-column"> |
| 52 |
<label class="screen-reader-text" for="cb-select-all-1"><?php _e( 'Select All', 'content-control' ); ?></label> |
| 53 |
<input id="cb-select-all-1" type="checkbox" /> |
| 54 |
</td> |
| 55 |
<th width="60" id="priority" class="manage-column column-priority" scope="col"><?php _e( 'Priority', 'content-control' ); ?></th> |
| 56 |
<th id="title" class="manage-column column-title column-primary" scope="col"><?php _e( 'Restriction Title', 'content-control' ); ?></th> |
| 57 |
<th id="overview" class="manage-column column-overview" scope="col"><?php _e( 'Overview', 'content-control' ); ?></th> |
| 58 |
</tr> |
| 59 |
</thead> |
| 60 |
<tfoot> |
| 61 |
<tr> |
| 62 |
<td id="cb" class="manage-column column-cb check-column"> |
| 63 |
<label class="screen-reader-text" for="cb-select-all-1"><?php _e( 'Select All', 'content-control' ); ?></label> |
| 64 |
<input id="cb-select-all-1" type="checkbox" /> |
| 65 |
</td> |
| 66 |
<th id="priority" class="manage-column column-priority" scope="col"><?php _e( 'Priority', 'content-control' ); ?></th> |
| 67 |
<th id="title" class="manage-column column-title column-primary" scope="col"><?php _e( 'Restriction Title', 'content-control' ); ?></th> |
| 68 |
<th id="overview" class="manage-column column-overview" scope="col"><?php _e( 'Overview', 'content-control' ); ?></th> |
| 69 |
</tr> |
| 70 |
</tfoot> |
| 71 |
<tbody class="no-items"> |
| 72 |
<tr> |
| 73 |
<td class="colspanchange" colspan="4"><?php _e( 'No restrictions found.', 'content-control' ); ?></td> |
| 74 |
</tr> |
| 75 |
</tbody> |
| 76 |
<tbody class="has-items"> |
| 77 |
</tbody> |
| 78 |
</table> |
| 79 |
<div class="tablenav bottom"> |
| 80 |
<div class="alignleft actions bulkactions"> |
| 81 |
<label for="bulk-action-selector-bottom" class="screen-reader-text">Select bulk action</label><select name="action2" id="bulk-action-selector-bottom"> |
| 82 |
<option value="-1"><?php _e( 'Bulk Actions', 'content-control' ); ?></option> |
| 83 |
<option value="trash"><?php _e( 'Move to Trash', 'content-control' ); ?></option> |
| 84 |
</select> |
| 85 |
<input type="button" class="button action" value="<?php _e( 'Apply', 'content-control' ); ?>" /> |
| 86 |
</div> |
| 87 |
<br class="clear"> |
| 88 |
</div> |
| 89 |
<?php |
| 90 |
} |
| 91 |
|
| 92 |
public static function fields() { |
| 93 |
return array( |
| 94 |
'general' => array( |
| 95 |
array( |
| 96 |
'type' => 'text', |
| 97 |
'id' => 'title', |
| 98 |
'name' => 'title', |
| 99 |
'label' => __( 'Restriction Title', 'content-control' ), |
| 100 |
'placeholder' => __( 'Pages restricted to logged in users', 'content-control' ), |
| 101 |
'std' => '' |
| 102 |
), |
| 103 |
array( |
| 104 |
'type' => 'select', |
| 105 |
'id' => 'who', |
| 106 |
'name' => 'who', |
| 107 |
'label' => __( 'Who can see this content?', 'content-control' ), |
| 108 |
'std' => '', |
| 109 |
'options' => array( |
| 110 |
//__( "Everyone", 'content-control' ) => '', |
| 111 |
__( "Logged In Users", 'content-control' ) => 'logged_in', |
| 112 |
__( "Logged Out Users", 'content-control' ) => 'logged_out', |
| 113 |
) |
| 114 |
), |
| 115 |
array( |
| 116 |
'type' => 'multicheck', |
| 117 |
'id' => 'roles', |
| 118 |
'name' => 'roles', |
| 119 |
'label' => __( 'Choose which roles can see this content', 'content-control' ), |
| 120 |
'options' => array_flip( \JP\CC\Roles::allowed_user_roles() ), |
| 121 |
), |
| 122 |
), |
| 123 |
'protection' => array( |
| 124 |
array( |
| 125 |
'type' => 'select', |
| 126 |
'id' => 'protection_method', |
| 127 |
'name' => 'protection_method', |
| 128 |
'label' => __( 'Choose how to protect your content', 'content-control' ), |
| 129 |
'options' => array( |
| 130 |
__( 'Custom Message', 'content-control' ) => 'custom_message', |
| 131 |
__( 'Redirect', 'content-control' ) => 'redirect', |
| 132 |
), |
| 133 |
'std' => 'redirect', |
| 134 |
), |
| 135 |
array( |
| 136 |
'type' => 'checkbox', |
| 137 |
'id' => 'show_excerpts', |
| 138 |
'name' => 'show_excerpts', |
| 139 |
'classes' => 'protection_method--custom_message', |
| 140 |
'label' => __( 'Show excerpts above access denied message?', 'content-control' ), |
| 141 |
), |
| 142 |
array( |
| 143 |
'type' => 'checkbox', |
| 144 |
'id' => 'override_default_message', |
| 145 |
'name' => 'override_default_message', |
| 146 |
'classes' => 'protection_method--custom_message', |
| 147 |
'label' => __( 'Override the default message?', 'content-control' ), |
| 148 |
), |
| 149 |
array( |
| 150 |
'type' => 'editor', |
| 151 |
'id' => 'custom_message', |
| 152 |
'name' => 'custom_message', |
| 153 |
'classes' => array( |
| 154 |
'protection_method--custom_message', |
| 155 |
'override_default_message--checked', |
| 156 |
), |
| 157 |
'label' => __( 'Enter a custom message to display to restricted users', 'content-control' ), |
| 158 |
), |
| 159 |
array( |
| 160 |
'type' => 'select', |
| 161 |
'id' => 'redirect_type', |
| 162 |
'name' => 'redirect_type', |
| 163 |
'label' => __( 'Where will they be taken?', 'content-control' ), |
| 164 |
'classes' => 'protection_method--redirect', |
| 165 |
'options' => array( |
| 166 |
__( 'Login & Back', 'content-control' ) => 'login', |
| 167 |
__( 'Home Page', 'content-control' ) => 'home', |
| 168 |
__( 'Custom URL', 'content-control' ) => 'custom', |
| 169 |
), |
| 170 |
'std' => 'login', |
| 171 |
), |
| 172 |
array( |
| 173 |
'type' => 'link', |
| 174 |
'id' => 'redirect_url', |
| 175 |
'name' => 'redirect_url', |
| 176 |
'classes' => 'redirect_type--custom', |
| 177 |
'label' => __( 'Redirect URL', 'content-control' ), |
| 178 |
'placeholder' => __( 'http://example.com', 'content-control' ), |
| 179 |
'std' => '', |
| 180 |
), |
| 181 |
), |
| 182 |
'content' => array( |
| 183 |
array( |
| 184 |
'type' => 'conditions', |
| 185 |
'id' => 'conditions', |
| 186 |
'name' => 'conditions' |
| 187 |
) |
| 188 |
), |
| 189 |
); |
| 190 |
} |
| 191 |
|
| 192 |
} |
| 193 |
|