function testFailedRoute() { $_SERVER['REQUEST_METHOD'] = 'GET'; global $matches; $matches = array(); $phpunit = $this; Timber::add_route('foo', function () use($phpunit) { $phpunit->assertTrue(false); $matches[] = true; }); $this->go_to(home_url('bar')); global $timber; $timber->init_routes(); $this->assertEquals(0, count($matches)); }
function add_to_twig($twig) { /* this is where you can add your own fuctions to twig */ $twig->addExtension(new Twig_Extension_StringLoader()); $twig->addFilter('myfoo', new Twig_Filter_Function('myfoo')); return $twig; } } new StarterSite(); function myfoo($text) { $text .= ' bar!'; return $text; } Timber::add_route('guests', function ($params) { Timber::load_view('guests.php', null, 200, $params); }); function cc_mime_types($mimes) { $mimes['svg'] = 'image/svg+xml'; return $mimes; } function annointed_admin_bar_remove() { global $wp_admin_bar; /* Remove their stuff */ $wp_admin_bar->remove_menu('wp-logo'); } function remove_menus() { remove_menu_page('edit-comments.php');
add_action('wp_enqueue_scripts', 'load_scripts'); update_option('siteurl', 'http://' . $_SERVER['HTTP_HOST']); update_option('home', 'http://' . $_SERVER['HTTP_HOST']); if (class_exists('Timber')) { Timber::add_route('blog', function ($params) { $sticky = get_option('sticky_posts'); $sticky = TimberHelper::array_truncate($sticky, 4); $page = 0; $query = array('post_type' => 'post', 'posts_per_page' => 6, 'post__not_in' => $sticky, 'offset' => $page * 6); Timber::load_template('archive-blog.php', $query); }); Timber::add_route('blog/page/:pg', function ($params) { $sticky = get_option('sticky_posts'); $sticky = TimberHelper::array_truncate($sticky, 4); $page = $params['pg']; $page -= 1; $page = max(0, $page); $query = array('post_type' => 'post', 'posts_per_page' => 6, 'post__not_in' => $sticky, 'offset' => $page * 6); Timber::load_template('archive-blog.php', $query); }); } if (class_exists('BladesSite')) { BladesSite::register_post_types(); BladesSite::apply_admin_customizations(); add_action('init', function () { BladesSite::register_post_types(); }); } if (class_exists('ChainsawDashboard')) { $dashboard = new ChainsawDashboard('wp-content/themes/blades/blades-dashboard.json'); }
global $current_user; get_currentuserinfo(); $has_comment = get_comments(array('user_id' => $current_user->ID, 'meta_key' => 'projeto', 'meta_value' => $params['name'])); if (count($has_comment) > 0) { //redirecionar para pagina de resultado $voting = ''; foreach ($has_comment as $comment) { $voting .= $comment->comment_content . ','; } header('Location: ' . get_bloginfo('url') . '/projetos/' . $params['name'] . '/resultados?answered=1&voting=' . $voting); exit; } $query = 'posts_per_page=12&post_type=avaliacao&cat_name=' . $params['name']; Timber::load_template('archive.php', $query); }); Timber::add_route('projetos/:name/resultados', function ($params) { if (!is_user_logged_in()) { wp_redirect(get_bloginfo('url') . '/entrar/?redirect_to=' . get_bloginfo('url') . '/projetos/' . $params['name'] . '/resultados'); exit; } $query = 'category_name=' . $params['name'] . '&posts_per_page=12&post_type=avaliacao'; Timber::load_template('resultado-passo-1.php', $query); }); Timber::add_route('projetos/:name/resultado-geral', function ($params) { $query = 'category_name=' . $params['name']; Timber::load_template('resultado-passo-1-geral.php', $query); }); Timber::add_route('projetos/:name/:user', function ($params) { $query = 'category_name=' . $params['name'] . '&posts_per_page=12&post_type=avaliacao&username='******'user']; Timber::load_template('resultado-passo-1.php', $query); });
foreach ($values as $value) { if (array_search($value, $array) !== false) { return true; } else { return false; } } } function matchesAny($matcher, $values) { foreach ($values as $value) { if ($matcher === $value) { return true; } } } /* NEWS PAGINATION */ Timber::add_route('news', function () { $page = 0; $query = array('post_type' => 'post', 'posts_per_page' => 2, 'offset' => $page * 2); query_posts($query); Timber::load_template('archive.php'); }); Timber::add_route('news/page/:pg', function ($params) { $page = $params['pg']; $page = max(0, $page); $page = $page; $query = array('post_type' => 'post', 'posts_per_page' => 2, 'paged' => $page); query_posts($query); Timber::load_template('archive.php'); });
<?php Timber::add_route('/makerspaces', function () { die(json_encode(Timber::get_posts('post_type=makerspace'))); });
function testVerySimpleRoutePreceedingSlash() { $_SERVER['REQUEST_METHOD'] = 'GET'; global $matches; $matches = array(); $phpunit = $this; Timber::add_route('/gobbles', function () use($phpunit) { global $matches; $matches = array(); $matches[] = true; }); $this->go_to(home_url('gobbles')); $this->matchRoutes(); $this->assertEquals(1, count($matches)); }
} } new SustainableSite(); if (function_exists('acf_add_options_page')) { acf_add_options_page(array('page_title' => 'General Theme Settings', 'menu_title' => 'Theme Settings', 'menu_slug' => 'theme-settings', 'capability' => 'edit_posts', 'redirect' => false)); } Timber::add_route('posts/get/:offset', function ($params) { $intPostsPerPage = intval(get_option('posts_per_page')); $intOffset = intval($params['offset']); $strPostType = $_POST['post_type'] ? $_POST['post_type'] : 'post'; $strQuery = 'posts_per_page=' . ($intPostsPerPage + 1) . '&post_type=' . $strPostType . '&offset=' . ($intOffset > 0 ? $intOffset : 0); if ($strPostType === 'portfolio-cpt') { $strQuery .= '&orderby=menu_order&order=ASC'; } $arrPosts = Timber::get_posts($strQuery); $blnHasMore = count($arrPosts) < $intPostsPerPage + 1 ? false : true; // Remove the last post if we got the number of posts we asked for if ($blnHasMore) { array_pop($arrPosts); } $strRet = Timber::compile('partials/ajax-results.twig', array('posts' => $arrPosts, 'post_type' => $strPostType)); $arrRet = array('posts' => $arrPosts, 'markup' => $strRet, 'hasMore' => $blnHasMore, 'offset' => $intOffset + $intPostsPerPage, 'query' => $strQuery); echo json_encode($arrRet); exit; }); function my_login_logo() { ?> <style type="text/css"> .login h1 a { background-image: url(<?php