Skip to content

Commit

Permalink
2.0.2
Browse files Browse the repository at this point in the history
- 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
hrsetyono committed Mar 27, 2019
1 parent a2b0a5e commit 21450a5
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 140 deletions.
36 changes: 16 additions & 20 deletions activation-hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class H_Hook {
/*
Run when the plugin is activated
*/
function activation_hook() {
function on_activation() {
$options = get_option('h_options');

// create empty option if doesn't exist
Expand Down Expand Up @@ -104,40 +104,36 @@ private function _create_blogpage() {
private function _create_default_nav() {
$navs = array(
// MAIN
array(
[
'name' => 'Main Nav',
'location' => 'main-nav',
'items' => array(
array(
'menu-item-title' => 'Home',
'menu-item-url' => home_url(),
'menu-item-status' => 'publish'
)
)
),
'items' => [
[ 'menu-item-title' => 'Home', 'menu-item-url' => home_url(), 'menu-item-status' => 'publish' ]
]
],

// SOCIAL
array(
[
'name' => 'Social Nav',
'location' => 'social-nav',
'items' => array(
array(
'items' => [
[
'menu-item-title' => 'facebook',
'menu-item-url' => 'https://www.facebook.com/username',
'menu-item-status' => 'publish'
),
array(
],
[
'menu-item-title' => 'twitter',
'menu-item-url' => 'https://twitter.com/username',
'menu-item-status' => 'publish'
),
array(
],
[
'menu-item-title' => 'google-plus',
'menu-item-url' => 'https://plus.google.com/+username',
'menu-item-status' => 'publish'
)
)
),
]
]
],
);

$locations = get_theme_mod('nav_menu_locations');
Expand Down
21 changes: 11 additions & 10 deletions edje-wp-library.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Plugin URI: http://github.com/hrsetyono/edje-wp-library
Author: Pixel Studio
Author URI: https://pixelstudio.id
Version: 2.0.1
Version: 2.0.2
*/

if( !defined( 'WPINC' ) ) { die; } // exit if accessed directly
Expand All @@ -22,7 +22,12 @@
class Edje_WP_Library {
function __construct() {
$this->load_modules();
$this->register_activation_hook();

// activation hook
if( defined( 'EDJE' ) ) {
require_once 'activation-hook.php';
register_activation_hook( H_BASE, [$this, 'register_activation_hook'] );
}
}

/*
Expand All @@ -42,13 +47,9 @@ private function load_modules() {
/*
Register activation and deactivation hook
*/
private function register_activation_hook() {
if( defined( 'EDJE' ) ) {
require_once 'activation-hook.php';

register_activation_hook( H_BASE, ['H_Hook', 'activation_hook'] );
register_deactivation_hook( H_BASE, ['H_Hook', 'deactivation_hook'] );
}
function register_activation_hook() {
$hook = new H_Hook();
$hook->on_activation();
}

//
Expand All @@ -58,7 +59,7 @@ private function module_helper() {

// only if not in admin
if( !is_admin() ) {
require_once 'module-helper/h-shortcode.php';
require_once 'module-helper/custom-shortcode.php';
new H_Shortcode();
}

Expand Down
76 changes: 76 additions & 0 deletions module-helper/custom-shortcode.php
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;
}
}
109 changes: 0 additions & 109 deletions module-helper/h-shortcode.php

This file was deleted.

2 changes: 1 addition & 1 deletion module-post-type/post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function add_custom_post_glance() {
@param string $slug
@return array
*/
private function _create_labels( string $slug ) : string {
private function _create_labels( string $slug ) : array {
$name = \_H::to_title( $slug );
$plural = \Inflector::pluralize( $name );
$singular = $name;
Expand Down

0 comments on commit 21450a5

Please sign in to comment.