-
Notifications
You must be signed in to change notification settings - Fork 8
/
wpsf-framework.php
155 lines (137 loc) · 5.72 KB
/
wpsf-framework.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/*-------------------------------------------------------------------------------------------------
- This file is part of the WPSF package. -
- This package is Open Source Software. For the full copyright and license -
- information, please view the LICENSE file which was distributed with this -
- source code. -
- -
- @package WPSF -
- @author Varun Sridharan <varunsridharan23@gmail.com> -
-------------------------------------------------------------------------------------------------*/
if( ! defined('ABSPATH') ) {
die ();
}
/**
* ------------------------------------------------------------------------------------------------
* WordPress-Settings-Framework Framework
* A Lightweight and easy-to-use WordPress Options Framework
*
* Copyright 2015 WordPress-Settings-Framework <info@wpsf.com>
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* ------------------------------------------------------------------------------------------------
*/
add_action('after_setup_theme', 'wpsf_framework_init');
require_once plugin_dir_path(__FILE__) . '/wpsf-framework-path.php';
if( ! function_exists("wpsf_template") ) {
/**
* @param $override_location
* @param $template_name
* @param array $args
* @return bool
*/
function wpsf_template($override_location, $template_name, $args = array()) {
if( file_exists($override_location . '/' . $template_name) ) {
$path = $override_location . '/' . $template_name;
} else if( file_exists(WPSF_DIR . '/templates/' . $template_name) ) {
$path = WPSF_DIR . '/templates/' . $template_name;
} else {
return FALSE;
}
extract($args);
include( $path );
return TRUE;
}
}
if( ! function_exists("wpsf_autoloader") ) {
/**
* @param $class
* @param bool $check
* @return bool
*/
function wpsf_autoloader($class, $check = FALSE) {
if( $class === TRUE && class_exists($class) === TRUE ) {
return TRUE;
}
if( 0 === strpos($class, 'WPSFramework_Option_') ) {
$path = strtolower(substr($class, 20));
wpsf_locate_template('fields/' . $path . '/' . $path . '.php');
} else if( 0 === strpos($class, 'WPSFramework_') ) {
$path = strtolower(substr(str_replace('_', '-', $class), 13));
include( 'classes/' . $path . '.php' );
}
return TRUE;
}
}
if( ! function_exists('wpsf_framework_init') ) {
function wpsf_framework_init() {
if( class_exists('WPSFramework') ) {
return;
}
// helpers
require_once( WPSF_DIR . '/functions/fallback.php' );
require_once( WPSF_DIR . '/functions/helpers.php' );
require_once( WPSF_DIR . '/functions/actions.php' );
require_once( WPSF_DIR . '/functions/enqueue.php' );
require_once( WPSF_DIR . '/functions/sanitize.php' );
require_once( WPSF_DIR . '/functions/validate.php' );
// classes
require_once( WPSF_DIR . '/classes/abstract.php' );
require_once( WPSF_DIR . '/classes/wpsf-ajax.php' );
require_once( WPSF_DIR . '/classes/wpsf-query.php' );
require_once( WPSF_DIR . '/classes/options.php' );
require_once( WPSF_DIR . '/classes/framework.php' );
wpsf_load_options();
wpsf_framework_widgets();
spl_autoload_register('wpsf_autoloader');
add_action('widgets_init', 'wpsf_framework_widgets', 10);
do_action("wpsf_framework_loaded");
}
}
if( ! function_exists('wpsf_framework_widgets') ) {
function wpsf_framework_widgets() {
wpsf_locate_template('classes/widget.php');
do_action('wpsf_widgets');
}
}
if( ! function_exists('wpsf_register_settings') ) {
/**
* @param string $slug
*/
function wpsf_register_settings($slug = '') {
$ex_data = get_option('_wpsf_registered_settings', TRUE);
if( ! is_array($ex_data) ) {
$ex_data = array();
}
if( ! in_array($slug, $ex_data) ) {
$ex_data[] = $slug;
}
update_option('_wpsf_registered_settings', $ex_data);
}
}
if( ! function_exists("wpsf_load_options") ) {
function wpsf_load_options() {
$ex_data = get_option('_wpsf_registered_settings', TRUE);
if( ! is_array($ex_data) ) {
$ex_data = array();
}
if( ! empty($ex_data) ) {
foreach( $ex_data as $slug ) {
$mslug = ltrim($slug, "_");
$mslug = rtrim($mslug, "_");
$data = get_option($slug, TRUE);
$data = ( ! is_array($data) ) ? array() : $data;
$GLOBALS[$mslug] = $data;
}
}
}
}