本文整理汇总了PHP中Blade::compileString方法的典型用法代码示例。如果您正苦于以下问题:PHP Blade::compileString方法的具体用法?PHP Blade::compileString怎么用?PHP Blade::compileString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Blade
的用法示例。
在下文中一共展示了Blade::compileString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: boot
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
\Blade::directive('combine', function ($expr) {
return \Blade::compileString("implode(' ', with{$expr})");
});
\Blade::directive('capitalize', function ($expr) {
return \Blade::compileString("ucfirst(with{$expr})");
});
}
示例2: register
public static function register()
{
foreach (glob(__DIR__ . '/Helpers/*.php') as $file) {
if (preg_match("/^\\w+/", basename($file))) {
require $file;
}
}
//使WordPress支持post thumbnail
if (function_exists('add_theme_support')) {
add_theme_support('post-thumbnails');
}
// 支持自定义菜单
if (function_exists('register_nav_menus')) {
register_nav_menus(array('header-menu' => __('topnav')));
}
$sidebars = array('sidebar-profile', 'Post Sidebar', 'Page Sidebar');
foreach ($sidebars as $name) {
register_sidebar(array('name' => $name, 'before_widget' => '<div>', 'after_widget' => '</div>', 'before_title' => '<h3>', 'after_title' => '</h3>'));
}
if (function_exists('add_image_size')) {
add_image_size('60x60', 60, 60, true);
// (cropped)
add_image_size('245x163', 245, 163, true);
// (cropped)
add_image_size('337x225', 337, 225, true);
// (cropped)
}
/* //自动选择模板的函数
//通过 single_template 钩子挂载函数
add_filter('single_template', function ($single) {
//定义模板文件所在目录为 single 文件夹
define('SINGLE_PATH', TEMPLATEPATH . '/single');
global $wp_query, $post;
//通过分类别名或ID选择模板文件
$ext = '.blade.php';
foreach ((array)get_the_category() as $cat) :
if (file_exists(SINGLE_PATH . '/' . $cat->slug . $ext)) {
return SINGLE_PATH . '/' . $cat->slug . $ext;
} elseif (file_exists(SINGLE_PATH . '/' . $cat->term_id . $ext)) {
return SINGLE_PATH . '/' . $cat->term_id . $ext;
}
endforeach;
return $single;
});
*/
add_action('load-themes.php', function () {
if ($GLOBALS['pagenow'] != 'themes.php' || !isset($_GET['activated'])) {
return;
}
//仅主题启用时执行
flush_rewrite_rules();
//更新伪静态规则, 解决自定义文章类型页面 404 的问题
});
add_filter('excerpt_more', function ($more) {
return ' ...';
});
add_filter('excerpt_length', function ($length) {
return 200;
});
//apply_filters('logout_url', 'my_fixed_wp_logout_url');
add_filter('show_admin_bar', '__return_false');
add_filter('gettext', function ($translated, $text, $domain) {
if ($domain != 'cutlass') {
$t = __($text, 'cutlass');
if ($t != $text) {
$translated = $t;
}
}
return $translated;
}, 10, 3);
//让主题支持语言包
add_action('after_setup_theme', function () {
load_theme_textdomain('cutlass', get_template_directory() . '/Resources/lang');
$locale = get_locale();
$locale_file = get_template_directory() . "/Resources/lang/{$locale}.php";
if (is_readable($locale_file)) {
require_once $locale_file;
}
});
add_filter('the_content', function ($content) {
if (!is_page()) {
return $content;
}
$generated = \Blade::compileString($content);
ob_start();
extract($GLOBALS, EXTR_SKIP);
try {
eval("?>" . $generated);
} catch (\Exception $e) {
ob_get_clean();
throw $e;
}
$content = ob_get_clean();
return $content;
});
}
示例3: register
//.........这里部分代码省略.........
}
if (!current_user_can('manage_options') && !current_user_can('manage_media_library')) {
$wp_query_obj->set('author', $current_user->ID);
}
return;
});
//在[媒体库]只显示用户上传的文件
add_filter('parse_query', function (\WP_Query $wp_query) {
if (strpos($_SERVER['REQUEST_URI'], '/wp-admin/upload.php') !== false) {
if (!current_user_can("edit_others_posts") && !current_user_can('manage_media_library')) {
global $current_user;
$wp_query->set('author', $current_user->id);
}
}
});
// 为页面添加 Blade 解析功能
/** @todo 修复模板解析
* 格式: <pre tpl="section_name">...</pre>
* 或者: <pre tpl>...</pre>
* 星期三[1537]2015-09-09/06:01:58.221+0800 @foolant
*/
add_filter('the_content', function ($content) {
if (!is_page()) {
return $content;
}
extract($GLOBALS, EXTR_SKIP);
extract(\View::getShared());
if (preg_match_all("/\\s*<pre[^>]+tpl(\\=(\")?(\\w+)\\2)?[^>]*?>(.+?)<\\/pre>\\s*/s", $content, $ms, PREG_SET_ORDER)) {
foreach ($ms as $match) {
list($all, $tplsign, $t, $tpl, $code) = $match;
if ($tpl) {
$code = "@section('{$tpl}')\n{$code}\n@endsection";
}
$generated = \Blade::compileString($code);
ob_start();
try {
eval("?>" . $generated);
} catch (\Exception $e) {
ob_get_clean();
throw $e;
}
$result = ob_get_clean();
$content = str_replace($all, $result, $content);
}
}
return $content;
});
require __DIR__ . '/Helpers/admin/theme-options.php';
/* function auto_login_new_user($user_id)
{
// 这里设置的是跳转到首页,要换成其他页面
// 可以将home_url()改成你指定的URL
// 如 wp_redirect( 'http://www.baidu.com' );
//wp_redirect( home_url() );
//exit;
}
*/
// 用户注册成功后自动登录,并跳转到指定页面
// 不能使用, 后台手工注册用户也会自动登录
add_action('user_register', function ($user_id) {
if (!is_admin()) {
wp_set_current_user($user_id);
wp_set_auth_cookie($user_id);
}
});
add_filter('get_user_option_admin_color', function () {