Skip to content

Commit

Permalink
2.1.4
Browse files Browse the repository at this point in the history
- [Activation Hook] Added "blog-nav" menu containing 2 links: All Posts and Uncategorized category
- [Helper] Refactored Twig Helper
  • Loading branch information
hrsetyono authored Apr 18, 2019
1 parent 1754e59 commit 986bd13
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 65 deletions.
55 changes: 40 additions & 15 deletions activation-hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ private function _create_default_nav() {
'name' => 'Main Nav',
'location' => 'main-nav',
'items' => [
[ 'menu-item-title' => 'Home', 'menu-item-url' => home_url(), 'menu-item-status' => 'publish' ]
[
'menu-item-title' => 'Home',
'menu-item-url' => home_url(),
'menu-item-status' => 'publish',
]
]
],

Expand All @@ -134,27 +138,48 @@ private function _create_default_nav() {
]
]
],

// BLOG
[
'name' => 'Blog Nav',
'location' => 'blog-nav',
'items' => [
[
'menu-item-title' => 'All Posts',
'menu-item-object' => 'post',
'menu-item-status' => 'publish',
'menu-item-type' => 'post_type_archive',
],
[
'menu-item-object-id' => 1,
'menu-item-object' => 'category',
'menu-item-status' => 'publish',
'menu-item-type' => 'taxonomy',
],
]
]
);

$locations = get_theme_mod('nav_menu_locations');
$locations = get_theme_mod( 'nav_menu_locations' );

foreach($navs as $nav):
// if doesn't exist AND the location isn't occupied
if(! wp_get_nav_menu_object($nav['name'] && !has_nav_menu($nav['location'])) ) {
// create empty menu
$menu_id = wp_create_nav_menu($nav['name']);
foreach( $navs as $nav ):
// if the nav location is occupied OR nav name already exists
if( has_nav_menu( $nav['location'] ) || wp_get_nav_menu_object( $nav['name'] ) ) {
continue;
}

// add menu items
foreach($nav['items'] as $item) {
wp_update_nav_menu_item($menu_id, 0, $item);
}
// create empty menu
$menu_id = wp_create_nav_menu( $nav['name'] );

// set the menu location
$locations[$nav['location']] = $menu_id;
set_theme_mod('nav_menu_locations', $locations);
// add menu items
foreach( $nav['items'] as $item ) {
wp_update_nav_menu_item( $menu_id, 0, $item );
}
endforeach;

// set the menu location
$locations[ $nav['location'] ] = $menu_id;
set_theme_mod( 'nav_menu_locations', $locations );
endforeach;
}

/*
Expand Down
8 changes: 4 additions & 4 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.1.2
Version: 2.1.4
*/

if( !defined( 'WPINC' ) ) { die; } // exit if accessed directly
Expand All @@ -23,7 +23,7 @@ class Edje_WP_Library {
function __construct() {
add_action( 'plugins_loaded' , [$this, 'load_modules'] );

if( defined( 'EDJE' ) ) {
if( defined( 'EDJE' ) ) {
require_once 'activation-hook.php';
register_activation_hook( H_BASE, [$this, 'register_activation_hook'] );
}
Expand Down Expand Up @@ -59,8 +59,8 @@ private function module_helper() {

// If Timber is activated
if( _H::is_plugin_active('timber') ) {
require_once 'module-helper/h-twig.php';
new H_Twig();
require_once 'module-helper/twig-helper.php';
new \h\Twig_Helper();
}
}

Expand Down
1 change: 1 addition & 0 deletions module-helper/h-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ static function is_plugin_active( $slug ) {
$path[] = 'timber-library-160/timber.php';
$path[] = 'timber-library-170/timber.php';
$path[] = 'timber-library-180/timber.php';
$path[] = 'timber-library-190/timber.php';
break;

case 'acf':
Expand Down
46 changes: 0 additions & 46 deletions module-helper/h-twig.php

This file was deleted.

58 changes: 58 additions & 0 deletions module-helper/twig-helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php namespace h;
/**
* Add extra functionality to Twig module
*/
class Twig_Helper {
function __construct() {
add_filter('get_twig', array($this, 'add_to_twig') );

// enable password-protected post
add_filter( 'timber/post/content/show_password_form_for_protected', '__return_true' );
}


/**
* Add default filter to Twig
* @filter get_twig
*/
function add_to_twig( $twig ) {
$twig->addFilter( new \Twig_SimpleFilter( 'markdown', [$this, '_filter_markdown'] ) );

// only if set to Debug mode
if( defined('WP_DEBUG') && WP_DEBUG === true ) {
$twig->addFilter( new \Twig_SimpleFilter( 'dump', [$this, '_filter_dump'] ) );
$twig->addFilter( new \Twig_SimpleFilter( 'methods', [$this, '_filter_methods'] ) );
}

return $twig;
}

//


/**
* Parse Markdown
* {{ post.custom_field | markdown }}
*/
function _filter_markdown( $text ) {
$pd = new \Parsedown();
$text_compiled = $pd->text( $text );
return do_shortcode( $text_compiled );
}

/**
* Echo the data
* {{ post | dump }}
*/
function _filter_dump( $anything ) {
var_dump( $anything );
}

/**
* Echo all the methods of an object
* {{ post | methods }}
*/
function _filter_methods( $object ) {
var_dump( get_class_methods( $object ) );
}
}

0 comments on commit 986bd13

Please sign in to comment.