├── README.md
├── extend-widgets-bundle
├── custom-fields
│ └── better-text.class.php
├── extend-widgets-bundle.php
└── extra-widgets
│ ├── hello-world-widget
│ ├── assets
│ │ └── banner.svg
│ ├── hello-world-widget.php
│ ├── styles
│ │ └── hello-world-widget-style.less
│ └── tpl
│ │ └── hello-world-widget-template.php
│ ├── my-awesome-widget
│ ├── images
│ │ └── awesome_widget_banner.svg
│ ├── my-awesome-widget.php
│ ├── styles
│ │ └── my-awesome-widget-style.less
│ └── tpl
│ │ └── my-awesome-widget-template.php
│ └── my-custom-field-test-widget
│ └── my-custom-field-test-widget.php
└── widget-form-fields-demo
├── widget-form-fields-demo.php
└── widgets
└── widget-form-fields
└── widget-form-fields.php
/README.md:
--------------------------------------------------------------------------------
1 | Developer docs code examples
2 | ===============
3 |
4 | Some code examples for developer documentation.
5 |
6 | Here we will demonstrate various developer related concepts.
7 |
8 | >These examples are meant to demonstrate how a WordPress plugin developer may use the [SiteOrigin Widgets Bundle](https://wordpress.org/plugins/so-widgets-bundle/) plugin as a framework for creating widgets. As such, they do not function as independent plugins, but rather as an extension of the Widgets Bundle plugin. That means the Widgets Bundle plugin must be installed and activated for these examples to work.
9 |
10 | >The so-dev-examples folder is not a plugin itself, but rather a container for a collection of individual example plugins. Currently, the collection consists of only two example plugins, but we will add to these in future.
11 |
12 | >Inside so-dev-examples, the plugin folders each have the familiar plugin structure as put forth by WordPress [here](http://codex.wordpress.org/Writing_a_Plugin#Names.2C_Files.2C_and_Locations). If you copy any one of these folders into your plugins folder you should see the example widgets, assuming you have installed and activated the Widgets Bundle plugin.
13 |
--------------------------------------------------------------------------------
/extend-widgets-bundle/custom-fields/better-text.class.php:
--------------------------------------------------------------------------------
1 |
18 |
20 |
35 |
My custom label rendering
36 | render_field_description();
43 | }
44 |
45 | protected function render_after_field( $value, $instance ) {
46 | // Leave this blank so that the description is not rendered twice
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/extend-widgets-bundle/extend-widgets-bundle.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
19 |
21 |
39 |
41 |
42 |
44 | image/svg+xml
45 |
47 |
48 |
49 |
50 |
51 |
55 | Hello World!
72 |
73 |
74 |
--------------------------------------------------------------------------------
/extend-widgets-bundle/extra-widgets/hello-world-widget/hello-world-widget.php:
--------------------------------------------------------------------------------
1 | __('A hello world widget.', 'hello-world-widget-text-domain'),
18 | ),
19 | array(
20 |
21 | ),
22 | array(
23 | 'text' => array(
24 | 'type' => 'text',
25 | 'label' => __('Hello world! goes here.', 'hello-world-widget-text-domain'),
26 | 'default' => 'Hello world!'
27 | ),
28 | ),
29 | plugin_dir_path(__FILE__)
30 | );
31 | }
32 |
33 | function get_template_name($instance) {
34 | return 'hello-world-widget-template';
35 | }
36 |
37 | function get_style_name($instance) {
38 | return 'hello-world-widget-style';
39 | }
40 |
41 | }
42 |
43 | siteorigin_widget_register('hello-world-widget', __FILE__, 'Hello_World_Widget');
--------------------------------------------------------------------------------
/extend-widgets-bundle/extra-widgets/hello-world-widget/styles/hello-world-widget-style.less:
--------------------------------------------------------------------------------
1 | @import "../../../base/less/mixins";
2 | @import "path/to/some/file";
3 |
4 | @a_variable: #41a9d5;
5 |
6 | .a-class {
7 | }
--------------------------------------------------------------------------------
/extend-widgets-bundle/extra-widgets/hello-world-widget/tpl/hello-world-widget-template.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/extend-widgets-bundle/extra-widgets/my-awesome-widget/images/awesome_widget_banner.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
19 |
21 |
39 |
41 |
42 |
44 | image/svg+xml
45 |
47 |
48 |
49 |
50 |
51 |
55 | Awesome!
66 |
83 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/extend-widgets-bundle/extra-widgets/my-awesome-widget/my-awesome-widget.php:
--------------------------------------------------------------------------------
1 | __('A totally awesome widget.', 'my-awesome-widget-text-domain'),
26 | ),
27 | array(
28 |
29 | ),
30 | array(
31 | 'text' => array(
32 | 'type' => 'text',
33 | 'label' => __('Hello world! goes here.', 'my-awesome-widget-text-domain'),
34 | 'default' => 'Hello world!'
35 | ),
36 | ),
37 | plugin_dir_path(__FILE__)
38 | );
39 | }
40 |
41 | function get_template_name($instance) {
42 | return 'my-awesome-widget-template';
43 | }
44 |
45 | function get_style_name($instance) {
46 | return 'my-awesome-widget-style';
47 | }
48 | }
49 |
50 | siteorigin_widget_register('my-awesome-widget', __FILE__, 'My_Awesome_Widget');
--------------------------------------------------------------------------------
/extend-widgets-bundle/extra-widgets/my-awesome-widget/styles/my-awesome-widget-style.less:
--------------------------------------------------------------------------------
1 | @import "../../../../so-widgets-bundle/base/less/mixins";
2 |
3 | @a_variable: #bada55;
4 |
5 | .a-class {
6 | }
--------------------------------------------------------------------------------
/extend-widgets-bundle/extra-widgets/my-awesome-widget/tpl/my-awesome-widget-template.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/extend-widgets-bundle/extra-widgets/my-custom-field-test-widget/my-custom-field-test-widget.php:
--------------------------------------------------------------------------------
1 | __('A custom field widget.', 'my-custom-field-test-widget-text-domain'),
18 | ),
19 | array(
20 |
21 | ),
22 | array(
23 | 'text' => array(
24 | 'type' => 'better-text',
25 | 'my_property' => 'This is my custom property value',
26 | 'label' => __( 'A better text field.', 'my-custom-field-test-widget-text-domain' ),
27 | 'description' => __( 'A description for my custom text field.' ),
28 | 'default' => 'Some better text.'
29 | ),
30 | ),
31 | plugin_dir_path(__FILE__)
32 | );
33 | }
34 |
35 | function get_template_name($instance) {
36 | return '';
37 | }
38 |
39 | function get_style_name($instance) {
40 | return '';
41 | }
42 | }
43 |
44 | siteorigin_widget_register('my-custom-field-test-widget', __FILE__, 'My_Custom_Field_Test_Widget');
--------------------------------------------------------------------------------
/widget-form-fields-demo/widget-form-fields-demo.php:
--------------------------------------------------------------------------------
1 | array(
14 | 'type' => 'tinymce',
15 | 'label' => __( 'Visually edit, richly.', 'widget-form-fields-text-domain' ),
16 | 'default' => 'An example of a long message.It is even possible to add a few html tags.Links! ',
17 | 'rows' => 10,
18 | 'default_editor' => 'html',
19 | 'button_filters' => array(
20 | 'mce_buttons' => array( $this, 'filter_mce_buttons' ),
21 | 'mce_buttons_2' => array( $this, 'filter_mce_buttons_2' ),
22 | 'mce_buttons_3' => array( $this, 'filter_mce_buttons_3' ),
23 | 'mce_buttons_4' => array( $this, 'filter_mce_buttons_5' ),
24 | 'quicktags_settings' => array( $this, 'filter_quicktags_settings' ),
25 | ),
26 | ),
27 | 'some_text' => array(
28 | 'type' => 'text',
29 | 'label' => __( 'Some text goes here', 'widget-form-fields-text-domain' ),
30 | 'default' => 'Some default text.'
31 | ),
32 | 'some_url' => array(
33 | 'type' => 'link',
34 | 'label' => __('Some URL goes here', 'widget-form-fields-text-domain'),
35 | 'default' => 'http://www.example.com'
36 | ),
37 | 'some_color' => array(
38 | 'type' => 'color',
39 | 'label' => __( 'Choose a color', 'widget-form-fields-text-domain' ),
40 | 'default' => '#bada55'
41 | ),
42 | 'some_number' => array(
43 | 'type' => 'number',
44 | 'label' => __( 'Enter a number', 'widget-form-fields-text-domain' ),
45 | 'default' => '12654'
46 | ),
47 | 'some_long_message' => array(
48 | 'type' => 'textarea',
49 | 'label' => __( 'Type a message', 'widget-form-fields-text-domain' ),
50 | 'default' => 'An example of a long message.It is even possible to add a few html tags.Links! Strong and emphasized text.',
51 | 'rows' => 5
52 | ),
53 | 'some_number_in_a_range' => array(
54 | 'type' => 'slider',
55 | 'label' => __( 'Choose a number', 'widget-form-fields-text-domain' ),
56 | 'default' => 24,
57 | 'min' => 0,
58 | 'max' => 42
59 | ),
60 | 'some_selection' => array(
61 | 'type' => 'select',
62 | 'label' => __( 'Choose a thing from a long list of things', 'widget-form-fields-text-domain' ),
63 | 'default' => 'the_other_thing',
64 | 'options' => array(
65 | 'this_thing' => __( 'This thing', 'widget-form-fields-text-domain' ),
66 | 'that_thing' => __( 'That thing', 'widget-form-fields-text-domain' ),
67 | 'the_other_thing' => __( 'The other thing', 'widget-form-fields-text-domain' ),
68 | 'thing_1' => __( 'Thing One', 'widget-form-fields-text-domain' ),
69 | 'thing_2' => __( 'Thing Two', 'widget-form-fields-text-domain' ),
70 | 'thing_3' => __( 'Thing Three', 'widget-form-fields-text-domain' ),
71 | 'thing_4' => __( 'Thing Four', 'widget-form-fields-text-domain' ),
72 | 'thing_5' => __( 'Thing Five', 'widget-form-fields-text-domain' ),
73 | 'thing_6' => __( 'Thing Six', 'widget-form-fields-text-domain' ),
74 | 'thing_7' => __( 'Thing Seven', 'widget-form-fields-text-domain' ),
75 | 'thing_8' => __( 'Thing Eight', 'widget-form-fields-text-domain' ),
76 | 'thing_9' => __( 'Thing Nine', 'widget-form-fields-text-domain' ),
77 | 'thing_10' => __( 'Thing Ten', 'widget-form-fields-text-domain' ),
78 | )
79 | ),
80 | 'some_multiple_selection' => array(
81 | 'type' => 'select',
82 | 'label' => __( 'Choose many things from a long list of things', 'widget-form-fields-text-domain' ),
83 | 'multiple' => true,
84 | 'default' => 'the_other_thing',
85 | 'options' => array(
86 | 'this_thing' => __( 'This thing', 'widget-form-fields-text-domain' ),
87 | 'that_thing' => __( 'That thing', 'widget-form-fields-text-domain' ),
88 | 'the_other_thing' => __( 'The other thing', 'widget-form-fields-text-domain' ),
89 | 'thing_1' => __( 'Thing One', 'widget-form-fields-text-domain' ),
90 | 'thing_2' => __( 'Thing Two', 'widget-form-fields-text-domain' ),
91 | 'thing_3' => __( 'Thing Three', 'widget-form-fields-text-domain' ),
92 | 'thing_4' => __( 'Thing Four', 'widget-form-fields-text-domain' ),
93 | 'thing_5' => __( 'Thing Five', 'widget-form-fields-text-domain' ),
94 | 'thing_6' => __( 'Thing Six', 'widget-form-fields-text-domain' ),
95 | 'thing_7' => __( 'Thing Seven', 'widget-form-fields-text-domain' ),
96 | 'thing_8' => __( 'Thing Eight', 'widget-form-fields-text-domain' ),
97 | 'thing_9' => __( 'Thing Nine', 'widget-form-fields-text-domain' ),
98 | 'thing_10' => __( 'Thing Ten', 'widget-form-fields-text-domain' ),
99 | )
100 | ),
101 | 'another_selection' => array(
102 | 'type' => 'select',
103 | 'prompt' => __( 'Choose a thing from a long list of things', 'widget-form-fields-text-domain' ),
104 | 'options' => array(
105 | 'this_thing' => __( 'This thing', 'widget-form-fields-text-domain' ),
106 | 'that_thing' => __( 'That thing', 'widget-form-fields-text-domain' ),
107 | 'the_other_thing' => __( 'The other thing', 'widget-form-fields-text-domain' ),
108 | 'thing_1' => __( 'Thing One', 'widget-form-fields-text-domain' ),
109 | 'thing_2' => __( 'Thing Two', 'widget-form-fields-text-domain' ),
110 | 'thing_3' => __( 'Thing Three', 'widget-form-fields-text-domain' ),
111 | 'thing_4' => __( 'Thing Four', 'widget-form-fields-text-domain' ),
112 | 'thing_5' => __( 'Thing Five', 'widget-form-fields-text-domain' ),
113 | 'thing_6' => __( 'Thing Six', 'widget-form-fields-text-domain' ),
114 | 'thing_7' => __( 'Thing Seven', 'widget-form-fields-text-domain' ),
115 | 'thing_8' => __( 'Thing Eight', 'widget-form-fields-text-domain' ),
116 | 'thing_9' => __( 'Thing Nine', 'widget-form-fields-text-domain' ),
117 | 'thing_10' => __( 'Thing Ten', 'widget-form-fields-text-domain' ),
118 | )
119 | ),
120 | 'some_boolean' => array(
121 | 'type' => 'checkbox',
122 | 'label' => __( 'Allow this thing?', 'widget-form-fields-text-domain' ),
123 | 'default' => true
124 | ),
125 | 'radio_selection' => array(
126 | 'type' => 'radio',
127 | 'label' => __( 'Choose a thing from a short list of things', 'widget-form-fields-text-domain' ),
128 | 'default' => 'that_thing',
129 | 'options' => array(
130 | 'this_thing' => __( 'This thing', 'widget-form-fields-text-domain' ),
131 | 'that_thing' => __( 'That thing', 'widget-form-fields-text-domain' ),
132 | 'the_other_thing' => __( 'The other thing', 'widget-form-fields-text-domain' )
133 | )
134 | ),
135 | 'some_media' => array(
136 | 'type' => 'media',
137 | 'label' => __( 'Choose a media thing', 'widget-form-fields-text-domain' ),
138 | 'choose' => __( 'Choose image', 'widget-form-fields-text-domain' ),
139 | 'update' => __( 'Set image', 'widget-form-fields-text-domain' ),
140 | 'library' => 'image',//'image', 'audio', 'video', 'file'
141 | 'fallback' => true
142 | ),
143 | 'some_posts' => array(
144 | 'type' => 'posts',
145 | 'label' => __('Some posts query', 'widget-form-fields-text-domain'),
146 | ),
147 | 'a_section' => array(
148 | 'type' => 'section',
149 | 'label' => __( 'A section containing related fields.' , 'widget-form-fields-text-domain' ),
150 | 'hide' => true,
151 | 'fields' => array(
152 | 'grouped_text' => array(
153 | 'type' => 'text',
154 | 'label' => __( 'A grouped text field', 'widget-form-fields-text-domain' )
155 | ),
156 | 'grouped_checkbox' => array(
157 | 'type' => 'checkbox',
158 | 'label' => __( 'A grouped checkbox', 'widget-form-fields-text-domain' )
159 | )
160 | )
161 | ),
162 | 'a_repeater' => array(
163 | 'type' => 'repeater',
164 | 'label' => __( 'A repeating repeater.' , 'widget-form-fields-text-domain' ),
165 | 'item_name' => __( 'Repeater item', 'siteorigin-widgets' ),
166 | 'scroll_count' => 10,
167 | 'item_label' => array(
168 | 'selector' => "[id*='repeat_text']",
169 | 'update_event' => 'change',
170 | 'value_method' => 'val'
171 | ),
172 | 'fields' => array(
173 | 'repeat_text' => array(
174 | 'type' => 'text',
175 | 'label' => __( 'A text field in a repeater item.', 'widget-form-fields-text-domain' )
176 | ),
177 | 'repeat_checkbox' => array(
178 | 'type' => 'checkbox',
179 | 'label' => __( 'A checkbox in a repeater item.', 'widget-form-fields-text-domain' )
180 | )
181 | )
182 | ),
183 | 'some_widget' => array(
184 | 'type' => 'widget',
185 | 'label' => __( 'Button Widget', 'widget-form-fields-text-domain' ),
186 | 'class' => 'SiteOrigin_Widget_Button_Widget',
187 | 'hide' => true
188 | ),
189 | 'some_icon' => array(
190 | 'type' => 'icon',
191 | 'label' => __('Select an icon', 'widget-form-fields-text-domain'),
192 | ),
193 | 'some_font' => array(
194 | 'type' => 'font',
195 | 'label' => __('Select a font', 'widget-form-fields-text-domain'),
196 | ),
197 | 'some_date' => array(
198 | 'type' => 'text',
199 | 'label' => __( 'Some date goes here', 'widget-form-fields-text-domain' ),
200 | 'sanitize' => 'date',
201 | ),
202 | );
203 |
204 | add_filter( 'siteorigin_widgets_sanitize_field_date', array( $this, 'sanitize_date' ) );
205 |
206 | parent::__construct(
207 | 'widget-form-fields',
208 | __('Widget Form Fields Example', 'widget-form-fields-text-domain'),
209 | array(
210 | 'description' => __('A blank widget which simply demonstrates the use of all the widget admin form fields.', 'widget-form-fields-text-domain'),
211 | ),
212 | array(),
213 | $form_options,
214 | plugin_dir_path(__FILE__)
215 | );
216 | }
217 |
218 | function filter_mce_buttons( $buttons, $editor_id ) {
219 | if ( ( $key = array_search( 'fullscreen', $buttons ) ) !== false ||
220 | ( $key = array_search( 'dfw', $buttons ) ) !== false) {
221 | unset($buttons[$key]);
222 | }
223 | return $buttons;
224 | }
225 |
226 | function filter_mce_buttons_2( $buttons, $editor_id ) {
227 | if ( ( $key = array_search( 'fullscreen', $buttons ) ) !== false ||
228 | ( $key = array_search( 'dfw', $buttons ) ) !== false) {
229 | unset($buttons[$key]);
230 | }
231 | return $buttons;
232 | }
233 |
234 | function filter_mce_buttons_3( $buttons, $editor_id ) {
235 | if ( ( $key = array_search( 'fullscreen', $buttons ) ) !== false ||
236 | ( $key = array_search( 'dfw', $buttons ) ) !== false) {
237 | unset($buttons[$key]);
238 | }
239 | return $buttons;
240 | }
241 |
242 | function filter_mce_buttons_4( $buttons, $editor_id ) {
243 | if ( ( $key = array_search( 'fullscreen', $buttons ) ) !== false ||
244 | ( $key = array_search( 'dfw', $buttons ) ) !== false) {
245 | unset($buttons[$key]);
246 | }
247 | return $buttons;
248 | }
249 |
250 | public function quicktags_settings( $settings, $editor_id ) {
251 | $settings['buttons'] = preg_replace( '/,fullscreen/', '', $settings['buttons'] );
252 | $settings['buttons'] = preg_replace( '/,dfw/', '', $settings['buttons'] );
253 | return $settings;
254 | }
255 |
256 | function sanitize_date( $date_to_sanitize ) {
257 | // Perform custom date sanitization here.
258 | $sanitized_date = sanitize_text_field( $date_to_sanitize );
259 | return $sanitized_date;
260 | }
261 |
262 | function get_template_name($instance) {
263 | return '';
264 | }
265 |
266 | function get_style_name($instance) {
267 | return '';
268 | }
269 | }
270 |
271 | siteorigin_widget_register('widget-form-fields', __FILE__, 'Widget_Form_Fields');
--------------------------------------------------------------------------------