PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / 1.5.0
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution v1.5.0
2.0.1 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.9.0 2.0.0
solid-performance / src / Performance / Config / Writers / Network_Option_Writer.php

Network_Option_Writer.php in Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution 1.5.0, at src/Performance/Config/Writers/Network_Option_Writer.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 * Writes config items to the network sitemeta table.
4 *
5 * @package SolidWP\Performance
6 */
7
8 declare( strict_types=1 );
9
10 namespace SolidWP\Performance\Config\Writers;
11
12 use RuntimeException;
13 use SolidWP\Performance\Config\Config;
14 use SolidWP\Performance\Config\Config_Loader;
15 use SolidWP\Performance\Config\Writers\Contracts\Writable;
16
17 /**
18 * Writes config items to the network sitemeta table.
19 *
20 * @package SolidWP\Performance
21 */
22 final class Network_Option_Writer implements Writable {
23
24 /**
25 * @var Config
26 */
27 private Config $config;
28
29 /**
30 * @param Config $config The config singleton.
31 */
32 public function __construct( Config $config ) {
33 $this->config = $config;
34 }
35
36 /**
37 * Save config to the sitemeta table, as long as multisite is enabled.
38 *
39 * @action solidwp/performance/config/save
40 *
41 * @throws RuntimeException If trying to save before WordPress is fully bootstrapped.
42 *
43 * @return bool
44 */
45 public function save(): bool {
46 if ( ! is_multisite() ) {
47 return false;
48 }
49
50 if ( ! function_exists( 'update_network_option' ) ) {
51 throw new RuntimeException(
52 sprintf(
53 '%s::save() was called too early in the execution. Wait until plugins_loaded has fired.',
54 Config::class
55 )
56 );
57 }
58
59 $items = $this->config->all();
60
61 return update_network_option( get_main_network_id(), Config_Loader::OPTION_KEY, $items );
62 }
63 }
64