This repository has been archived by the owner on Dec 1, 2021. It is now read-only.
forked from tmtrademark/cheezcap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
139 lines (100 loc) · 5.14 KB
/
README
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
//
// CheezCap - Cheezburger Custom Administration Panel
// (c) 2008 - 2010 Cheezburger Network (Pet Holdings, Inc.)
// LOL: http://cheezburger.com
// Source: http://github.com/cheezburger/cheezcap/
// Authors: Kyall Barrows, Toby McKes, Stefan Rusek, Scott Porad
// License: GNU General Public License, version 2 (GPL), http://www.gnu.org/licenses/gpl-2.0.html
//
##
## Quick Start
##
1. Copy the CheezCap folder into your theme directory
2. Add the follwowing line to functions.php (if you don't have a functions.php, create one in your theme directory)
require_once('cheezcap/cheezcap.php');
3. Edit cheezcap/config.php
4. Sprinkle theme options around your code, like this:
if ($cap->my_boolean_option) {
// do stuff
}
5. Enjoy!
##
## Background
##
In order to use the same Wordpress theme for many different Wordpress sites, one of the things we've
done at Cheezburger is create themes with lots and lots of theme options. CheezCap is a simple library
we've made for creating custom wp-admin panels really, really easily.
At a high level, the way it works is simple: edit the arrays in config.php in order to setup your
theme options, and then use the values from those theme options to customize your theme.
It's just that easy!
##
## Installation
##
Installation is a two step process. First, copy the CheezCap folder into your theme directory. Next,
add the following line to functions.php in your theme (if you don't have a functions.php, create one
in the root of your theme directory).
require_once('cheezcap/cheezcap.php');
Finally, to verify that CheezCap has installed correctly, simply open wp-admin and look for the
"CheezCap Settings" link on the left navigation panel toward the bottom.
##
## Configuration
##
Setting up your options happens inside config.php, and involves editing an array function
called cap_get_options(). What you will be doing is building an array that
contains "Group" objects.
A Group is a grouping of theme options. Each Group appears as a tab on your custom admin panel.
The way we have it written in config.php is that each group is instantiated inline, that is, within
in the array, although you don't have to do it that way. When you instantiate a new Group, there are
three parameters:
1. Name = will appear on the tab, should be human readable
2. ID = used internally, cannot have spaces and must be unique
3. Options Array = this is another array of options
The options array consists of Options objects. Each option represents a value that you can use to
customize your theme. (Like the groups, we instantiate these inline, but it's not required.) There
are three types of Options available to create:
1. Boolean Option
2. Text Option
3. Dropdown Option
## 1. Boolean Option
The simplest form of option...creates a true or false dropdown that can be used to turn features on or off.
new BooleanOption(Name, Description, OptionID, Default)
Name = a human readable name for the option.
Description = a human readable description for the option.
OptionID = a machine readable option identifier, cannot have spaces and must be unique
Default = a boolean describing the default value for the option; if not specified, the default is "false"
## 2. Text Option
A simple text field that can be used for configurable text, etc.
new TextOption(Name, Description, OptionID, Default, UseTextArea)
Name = a human readable name for the option.
Description = a human readable description for the option.
OptionID = a machine readable option identifier, cannot have spaces and must be unique
Default = a string as the default value for the option; if not specified, the default is ""
UseTextArea = a boolean describing if the text option should be written as a text area; if not specified, the
default is false;
## 3. Dropdown Option
Allows you to create a dropdown with custom values by passing the constructor an array of options
new DropdownOption(Name, Description, OptionID, OptionsArray, DefaultIndex)
Name = a human readable name for the option.
Description = a human readable description for the option.
OptionID = a machine readable option identifier, cannot have spaces and must be unique
OptionsArray = an array containing the values for the dropdown menu
DefaultIndex = an integer identifying the item in the array that is the default value; if not specified,
the default is 0.
##
## Usage
##
CheezCap makes it easy to access the values that are set in your custom admin pages is easy. A global
variable $cap exists to allow you to access any variable by OptionID. (Hence, the need for OptionID
to be unique.)
For example, if you have created a DropdownOption with the OptionID "my_first_dropdown" then you
would access the value of that option like so:
$cap->my_first_dropdown
For example, you might want to write that value to the screen:
echo($cap->my_first_dropdown);
And, in many cases, you will be accessing $cap from inside a function, so you will need to call
the global variable declaration in order to access $cap, like so:
function some_function() {
global $cap;
echo($cap->my_first_dropdown);
}
*/