| @@ -9,9 +9,9 @@ | ||
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * Get all options |
| 12 | 12 | * |
| 13 | - * @return array | |
| 13 | + * @return array<string,mixed> | |
| 14 | 14 | */ |
| 15 | 15 | function get_all_plugin_options() { |
| 16 | 16 | return plugin( 'options' )->get_all(); |
| 17 | 17 | } |
| @@ -48,9 +48,9 @@ | ||
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * Update many values at once. |
| 51 | 51 | * |
| 52 | - * @param array $new_options Array of new replacement options. | |
| 52 | + * @param array<string,mixed> $new_options Array of new replacement options. | |
| 53 | 53 | * |
| 54 | 54 | * @return bool |
| 55 | 55 | */ |
| 56 | 56 | function update_plugin_options( $new_options = [] ) { |
| @@ -70,9 +70,9 @@ | ||
| 70 | 70 | |
| 71 | 71 | /** |
| 72 | 72 | * Get index of blockTypes. |
| 73 | 73 | * |
| 74 | - * @return array | |
| 74 | + * @return array<array{name:string,category:string,description:string,keywords:string[],title:string}> | |
| 75 | 75 | */ |
| 76 | 76 | function get_block_types() { |
| 77 | 77 | return \get_option( 'content_control_known_blockTypes', [] ); |
| 78 | 78 | } |
| @@ -77,13 +77,38 @@ | ||
| 77 | 77 | return \get_option( 'content_control_known_blockTypes', [] ); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
| 81 | - * Sanitize expeced block type data. | |
| 81 | + * Delete block types cache. | |
| 82 | 82 | * |
| 83 | - * @param array $type Block type definition. | |
| 84 | - * @return array Sanitized definition. | |
| 83 | + * @return void | |
| 85 | 84 | */ |
| 85 | +function delete_block_types_cache() { | |
| 86 | + \delete_option( 'content_control_known_blockTypes' ); | |
| 87 | +} | |
| 88 | + | |
| 89 | +/** | |
| 90 | + * Purge block types cache on update. | |
| 91 | + * | |
| 92 | + * @param string $old_version The old version. | |
| 93 | + * @param string $new_version The new version. | |
| 94 | + * | |
| 95 | + * @return void | |
| 96 | + */ | |
| 97 | +function purge_block_types_cache_on_update( $old_version, $new_version ) { | |
| 98 | + if ( version_compare( '2.5.0', $new_version, '>=' ) && version_compare( $old_version, '2.5.0', '<' ) ) { | |
| 99 | + delete_block_types_cache(); | |
| 100 | + } | |
| 101 | +} | |
| 102 | + | |
| 103 | +add_action( 'content_control/update_version', __NAMESPACE__ . '\\purge_block_types_cache_on_update', 10, 2 ); | |
| 104 | + | |
| 105 | +/** | |
| 106 | + * Sanitize expetced block type data. | |
| 107 | + * | |
| 108 | + * @param array<string,string|string[]> $type Block type definition. | |
| 109 | + * @return array<string,mixed> Sanitized definition. | |
| 110 | + */ | |
| 86 | 111 | function sanitize_block_type( $type = [] ) { |
| 87 | 112 | foreach ( $type as $key => $value ) { |
| 88 | 113 | $type[ $key ] = is_array( $value ) |
| 89 | 114 | ? sanitize_block_type( $value ) |
| @@ -95,9 +120,11 @@ | ||
| 95 | 120 | |
| 96 | 121 | /** |
| 97 | 122 | * Update block type list. |
| 98 | 123 | * |
| 99 | - * @param array $incoming_block_types Array of updated block type declarations. | |
| 124 | + * @param array<array{name:string,category:string,description:string,keywords:string[],title:string}> $incoming_block_types Array of updated block type declarations. | |
| 125 | + * | |
| 126 | + * @return void | |
| 100 | 127 | */ |
| 101 | 128 | function update_block_types( $incoming_block_types = [] ) { |
| 102 | 129 | $block_types = []; |
| 103 | 130 | |
| @@ -114,9 +141,9 @@ | ||
| 114 | 141 | |
| 115 | 142 | // Flatten values to a simple array for storage. |
| 116 | 143 | $block_types = array_values( $block_types ); |
| 117 | 144 | |
| 118 | - \update_option( 'content_control_known_blockTypes', $block_types ); | |
| 145 | + \update_option( 'content_control_known_blockTypes', $block_types, false ); | |
| 119 | 146 | } |
| 120 | 147 | |
| 121 | 148 | /** |
| 122 | 149 | * Get default denial message. |
| @@ -129,6 +156,8 @@ | ||
| 129 | 156 | |
| 130 | 157 | return isset( $settings['default_denial_message'] ) ? $settings['default_denial_message'] : ''; |
| 131 | 158 | } |
| 132 | 159 | |
| 133 | - return get_plugin_option( 'defaultDenialMessage', '' ); | |
| 160 | + $default = __( 'This content is restricted.', 'content-control' ); | |
| 161 | + | |
| 162 | + return get_plugin_option( 'defaultDenialMessage', $default ); | |
| 134 | 163 | } |