-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fixed activation_hook not working due to wrong class scope. - Changed [grid] shortcode format. Check wiki for details. - Added [button] shortcode format. Check wiki for details. - Fixed wrong return format on Post Type function create_labels();
- Loading branch information
Showing
5 changed files
with
104 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
class H_Shortcode { | ||
function __construct() { | ||
add_shortcode( 'grid', [$this, 'grid'] ); | ||
add_shortcode( 'button', [$this, 'button'] ); | ||
} | ||
|
||
/* | ||
Wrap content with Edje's CSS Grid | ||
[grid $sizes <$state>] ... [/grid] | ||
@atts $sizes - Column size between 1 to 12. Can specify mobile column with dash like 8-6 (meaning 8 on desktop, 6 on mobile). | ||
@atts $state (optional) - Either "start" or "end". | ||
Example: | ||
[grid 8-6 start] | ||
... | ||
[/grid] [grid 4-6 end] | ||
... | ||
[/grid] | ||
Result: | ||
<h-grid> <div class="large-8 small-6"> | ||
... | ||
</div> <div class="large-4 small-6"> | ||
... | ||
</div> </h-grid> | ||
*/ | ||
function grid( $atts, $content = null ) { | ||
$size = $atts[0] ?? '12'; | ||
$state = $atts[1] ?? 'start'; | ||
|
||
preg_match( '/^\d+/', $size, $large_size ); | ||
preg_match( '/-(\d+)$/', $size, $small_size ); | ||
|
||
// create opening and closing tag | ||
$opening = $state == 'start' ? '<h-grid>' : ''; | ||
$closing = $state == 'end' ? '</div> </h-grid>' : '</div>'; | ||
|
||
// form the column classes | ||
$classes = "large-$large_size[0]"; | ||
$classes .= isset( $small_size[1] ) ? " small-$small_size[1]" : ''; | ||
|
||
return $opening . "<div class='$classes'>" . do_shortcode($content) . $closing; | ||
} | ||
|
||
/* | ||
Add button class to the link inside | ||
[button $class] link [/button] | ||
@atts $class (string, optional) - Extra class name, will be prefixed with "button--". | ||
Example: | ||
[button line] link [/button] | ||
Result: | ||
<a class="button button--line" href="..."> ... </a> | ||
*/ | ||
function button( $atts, $content = null ) { | ||
$extra_class = isset( $atts[0] ) ? "button--$atts[0]" : ''; | ||
|
||
// if have anchor inside, add button class | ||
if( preg_match( '/<a (.+?)>/', $content, $match ) ) { | ||
$content = substr_replace( $content, " class='button $extra_class' ", 3, 0 ); | ||
} | ||
// else, make it into do-nothing button | ||
else { | ||
$content = "<a class='button $extra_class'>" . $content . '</a>'; | ||
} | ||
|
||
return $content; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters