22
33/*
44Plugin Name: Column Shortcodes
5- Version: 0.6.6
5+ Version: 0.6.7
66Description: Adds shortcodes to easily create columns in your posts or pages
77Author: Codepress
88Author URI: http://www.codepresshq.com/
2727Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2828*/
2929
30- define ( 'CPSH_VERSION ' , '0.6.6 ' );
30+ define ( 'CPSH_VERSION ' , '0.6.7 ' );
3131define ( 'CPSH_URL ' , plugins_url ( '' , __FILE__ ) );
3232define ( 'CPSH_TEXTDOMAIN ' , 'column-shortcodes ' );
3333
@@ -55,7 +55,7 @@ class Codepress_Column_Shortcodes {
5555 */
5656 function __construct () {
5757
58- add_action ( 'wp_loaded ' , array ( $ this , 'init ' ) );
58+ add_action ( 'wp_loaded ' , array ( $ this , 'init ' ) );
5959 }
6060
6161 /**
@@ -71,11 +71,11 @@ public function init() {
7171 add_action ( 'admin_footer ' , array ( $ this , 'popup ' ) );
7272
7373 // styling
74- add_action ( 'admin_print_styles ' , array ( $ this , 'admin_styles ' ) );
75- add_action ( 'wp_enqueue_scripts ' , array ( $ this , 'frontend_styles ' ) );
74+ add_action ( 'admin_print_styles ' , array ( $ this , 'admin_styles ' ) );
75+ add_action ( 'wp_enqueue_scripts ' , array ( $ this , 'frontend_styles ' ) );
7676
7777 // scripts, only load when editor is available
78- add_filter ( 'tiny_mce_plugins ' , array ( $ this , 'admin_scripts ' ) );
78+ add_filter ( 'tiny_mce_plugins ' , array ( $ this , 'admin_scripts ' ) );
7979
8080 // translations
8181 load_plugin_textdomain ( CPSH_TEXTDOMAIN , false , dirname ( plugin_basename ( __FILE__ ) ) . '/languages/ ' );
@@ -121,9 +121,10 @@ public function admin_scripts( $plugins ) {
121121 public function frontend_styles () {
122122 if ( apply_filters ( 'cpsh_load_styles ' , true ) ) {
123123 if ( ! is_rtl () ) {
124- wp_enqueue_style ( 'cpsh-shortcodes ' , CPSH_URL .'/assets/css/shortcodes.css ' , array (), CPSH_VERSION , 'all ' );
125- } else {
126- wp_enqueue_style ( 'cpsh-shortcodes-rtl ' , CPSH_URL .'/assets/css/shortcodes-rtl.css ' , array (), CPSH_VERSION , 'all ' );
124+ wp_enqueue_style ( 'cpsh-shortcodes ' , CPSH_URL . '/assets/css/shortcodes.css ' , array (), CPSH_VERSION , 'all ' );
125+ }
126+ else {
127+ wp_enqueue_style ( 'cpsh-shortcodes-rtl ' , CPSH_URL . '/assets/css/shortcodes-rtl.css ' , array (), CPSH_VERSION , 'all ' );
127128 }
128129 }
129130 }
@@ -147,44 +148,46 @@ private function add_shortcodes() {
147148 * @param array $atts
148149 * @param string $content
149150 * @param string $name
151+ *
150152 * @return string $ouput Column HTML output
151153 */
152- function columns ( $ atts , $ content = null , $ name= '' ) {
154+ function columns ( $ atts , $ content = null , $ name = '' ) {
153155
154156 $ atts = shortcode_atts ( array (
155- "id " => '' ,
156- "class " => '' ,
157- "padding " => '' ,
157+ "id " => '' ,
158+ "class " => '' ,
159+ "padding " => '' ,
158160 ), $ atts );
159161
160- $ id = sanitize_text_field ( $ atts ['id ' ] );
161- $ class = sanitize_text_field ( $ atts ['class ' ] );
162+ $ id = sanitize_text_field ( $ atts ['id ' ] );
163+ $ class = sanitize_text_field ( $ atts ['class ' ] );
162164 $ padding = sanitize_text_field ( $ atts ['padding ' ] );
163165
164- $ id = ( $ id <> '' ) ? " id=' " . esc_attr ( $ id ) . "' " : '' ;
165- $ class = ( $ class <> '' ) ? esc_attr ( ' ' . $ class ) : '' ;
166+ $ id = ( $ id <> '' ) ? " id=' " . esc_attr ( $ id ) . "' " : '' ;
167+ $ class = ( $ class <> '' ) ? esc_attr ( ' ' . $ class ) : '' ;
166168
167169 $ content = $ this ->content_helper ( $ content );
168170
169171 // padding generator
170172 if ( $ padding <> '' ) {
171- $ parts = explode (" " , $ padding );
173+ $ parts = explode ( " " , $ padding );
172174
173175 // check for '0' values. if true we will split padding attributes into top,right,bottom and left.
174176 if ( $ parts && in_array ( '0 ' , $ parts ) ) {
175- $ padding = !empty ( $ parts [0 ] ) ? "padding-top: {$ parts [0 ]}; " : '' ;
176- $ padding .= !empty ( $ parts [1 ] ) ? "padding-right: {$ parts [1 ]}; " : '' ;
177- $ padding .= !empty ( $ parts [2 ] ) ? "padding-bottom: {$ parts [2 ]}; " : '' ;
178- $ padding .= !empty ( $ parts [3 ] ) ? "padding-left: {$ parts [3 ]}; " : '' ;
177+ $ padding = ! empty ( $ parts [0 ] ) ? "padding-top: {$ parts [0 ]}; " : '' ;
178+ $ padding .= ! empty ( $ parts [1 ] ) ? "padding-right: {$ parts [1 ]}; " : '' ;
179+ $ padding .= ! empty ( $ parts [2 ] ) ? "padding-bottom: {$ parts [2 ]}; " : '' ;
180+ $ padding .= ! empty ( $ parts [3 ] ) ? "padding-left: {$ parts [3 ]}; " : '' ;
179181 }
180182 else {
181183 $ padding = "padding: {$ padding }; " ;
182184 }
183185
184186 // wraps the content in an extra div with padding applied
185187 $ content = '<div style=" ' . esc_attr ( $ padding ) . '"><p> ' . $ content . '</p></div> ' ;
186- } else {
187- $ content = '<p> ' . $ content . '</p> ' ;
188+ }
189+ else {
190+ $ content = '<p> ' . $ content . '</p> ' ;
188191 }
189192
190193 // last class
@@ -232,8 +235,9 @@ private function is_edit_screen() {
232235 * @since 0.4
233236 */
234237 private function has_permissions () {
235- if ( current_user_can ( 'edit_posts ' ) && current_user_can ( 'edit_pages ' ) )
238+ if ( current_user_can ( 'edit_posts ' ) && current_user_can ( 'edit_pages ' ) ) {
236239 return true ;
240+ }
237241
238242 return false ;
239243 }
@@ -245,11 +249,12 @@ private function has_permissions() {
245249 */
246250 function add_editor_buttons () {
247251
248- if ( ! $ this ->has_permissions () || ! $ this ->is_edit_screen () )
252+ if ( ! $ this ->has_permissions () || ! $ this ->is_edit_screen () ) {
249253 return false ;
254+ }
250255
251256 // add html buttons, when using this filter
252- if ( apply_filters ( 'add_shortcode_html_buttons ' , false ) ) {
257+ if ( apply_filters ( 'add_shortcode_html_buttons ' , false ) ) {
253258 add_action ( 'admin_head ' , array ( $ this , 'add_html_buttons ' ) );
254259 }
255260
@@ -267,9 +272,9 @@ function add_editor_buttons() {
267272 */
268273 public function add_shortcode_button ( $ page = null , $ target = null ) {
269274 ?>
270- <a href="#TB_inline?width=640&height=600&inlineId=cpsh-wrap" class="thickbox button" title="<?php _e ( 'Select shortcode ' , CPSH_TEXTDOMAIN ); ?> " data-page="<?php echo $ page ; ?> " data-target="<?php echo $ target ; ?> ">
271- <img src="<?php echo CPSH_URL . "/assets/images/shortcode.png " ;?> " alt="" />
272- </a>
275+ <a href="#TB_inline?width=640&height=600&inlineId=cpsh-wrap" class="thickbox button" title="<?php _e ( 'Select shortcode ' , CPSH_TEXTDOMAIN ); ?> " data-page="<?php echo $ page ; ?> " data-target="<?php echo $ target ; ?> ">
276+ <img src="<?php echo CPSH_URL . "/assets/images/shortcode.png " ; ?> " alt=""/>
277+ </a>
273278 <?php
274279 }
275280
@@ -285,8 +290,8 @@ public function popup() {
285290 $ select = '' ;
286291 foreach ( $ buttons as $ button ) {
287292
288- $ open_tag = str_replace ( '\n ' , '' , $ button ['options ' ]['open_tag ' ] );
289- $ close_tag = str_replace ( '\n ' , '' , $ button ['options ' ]['close_tag ' ] );
293+ $ open_tag = str_replace ( '\n ' , '' , $ button ['options ' ]['open_tag ' ] );
294+ $ close_tag = str_replace ( '\n ' , '' , $ button ['options ' ]['close_tag ' ] );
290295
291296 $ select .= "
292297 <a href='javascript:;' rel=' {$ open_tag }{$ close_tag }' data-tag=' {$ open_tag }{$ close_tag }' class='cp- {$ button ['class ' ]} columns insert-shortcode'>
@@ -307,32 +312,32 @@ public function popup() {
307312 <?php echo $ select ; ?>
308313 </div><!--.cpsh-shortcodes-->
309314
310- <?php if ( ! apply_filters ( 'cpsh_hide_padding_settings ' , false ) ) : ?>
311-
312- <div class="cpsh-settings">
313- <h2 class="cpsh-title"><?php _e ( "Column padding ( optional ) " , CPSH_TEXTDOMAIN ); ?> </h2>
314- <p class="description">
315- <?php _e ( "Use the input fields below to customize the padding of your column shortcode. " , CPSH_TEXTDOMAIN ); ?>
316- <?php _e ( "Enter padding first, then select your column shortcode. " , CPSH_TEXTDOMAIN ); ?>
317- </p>
318-
319- <div id="preview-padding">
320- <div class="column-container">
321- <div class="column-inner">
315+ <?php if ( ! apply_filters ( 'cpsh_hide_padding_settings ' , false ) ) : ?>
316+
317+ <div class="cpsh-settings">
318+ <h2 class="cpsh-title"><?php _e ( "Column padding ( optional ) " , CPSH_TEXTDOMAIN ); ?> </h2>
319+ <p class="description">
320+ <?php _e ( "Use the input fields below to customize the padding of your column shortcode. " , CPSH_TEXTDOMAIN ); ?>
321+ <?php _e ( "Enter padding first, then select your column shortcode. " , CPSH_TEXTDOMAIN ); ?>
322+ </p>
323+
324+ <div id="preview-padding">
325+ <div class="column-container">
326+ <div class="column-inner">
327+ </div>
328+ <div class="padding-fields">
329+ <input id="padding-top" placeholder="0" value=""/>
330+ <input id="padding-right" placeholder="0" value=""/>
331+ <input id="padding-bottom" placeholder="0" value=""/>
332+ <input id="padding-left" placeholder="0" value=""/>
333+ </div>
322334 </div>
323- <div class="padding-fields">
324- <input id="padding-top" placeholder="0" value=""/>
325- <input id="padding-right" placeholder="0" value=""/>
326- <input id="padding-bottom" placeholder="0" value=""/>
327- <input id="padding-left" placeholder="0" value=""/>
328- </div>
329- </div>
330335
331- <a class="padding-reset" href="javascript:;"><?php _e ( "reset " , CPSH_TEXTDOMAIN ); ?> </a>
332- </div>
333- </div><!--.cpsh-settings-->
336+ <a class="padding-reset" href="javascript:;"><?php _e ( "reset " , CPSH_TEXTDOMAIN ); ?> </a>
337+ </div>
338+ </div><!--.cpsh-settings-->
334339
335- <?php endif ; ?>
340+ <?php endif ; ?>
336341
337342 </div><!--cpsh-generator-header-->
338343
@@ -353,55 +358,59 @@ public function popup() {
353358 function get_shortcodes () {
354359 static $ shortcodes ;
355360
356- if ( ! empty ( $ shortcodes ) )
361+ if ( ! empty ( $ shortcodes ) ) {
357362 return $ shortcodes ;
363+ }
358364
359365 // define column shortcodes
360366 $ column_shortcodes = apply_filters ( 'cpsh_column_shortcodes ' , array (
361- 'full_width ' => array ( 'display_name ' => __ ('full width ' , CPSH_TEXTDOMAIN ) ),
362- 'one_half ' => array ( 'display_name ' => __ ('one half ' , CPSH_TEXTDOMAIN ) ),
363- 'one_third ' => array ( 'display_name ' => __ ('one third ' , CPSH_TEXTDOMAIN ) ),
364- 'one_fourth ' => array ( 'display_name ' => __ ('one fourth ' , CPSH_TEXTDOMAIN ) ),
365- 'two_third ' => array ( 'display_name ' => __ ('two third ' , CPSH_TEXTDOMAIN ) ),
366- 'three_fourth ' => array ( 'display_name ' => __ ('three fourth ' , CPSH_TEXTDOMAIN ) ),
367- 'one_fifth ' => array ( 'display_name ' => __ ('one fifth ' , CPSH_TEXTDOMAIN ) ),
368- 'two_fifth ' => array ( 'display_name ' => __ ('two fifth ' , CPSH_TEXTDOMAIN ) ),
369- 'three_fifth ' => array ( 'display_name ' => __ ('three fifth ' , CPSH_TEXTDOMAIN ) ),
370- 'four_fifth ' => array ( 'display_name ' => __ ('four fifth ' , CPSH_TEXTDOMAIN ) ),
371- 'one_sixth ' => array ( 'display_name ' => __ ('one sixth ' , CPSH_TEXTDOMAIN ) ),
372- 'five_sixth ' => array ( 'display_name ' => __ ('five sixth ' , CPSH_TEXTDOMAIN ) )
373- ));
374-
375- if ( ! $ column_shortcodes )
367+ 'full_width ' => array ( 'display_name ' => __ ( 'full width ' , CPSH_TEXTDOMAIN ) ),
368+ 'one_half ' => array ( 'display_name ' => __ ( 'one half ' , CPSH_TEXTDOMAIN ) ),
369+ 'one_third ' => array ( 'display_name ' => __ ( 'one third ' , CPSH_TEXTDOMAIN ) ),
370+ 'one_fourth ' => array ( 'display_name ' => __ ( 'one fourth ' , CPSH_TEXTDOMAIN ) ),
371+ 'two_third ' => array ( 'display_name ' => __ ( 'two third ' , CPSH_TEXTDOMAIN ) ),
372+ 'three_fourth ' => array ( 'display_name ' => __ ( 'three fourth ' , CPSH_TEXTDOMAIN ) ),
373+ 'one_fifth ' => array ( 'display_name ' => __ ( 'one fifth ' , CPSH_TEXTDOMAIN ) ),
374+ 'two_fifth ' => array ( 'display_name ' => __ ( 'two fifth ' , CPSH_TEXTDOMAIN ) ),
375+ 'three_fifth ' => array ( 'display_name ' => __ ( 'three fifth ' , CPSH_TEXTDOMAIN ) ),
376+ 'four_fifth ' => array ( 'display_name ' => __ ( 'four fifth ' , CPSH_TEXTDOMAIN ) ),
377+ 'one_sixth ' => array ( 'display_name ' => __ ( 'one sixth ' , CPSH_TEXTDOMAIN ) ),
378+ 'five_sixth ' => array ( 'display_name ' => __ ( 'five sixth ' , CPSH_TEXTDOMAIN ) ),
379+ ) );
380+
381+ if ( ! $ column_shortcodes ) {
376382 return array ();
383+ }
377384
378385 foreach ( $ column_shortcodes as $ short => $ options ) {
379386
380387 // add prefix
381388 $ shortcode = $ this ->prefix . $ short ;
382389
383- $ shortcodes [] = array (
384- 'name ' => $ shortcode ,
385- 'class ' => $ short ,
386- 'options ' => array (
387- 'display_name ' => $ options ['display_name ' ],
388- 'open_tag ' => '\n ' . "[ {$ shortcode }] " ,
389- 'close_tag ' => "[/ {$ shortcode }] " . '\n ' ,
390- 'key ' => ''
391- )
390+ $ shortcodes [] = array (
391+ 'name ' => $ shortcode ,
392+ 'class ' => $ short ,
393+ 'options ' => array (
394+ 'display_name ' => $ options ['display_name ' ],
395+ 'open_tag ' => '\n ' . "[ {$ shortcode }] " ,
396+ 'close_tag ' => "[/ {$ shortcode }] " . '\n ' ,
397+ 'key ' => '' ,
398+ ),
392399 );
393400
394- if ( 'full_width ' == $ short ) continue ;
395-
396- $ shortcodes [] = array (
397- 'name ' => "{$ shortcode }_last " ,
398- 'class ' => "{$ short }_last " ,
399- 'options ' => array (
400- 'display_name ' => $ options ['display_name ' ] . ' ( ' . __ ('last ' , CPSH_TEXTDOMAIN ) . ') ' ,
401- 'open_tag ' => '\n ' ."[ {$ shortcode }_last] " ,
402- 'close_tag ' => "[/ {$ shortcode }_last] " .'\n ' ,
403- 'key ' => ''
404- )
401+ if ( 'full_width ' == $ short ) {
402+ continue ;
403+ }
404+
405+ $ shortcodes [] = array (
406+ 'name ' => "{$ shortcode }_last " ,
407+ 'class ' => "{$ short }_last " ,
408+ 'options ' => array (
409+ 'display_name ' => $ options ['display_name ' ] . ' ( ' . __ ( 'last ' , CPSH_TEXTDOMAIN ) . ') ' ,
410+ 'open_tag ' => '\n ' . "[ {$ shortcode }_last] " ,
411+ 'close_tag ' => "[/ {$ shortcode }_last] " . '\n ' ,
412+ 'key ' => '' ,
413+ ),
405414 );
406415 }
407416
@@ -450,6 +459,7 @@ function add_html_buttons() {
450459 * @param string $content
451460 * @param bool $paragraph_tag Filter p-tags
452461 * @param bool $br_tag Filter br-tags
462+ *
453463 * @return string Shortcode
454464 */
455465 function content_helper ( $ content , $ paragraph_tag = false , $ br_tag = false ) {
0 commit comments