Skip to content

Commit a2c9aac

Browse files
Merge pull request #12 from alex-storojenko/develop
ver 1.14.0
2 parents 2cfc45a + 40a6462 commit a2c9aac

File tree

9 files changed

+145
-129
lines changed

9 files changed

+145
-129
lines changed

contracts/interface-think-walk-fields.php

Lines changed: 0 additions & 14 deletions
This file was deleted.

customizer/class-think-customizer.php

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
class Think_Customizer {
1212

1313
/**
14-
* @var $instance
14+
* @var null|Think_Customizer $instance
1515
*
1616
* Container for only one exemplar of @static
1717
*
@@ -50,6 +50,7 @@ class Think_Customizer {
5050
* ],
5151
* [
5252
* 'id' => 'custom_background',
53+
* 'label' => 'Background COLOR',
5354
* 'type' => 'color',
5455
* 'selector' => '.custom-background'
5556
* ],
@@ -158,9 +159,7 @@ class Think_Customizer {
158159
protected $structure = array();
159160

160161
/** Think_Customizer constructor */
161-
protected function __construct( $structure ) {
162-
$this->structure = $structure;
163-
162+
protected function __construct() {
164163
add_action( 'customize_preview_init', function () {
165164
$this->js_for_preview();
166165
} );
@@ -170,6 +169,49 @@ protected function __construct( $structure ) {
170169
} );
171170
}
172171

172+
/**
173+
* Method returned only one exemplar of @static
174+
*
175+
* According with realization singleton
176+
*
177+
* @param array $structure @see Think_Customizer::$structure
178+
*
179+
* @return mixed
180+
*/
181+
public static function customize( array $structure ) {
182+
if ( null === static::$instance ) {
183+
static::$instance = new static();
184+
}
185+
186+
static::$instance->merge_structures( $structure );
187+
188+
return static::$instance;
189+
}
190+
191+
protected function merge_structures( array $structure ) {
192+
$this->structure = array_merge( $this->structure, $structure );
193+
194+
return $this;
195+
}
196+
197+
/**
198+
* Ban on cloning
199+
*
200+
* According with realization singleton
201+
*/
202+
private function __clone() {
203+
//
204+
}
205+
206+
/**
207+
* The ban on unserialization from outside the class
208+
*
209+
* According with realization singleton
210+
*/
211+
protected function __wakeup() {
212+
//
213+
}
214+
173215
/**
174216
* Return theme option, replace with default value if empty
175217
*
@@ -292,40 +334,5 @@ protected function get_control( $wp_customize, $setting_id, $class_args, $type =
292334
break;
293335
}
294336
}
295-
296-
/**
297-
* Method returned only one exemplar of @static
298-
*
299-
* According with realization singleton
300-
*
301-
* @param array $structure
302-
*
303-
* @return mixed
304-
*/
305-
public static function instance( array $structure ) {
306-
if ( null === static::$instance ) {
307-
static::$instance = new static( $structure );
308-
}
309-
310-
return static::$instance;
311-
}
312-
313-
/**
314-
* Ban on cloning
315-
*
316-
* According with realization singleton
317-
*/
318-
private function __clone() {
319-
//
320-
}
321-
322-
/**
323-
* The ban on unserialization from outside the class
324-
*
325-
* According with realization singleton
326-
*/
327-
protected function __wakeup() {
328-
//
329-
}
330337
}
331338
}

