PluginProbe
WP Ultimate Post Grid / 4.0.1
WP Ultimate Post Grid v4.0.1
4.1.1 trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.8 1.9 2.0 2.1 2.2 2.3 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.2 3.0.0 3.3.0 3.4.0 3.5.0 3.6.0 3.7.0 All 32 releases
wp-ultimate-post-grid / vendor / bv-settings / includes / class-bv-settings.php

class-bv-settings.php in WP Ultimate Post Grid 4.0.1, at vendor/bv-settings/includes/class-bv-settings.php

144 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The core component class.
4 *
5 * @link https://bootstrapped.ventures
6 * @since 1.0.0
7 *
8 * @package BV_Settings
9 */
10
11 /**
12 * The core component class.
13 *
14 * @since 1.0.0
15 * @package BV_Settings
16 * @author Brecht Vandersmissen <[email protected]>
17 */
18 class BV_Settings {
19 public $atts;
20 public $helpers;
21
22 /**
23 * Make sure all is set up for the component to load.
24 *
25 * @since 1.0.0
26 */
27 public function __construct( $atts = array() ) {
28 // Set defaults.
29 $atts = shortcode_atts( array(
30 'uid' => '',
31 'menu_priority' => 10,
32 'menu_title' => __( 'Settings', 'bv-settings' ),
33 'menu_parent' => 'options-general.php',
34 'page_title' => __( 'Settings', 'bv-settings' ),
35 'page_slug' => false,
36 'required_capability' => 'manage_options',
37 'settings' => array(),
38 'required_addons' => array(),
39 ), $atts );
40
41 // Make sure required fields are set.
42 $atts['uid'] = sanitize_title( $atts['uid'] );
43 if ( ! $atts['uid'] ) {
44 throw new Exception( 'You need to initialize the settings with a UID.' );
45 }
46
47 // Calculated defaults.
48 if ( ! $atts['page_slug'] ) {
49 $atts['page_slug'] = 'bv_settings_' . $atts['uid'];
50 }
51
52 // Save attributes and load helpers.
53 $this->atts = $atts;
54 $this->load_helpers();
55 }
56
57 /**
58 * Load helper classes.
59 *
60 * @since 1.0.0
61 */
62 private function load_helpers() {
63 require_once( BVS_DIR . 'includes/class-bvs-api.php' );
64 $this->helpers['api'] = new BV_API( $this );
65
66 require_once( BVS_DIR . 'includes/class-bvs-menu.php' );
67 $this->helpers['menu'] = new BV_Menu( $this );
68
69 require_once( BVS_DIR . 'includes/class-bvs-saver.php' );
70 $this->helpers['saver'] = new BV_Saver( $this );
71
72 require_once( BVS_DIR . 'includes/class-bvs-structure.php' );
73 $this->helpers['structure'] = new BV_Structure( $this );
74 }
75
76 /**
77 * Get the settings structure.
78 *
79 * @since 1.0.0
80 * @param mixed $resolve_callbacks Wether to resolve the callbacks.
81 */
82 public function get_structure( $resolve_callbacks = false ) {
83 return $this->helpers['structure']->get_structure( $resolve_callbacks );
84 }
85
86 /**
87 * Get the value for a specific setting.
88 *
89 * @since 1.0.0
90 * @param mixed $setting Setting to get the value for.
91 */
92 public function get( $setting ) {
93 return $this->helpers['structure']->get( $setting );
94 }
95
96 /**
97 * Get all the settings.
98 *
99 * @since 1.0.0
100 */
101 public function get_settings() {
102 return $this->helpers['structure']->get_settings();
103 }
104
105 /**
106 * Get all the settings with defaults if not set.
107 *
108 * @since 1.0.0
109 */
110 public function get_settings_with_defaults() {
111 return $this->helpers['structure']->get_settings_with_defaults();
112 }
113
114 /**
115 * Get the default for a specific setting.
116 *
117 * @since 1.0.0
118 * @param mixed $setting Setting to get the default for.
119 */
120 public function get_default( $setting ) {
121 return $this->helpers['structure']->get_default( $setting );
122 }
123
124 /**
125 * Get the default settings.
126 *
127 * @since 1.0.0
128 * @param boolean $force_update Wether to force an update of the cache.
129 */
130 public function get_defaults( $force_update = false ) {
131 return $this->helpers['structure']->get_defaults( $force_update );
132 }
133
134 /**
135 * Update the settings.
136 *
137 * @since 1.0.0
138 * @param array $settings_to_update Settings to update.
139 */
140 public function update_settings( $settings_to_update ) {
141 return $this->helpers['saver']->update_settings( $settings_to_update );
142 }
143 }
144