Homepage Control - Version 2.0.0

Version Description

  • 2015-04-28
  • Removed custom admin page and moved Homepage Control to the WordPress Customizer in Appearance > Customizer.
Download this release

Release Info

Developer tiagonoronha
Plugin Icon wp plugin Homepage Control
Version 2.0.0
Comparing to
See all releases

Code changes from version 1.0.0 to 2.0.0

assets/css/settings.css CHANGED
@@ -1,43 +1,51 @@
1
- .homepage-control-wrap .ui-sortable-placeholder {
2
- background: #EBEBEB;
3
- border: 1px dashed #DDDDDD;
4
- visibility: visible !important;
5
- margin: 3px;
6
  }
7
- .homepage-control-wrap .wp-list-table .item-row:hover {
8
- cursor: move;
 
 
 
 
 
 
 
 
9
  }
10
- .homepage-control-wrap td {
11
- vertical-align: middle;
12
- overflow: hidden;
13
- zoom: 1;
14
- line-height: 16px;
15
  }
16
- .homepage-control-wrap .disabled .visibility:before {
17
- content: "";
 
 
 
 
 
 
 
 
 
 
 
18
  }
19
- .homepage-control-wrap .visibility {
20
- display: inline-block;
21
- width: 16px;
22
- height: 16px;
23
- position: relative;
24
- font-size: 0;
25
- cursor: pointer;
26
- border: 1px solid #ddd;
27
- background-color: #fff;
28
- float: left;
29
- margin-right: 9px;
30
- border-radius: 2px;
31
- }
32
- .homepage-control-wrap .visibility:before {
33
- -webkit-font-smoothing: antialiased;
34
- font: normal 14px/1 'dashicons';
35
- content: "\f147";
36
- position: absolute;
37
- top: 0;
38
- left: 0;
39
- right: 0;
40
- bottom: 0;
41
- line-height: 16px;
42
- text-align: center;
43
  }
 
 
 
 
1
+ ul.homepage-control {
2
+ margin-top: 15px;
 
 
 
3
  }
4
+
5
+ ul.homepage-control li {
6
+ padding: 13px 15px;
7
+ background: #fafafa;
8
+ color: #222;
9
+ font-size: 13px;
10
+ font-weight: 600;
11
+ border: 1px solid #e5e5e5;
12
+ cursor: move;
13
+ line-height: 16px;
14
  }
15
+
16
+ ul.homepage-control li:hover {
17
+ border-color: #999;
18
+ -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.1);
19
+ box-shadow: 0 1px 2px rgba(0,0,0,.1);
20
  }
21
+
22
+ ul.homepage-control li .visibility {
23
+ display: inline-block;
24
+ width: 16px;
25
+ height: 16px;
26
+ position: relative;
27
+ font-size: 0;
28
+ cursor: pointer;
29
+ border: 1px solid #ddd;
30
+ background-color: #fff;
31
+ float: left;
32
+ margin-right: 12px;
33
+ border-radius: 2px;
34
  }
35
+
36
+ ul.homepage-control li .visibility:before {
37
+ -webkit-font-smoothing: antialiased;
38
+ font: normal 14px/1 'dashicons';
39
+ content: "\f147";
40
+ position: absolute;
41
+ top: 0;
42
+ left: 0;
43
+ right: 0;
44
+ bottom: 0;
45
+ line-height: 16px;
46
+ text-align: center;
 
 
 
 
 
 
 
 
 
 
 
 
47
  }