inputs/class-think-input-image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function render() {
2828
<div id="popup-<?= $this->id; ?>" class="wp-think-framework popup-overlay hidden">
2929
<div class="wp-think-framework popup-preview-image">
3030
<span class="wp-think-framework popup-preview-image-title">Image preview</span>
31-
<img class="wp-think-framework image" src="<?= $value ?: 'javascript:;' ?>"/>
31+
<img class="wp-think-framework image" src="<?= $value ?: '#' ?>"/>
3232
<a class="close" href="javascript:;">&times;</a>
3333
</div>
3434
</div>

metabox/class-think-metaboxes.php

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -213,27 +213,6 @@ public function get_nonce_key() {
213213
return $this->nonce_key;
214214
}
215215

216-
/**
217-
* Get fields
218-
*
219-
* @param null $metabox_id
220-
*
221-
* @return bool|array
222-
*/
223-
public function get_fields( $metabox_id = null ) {
224-
$fields = array();
225-
226-
if ( $metabox_id ) {
227-
$fields = $this->walk_fields( $this->structure[ $metabox_id ]['fields'] );
228-
} else {
229-
foreach ( $this->structure as $section_id => $section ) {
230-
$fields = array_merge( $fields, $this->walk_fields( $section['fields'] ) );
231-
}
232-
}
233-
234-
return $fields;
235-
}
236-
237216
/**
238217
* Add metabox logic
239218
*
@@ -245,7 +224,9 @@ protected function add_metabox( $id, $title, $fields ) {
245224
add_meta_box( $id, $title, function () use ( $fields ) {
246225
if ( $fields ) {
247226
foreach ( $fields as $field ) {
248-
( Think_Input_Factory::make( $this, $field ) )->render();
227+
$input = Think_Input_Factory::make( $this, $field );
228+
229+
$input->render();
249230
}
250231
}
251232
}, $this->post_type, $this->place, $this->priority );

options/class-think-options.php

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Think_Options implements Think_Input_Initiator {
4040
* 'fields' //array of fields => [
4141
* [
4242
* //id is Required. Attention! id must always be unique, otherwise the result will be unexpected.
43-
* 'id' => 'facebook'
43+
* 'id' => 'facebook',
4444
* 'label' => 'Facebook',
4545
* 'type' => 'text', //@see @input_types or wp-thinkframework/inputs classes
4646
* 'options' => [], //additional options e.g for select [$title => $value]
@@ -165,27 +165,6 @@ function () {
165165
);
166166
}
167167

168-
/**
169-
* Get fields
170-
*
171-
* @param null $section_id
172-
*
173-
* @return bool|array
174-
*/
175-
public function get_fields( $section_id = null ) {
176-
$fields = array();
177-
178-
if ( $section_id ) {
179-
$fields = $this->walk_fields( $this->structure[ $section_id ]['fields'] );
180-
} else {
181-
foreach ( $this->structure as $section_id => $section ) {
182-
$fields = array_merge( $fields, $this->walk_fields( $section['fields'] ) );
183-
}
184-
}
185-
186-
return $fields;
187-
}
188-
189168
/**
190169
* Return data from DB by input_id
191170
*
@@ -223,7 +202,9 @@ protected function add_settings() {
223202

224203
foreach ( $fields as $field ) {
225204
add_settings_field( $field['id'], $field['label'], function ( $field ) {
226-
return ( Think_Input_Factory::make( $this, $field ) )->render();
205+
$input = Think_Input_Factory::make( $this, $field );
206+
207+
return $input->render();
227208
}, $this->slug, $section_id, $field );
228209

229210
$this->register_setting( $section_id, $field );
@@ -273,7 +254,7 @@ public static function create( $structure, $title, $parent_slug = 'options-gener
273254
* @param $options_key
274255
* @param null $input_id
275256
*
276-
* @return $mixed
257+
* @return mixed
277258
*/
278259
public static function get_options( $options_key, $input_id = null ) {
279260
if ( ! $input_id ) {

options/templates/class-think-options-page-template.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ class Think_Options_Page_Template implements Think_Template {
1515
*
1616
* @throws Think_Exception_Bad_Args_For_Called_Func
1717
*
18-
* @return string|void
18+
* @return void
1919
*/
2020
public static function render( array $data ) {
21-
ob_start();
22-
2321
if ( empty( $data['slug'] ) ) {
2422
throw new Think_Exception_Bad_Args_For_Called_Func( 'Required argument "slug" don\'t exist or empty' );
2523
}
@@ -30,7 +28,8 @@ public static function render( array $data ) {
3028
<div class="wrap custom_theme_options">
3129
<h2><?= __( 'Edit Options', 'wp-think-framework' ) ?></h2>
3230

33-
<?php global $wp_settings_sections, $wp_settings_fields;
31+
<?php
32+
global $wp_settings_sections, $wp_settings_fields;
3433

3534
if ( ! isset( $wp_settings_sections[ $slug ] ) ) {
3635
return;
@@ -43,7 +42,8 @@ public static function render( array $data ) {
4342
foreach ( (array) $wp_settings_sections[ $slug ] as $id => $section ) {
4443
?><a class="nav-tab <?= ( $count === 0 ) ? 'nav-tab-active' : '' ?>" href="javascript:;"
4544
data-tab="<?= $id ?>"><?= $section['title'] ?></a>
46-
<?php $count ++;
45+
<?php
46+
$count ++;
4747
}
4848
?>
4949
</h2>
@@ -60,26 +60,24 @@ public static function render( array $data ) {
6060
if ( ! isset( $wp_settings_fields ) || ! isset( $wp_settings_fields[ $slug ] ) || ! isset( $wp_settings_fields[ $slug ][ $section['id'] ] ) ) {
6161
continue;
6262
}
63-
64-
settings_fields( $options_key . '_' . $section['id'] ); ?>
65-
63+
?>
6664
<section class="tab_content" id="<?= $id ?>">
6765
<table class="form-table">
68-
<?php do_settings_fields( $slug, $section['id'] ); ?>
66+
<?php
67+
do_settings_fields( $slug, $section['id'] );
68+
settings_fields( $options_key . '_' . $section['id'] );
69+
?>
6970
</table>
7071
</section>
72+
<?php
73+
}
7174

72-
<?php }
7375
submit_button();
7476
?>
7577
</form>
7678
</div>
7779
</div>
7880
<?php
79-
80-
$content = ob_get_contents();
81-
82-
return $content;
8381
}
8482
}
8583
}

readme.txt

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
=== wp-think-framework ===
2-
3-
Contributors: Alex Storozhenko
1+
=== WP Think Framework ===
2+
Contributors: allrain
43
Tags: wordpress-framework, theme-framework, options-framework
54

65
Requires at least: 4.0
@@ -17,20 +16,22 @@ WordPress Think Framework gives you the ability to quickly and easily create inc
1716

1817
1. Download framework from Github repo - https://github.com/alex-storojenko/wp-think-framework
1918
2. Extract and copy folder with files of framework to theme dir({wp-installation-folder}/wp-content/themes/{your-theme-directory})
20-
3. Include wp-think-framework.php to functions.php of your theme(require_once get_template_directory() . '/wp-think-framework/wp-think-framework.php')
21-
4. Create something amazing
19+
3. OR You can copy folder with framework somewhere.
20+
4. Include wp-think-framework.php to functions.php of your theme(require_once get_template_directory() . '/{wp-think-framework_root_dir}/wp-think-framework.php')
21+
5. (exclude this until wp-think-framework1.12.* version) Create instance of framework - Think_Framework::get_instance() in functions.php of your current theme;
22+
6. Create something amazing
2223

2324
== Changelog ==
2425

25-
= 1.0 - May 15 2017 =
26+
= 1.0 =
2627
* Initial release
2728
* Added server requirements and short description how to install
2829

29-
= 1.0.1 - May 15 2017 =
30+
= 1.0.1 =
3031
* Fix critical bug Think_Metaboxes::create()
3132
* Fix small bug with enqueue assets for Think_Metaboxes
3233

33-
= 1.11.9 - June 11 2017 =
34+
= 1.11.9 =
3435
* Global refactor according WordPress codestyle
3536
* Refactor include assets
3637
* Rework metabox registration
@@ -54,9 +55,14 @@ WordPress Think Framework gives you the ability to quickly and easily create inc
5455
* Refactor CSS
5556
* Fix bug preview image popup
5657

57-
= 1.12.0 - June 12 2017 =
58+
= 1.12.0 =
5859
* Change mechanism of framework installation
5960

60-
= 1.13.2 - June 13 2017 =
61+
= 1.13.2 =
6162
* Fix small bags
62-
* And Change Think_Customizer caller Think_Customizer::customizer($structure) to Think_Customizer::instance($structure)
63+
* And Change Think_Customizer caller Think_Customizer::customizer($structure) to Think_Customizer::instance($structure)
64+
65+
= 1.14.0 =
66+
* Fix small bugs
67+
* Change Think_Customizer caller Think_Customizer::customize($structure)
68+
* Add possible multiple uses Think_Customizer::customize();

0 commit comments

Comments
 (0)