Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 266 lines (219 sloc) 7.385 kb
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
1 <?php
2 /*
8fd23c1 @justintadlock Rename plugin to Grid Columns and update class/function names and hoo…
authored
3 * Plugin Name: Grid Columns
24007fd @justintadlock Update opening inline plugin docs.
authored
4 * Plugin URI: http://themehybrid.com/plugins/grid-columns
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
5 * Description: A [column] shortcode plugin.
73becfd @justintadlock Bump to 0.1 Beta 1.
authored
6 * Version: 0.1 Beta 1
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
7 * Author: Justin Tadlock
8 * Author URI: http://justintadlock.com
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
9 *
24007fd @justintadlock Update opening inline plugin docs.
authored
10 * Grid Columns was created because of the sheer number of WordPress themes adding poorly-coded
11 * column shortcodes, which lock users into use that theme and system forever. The plugin is
12 * meant to be an all-around solution for any WordPress user, regardless of theme, to be able
13 * to have columnized content using a simple [column] shortcode.
14 *
15 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
16 * General Public License as published by the Free Software Foundation; either version 2 of the License,
17 * or (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
20 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 *
22 * You should have received a copy of the GNU General Public License along with this program; if not, write
23 * to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 *
8fd23c1 @justintadlock Rename plugin to Grid Columns and update class/function names and hoo…
authored
25 * @package GridColumns
73becfd @justintadlock Bump to 0.1 Beta 1.
authored
26 * @version 0.1.0 Beta 1
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
27 * @author Justin Tadlock <justin@justintadlock.com>
28 * @copyright Copyright (c) 2012, Justin Tadlock
24007fd @justintadlock Update opening inline plugin docs.
authored
29 * @link http://themehybrid.com/plugins/grid-columns
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
30 * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
31 */
32
8fd23c1 @justintadlock Rename plugin to Grid Columns and update class/function names and hoo…
authored
33 class Grid_Columns {
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
34
35 /**
36 * The current grid.
37 *
38 * @since 0.1.0
39 * @access public
40 * @var int
41 */
488b98e @justintadlock Rewrite the logic, change some default properties, and introduce the …
authored
42 public $grid = 4;
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
43
44 /**
45 * The current total number of columns in the grid.
46 *
47 * @since 0.1.0
48 * @access public
49 * @var int
50 */
51 public $span = 0;
52
53 /**
54 * Whether we're viewing the first column.
55 *
56 * @since 0.1.0
57 * @access public
58 * @var bool
59 */
488b98e @justintadlock Rewrite the logic, change some default properties, and introduce the …
authored
60 public $is_first_column = true;
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
61
62 /**
63 * Whether we're viewing the last column.
64 *
65 * @since 0.1.0
66 * @access public
67 * @var bool
68 */
69 public $is_last_column = false;
70
71 /**
b087784 @justintadlock Inline doc update.
authored
72 * Allowed grids can be 2, 3, 4, 5, or 12 columns.
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
73 *
74 * @since 0.1.0
75 * @access public
76 * @var array
77 */
08f5bd6 @justintadlock Update allowed grids code.
authored
78 public $allowed_grids = array( 2, 3, 4, 5, 12 );
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
79
80 /**
81 * Sets up our actions/filters.
82 *
83 * @since 0.1.0
84 * @access public
85 * @return void
86 */
87 public function __construct() {
88
89 /* Register shortcodes on 'init'. */
90 add_action( 'init', array( &$this, 'register_shortcode' ) );
91
92 /* Enqueue stylesheets on 'wp_enqueue_scripts'. */
93 add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_styles' ), 1 );
94 }
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
95
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
96 /**
97 * Registers the [column] shortcode.
98 *
99 * @since 0.1.0
100 * @access public
101 * @return void
102 */
103 public function register_shortcode() {
104 add_shortcode( 'column', array( &$this, 'do_shortcode' ) );
105 }
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
106
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
107 /**
108 * Enqueues the columns.css stylesheet to make the columns pretty.
109 *
110 * @since 0.1.0
111 * @access public
112 * @return void
113 */
114 public function enqueue_styles() {
115
358f47f @justintadlock Add support for the columns.min.css file.
authored
116 /* Use the .min stylesheet if SCRIPT_DEBUG is turned off. */
117 $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
118
119 /* Enqueue the stylesheet. */
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
120 wp_enqueue_style(
aae663d @justintadlock Change style ID to 'grid-columns'.
authored
121 'grid-columns',
81b394d @justintadlock Move stylesheet files to the CSS folder.
authored
122 trailingslashit( plugin_dir_url( __FILE__ ) ) . "css/columns$suffix.css",
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
123 null,
25e87de @justintadlock Update CSS version number.
authored
124 '20120917'
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
125 );
126 }
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
127
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
128 /**
129 * Returns the content of the column shortcode.
130 *
131 * @since 0.1.0
132 * @access public
133 * @param array $attr The user-inputted arguments.
134 * @param string $content The content to wrap in a shortcode.
135 * @return string
136 */
137 public function do_shortcode( $attr, $content = null ) {
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
138
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
139 /* If there's no content, just return back what we got. */
140 if ( is_null( $content ) )
141 return $content;
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
142
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
143 /* Set up the default variables. */
144 $output = '';
2d82e2a @justintadlock Some useful hooks for changing up things.
authored
145 $row_classes = array();
146 $column_classes = array();
90d3d06 @justintadlock Add some extra filter hooks to allow for some flexibility.
authored
147
148 /* Set up the default arguments. */
13ea202 @justintadlock Allow for a custom 'class' to be entered for each column.
authored
149 $defaults = apply_filters(
150 'gc_column_defaults',
151 array(
488b98e @justintadlock Rewrite the logic, change some default properties, and introduce the …
authored
152 'grid' => $this->grid,
13ea202 @justintadlock Allow for a custom 'class' to be entered for each column.
authored
153 'span' => 1,
154 'push' => 0,
155 'class' => ''
156 )
157 );
90d3d06 @justintadlock Add some extra filter hooks to allow for some flexibility.
authored
158
159 /* Parse the arguments. */
160 $attr = shortcode_atts( $defaults, $attr );
161
162 /* Allow devs to filter the arguments. */
8fd23c1 @justintadlock Rename plugin to Grid Columns and update class/function names and hoo…
authored
163 $attr = apply_filters( 'gc_column_args', $attr );
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
164
2fae04d @justintadlock Change 'allowed_grid' to 'allowed_grids' and allow it to be filtered.
authored
165 /* Allow devs to overwrite the allowed grids. */
8fd23c1 @justintadlock Rename plugin to Grid Columns and update class/function names and hoo…
authored
166 $this->allowed_grids = apply_filters( 'gc_allowed_grids', $this->allowed_grids );
2fae04d @justintadlock Change 'allowed_grid' to 'allowed_grids' and allow it to be filtered.
authored
167
08f5bd6 @justintadlock Update allowed grids code.
authored
168 /* Make sure the grid is in the allowed grids array. */
488b98e @justintadlock Rewrite the logic, change some default properties, and introduce the …
authored
169 if ( $this->is_first_column && in_array( $attr['grid'], $this->allowed_grids ) )
170 $this->grid = absint( $attr['grid'] );
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
171
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
172 /* Span cannot be greater than the grid. */
488b98e @justintadlock Rewrite the logic, change some default properties, and introduce the …
authored
173 $attr['span'] = ( $this->grid >= $attr['span'] ) ? absint( $attr['span'] ) : 1;
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
174
e0f8de3 @justintadlock Inline doc updates.
authored
175 /* The push argument should always be less than the grid. */
488b98e @justintadlock Rewrite the logic, change some default properties, and introduce the …
authored
176 $attr['push'] = ( $this->grid > $attr['push'] ) ? absint( $attr['push'] ) : 0;
17a3025 @justintadlock Add 'push' ability.
authored
177
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
178 /* Add to the total $span. */
17a3025 @justintadlock Add 'push' ability.
authored
179 $this->span = $this->span + $attr['span'] + $attr['push'];
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
180
2d82e2a @justintadlock Some useful hooks for changing up things.
authored
181 /* Column classes. */
182 $column_classes[] = 'column';
183 $column_classes[] = "column-span-{$attr['span']}";
17a3025 @justintadlock Add 'push' ability.
authored
184 $column_classes[] = "column-push-{$attr['push']}";
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
185
13ea202 @justintadlock Allow for a custom 'class' to be entered for each column.
authored
186 /* Add user-input custom class(es). */
187 if ( !empty( $attr['class'] ) ) {
188 if ( !is_array( $attr['class'] ) )
189 $attr['class'] = preg_split( '#\s+#', $attr['class'] );
190 $column_classes = array_merge( $column_classes, $attr['class'] );
191 }
192
488b98e @justintadlock Rewrite the logic, change some default properties, and introduce the …
authored
193 /* Add the 'column-first' class if this is the first column. */
194 if ( $this->is_first_column )
2d82e2a @justintadlock Some useful hooks for changing up things.
authored
195 $column_classes[] = 'column-first';
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
196
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
197 /* If the $span property is greater than (shouldn't be) or equal to the $grid property. */
198 if ( $this->span >= $this->grid ) {
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
199
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
200 /* Add the 'column-last' class. */
2d82e2a @justintadlock Some useful hooks for changing up things.
authored
201 $column_classes[] = 'column-last';
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
202
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
203 /* Set the $is_last_column property to true. */
204 $this->is_last_column = true;
205 }
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
206
2d82e2a @justintadlock Some useful hooks for changing up things.
authored
207 /* Object properties. */
208 $object_vars = get_object_vars( $this );
209
210 /* Allow devs to create custom classes. */
8fd23c1 @justintadlock Rename plugin to Grid Columns and update class/function names and hoo…
authored
211 $column_classes = apply_filters( 'gc_column_class', $column_classes, $attr, $object_vars );
2d82e2a @justintadlock Some useful hooks for changing up things.
authored
212
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
213 /* Sanitize and join all classes. */
2d82e2a @justintadlock Some useful hooks for changing up things.
authored
214 $column_class = join( ' ', array_map( 'sanitize_html_class', array_unique( $column_classes ) ) );
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
215
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
216 /* Output */
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
217
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
218 /* If this is the first column. */
219 if ( $this->is_first_column ) {
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
220
e7fb787 @justintadlock Move the row classes inside the check for the first column. It's the …
authored
221 /* Row classes. */
222 $row_classes = array( 'column-grid', "column-grid-{$this->grid}" );
223 $row_classes = apply_filters( 'gc_row_class', $row_classes, $attr, $object_vars );
224 $row_class = join( ' ', array_map( 'sanitize_html_class', array_unique( $row_classes ) ) );
225
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
226 /* Open a wrapper <div> to contain the columns. */
2d82e2a @justintadlock Some useful hooks for changing up things.
authored
227 $output .= '<div class="' . $row_class . '">';
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
228
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
229 /* Set the $is_first_column property back to false. */
230 $this->is_first_column = false;
231 }
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
232
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
233 /* Add the current column to the output. */
2d82e2a @justintadlock Some useful hooks for changing up things.
authored
234 $output .= '<div class="' . $column_class . '">' . wpautop( do_shortcode( $content ) ) . '</div>';
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
235
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
236 /* If this is the last column. */
237 if ( $this->is_last_column ) {
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
238
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
239 /* Close the wrapper. */
240 $output .= '</div>';
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
241
488b98e @justintadlock Rewrite the logic, change some default properties, and introduce the …
authored
242 /* Reset the properties that have been changed. */
243 $this->reset();
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
244 }
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
245
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
246 /* Return the output of the column. */
8fd23c1 @justintadlock Rename plugin to Grid Columns and update class/function names and hoo…
authored
247 return apply_filters( 'gc_column', $output );
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
248 }
488b98e @justintadlock Rewrite the logic, change some default properties, and introduce the …
authored
249
250 /**
251 * Resets the properties to their original states.
252 *
253 * @since 0.1.0
254 * @access public
255 * @return void
256 */
257 public function reset() {
258
259 foreach ( get_class_vars( __CLASS__ ) as $name => $default )
260 $this->$name = $default;
261 }
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
262 }
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
263
8fd23c1 @justintadlock Rename plugin to Grid Columns and update class/function names and hoo…
authored
264 new Grid_Columns();
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
265
266 ?>
Something went wrong with that request. Please try again.