48
+
49
+ ul.homepage-control li.disabled .visibility:before {
50
+ content: "";
51
+ }
assets/css/settings.less DELETED
@@ -1,58 +0,0 @@
1
- .homepage-control-wrap {
2
- .ui-sortable-placeholder {
3
- background: #EBEBEB;
4
- border: 1px dashed #DDDDDD;
5
- visibility: visible !important;
6
- margin: 3px;
7
- }
8
-
9
- .wp-list-table {
10
- .item-row {
11
- &:hover {
12
- cursor: move;
13
- }
14
- }
15
- }
16
-
17
- td {
18
- vertical-align: middle;
19
- overflow: hidden;
20
- zoom: 1;
21
- line-height: 16px;
22
- }
23
-
24
- .disabled {
25
- .visibility {
26
- &:before {
27
- content: "";
28
- }
29
- }
30
- }
31
-
32
- .visibility {
33
- display: inline-block;
34
- width: 16px;
35
- height: 16px;
36
- position: relative;
37
- font-size: 0;
38
- cursor: pointer;
39
- border: 1px solid #ddd;
40
- background-color: #fff;
41
- float: left;
42
- margin-right: 9px;
43
- border-radius: 2px;
44
-
45
- &:before {
46
- -webkit-font-smoothing: antialiased;
47
- font: normal 14px/1 'dashicons';
48
- content: "\f147";
49
- position: absolute;
50
- top: 0;
51
- left: 0;
52
- right: 0;
53
- bottom: 0;
54
- line-height: 16px;
55
- text-align: center;
56
- }
57
- }
58
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/js/sortables.js CHANGED
@@ -1,28 +1,41 @@
1
- jQuery( document ).ready( function ( e ) {
2
- jQuery( '.homepage-control-wrap tbody' ).sortable();
3
- jQuery( '.homepage-control-wrap tbody' ).disableSelection();
 
4
 
5
- jQuery( '.homepage-control-wrap tbody' ).bind( 'sortstop', function ( e, ui ) {
6
- var orderString = '';
 
7
 
8
- jQuery( e.target ).find( 'tr' ).each( function ( i, e ) {
9
- if ( i > 0 ) { orderString += ','; }
10
- orderString += jQuery( this ).attr( 'id' );
 
 
 
11
  });
12
 
13
- jQuery( 'input[id="component_order"]' ).attr( 'value', orderString );
 
 
14
  });
15
 
16
- jQuery( '.homepage-control-wrap .visibility' ).bind( 'click', function ( e ) {
17
- var disabledString = '';
 
18
 
19
- jQuery( this ).parents( 'tr.item-row' ).toggleClass( 'disabled' );
20
 
21
- jQuery( this ).parents( '.homepage-control-wrap' ).find( 'tr.disabled' ).each( function ( i, e ) {
22
- if ( i > 0 ) { disabledString += ','; }
23
- disabledString += jQuery( this ).attr( 'id' );
 
 
 
24
  });
25
 
26
- jQuery( 'input[id="disabled_components"]' ).attr( 'value', disabledString );
 
 
27
  });
28
  });
1
+ jQuery(document).ready(function($) {
2
+ "use strict";
3
+ $( '.homepage-control' ).sortable();
4
+ $( '.homepage-control' ).disableSelection();
5
 
6
+ $( '.homepage-control' ).bind( 'sortstop', function ( e, ui ) {
7
+ var components = new Array();
8
+ var disabled = '[disabled]';
9
 
10
+ $( e.target ).find( 'li' ).each( function ( i, e ) {
11
+ if ( $( this ).hasClass( 'disabled' ) ) {
12
+ components.push( disabled + $( this ).attr( 'id' ) );
13
+ } else {
14
+ components.push( $( this ).attr( 'id' ) );
15
+ }
16
  });
17
 
18
+ components = components.join( ',' );
19
+
20
+ $( 'input[data-customize-setting-link="homepage_control"]' ).attr( 'value', components ).trigger( 'change' );
21
  });
22
 
23
+ $( '.homepage-control .visibility' ).bind( 'click', function ( e ) {
24
+ var components = new Array();
25
+ var disabled = '[disabled]';
26
 
27
+ $( this ).parent( 'li' ).toggleClass( 'disabled' );
28
 
29
+ $( this ).parents( '.homepage-control' ).find( 'li' ).each( function ( i, e ) {
30
+ if ( $( this ).hasClass( 'disabled' ) ) {
31
+ components.push( disabled + $( this ).attr( 'id' ) );
32
+ } else {
33
+ components.push( $( this ).attr( 'id' ) );
34
+ }
35
  });
36
 
37
+ components = components.join( ',' );
38
+
39
+ $( 'input[data-customize-setting-link="homepage_control"]' ).attr( 'value', components ).trigger( 'change' );
40
  });
41
  });
classes/class-homepage-control-admin.php DELETED
@@ -1,268 +0,0 @@
1
- <?php
2
- if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly.
3
-
4
- /**
5
- * Homepage_Control_Admin Class
6
- *
7
- * All functionality pertaining to the homepage control administration interface.
8
- *
9
- * @package WordPress
10
- * @subpackage Homepage_Control
11
- * @category Plugin
12
- * @author Matty
13
- * @since 1.0.0
14
- */
15
- class Homepage_Control_Admin {
16
- /**
17
- * Constructor function.
18
- * @access public
19
- * @since 1.0.0
20
- * @return void
21
- */
22
- public function __construct () {
23
- add_action( 'admin_menu', array( $this, 'register_settings_screen' ), 15 );
24
- add_action( 'admin_init', array( $this, 'register_settings' ) );
25
- // Register necessary scripts and styles, to enable others to enqueue them at will as well.
26
- add_action( 'admin_init', array( $this, 'register_enqueues' ) );
27
-
28
- add_action( 'admin_notices', array( $this, 'settings_notices' ) );
29
- } // End __construct()
30
-
31
- /**
32
- * Register the admin screen.
33
- * @access public
34
- * @since 1.0.0
35
- * @return void
36
- */
37
- public function register_settings_screen () {
38
- if ( defined( 'THEME_FRAMEWORK' ) && 'woothemes' == constant( 'THEME_FRAMEWORK' ) ) {
39
- $parent = 'woothemes';
40
- } else {
41
- $parent = 'themes.php';
42
- }
43
-
44
- $this->_hook = add_submenu_page( $parent, __( 'Homepage', 'homepage-control' ), __( 'Homepage', 'homepage-control' ), 'edit_theme_options', 'homepage-control', array( $this, 'settings_screen' ) );
45
-
46
- // Enqueue our registered scripts and styles on our own admin screen by default.
47
- add_action( 'admin_print_scripts-' . $this->_hook, array( $this, 'enqueue_scripts' ) );
48
- add_action( 'admin_print_styles-' . $this->_hook, array( $this, 'enqueue_styles' ) );
49
- } // End register_settings_screen()
50
-
51
- /**
52
- * Output the markup for the settings screen.
53
- * @access public
54
- * @since 1.0.0
55
- * @return void
56
- */
57
- public function settings_screen () {
58
- ?>
59
- <div class="wrap homepage-control-wrap">
60
- <h2><?php _e( 'Homepage', 'homepage-control' ); ?></h2>
61
- <form action="options.php" method="post">
62
- <?php
63
- settings_fields( 'homepage_control_settings' );
64
- do_settings_sections( 'homepage_control' );
65
- submit_button( __( 'Save Changes', 'homepage-control' ) );
66
- ?>
67
- </form>
68
- </div><!--/.wrap-->
69
- <?php
70
- } // End settings_screen()
71
-
72
- /**
73
- * Register the settings within the Settings API.
74
- * @access public
75
- * @since 1.0.0
76
- * @return void
77
- */
78
- public function register_settings () {
79
- register_setting( 'homepage_control_settings', 'homepage_control', array( $this, 'validate_settings' ) );
80
- add_settings_section( 'homepage_components', __( 'Homepage Components', 'homepage-control' ), array( $this, 'render_settings' ), 'homepage_control' );
81
- } // End register_settings()
82
-
83
- /**
84
- * Render the settings.
85
- * @access public
86
- * @since 1.0.0
87
- * @return void
88
- */
89
- public function render_settings () {
90
- $theme = wp_get_theme();
91
- $components = $this->_get_hooked_functions();
92
-
93
- $default_order = array();
94
- if ( 0 < count( $components ) ) {
95
- $default_order = join( ',', array_keys( $components ) );
96
- } else {
97
- $default_order = '';
98
- }
99
-
100
- $options = get_option( 'homepage_control' );
101
-
102
- // Set defaults. We need to do this separately, instead of on get_option(), as we're actually using get_theme_mod() instead.
103
- if ( '' == $options ) $options = array( 'component_order' => $default_order, 'disabled_components' => '' );
104
-
105
- $disabled_keys = explode( ',', $options['disabled_components'] );
106
-
107
- $components = $this->_reorder_components( $components, $options['component_order'] );
108
- ?>
109
- <p><?php printf( __( 'Re-order the homepage components in %s.', 'homepage-control' ), $theme->__get( 'Name' ) ); ?></p>
110
- <?php
111
- if ( 0 < count( $components ) ) {
112
- ?>
113
- <table class="wp-list-table widefat fixed">
114
- <thead>
115
- <th colspan="2"><?php _e( 'Component', 'homepage-control' ); ?></th>
116
- </thead>
117
- <tbody>
118
- <?php
119
- $count = 0;
120
- foreach ( $components as $k => $v ) {
121
- $count++;
122
- $class = 'odd alternate';
123
- if ( 0 == $count % 2 ) $class = 'even';
124
-
125
- if ( in_array( $k, $disabled_keys ) ) $class .= ' disabled';
126
- ?>
127
- <tr valign="top" id="<?php echo esc_attr( $k ); ?>" class="item-row <?php echo esc_attr( $k ) . ' ' . $class; ?>">
128
- <td colspan="2"><span class="visibility"></span> <?php echo esc_html( $v['title'] ); ?></td>
129
- </tr>
130
- <?php
131
- }
132
- ?>
133
- </tbody>
134
- </table>
135
- <?php
136
- } else {
137
- echo '<div class="message"><p>' . sprintf( __( 'Your theme doesn\'t include any homepage components which are suitable for re-ordering or disabling. %sView documentation%s on what makes a theme compatible.', 'homepage-control' ), '<a href="' . esc_url( 'http://docs.woothemes.com/document/homepage-control/' ) . '" target="_blank">', '</a>' ) . '</p></div>' . "\n";
138
- }
139
- ?>
140
- <input type="hidden" id="component_order" name="homepage_control[component_order]" value="<?php echo esc_attr( $options['component_order'] ); ?>" />
141
- <input type="hidden" id="disabled_components" name="homepage_control[disabled_components]" value="<?php echo esc_attr( $options['disabled_components'] ); ?>" />
142
- <?php
143
- } // End settings_screen()
144
-
145
- /**
146
- * Display settings notices within the admin.
147
- * @access public
148
- * @since 1.0.0
149
- * @return void
150
- */
151
- public function settings_notices () {
152
- settings_errors();
153
- } // End settings_notices()
154
-
155
- /**
156
- * Validate the settings.
157
- * @access public
158
- * @since 1.0.0
159
- * @param array $input Inputted data.
160
- * @return array Validated data.
161
- */
162
- public function validate_settings ( $input ) {
163
- if ( isset( $input['component_order'] ) ) $input['component_order'] = esc_html( $input['component_order'] );
164
- if ( isset( $input['disabled_components'] ) ) $input['disabled_components'] = esc_html( $input['disabled_components'] );
165
- return $input;
166
- } // End validate_settings()
167
-
168
- /**
169
- * Register scripts and styles, preparing for enqueue.
170
- * @access public
171
- * @since 1.0.0
172
- * @return void
173
- */
174
- public function register_enqueues () {
175
- wp_register_script( Homepage_Control()->token . '-sortables', esc_url( Homepage_Control()->plugin_url . 'assets/js/sortables.js' ), array( 'jquery', 'jquery-ui-sortable' ), Homepage_Control()->version );
176
- wp_register_style( Homepage_Control()->token . '-admin', esc_url( Homepage_Control()->plugin_url . 'assets/css/settings.css' ), '', Homepage_Control()->version );
177
- } // End register_enqueues()
178
-
179
- /**
180
- * Enqueue JavaScripts for the administration screen.
181
- * @access public
182
- * @since 1.0.0
183
- * @return void
184
- */
185
- public function enqueue_scripts () {
186
- wp_enqueue_script( Homepage_Control()->token . '-sortables' );
187
- } // End enqueue_scripts()
188
-
189
- /**
190
- * Enqueue styles for the administration screen.
191
- * @access public
192
- * @since 1.0.0
193
- * @return void
194
- */
195
- public function enqueue_styles () {
196
- wp_enqueue_style( Homepage_Control()->token . '-admin' );
197
- } // End enqueue_styles()
198
-
199
- /**
200
- * Re-order the components in the given array, based on the stored order.
201
- * @access private
202
- * @since 1.0.0
203
- * @return array An array of components, in the correct order.
204
- */
205
- private function _reorder_components ( $components, $order ) {
206
- $order_entries = array();
207
- if ( '' != $order ) {
208
- $order_entries = explode( ',', $order );
209
- }
210
-
211
- // Re-order the components according to the stored order.
212
- if ( 0 < count( $order_entries ) ) {
213
- $original_components = $components; // Make a backup before we overwrite.
214
- $components = array();
215
- foreach ( $order_entries as $k => $v ) {
216
- $components[$v] = $original_components[$v];
217
- unset( $original_components[$v] );
218
- }
219
- if ( 0 < count( $original_components ) ) {
220
- $components = array_merge( $components, $original_components );
221
- }
222
- }
223
-
224
- return $components;
225
- } // End _reorder_components()
226
-
227
- /**
228
- * Retrive the functions hooked on to the "woo_homepage" hook.
229
- * @access private
230
- * @since 1.0.0
231
- * @return array An array of the functions, grouped by function name, with a formatted title and their priority.
232
- */
233
- private function _get_hooked_functions () {
234
- global $wp_filter;
235
-
236
- $response = array();
237
-
238
- if ( isset( $wp_filter[Homepage_Control()->hook] ) && 0 < count( $wp_filter[Homepage_Control()->hook] ) ) {
239
- foreach ( $wp_filter[Homepage_Control()->hook] as $k => $v ) {
240
- if ( is_array( $v ) ) {
241
- foreach ( $v as $i => $j ) {
242
- $response[$i] = array( 'title' => $this->_maybe_format_title( $i ), 'priority' => $k );
243
- }
244
- }
245
- }
246
- }
247
-
248
- return $response;
249
- } // End _get_hooked_functions()
250
-
251
- /**
252
- * Format a given key into a title.
253
- * @access private
254
- * @since 1.0.0
255
- * @return string A formatted title. If no formatting is possible, return the key.
256
- */
257
- private function _maybe_format_title ( $key ) {
258
- $prefix = (string)apply_filters( 'hompage_control_prefix', 'woo_display_' );
259
- $title = $key;
260
-
261
- $title = str_replace( $prefix, '', $title );
262
- $title = str_replace( '_', ' ', $title );
263
- $title = ucwords( $title );
264
-
265
- return $title;
266
- } // End _maybe_format_title()
267
- } // End Class
268
- ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
classes/class-homepage-control-customizer-control.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Homepage_Control_Customizer_Control extends WP_Customize_Control {
4
+
5
+ /**
6
+ * Enqueue jQuery Sortable and its dependencies.
7
+ * @access public
8
+ * @since 2.0.0
9
+ * @return void
10
+ */
11
+ public function enqueue() {
12
+ wp_enqueue_script( 'jquery-ui-core' );
13
+ wp_enqueue_script( 'jquery-ui-sortable' );
14
+ }
15
+
16
+ /**
17
+ * Display list of ordered components.
18
+ * @access public
19
+ * @since 2.0.0
20
+ * @return void
21
+ */
22
+ public function render_content() {
23
+ if ( ! is_array( $this->choices ) || ! count( $this->choices ) ) {
24
+ printf( __( 'No homepage components found. See the %sdocs%s for details of available homepage component plugins/themes.', 'homepage-control' ), '<a href="' . esc_url( 'http://docs.woothemes.com/document/homepage-control/' ) . '">', '</a>' );
25
+ } else {
26
+ $components = $this->choices;
27
+ $order = $this->value();
28
+ $disabled = $this->_get_disabled_components( $this->value() );
29
+ ?>
30
+ <label>
31
+ <?php
32
+ if ( ! empty( $this->label ) ) : ?>
33
+ <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
34
+ <?php endif;
35
+ if ( ! empty( $this->description ) ) : ?>
36
+ <span class="description customize-control-description"><?php echo $this->description ; ?></span>
37
+ <?php endif;
38
+ ?>
39
+ <ul class="homepage-control">
40
+ <?php $components = $this->_reorder_components( $components, $order ); ?>
41
+ <?php foreach ( $components as $k => $v ) : ?>
42
+ <?php
43
+ $class = '';
44
+ if ( in_array( $k, $disabled ) ) {
45
+ $class = 'disabled';
46
+ }
47
+ ?>
48
+ <li id="<?php echo esc_attr( $k ); ?>" class="<?php echo $class; ?>"><span class="visibility"></span><?php echo esc_attr( $v ); ?></li>
49
+ <?php endforeach; ?>
50
+ </ul>
51
+ <input type="hidden" <?php $this->link(); ?> value="<?php echo esc_attr( $this->value() ); ?>"/>
52
+ </label>
53
+ <?php
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Re-order the components in the given array, based on the stored order.
59
+ * @access private
60
+ * @since 1.0.0
61
+ * @return array An array of components, in the correct order.
62
+ */
63
+ private function _reorder_components ( $components, $order ) {
64
+ $order_entries = array();
65
+ if ( '' != $order ) {
66
+ $order_entries = explode( ',', $order );
67
+ }
68
+
69
+ // Re-order the components according to the stored order.
70
+ if ( 0 < count( $order_entries ) ) {
71
+ $original_components = $components; // Make a backup before we overwrite.
72
+ $components = array();
73
+ foreach ( $order_entries as $k => $v ) {
74
+ if ( $this->_is_component_disabled( $v ) ) {
75
+ $v = str_replace( '[disabled]', '', $v );
76
+ }
77
+ $components[ $v ] = $original_components[ $v ];
78
+ unset( $original_components[ $v ] );
79
+ }
80
+ if ( 0 < count( $original_components ) ) {
81
+ $components = array_merge( $components, $original_components );
82
+ }
83
+ }
84
+
85
+ return $components;
86
+ } // End _reorder_components()
87
+
88
+ /**
89
+ * Check if a component is disabled.
90
+ * @access private
91
+ * @since 2.0.0
92
+ * @return boolean True if a component if disabled.
93
+ */
94
+ private function _is_component_disabled ( $component ) {
95
+ if ( false !== strpos( $component, '[disabled]' ) ) {
96
+ return true;
97
+ }
98
+ return false;
99
+ }
100
+
101
+ /**
102
+ * Return the disabled components in the given array, based on the format of the key.
103
+ * @access private
104
+ * @since 2.0.0
105
+ * @return array An array of disabled components.
106
+ */
107
+ private function _get_disabled_components ( $components ) {
108
+ $disabled = array();
109
+ if ( '' != $components ) {
110
+ $components = explode( ',', $components );
111
+
112
+ if ( 0 < count( $components ) ) {
113
+ foreach ( $components as $k => $v ) {
114
+ if ( $this->_is_component_disabled( $v ) ) {
115
+ $disabled[] = str_replace( '[disabled]', '', $v );
116
+ }
117
+ }
118
+ }
119
+ }
120
+ return $disabled;
121
+ }
122
+ }
classes/class-homepage-control-customizer.php ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4
+
5
+ class Homepage_Control_Customizer {
6
+ /**
7
+ * Constructor function.
8
+ * @access public
9
+ * @since 2.0.0
10
+ * @return void
11
+ */
12
+ public function __construct () {
13
+ add_filter( 'customize_register', array( $this, 'customizer_setup' ) );
14
+ add_action( 'customize_controls_print_footer_scripts', array( $this, 'enqueue_scripts' ) );
15
+ add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_styles' ) );
16
+ } // End __construct()
17
+
18
+ /**
19
+ * Add section, setting and load custom customizer control.
20
+ * @access public
21
+ * @since 2.0.0
22
+ * @return void
23
+ */
24
+ public function customizer_setup ( $wp_customize ) {
25
+ $wp_customize->add_section( 'homepage_control', array(
26
+ 'title' => __( 'Homepage Control', 'homepage-control' ),
27
+ 'priority' => 70,
28
+ ) );
29
+
30
+ $wp_customize->add_setting( 'homepage_control', array(
31
+ 'default' => $this->_format_defaults(), // get default order
32
+ 'type' => 'theme_mod',
33
+ 'capability' => 'edit_theme_options',
34
+ ) );
35
+
36
+ require_once( 'class-homepage-control-customizer-control.php' );
37
+
38
+ $theme = wp_get_theme();
39
+
40
+ $wp_customize->add_control( new Homepage_Control_Customizer_Control( $wp_customize, 'homepage_control', array(
41
+ 'description' => sprintf( __( 'Re-order the homepage components in %s.', 'homepage-control' ), $theme->__get( 'Name' ) ),
42
+ 'section' => 'homepage_control',
43
+ 'settings' => 'homepage_control',
44
+ 'choices' => $this->_get_hooked_functions(),
45
+ 'priority' => 10,
46
+ 'type' => 'hidden',
47
+ 'sanitize_callback' => array( $this, '_canvas_sanitize_components' ),
48
+ ) ) );
49
+ }
50
+
51
+ /**
52
+ * Enqueue scripts.
53
+ * @access public
54
+ * @since 2.0.0
55
+ * @return void
56
+ */
57
+ public function enqueue_scripts() {
58
+ wp_enqueue_script( Homepage_Control()->token . '-sortables', esc_url( Homepage_Control()->plugin_url . 'assets/js/sortables.js' ), array( 'jquery', 'jquery-ui-sortable' ), Homepage_Control()->version );
59
+ }
60
+
61
+ /**
62
+ * Enqueue styles.
63
+ * @access public
64
+ * @since 2.0.0
65
+ * @return void
66
+ */
67
+ public function enqueue_styles() {
68
+ wp_enqueue_style( Homepage_Control()->token . '-customizer', esc_url( Homepage_Control()->plugin_url . 'assets/css/settings.css' ), '', Homepage_Control()->version );
69
+ }
70
+
71
+ /**
72
+ * Ensures only array keys matching the original settings specified in add_control() are valid.
73
+ * @access public
74
+ * @since 2.0.0
75
+ * @return string The valid component.
76
+ */
77
+ public function _canvas_sanitize_components( $input ) {
78
+ $valid = $this->_get_hooked_functions();
79
+
80
+ if ( array_key_exists( $input, $valid ) || array_key_exists( str_replace( '[disabled]', '', $input ), $valid ) ) {
81
+ return $input;
82
+ } else {
83
+ return '';
84
+ }
85
+ }
86
+
87
+ /**
88
+ * Retrive the functions hooked on to the "woo_homepage" hook.
89
+ * @access private
90
+ * @since 2.0.0
91
+ * @return array An array of the functions, grouped by function name, with a formatted title.
92
+ */
93
+ private function _get_hooked_functions () {
94
+ global $wp_filter;
95
+
96
+ $response = array();
97
+
98
+ if ( isset( $wp_filter[Homepage_Control()->hook] ) && 0 < count( $wp_filter[Homepage_Control()->hook] ) ) {
99
+ foreach ( $wp_filter[Homepage_Control()->hook] as $k => $v ) {
100
+ if ( is_array( $v ) ) {
101
+ foreach ( $v as $i => $j ) {
102
+ if ( is_array( $j['function'] ) ) {
103
+ $i = get_class( $j['function'][0] ) . '@' . $j['function'][1];
104
+ $response[$i] = $this->_maybe_format_title( $j['function'][1] );
105
+ } else {
106
+ $response[$i] = $this->_maybe_format_title( $i );
107
+ }
108
+ }
109
+ }
110
+ }
111
+ }
112
+
113
+ return $response;
114
+ } // End _get_hooked_functions()
115
+
116
+ /**
117
+ * Format a given key into a title.
118
+ * @access private
119
+ * @since 2.0.0
120
+ * @return string A formatted title. If no formatting is possible, return the key.
121
+ */
122
+ private function _maybe_format_title ( $key ) {
123
+ $prefix = (string)apply_filters( 'hompage_control_prefix', 'woo_display_' );
124
+ $title = $key;
125
+
126
+ $title = str_replace( $prefix, '', $title );
127
+ $title = str_replace( '_', ' ', $title );
128
+ $title = ucwords( $title );
129
+
130
+ return $title;
131
+ } // End _maybe_format_title()
132
+
133
+ /**
134
+ * Format an array of components as a comma separated list.
135
+ * @access private
136
+ * @since 2.0.0
137
+ * @return string A list of components separated by a comma.
138
+ */
139
+ private function _format_defaults () {
140
+ $components = $this->_get_hooked_functions();
141
+ $defaults = array();
142
+
143
+ foreach ( $components as $k => $v ) {
144
+ if ( apply_filters( 'homepage_control_hide_' . $k, false ) ) {
145
+ $defaults[] = '[disabled]' . $k;
146
+ } else {
147
+ $defaults[] = $k;
148
+ }
149
+ }
150
+
151
+ return join( ',', $defaults );
152
+ }
153
+ }
154
+
155
+ new Homepage_Control_Customizer();
homepage-control.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Homepage Control
4
  * Plugin URI: http://www.woothemes.com/products/homepage-control/
5
  * Description: Hi! I'm here to assist you with re-ordering or disabling components of your theme's homepage design.
6
- * Version: 1.0.0
7
  * Author: WooThemes
8
  * Author URI: http://woothemes.com/
9
  * Requires at least: 3.8.1
@@ -91,21 +91,20 @@ final class Homepage_Control {
91
  $this->token = 'homepage-control';
92
  $this->plugin_url = plugin_dir_url( __FILE__ );
93
  $this->plugin_path = plugin_dir_path( __FILE__ );
94
- $this->version = '1.0.0';
95
  $this->hook = (string)apply_filters( 'homepage_control_hook', 'homepage' );
96
 
 
 
97
  register_activation_hook( __FILE__, array( $this, 'install' ) );
98
 
99
  add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
100
 
101
- add_filter( 'pre_option_homepage_control', array( $this, 'force_theme_mod_get' ), 10 );
102
- add_filter( 'pre_update_option_homepage_control', array( $this, 'force_theme_mod_set' ), 10, 2 );
103
 
104
- /* Conditionally load the admin. */
105
- if ( is_admin() ) {
106
- require_once( 'classes/class-homepage-control-admin.php' );
107
- $this->admin = new Homepage_Control_Admin();
108
- } else {
109
  add_action( 'get_header', array( $this, 'maybe_apply_restructuring_filter' ) );
110
  }
111
  } // End __construct()
@@ -172,32 +171,51 @@ final class Homepage_Control {
172
  */
173
  private function _log_version_number () {
174
  // Log the version number.
175
- update_option( $this->_token . '_version', $this->_version );
176
  } // End _log_version_number()
177
 
178
  /**
179
- * Bypass any options checks and use get_theme_mod() instead.
180
  * @access public
181
- * @since 1.0.0
182
- * @param boolean $value This value is false by default, on the pre_option_ filters.
183
- * @return mixed
184
  */
185
- public function force_theme_mod_get ( $value ) {
186
- return get_theme_mod( 'homepage_control' );
187
- } // End force_theme_mod_get()
188
 
189
- /**
190
- * Bypass any options checks and use get_theme_mod() instead.
191
- * @access public
192
- * @since 1.0.0
193
- * @param mixed $value
194
- * @param mixed $old_value
195
- * @return mixed
196
- */
197
- public function force_theme_mod_set ( $value, $old_value ) {
198
- set_theme_mod( 'homepage_control', $value );
199
- return $old_value; // We return the $old_value so the rest of update_option() doesn't run.
200
- } // End force_theme_mod_set()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201
 
202
  /**
203
  * Work through the stored data and display the components in the desired order, without the disabled components.
@@ -206,31 +224,33 @@ final class Homepage_Control {
206
  * @return void
207
  */
208
  public function maybe_apply_restructuring_filter () {
209
- $options = (array)get_theme_mod( 'homepage_control' );
210
- $order = '';
211
- $disabled = '';
212
  $components = array();
213
 
214
- if ( isset( $options['component_order'] ) ) {
215
- $order = $options['component_order'];
216
-
217
- if ( isset( $options['disabled_components'] ) ) {
218
- $disabled = $options['disabled_components'];
219
- }
220
-
221
- // Attempt to remove disabled components.
222
- if ( '' != $order ) {
223
- $components = $this->_maybe_remove_disabled_items( $order, $disabled );
224
- }
225
 
226
  // Remove all existing actions on woo_homepage.
227
  remove_all_actions( $this->hook );
228
 
 
 
 
229
  // Perform the reordering!
230
  if ( 0 < count( $components ) ) {
231
  $count = 5;
232
  foreach ( $components as $k => $v ) {
233
- add_action( $this->hook, esc_attr( $v ), $count );
 
 
 
 
 
 
 
 
 
 
234
  $count + 5;
235
  }
236
  }
@@ -241,25 +261,18 @@ final class Homepage_Control {
241
  * Maybe remove disabled items from the main ordered array.
242
  * @access private
243
  * @since 1.0.0
244
- * @param string $order Stored comma separated data for the components order.
245
- * @param string $disabled Stored comma separated data for the disabled components.
246
- * @return array Re-ordered components with disabled components removed.
247
  */
248
- private function _maybe_remove_disabled_items ( $order, $disabled ) {
249
- // Transform into arrays.
250
- $order = explode( ',', $order );
251
- $disabled = explode( ',', $disabled );
252
-
253
- // Remove disabled items from the ordered array.
254
- if ( 0 < count( $order ) && 0 < count( $disabled ) ) {
255
- foreach ( $order as $k => $v ) {
256
- if ( in_array( $v, $disabled ) ) {
257
- unset( $order[$k] );
258
  }
259
  }
260
  }
261
-
262
- return $order;
263
  } // End _maybe_remove_disabled_items()
264
  } // End Class
265
  ?>
3
  * Plugin Name: Homepage Control
4
  * Plugin URI: http://www.woothemes.com/products/homepage-control/
5
  * Description: Hi! I'm here to assist you with re-ordering or disabling components of your theme's homepage design.
6
+ * Version: 2.0.0
7
  * Author: WooThemes
8
  * Author URI: http://woothemes.com/
9
  * Requires at least: 3.8.1
91
  $this->token = 'homepage-control';
92
  $this->plugin_url = plugin_dir_url( __FILE__ );
93
  $this->plugin_path = plugin_dir_path( __FILE__ );
94
+ $this->version = '2.0.0';
95
  $this->hook = (string)apply_filters( 'homepage_control_hook', 'homepage' );
96
 
97
+ add_action( 'plugins_loaded', array( $this, 'maybe_migrate_data' ) );
98
+
99
  register_activation_hook( __FILE__, array( $this, 'install' ) );
100
 
101
  add_action( 'init', array( $this, 'load_plugin_textdomain' ) );
102
 
103
+ /* Setup Customizer. */
104
+ require_once( 'classes/class-homepage-control-customizer.php' );
105
 
106
+ /* Reorder Components. */
107
+ if ( ! is_admin() ) {
 
 
 
108
  add_action( 'get_header', array( $this, 'maybe_apply_restructuring_filter' ) );
109
  }
110
  } // End __construct()
171
  */
172
  private function _log_version_number () {
173
  // Log the version number.
174
+ update_option( $this->token . '_version', $this->version );
175
  } // End _log_version_number()
176
 
177
  /**
178
+ * Migrate data from versions prior to 2.0.0.
179
  * @access public
180
+ * @since 2.0.0
181
+ * @return void
 
182
  */
183
+ public function maybe_migrate_data () {
184
+ $options = get_theme_mod( 'homepage_control' );
 
185
 
186
+ if ( ! isset( $options ) ) {
187
+ return; // Option is empty, probably first time installing the plugin.
188
+ }
189
+
190
+ if ( is_array( $options ) ) {
191
+ $order = '';
192
+ $disabled = '';
193
+ $components = array();
194
+
195
+ if ( isset( $options['component_order'] ) ) {
196
+ $order = explode( ',', $options['component_order'] );
197
+
198
+ if ( isset( $options['disabled_components'] ) ) {
199
+ $disabled = explode( ',', $options['disabled_components'] );
200
+ }
201
+
202
+ if ( 0 < count( $order ) ) {
203
+ foreach ( $order as $k => $v ) {
204
+ if ( in_array( $v, $disabled ) ) {
205
+ $components[] = '[disabled]' . $v; // Add disabled tag
206
+ } else {
207
+ $components[] = $v;
208
+ }
209
+ }
210
+ }
211
+ }
212
+
213
+ $components = join( ',', $components );
214
+
215
+ // Replace old data
216
+ set_theme_mod( 'homepage_control', $components );
217
+ }
218
+ } // End maybe_migrate_data()
219
 
220
  /**
221
  * Work through the stored data and display the components in the desired order, without the disabled components.
224
  * @return void
225
  */
226
  public function maybe_apply_restructuring_filter () {
227
+ $options = get_theme_mod( 'homepage_control' );
 
 
228
  $components = array();
229
 
230
+ if ( isset( $options ) && '' != $options ) {
231
+ $components = explode( ',', $options );
 
 
 
 
 
 
 
 
 
232
 
233
  // Remove all existing actions on woo_homepage.
234
  remove_all_actions( $this->hook );
235
 
236
+ // Remove disabled components
237
+ $components = $this->_maybe_remove_disabled_items( $components );
238
+
239
  // Perform the reordering!
240
  if ( 0 < count( $components ) ) {
241
  $count = 5;
242
  foreach ( $components as $k => $v ) {
243
+ if (strpos( $v, '@' ) !== FALSE) {
244
+ $obj_v = explode( '@' , $v );
245
+ if ( class_exists( $obj_v[0] ) && method_exists( $obj_v[0], $obj_v[1] ) ) {
246
+ add_action( $this->hook, array( $obj_v[0], $obj_v[1] ), $count );
247
+ } // End If Statement
248
+ } else {
249
+ if ( function_exists( $v ) ) {
250
+ add_action( $this->hook, esc_attr( $v ), $count );
251
+ }
252
+ } // End If Statement
253
+
254
  $count + 5;
255
  }
256
  }
261
  * Maybe remove disabled items from the main ordered array.
262
  * @access private
263
  * @since 1.0.0
264
+ * @param array $components Array with components order.
265
+ * @return array Re-ordered components with disabled components removed.
 
266
  */
267
+ private function _maybe_remove_disabled_items( $components ) {
268
+ if ( 0 < count( $components ) ) {
269
+ foreach ( $components as $k => $v ) {
270
+ if ( false !== strpos( $v, '[disabled]' ) ) {
271
+ unset( $components[ $k ] );
 
 
 
 
 
272
  }
273
  }
274
  }
275
+ return $components;
 
276
  } // End _maybe_remove_disabled_items()
277
  } // End Class
278
  ?>
languages/homepage-control.pot CHANGED
@@ -1,43 +1,30 @@
1
- # Copyright (C) 2014 Homepage Control
2
  # This file is distributed under the same license as the Homepage Control package.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: Homepage Control 1.0.0\n"
6
- "Report-Msgid-Bugs-To: http://wordpress.org/tag/homepage-control\n"
7
- "POT-Creation-Date: 2014-03-18 11:52:28+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
11
- "PO-Revision-Date: 2014-MO-DA HO:MI+ZONE\n"
12
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
  "Language-Team: LANGUAGE <LL@li.org>\n"
14
 
15
- #: classes/class-homepage-control-admin.php:44
16
- #: classes/class-homepage-control-admin.php:60
17
- msgid "Homepage"
18
  msgstr ""
19
 
20
- #: classes/class-homepage-control-admin.php:65
21
- msgid "Save Changes"
22
- msgstr ""
23
-
24
- #: classes/class-homepage-control-admin.php:80
25
- msgid "Homepage Components"
26
  msgstr ""
27
 
28
- #: classes/class-homepage-control-admin.php:109
29
  msgid "Re-order the homepage components in %s."
30
  msgstr ""
31
 
32
- #: classes/class-homepage-control-admin.php:115
33
- msgid "Component"
34
- msgstr ""
35
-
36
- #: classes/class-homepage-control-admin.php:137
37
- msgid "Your theme doesn't include any homepage components which are suitable for re-ordering or disabling. %sView documentation%s on what makes a theme compatible."
38
- msgstr ""
39
-
40
- #: homepage-control.php:145 homepage-control.php:154
41
  msgid "Cheatin&#8217; huh?"
42
  msgstr ""
43
  #. Plugin Name of the plugin/theme
1
+ # Copyright (C) 2015 Homepage Control
2
  # This file is distributed under the same license as the Homepage Control package.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: Homepage Control 2.0.0\n"
6
+ "Report-Msgid-Bugs-To: http://wordpress.org/support/plugin/homepage-control\n"
7
+ "POT-Creation-Date: 2015-04-30 14:54:39+00:00\n"
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
11
+ "PO-Revision-Date: 2015-MO-DA HO:MI+ZONE\n"
12
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
  "Language-Team: LANGUAGE <LL@li.org>\n"
14
 
15
+ #: classes/class-homepage-control-customizer-control.php:24
16
+ msgid "No homepage components found. See the %sdocs%s for details of available homepage component plugins/themes."
 
17
  msgstr ""
18
 
19
+ #: classes/class-homepage-control-customizer.php:26
20
+ msgid "Homepage Control"
 
 
 
 
21
  msgstr ""
22
 
23
+ #: classes/class-homepage-control-customizer.php:41
24
  msgid "Re-order the homepage components in %s."
25
  msgstr ""
26
 
27
+ #: homepage-control.php:144 homepage-control.php:153
 
 
 
 
 
 
 
 
28
  msgid "Cheatin&#8217; huh?"
29
  msgstr ""
30
  #. Plugin Name of the plugin/theme
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
  === Homepage Control ===
2
- Contributors: woothemes,mattyza,jameskoster
3
  Donate link: http://woothemes.com/
4
- Tags: homepage, hooks, theme-mod, components
5
  Requires at least: 3.8.1
6
- Tested up to: 3.8.1
7
- Stable tag: 1.0.0
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -18,7 +18,7 @@ Looking for a helping hand? [View plugin documentation](http://docs.woothemes.co
18
 
19
  == Usage ==
20
 
21
- Once activated, a "Homepage" menu item will display underneath the WooThemes administration menu. If you're not using a WooThemes theme, this menu will display under the "Appearance" menu item.
22
 
23
  Visiting this screen will display a table of the possible homepage components, with options for re-ordering them, or disabling individual components.
24
 
@@ -31,7 +31,7 @@ Installing "Homepage Control" can be done either by searching for "Homepage Cont
31
  1. Download the plugin via WordPress.org.
32
  1. Upload the ZIP file through the "Plugins > Add New > Upload" screen in your WordPress dashboard.
33
  1. Activate the plugin through the 'Plugins' menu in WordPress
34
- 1. Visit the "WooThemes > Homepage" (or "Appearance > Homepage") section and select which components you'd like to display, and in which order.
35
 
36
  == Frequently Asked Questions ==
37
 
@@ -62,6 +62,14 @@ We encourage everyone to contribute their ideas, thoughts and code snippets. Thi
62
 
63
  == Changelog ==
64
 
 
 
 
 
 
 
 
 
65
  = 1.0.0 =
66
  * 2014-03-18
67
  * Initial release. Woo!
1
  === Homepage Control ===
2
+ Contributors: woothemes,mattyza,jameskoster,tiagonoronha
3
  Donate link: http://woothemes.com/
4
+ Tags: homepage, hooks, theme-mod, components, customizer
5
  Requires at least: 3.8.1
6
+ Tested up to: 4.2.1
7
+ Stable tag: 2.0.0
8
  License: GPLv3 or later
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
18
 
19
  == Usage ==
20
 
21
+ Once activated, a "Homepage Control" item will display in the Theme Customizer ( Appearance > Customizer ).
22
 
23
  Visiting this screen will display a table of the possible homepage components, with options for re-ordering them, or disabling individual components.
24
 
31
  1. Download the plugin via WordPress.org.
32
  1. Upload the ZIP file through the "Plugins > Add New > Upload" screen in your WordPress dashboard.
33
  1. Activate the plugin through the 'Plugins' menu in WordPress
34
+ 1. Visit the "Appearance > Customizer" section, select "Homepage Control". There you can select the components you'd like to display, and in which order.
35
 
36
  == Frequently Asked Questions ==
37
 
62
 
63
  == Changelog ==
64
 
65
+ = 2.0.0 =
66
+ * 2015-04-28
67
+ * Removed custom admin page and moved Homepage Control to the WordPress Customizer in Appearance > Customizer.
68
+
69
+ = 1.0.1 =
70
+ * 2014-11-21
71
+ * Improved handling of functions hooked in via classes.
72
+
73
  = 1.0.0 =
74
  * 2014-03-18
75
  * Initial release. Woo!