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 / Widget.php

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

68 lines 1.4 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;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 /**
10 * Class JP\CC\Widgets
11 */
12 class Widget {
13
14 /**
15 * Retrieve data for a widget from options table.
16 *
17 * @param string $widget_id The unique ID of a widget.
18 *
19 * @return array The array of widget settings or empty array if none
20 */
21 public static function get_options( $widget_id ) {
22
23 static $options = array();
24
25 // If already loaded, return existing settings.
26 if ( ! isset( $options[ $widget_id ] ) ) {
27
28 $split_pos = strrpos( $widget_id, '-' );
29
30 if ( false === $split_pos ) {
31 return array();
32 }
33
34 $basename = substr( $widget_id, 0, $split_pos ); // Examples: "text-2" will return "text", "recent-post-2" will return "recent-post"
35 $index = substr( $widget_id, $split_pos + 1 ); // Examples: "text-2" will return "2", "recent-post-2" will return "2"
36
37 $widget_settings = get_option( 'widget_' . $basename );
38
39 if ( isset( $widget_settings[ $index ] ) ) {
40 $options[ $widget_id ] = static::parse_options( $widget_settings[ $index ] );
41 }
42
43 }
44
45 return $options[ $widget_id ];
46 }
47
48 /**
49 * Checks for & adds missing widget options to prevent errors or missing data.
50 *
51 * @param array $options
52 *
53 * @return array
54 */
55 public static function parse_options( $options = array() ) {
56
57 if ( ! is_array( $options ) ) {
58 $options = array();
59 }
60
61 return wp_parse_args( $options, array(
62 'which_users' => '',
63 'roles' => array(),
64 ) );
65 }
66
67 }
68