PluginProbe
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More / 2.0.12
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More v2.0.12
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 / inc / functions / options.php

options.php in Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More 2.0.12, at inc/functions/options.php

139 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Option functions.
4 *
5 * @package ContentControl
6 */
7
8 namespace ContentControl;
9
10 /**
11 * Get all options
12 *
13 * @return array<string,mixed>
14 */
15 function get_all_plugin_options() {
16 return plugin( 'options' )->get_all();
17 }
18
19 /**
20 * Get an option
21 *
22 * Looks to see if the specified setting exists, returns default if not
23 *
24 * @param string $key Option key.
25 * @param mixed|bool $default_value Default value.
26 *
27 * @return mixed|void
28 */
29 function get_plugin_option( $key, $default_value = false ) {
30 return plugin( 'options' )->get( $key, $default_value );
31 }
32
33 /**
34 * Update an option
35 *
36 * Updates an setting value in both the db and the global variable.
37 * Warning: Passing in an empty, false or null string value will remove
38 * the key from the _options array.
39 *
40 * @param string $key The Key to update.
41 * @param string|bool|int $value The value to set the key to.
42 *
43 * @return boolean True if updated, false if not.
44 */
45 function update_plugin_option( $key = '', $value = false ) {
46 return plugin( 'options' )->update( $key, $value );
47 }
48
49 /**
50 * Update many values at once.
51 *
52 * @param array<string,mixed> $new_options Array of new replacement options.
53 *
54 * @return bool
55 */
56 function update_plugin_options( $new_options = [] ) {
57 return plugin( 'options' )->update_many( $new_options );
58 }
59
60 /**
61 * Remove an option
62 *
63 * @param string|string[] $keys Can be a single string or array of option keys.
64 *
65 * @return boolean True if updated, false if not.
66 */
67 function delete_plugin_options( $keys = '' ) {
68 return plugin( 'options' )->delete( $keys );
69 }
70
71 /**
72 * Get index of blockTypes.
73 *
74 * @return array<array{name:string,category:string,description:string,keywords:string[],title:string}>
75 */
76 function get_block_types() {
77 return \get_option( 'content_control_known_blockTypes', [] );
78 }
79
80 /**
81 * Sanitize expetced block type data.
82 *
83 * @param array<string,string|string[]> $type Block type definition.
84 * @return array<string,mixed> Sanitized definition.
85 */
86 function sanitize_block_type( $type = [] ) {
87 foreach ( $type as $key => $value ) {
88 $type[ $key ] = is_array( $value )
89 ? sanitize_block_type( $value )
90 : \sanitize_text_field( $value );
91 }
92
93 return $type;
94 }
95
96 /**
97 * Update block type list.
98 *
99 * @param array<array{name:string,category:string,description:string,keywords:string[],title:string}> $incoming_block_types Array of updated block type declarations.
100 *
101 * @return void
102 */
103 function update_block_types( $incoming_block_types = [] ) {
104 $block_types = [];
105
106 // Convert to a named index for deduplication.
107 foreach ( get_block_types() as $type ) {
108 $block_types[ $type['name'] ] = $type;
109 }
110
111 // Add or update incoming block types into the array.
112 foreach ( $incoming_block_types as $type ) {
113 // Sanitize each new block type.
114 $block_types[ $type['name'] ] = $type;
115 }
116
117 // Flatten values to a simple array for storage.
118 $block_types = array_values( $block_types );
119
120 \update_option( 'content_control_known_blockTypes', $block_types );
121 }
122
123 /**
124 * Get default denial message.
125 *
126 * @return string
127 */
128 function get_default_denial_message() {
129 if ( \ContentControl\get_data_version( 'settings' ) === 1 ) {
130 $settings = get_plugin_option( 'jp_cc_settings', [] );
131
132 return isset( $settings['default_denial_message'] ) ? $settings['default_denial_message'] : '';
133 }
134
135 $default = __( 'This content is restricted.', 'content-control' );
136
137 return get_plugin_option( 'defaultDenialMessage', $default );
138 }
139