Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/wp-rocket/inc/classes/admin/class-options.php

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + <?php
2 + namespace WP_Rocket\Admin;
3 +
4 + /**
5 + * Manages options using the WordPress options API.
6 + *
7 + * @since 3.0
8 + * @author Remy Perona
9 + */
10 + class Options extends Abstract_Options {
11 + /**
12 + * The prefix used by WP Rocket options.
13 + *
14 + * @since 3.0
15 + * @author Remy Perona
16 + *
17 + * @var string
18 + */
19 + private $prefix;
20 +
21 + /**
22 + * Constructor
23 + *
24 + * @since 3.0
25 + * @author Remy Perona
26 + *
27 + * @param string $prefix WP Rocket options prefix.
28 + */
29 + public function __construct( $prefix = '' ) {
30 + $this->prefix = $prefix;
31 + }
32 +
33 + /**
34 + * Gets the option name used to store the option in the WordPress database.
35 + *
36 + * @since 3.0
37 + * @author Remy Perona
38 + *
39 + * @param string $name Unprefixed name of the option.
40 + *
41 + * @return string Option name used to store it
42 + */
43 + public function get_option_name( $name ) {
44 + return $this->prefix . $name;
45 + }
46 +
47 + /**
48 + * Gets the option for the given name. Returns the default value if the value does not exist.
49 + *
50 + * @since 3.0
51 + * @author Remy Perona
52 + *
53 + * @param string $name Name of the option to get.
54 + * @param mixed $default Default value to return if the value does not exist.
55 + *
56 + * @return mixed
57 + */
58 + public function get( $name, $default = null ) {
59 + $option = get_option( $this->get_option_name( $name ), $default );
60 +
61 + if ( is_array( $default ) && ! is_array( $option ) ) {
62 + $option = (array) $option;
63 + }
64 +
65 + return $option;
66 + }
67 +
68 + /**
69 + * Sets the value of an option. Update the value if the option for the given name already exists.
70 + *
71 + * @since 3.0
72 + * @author Remy Perona
73 + * @param string $name Name of the option to set.
74 + * @param mixed $value Value to set for the option.
75 + *
76 + * @return void
77 + */
78 + public function set( $name, $value ) {
79 + update_option( $this->get_option_name( $name ), $value );
80 + }
81 +
82 + /**
83 + * Deletes the option with the given name.
84 + *
85 + * @since 3.0
86 + * @author Remy Perona
87 + *
88 + * @param string $name Name of the option to delete.
89 + *
90 + * @return void
91 + */
92 + public function delete( $name ) {
93 + delete_option( $this->get_option_name( $name ) );
94 + }
95 + }
96 +