Last active
December 21, 2018 05:50
-
-
Save webarthur/072fca2531cea59cd46c to your computer and use it in GitHub Desktop.
Extending Blade template engine for WordPress
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
<?php | |
require_once dirname(__FILE__).'/lib/class.blade.php'; | |
Blade::extend(function($value) { | |
$value = preg_replace('/(\s*)@wphead(\s*)/', '$1<?php wp_head() ?>$2', $value); | |
$value = preg_replace('/(\s*)@wpposts(\s*)/', '$1<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>$2', $value); | |
$value = preg_replace('/(\s*)@wpquery(\s*\(.*\))/', '$1<?php $q = new WP_Query$2; if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post(); ?> ', $value); | |
$value = preg_replace('/(\s*)@wpempty(\s*)/', '$1<?php endwhile; ?><?php else: ?>$2', $value); | |
$value = preg_replace('/(\s*)@wpend(\s*)/', '$1<?php endif; wp_reset_postdata(); ?>$2', $value); | |
$value = preg_replace('/(\s*)@avatar(\s*\(.*\))(\s*)/', '$1<?php echo get_avatar$2 ?>', $value); | |
$value = preg_replace('/(\s*)@thumbnail(\s*\(.*\))(\s*)/', '$1<?php the_post_thumbnail$2 ?>', $value); | |
$value = preg_replace('/(\s*)@thumbnail(\s*)/', '$1<?php the_post_thumbnail("thumbnail") ?>$2', $value); | |
$value = preg_replace('/(\s*)@permalink(\s*\(.*\))(\s*)/', '$1<?php echo get_permalink$2 ?>', $value); | |
$value = preg_replace('/(\s*)@permalink(\s*)/', '$1<?php the_permalink() ?>$2', $value); | |
$value = preg_replace('/(\s*)@title(\s*)/', '$1<?php the_title() ?>$2', $value); | |
$value = preg_replace('/(\s*)@excerpt(\s*)/', '$1<?php the_excerpt() ?>$2', $value); | |
$value = preg_replace('/(\s*)@content(\s*)/', '$1<?php the_content() ?>$2', $value); | |
$value = preg_replace('/(\s*)@author(\s*)/', '$1<?php the_author() ?>$2', $value); | |
$value = preg_replace('/(\s*)@meta(\s*)/', '$1<?php the_meta() ?>$2', $value); | |
$value = preg_replace('/(\s*)@time(\s*\(.*\))/', '$1<?php the_time$2 ?>', $value); | |
$value = preg_replace('/(\s*)@time(\s*)/', '$1<?php the_time() ?>$2', $value); | |
$value = preg_replace('/(\s*)@inc(.+)?(\s*)/', '$1<?php include trim("${2}").".php" ?>$3', $value); | |
$value = preg_replace('/(\s*)@php(.+)?(\s*)/', '$1<?php ${2} ?>$3', $value); | |
$value = preg_replace('/(\s*)@e(\s*\(.*\))/', '$1<?php _e$2 ?>', $value); | |
$value = preg_replace('/(\s*)@header(\s*\(.*\))/', '$1<?php get_header$2 ?>', $value); | |
$value = preg_replace('/(\s*)@header(\s*)/', '$1<?php get_header() ?>$3', $value); | |
$value = preg_replace('/(\s*)@sidebar(\s*\(.*\))/', '$1<?php get_sidebar$2 ?>', $value); | |
$value = preg_replace('/(\s*)@sidebar(.+)?(\s*)/', '$1<?php get_sidebar() ?>$3', $value); | |
$value = preg_replace('/(\s*)@comments(\s*\(.*\))/', '$1<?php comments_template$2 ?>', $value); | |
$value = preg_replace('/(\s*)@comments(.+)?(\s*)/', '$1<?php comments_template() ?>$3', $value); | |
$value = preg_replace('/(\s*)@footer(\s*\(.*\))/', '$1<?php get_footer$2 ?>', $value); | |
$value = preg_replace('/(\s*)@footer(.+)?(\s*)/', '$1<?php get_footer() ?>$3', $value); | |
$value = preg_replace('/(\s*)@template_url/', '$1<?php echo get_template_directory_uri() ?>', $value); | |
$value = preg_replace('/(\s*)@template(\s*\(.*\))/', '$1<?php get_template_part$2 ?>', $value); | |
$value = preg_replace('/(\s*)@template(.+)?(\s*)/', '$1<?php get_template_part() ?>$3', $value); | |
$value = preg_replace('/(\s*)@search_form(.+)?(\s*)/', '$1<?php get_search_form() ?>$3', $value); | |
$value = preg_replace('/(\s*)@site_url/', '$1<?php echo site_url() ?>', $value); | |
$value = preg_replace('/(\s*)@ajax_url/', '$1<?php echo admin_url(\'admin-ajax.php\' ) ?>', $value); | |
$value = preg_replace('/(\s*)@image(\s*\([\'"](.*)[\'"]\))/', '$1<img src="<?php echo get_bloginfo("template_url") ?>/$3" />', $value); | |
return $value; | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment