Version Description
- 2014-03-18
- Initial release. Woo!
=
Download this release
Release Info
Developer | jameskoster |
Plugin | Homepage Control |
Version | 1.0.0 |
Comparing to | |
See all releases |
Version 1.0.0
- assets/css/settings.css +43 -0
- assets/css/settings.less +58 -0
- assets/js/sortables.js +28 -0
- classes/class-homepage-control-admin.php +268 -0
- classes/index.php +1 -0
- homepage-control.php +265 -0
- index.php +1 -0
- languages/homepage-control.pot +61 -0
- readme.txt +67 -0
assets/css/settings.css
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
}
|
assets/css/settings.less
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
});
|
classes/class-homepage-control-admin.php
ADDED
@@ -0,0 +1,268 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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/index.php
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
<?php // Silence is golden... ?>
|
homepage-control.php
ADDED
@@ -0,0 +1,265 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
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
|
10 |
+
* Tested up to: 3.8.1
|
11 |
+
*
|
12 |
+
* Text Domain: homepage-control
|
13 |
+
* Domain Path: /languages/
|
14 |
+
*
|
15 |
+
* @package Homepage_Control
|
16 |
+
* @category Core
|
17 |
+
* @author Matty
|
18 |
+
*/
|
19 |
+
|
20 |
+
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
|
21 |
+
|
22 |
+
/**
|
23 |
+
* Returns the main instance of Homepage_Control to prevent the need to use globals.
|
24 |
+
*
|
25 |
+
* @since 1.0.0
|
26 |
+
* @return object Homepage_Control
|
27 |
+
*/
|
28 |
+
function Homepage_Control() {
|
29 |
+
return Homepage_Control::instance();
|
30 |
+
} // End Homepage_Control()
|
31 |
+
|
32 |
+
Homepage_Control();
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Main Homepage_Control Class
|
36 |
+
*
|
37 |
+
* @class Homepage_Control
|
38 |
+
* @version 1.0.0
|
39 |
+
* @since 1.0.0
|
40 |
+
* @package Kudos
|
41 |
+
* @author Matty
|
42 |
+
*/
|
43 |
+
final class Homepage_Control {
|
44 |
+
/**
|
45 |
+
* Homepage_Control The single instance of Homepage_Control.
|
46 |
+
* @var object
|
47 |
+
* @access private
|
48 |
+
* @since 1.0.0
|
49 |
+
*/
|
50 |
+
private static $_instance = null;
|
51 |
+
|
52 |
+
/**
|
53 |
+
* The token.
|
54 |
+
* @var string
|
55 |
+
* @access public
|
56 |
+
* @since 1.0.0
|
57 |
+
*/
|
58 |
+
public $token;
|
59 |
+
|
60 |
+
/**
|
61 |
+
* The version number.
|
62 |
+
* @var string
|
63 |
+
* @access public
|
64 |
+
* @since 1.0.0
|
65 |
+
*/
|
66 |
+
public $version;
|
67 |
+
|
68 |
+
/**
|
69 |
+
* An instance of the Homepage_Control_Admin class.
|
70 |
+
* @var object
|
71 |
+
* @access public
|
72 |
+
* @since 1.0.0
|
73 |
+
*/
|
74 |
+
public $admin;
|
75 |
+
|
76 |
+
/**
|
77 |
+
* The name of the hook on which we will be working our magic.
|
78 |
+
* @var string
|
79 |
+
* @access public
|
80 |
+
* @since 1.0.0
|
81 |
+
*/
|
82 |
+
public $hook;
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Constructor function.
|
86 |
+
* @access public
|
87 |
+
* @since 1.0.0
|
88 |
+
* @return void
|
89 |
+
*/
|
90 |
+
public function __construct () {
|
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()
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Main Homepage_Control Instance
|
115 |
+
*
|
116 |
+
* Ensures only one instance of Homepage_Control is loaded or can be loaded.
|
117 |
+
*
|
118 |
+
* @since 1.0.0
|
119 |
+
* @static
|
120 |
+
* @see Homepage_Control()
|
121 |
+
* @return Main Kudos instance
|
122 |
+
*/
|
123 |
+
public static function instance () {
|
124 |
+
if ( is_null( self::$_instance ) )
|
125 |
+
self::$_instance = new self();
|
126 |
+
return self::$_instance;
|
127 |
+
} // End instance()
|
128 |
+
|
129 |
+
/**
|
130 |
+
* Load the localisation file.
|
131 |
+
* @access public
|
132 |
+
* @since 1.0.0
|
133 |
+
* @return void
|
134 |
+
*/
|
135 |
+
public function load_plugin_textdomain() {
|
136 |
+
load_plugin_textdomain( 'homepage-control', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
|
137 |
+
} // End load_plugin_textdomain()
|
138 |
+
|
139 |
+
/**
|
140 |
+
* Cloning is forbidden.
|
141 |
+
*
|
142 |
+
* @since 1.0.0
|
143 |
+
*/
|
144 |
+
public function __clone () {
|
145 |
+
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?' ), '1.0.0' );
|
146 |
+
} // End __clone()
|
147 |
+
|
148 |
+
/**
|
149 |
+
* Unserializing instances of this class is forbidden.
|
150 |
+
*
|
151 |
+
* @since 1.0.0
|
152 |
+
*/
|
153 |
+
public function __wakeup () {
|
154 |
+
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?' ), '1.0.0' );
|
155 |
+
} // End __wakeup()
|
156 |
+
|
157 |
+
/**
|
158 |
+
* Installation. Runs on activation.
|
159 |
+
* @access public
|
160 |
+
* @since 1.0.0
|
161 |
+
* @return void
|
162 |
+
*/
|
163 |
+
public function install () {
|
164 |
+
$this->_log_version_number();
|
165 |
+
} // End install()
|
166 |
+
|
167 |
+
/**
|
168 |
+
* Log the plugin version number.
|
169 |
+
* @access public
|
170 |
+
* @since 1.0.0
|
171 |
+
* @return void
|
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.
|
204 |
+
* @access public
|
205 |
+
* @since 1.0.0
|
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 |
+
}
|
237 |
+
}
|
238 |
+
} // End maybe_apply_restructuring_filter()
|
239 |
+
|
240 |
+
/**
|
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 |
+
?>
|
index.php
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
<?php // Silence is golden... ?>
|
languages/homepage-control.pot
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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’ huh?"
|
42 |
+
msgstr ""
|
43 |
+
#. Plugin Name of the plugin/theme
|
44 |
+
msgid "Homepage Control"
|
45 |
+
msgstr ""
|
46 |
+
|
47 |
+
#. Plugin URI of the plugin/theme
|
48 |
+
msgid "http://www.woothemes.com/products/homepage-control/"
|
49 |
+
msgstr ""
|
50 |
+
|
51 |
+
#. Description of the plugin/theme
|
52 |
+
msgid "Hi! I'm here to assist you with re-ordering or disabling components of your theme's homepage design."
|
53 |
+
msgstr ""
|
54 |
+
|
55 |
+
#. Author of the plugin/theme
|
56 |
+
msgid "WooThemes"
|
57 |
+
msgstr ""
|
58 |
+
|
59 |
+
#. Author URI of the plugin/theme
|
60 |
+
msgid "http://woothemes.com/"
|
61 |
+
msgstr ""
|
readme.txt
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
11 |
+
Re-order or disable the homepage components in certain themes.
|
12 |
+
|
13 |
+
== Description ==
|
14 |
+
|
15 |
+
Using Homepage Control, any theme which uses a "homepage" (or other) hook to display components on a homepage, just got better. Re-order or disable any of the homepage components added by your theme, and control the display and order of any function hooked on to the "homepage" hook.
|
16 |
+
|
17 |
+
Looking for a helping hand? [View plugin documentation](http://docs.woothemes.com/document/homepage-control/).
|
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 |
+
|
25 |
+
Once done, click the "Save Changes" button, to commit your new component order into the system.
|
26 |
+
|
27 |
+
== Installation ==
|
28 |
+
|
29 |
+
Installing "Homepage Control" can be done either by searching for "Homepage Control" via the "Plugins > Add New" screen in your WordPress dashboard, or by using the following steps:
|
30 |
+
|
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 |
+
|
38 |
+
= No components show up in the administration area. Is my theme broken? =
|
39 |
+
|
40 |
+
Not at all. This simply means your theme doesn't support the "homepage" action hook, which is a method of adding components to a homepage design.
|
41 |
+
|
42 |
+
Please consult your theme developer if you have further queries about customising your homepage.
|
43 |
+
|
44 |
+
= What happens if I switch themes? Do I lose my settings? =
|
45 |
+
|
46 |
+
Not at all. :) If you switch themes, Homepage Control will remember the homepage component settings for each theme you apply changes to, making switching themes a breeze.
|
47 |
+
|
48 |
+
= How do I contribute? =
|
49 |
+
|
50 |
+
We encourage everyone to contribute their ideas, thoughts and code snippets. This can be done by forking the [repository over at GitHub](http://github.com/woothemes/homepage-control/).
|
51 |
+
|
52 |
+
== Screenshots ==
|
53 |
+
|
54 |
+
1. The Homepage Control administration screen.
|
55 |
+
|
56 |
+
|
57 |
+
== Upgrade Notice ==
|
58 |
+
|
59 |
+
= 1.0.0 =
|
60 |
+
* 2014-03-18
|
61 |
+
* Initial release. Woo!
|
62 |
+
|
63 |
+
== Changelog ==
|
64 |
+
|
65 |
+
= 1.0.0 =
|
66 |
+
* 2014-03-18
|
67 |
+
* Initial release. Woo!
|