Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 271 lines (223 sloc) 7.589 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.
31b629a @justintadlock Version bump to 0.1.1.
authored
6 * Version: 0.1.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
31b629a @justintadlock Version bump to 0.1.1.
authored
26 * @version 0.1.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 );
9eb9530 @justintadlock Create the 'gc_column_content' hook and separate formatting from the …
authored
94
95 /* Apply filters to the column content. */
96 add_filter( 'gc_column_content', 'wpautop' );
97 add_filter( 'gc_column_content', 'shortcode_unautop' );
98 add_filter( 'gc_column_content', 'do_shortcode' );
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
99 }
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
100
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
101 /**
102 * Registers the [column] shortcode.
103 *
104 * @since 0.1.0
105 * @access public
106 * @return void
107 */
108 public function register_shortcode() {
109 add_shortcode( 'column', array( &$this, 'do_shortcode' ) );
110 }
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
111
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
112 /**
113 * Enqueues the columns.css stylesheet to make the columns pretty.
114 *
115 * @since 0.1.0
116 * @access public
117 * @return void
118 */
119 public function enqueue_styles() {
120
358f47f @justintadlock Add support for the columns.min.css file.
authored
121 /* Use the .min stylesheet if SCRIPT_DEBUG is turned off. */
122 $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
123
124 /* Enqueue the stylesheet. */
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
125 wp_enqueue_style(
aae663d @justintadlock Change style ID to 'grid-columns'.
authored
126 'grid-columns',
81b394d @justintadlock Move stylesheet files to the CSS folder.
authored
127 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
128 null,
bca16e1 @justintadlock Prefix .column* classes with .column-grid to be more specific and add…
authored
129 '20121007'
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
130 );
131 }
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
132
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
133 /**
134 * Returns the content of the column shortcode.
135 *
136 * @since 0.1.0
137 * @access public
138 * @param array $attr The user-inputted arguments.
139 * @param string $content The content to wrap in a shortcode.
140 * @return string
141 */
142 public function do_shortcode( $attr, $content = null ) {
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
143
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
144 /* If there's no content, just return back what we got. */
145 if ( is_null( $content ) )
146 return $content;
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
147
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
148 /* Set up the default variables. */
149 $output = '';
2d82e2a @justintadlock Some useful hooks for changing up things.
authored
150 $row_classes = array();
151 $column_classes = array();
90d3d06 @justintadlock Add some extra filter hooks to allow for some flexibility.
authored
152
153 /* Set up the default arguments. */
13ea202 @justintadlock Allow for a custom 'class' to be entered for each column.
authored
154 $defaults = apply_filters(
155 'gc_column_defaults',
156 array(
488b98e @justintadlock Rewrite the logic, change some default properties, and introduce the …
authored
157 'grid' => $this->grid,
13ea202 @justintadlock Allow for a custom 'class' to be entered for each column.
authored
158 'span' => 1,
159 'push' => 0,
160 'class' => ''
161 )
162 );
90d3d06 @justintadlock Add some extra filter hooks to allow for some flexibility.
authored
163
164 /* Parse the arguments. */
165 $attr = shortcode_atts( $defaults, $attr );
166
167 /* Allow devs to filter the arguments. */
8fd23c1 @justintadlock Rename plugin to Grid Columns and update class/function names and hoo…
authored
168 $attr = apply_filters( 'gc_column_args', $attr );
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
169
2fae04d @justintadlock Change 'allowed_grid' to 'allowed_grids' and allow it to be filtered.
authored
170 /* Allow devs to overwrite the allowed grids. */
8fd23c1 @justintadlock Rename plugin to Grid Columns and update class/function names and hoo…
authored
171 $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
172
08f5bd6 @justintadlock Update allowed grids code.
authored
173 /* Make sure the grid is in the allowed grids array. */
488b98e @justintadlock Rewrite the logic, change some default properties, and introduce the …
authored
174 if ( $this->is_first_column && in_array( $attr['grid'], $this->allowed_grids ) )
175 $this->grid = absint( $attr['grid'] );
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
176
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
177 /* Span cannot be greater than the grid. */
488b98e @justintadlock Rewrite the logic, change some default properties, and introduce the …
authored
178 $attr['span'] = ( $this->grid >= $attr['span'] ) ? absint( $attr['span'] ) : 1;
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
179
e0f8de3 @justintadlock Inline doc updates.
authored
180 /* The push argument should always be less than the grid. */
488b98e @justintadlock Rewrite the logic, change some default properties, and introduce the …
authored
181 $attr['push'] = ( $this->grid > $attr['push'] ) ? absint( $attr['push'] ) : 0;
17a3025 @justintadlock Add 'push' ability.
authored
182
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
183 /* Add to the total $span. */
17a3025 @justintadlock Add 'push' ability.
authored
184 $this->span = $this->span + $attr['span'] + $attr['push'];
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
185
2d82e2a @justintadlock Some useful hooks for changing up things.
authored
186 /* Column classes. */
187 $column_classes[] = 'column';
188 $column_classes[] = "column-span-{$attr['span']}";
17a3025 @justintadlock Add 'push' ability.
authored
189 $column_classes[] = "column-push-{$attr['push']}";
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
190
13ea202 @justintadlock Allow for a custom 'class' to be entered for each column.
authored
191 /* Add user-input custom class(es). */
192 if ( !empty( $attr['class'] ) ) {
193 if ( !is_array( $attr['class'] ) )
194 $attr['class'] = preg_split( '#\s+#', $attr['class'] );
195 $column_classes = array_merge( $column_classes, $attr['class'] );
196 }
197
488b98e @justintadlock Rewrite the logic, change some default properties, and introduce the …
authored
198 /* Add the 'column-first' class if this is the first column. */
199 if ( $this->is_first_column )
2d82e2a @justintadlock Some useful hooks for changing up things.
authored
200 $column_classes[] = 'column-first';
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
201
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
202 /* If the $span property is greater than (shouldn't be) or equal to the $grid property. */
203 if ( $this->span >= $this->grid ) {
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
204
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
205 /* Add the 'column-last' class. */
2d82e2a @justintadlock Some useful hooks for changing up things.
authored
206 $column_classes[] = 'column-last';
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
207
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
208 /* Set the $is_last_column property to true. */
209 $this->is_last_column = true;
210 }
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
211
2d82e2a @justintadlock Some useful hooks for changing up things.
authored
212 /* Object properties. */
213 $object_vars = get_object_vars( $this );
214
215 /* Allow devs to create custom classes. */
8fd23c1 @justintadlock Rename plugin to Grid Columns and update class/function names and hoo…
authored
216 $column_classes = apply_filters( 'gc_column_class', $column_classes, $attr, $object_vars );
2d82e2a @justintadlock Some useful hooks for changing up things.
authored
217
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
218 /* Sanitize and join all classes. */
2d82e2a @justintadlock Some useful hooks for changing up things.
authored
219 $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
220
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
221 /* Output */
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
222
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
223 /* If this is the first column. */
224 if ( $this->is_first_column ) {
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
225
e7fb787 @justintadlock Move the row classes inside the check for the first column. It's the …
authored
226 /* Row classes. */
227 $row_classes = array( 'column-grid', "column-grid-{$this->grid}" );
228 $row_classes = apply_filters( 'gc_row_class', $row_classes, $attr, $object_vars );
229 $row_class = join( ' ', array_map( 'sanitize_html_class', array_unique( $row_classes ) ) );
230
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
231 /* Open a wrapper <div> to contain the columns. */
2d82e2a @justintadlock Some useful hooks for changing up things.
authored
232 $output .= '<div class="' . $row_class . '">';
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
233
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
234 /* Set the $is_first_column property back to false. */
235 $this->is_first_column = false;
236 }
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
237
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
238 /* Add the current column to the output. */
9eb9530 @justintadlock Create the 'gc_column_content' hook and separate formatting from the …
authored
239 $output .= '<div class="' . $column_class . '">' . apply_filters( 'gc_column_content', $content ) . '</div>';
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
240
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
241 /* If this is the last column. */
242 if ( $this->is_last_column ) {
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
243
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
244 /* Close the wrapper. */
245 $output .= '</div>';
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
246
488b98e @justintadlock Rewrite the logic, change some default properties, and introduce the …
authored
247 /* Reset the properties that have been changed. */
248 $this->reset();
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
249 }
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
250
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
251 /* Return the output of the column. */
8fd23c1 @justintadlock Rename plugin to Grid Columns and update class/function names and hoo…
authored
252 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
253 }
488b98e @justintadlock Rewrite the logic, change some default properties, and introduce the …
authored
254
255 /**
256 * Resets the properties to their original states.
257 *
258 * @since 0.1.0
259 * @access public
260 * @return void
261 */
262 public function reset() {
263
264 foreach ( get_class_vars( __CLASS__ ) as $name => $default )
265 $this->$name = $default;
266 }
6bd5eca @justintadlock More code than I'd like. Not as pretty as I'd like. But, we've got a …
authored
267 }
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
268
8fd23c1 @justintadlock Rename plugin to Grid Columns and update class/function names and hoo…
authored
269 new Grid_Columns();
b9c0d31 @justintadlock First pass. It's not pretty yet, but it works.
authored
270
271 ?>
Something went wrong with that request. Please try again.