PluginProbe
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More / 1.1.6
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More v1.1.6
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.10 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 47 releases
content-control / classes / Site / Widgets.php

Widgets.php in Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More 1.1.6, at classes/Site/Widgets.php

64 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace JP\CC\Site;
4
5 use JP\CC\Helpers;
6 use JP\CC\Widget;
7 use JP\CC\Is;
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit;
11 }
12
13 /**
14 * Class JP\CC\Site\Widgets
15 */
16 class Widgets {
17
18 /**
19 * Initialize Widgets
20 */
21 public static function init() {
22 add_action( 'sidebars_widgets', array( __CLASS__, 'exclude_widgets' ) );
23 }
24
25 /**
26 * Checks for and excludes widgets based on their chosen options.
27 *
28 * @param array $widget_areas An array of widget areas and their widgets.
29 *
30 * @return array The modified $widget_area array.
31 */
32 public static function exclude_widgets( $widget_areas ) {
33
34 if ( is_admin() || Helpers::is_customize_preview() ) {
35 return $widget_areas;
36 }
37
38 foreach ( $widget_areas as $widget_area => $widgets ) {
39
40 if ( ! empty( $widgets ) && 'wp_inactive_widgets' != $widget_area ) {
41
42 foreach ( $widgets as $position => $widget_id ) {
43
44 $options = Widget::get_options( $widget_id );
45
46 // If not accessible then exclude this item.
47 $exclude = ! Is::accessible( $options['which_users'], $options['roles'], 'widget' );
48
49 $exclude = apply_filters( 'jp_cc_should_exclude_widget', $exclude, $options, $widget_id );
50
51 // unset non-visible item
52 if ( $exclude ) {
53 unset( $widget_areas[ $widget_area ][ $position ] );
54 }
55
56 }
57 }
58 }
59
60 return $widget_areas;
61 }
62
63 }
64