本文整理汇总了PHP中TimberHelper类的典型用法代码示例。如果您正苦于以下问题:PHP TimberHelper类的具体用法?PHP TimberHelper怎么用?PHP TimberHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TimberHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_context
/**
* Custom implementation for get_context method.
*/
public function get_context()
{
global $content_width;
if (class_exists('Easy_Digital_Downloads')) {
global $edd_options;
}
$context = Timber::get_context();
$sidebar_primary = Timber::get_widgets('sidebar_primary');
$sidebar_footer = Timber::get_widgets('sidebar_footer');
$context['theme_mods'] = get_theme_mods();
$context['site_options'] = wp_load_alloptions();
$context['teaser_mode'] = apply_filters('maera/teaser/mode', 'excerpt');
$context['thumbnail']['width'] = apply_filters('maera/image/width', 600);
$context['thumbnail']['height'] = apply_filters('maera/image/height', 371);
$context['menu']['primary'] = has_nav_menu('primary_navigation') ? new TimberMenu('primary_navigation') : null;
$context['sidebar']['primary'] = apply_filters('maera/sidebar/primary', $sidebar_primary);
$context['sidebar']['footer'] = apply_filters('maera/sidebar/footer', $sidebar_footer);
$context['pagination'] = Timber::get_pagination();
$context['comment_form'] = TimberHelper::get_comment_form();
$context['comments_args'] = array('style' => 'ul', 'reply_text' => __('Reply', 'maera'), 'short_ping' => true, 'avatar_size' => 60);
$context['site_logo'] = get_option('site_logo', false);
$context['content_width'] = $content_width;
$context['sidebar_template'] = maera_templates_sidebar();
if (class_exists('Easy_Digital_Downloads')) {
$data['edd_options'] = $edd_options;
$data['download_categories'] = Timber::get_terms('download_category');
$data['download_tags'] = Timber::get_terms('download_tag');
$data['default_image'] = new TimberImage(get_template_directory_uri() . '/assets/images/default.png');
}
return apply_filters('maera/timber/context', $context);
}
示例2: handle_post_results
/**
* @param array $results
* @param string $PostClass
* @return array
*/
static function handle_post_results($results, $PostClass = 'TimberPost')
{
$posts = array();
foreach ($results as $rid) {
$PostClassUse = $PostClass;
if (is_array($PostClass)) {
$post_type = get_post_type($rid);
$PostClassUse = 'TimberPost';
if (isset($PostClass[$post_type])) {
$PostClassUse = $PostClass[$post_type];
} else {
if (is_array($PostClass)) {
TimberHelper::error_log($post_type . ' of ' . $rid . ' not found in ' . print_r($PostClass, true));
} else {
TimberHelper::error_log($post_type . ' not found in ' . $PostClass);
}
}
}
$post = new $PostClassUse($rid);
if (isset($post->ID)) {
$posts[] = $post;
}
}
return new TimberPostsCollection($posts, $PostClass);
}
示例3: initializeContext
public function initializeContext($context)
{
$context = parent::initializeContext($context);
$context['menu'] = new \TimberMenu();
$context['wp_nonce_field'] = \TimberHelper::function_wrapper('wp_nonce_field');
return $context;
}
示例4: __construct
public function __construct($posts = array(), $post_class = 'TimberPost')
{
$returned_posts = array();
if (is_null($posts)) {
$posts = array();
}
foreach ($posts as $post_object) {
$post_class_use = $post_class;
if (is_array($post_class)) {
$post_type = get_post_type($post_object);
$post_class_use = 'TimberPost';
if (isset($post_class[$post_type])) {
$post_class_use = $post_class[$post_type];
} else {
if (is_array($post_class)) {
TimberHelper::error_log($post_type . ' of ' . $post_object->ID . ' not found in ' . print_r($post_class, true));
} else {
TimberHelper::error_log($post_type . ' not found in ' . $post_class);
}
}
}
// Don't create yet another object if $post_object is already of the right type
if (is_a($post_object, $post_class_use)) {
$post = $post_object;
} else {
$post = new $post_class_use($post_object);
}
if (isset($post->ID)) {
$returned_posts[] = $post;
}
}
$returned_posts = self::maybe_set_preview($returned_posts);
parent::__construct($returned_posts, $flags = 0, 'TimberPostsIterator');
}
示例5: run
/**
* Performs the actual image manipulation,
* including saving the target file.
*
* @param string $load_filename filepath (not URL) to source file
* (ex: /src/var/www/wp-content/uploads/my-pic.jpg)
* @param string $save_filename filepath (not URL) where result file should be saved
* (ex: /src/var/www/wp-content/uploads/my-pic@2x.jpg)
* @return bool true if everything went fine, false otherwise
*/
function run($load_filename, $save_filename)
{
$image = wp_get_image_editor($load_filename);
if (!is_wp_error($image)) {
$current_size = $image->get_size();
$src_w = $current_size['width'];
$src_h = $current_size['height'];
// Get ratios
$w = $src_w * $this->factor;
$h = $src_h * $this->factor;
$image->crop(0, 0, $src_w, $src_h, $w, $h);
$result = $image->save($save_filename);
if (is_wp_error($result)) {
error_log('Error resizing image');
error_log(print_r($result, true));
return false;
} else {
return true;
}
} else {
if (isset($image->error_data['error_loading_image'])) {
TimberHelper::error_log('Error loading ' . $image->error_data['error_loading_image']);
} else {
TimberHelper::error_log($image);
}
}
return false;
}
示例6: __construct
public function __construct($query = false, $posts_class = 'TimberPost')
{
add_action('pre_get_posts', array($this, 'fix_number_posts_wp_quirk'));
if ($posts_class) {
$this->_posts_class = $posts_class;
}
if (is_a($query, 'WP_Query')) {
// We got a full-fledged WP Query, look no further!
$the_query = $query;
} elseif (false === $query) {
// If query is explicitly set to false, use the main loop
global $wp_query;
$the_query =& $wp_query;
} elseif (TimberHelper::is_array_assoc($query) || is_string($query) && strstr($query, '=')) {
// We have a regularly formed WP query string or array to use
$the_query = new WP_Query($query);
} elseif (is_numeric($query) || is_string($query)) {
// We have what could be a post name or post ID to pull out
$the_query = self::get_query_from_string($query);
} elseif (is_array($query) && count($query) && (is_integer($query[0]) || is_string($query[0]))) {
// We have a list of pids (post IDs) to extract from
$the_query = self::get_query_from_array_of_ids($query);
} else {
TimberHelper::error_log('I have failed you! in ' . basename(__FILE__) . '::' . __LINE__);
TimberHelper::error_log($query);
// We have failed hard, at least let get something.
$the_query = new WP_Query();
}
$this->_query = $the_query;
}
示例7: call
/**
*
*
* @return string
*/
public function call()
{
$args = $this->_parse_args(func_get_args(), $this->_args);
if ($this->_use_ob) {
return TimberHelper::ob_function($this->_function, $args);
} else {
return call_user_func_array($this->_function, $args);
}
}
示例8: add_to_context
function add_to_context($context)
{
$context['current_url'] = TimberHelper::get_current_url();
$context['pagination'] = Timber::get_pagination();
$context['bethel_header_menu'] = new TimberMenu('primary');
$context['bethel_sidebar_menu'] = new TimberMenu('sidebar');
$context['site'] = $this;
return $context;
}
示例9: init
function init()
{
$this->name = get_bloginfo('name');
$this->title = $this->name;
$this->description = get_bloginfo('description');
$this->url = get_bloginfo('url');
$this->language = get_bloginfo('language');
$this->charset = get_bloginfo('charset');
$this->pingback_url = get_bloginfo('pingback_url');
$this->language_attributes = TimberHelper::function_wrapper('language_attributes');
}
示例10: testGetPostsByMeta
function testGetPostsByMeta()
{
$pids = array();
$lauren = $this->factory->post->create(array('post_title' => 'Lauren Richler'));
$jared = $this->factory->post->create(array('post_title' => 'Jared Novack'));
update_post_meta($lauren, 'in', 'love');
update_post_meta($jared, 'in', 'love');
$in_love = TimberHelper::get_posts_by_meta('in', 'love');
$this->assertContains($lauren, $in_love);
$this->assertContains($jared, $in_love);
$this->assertEquals(2, count($in_love));
}
示例11: testGetObjectIndexByProperty
function testGetObjectIndexByProperty()
{
$obj1 = new stdClass();
$obj1->name = 'mark';
$obj1->skill = 'acro yoga';
$obj2 = new stdClass();
$obj2->name = 'austin';
$obj2->skill = 'cooking';
$arr = array($obj1, $obj2);
$index = TimberHelper::get_object_index_by_property($arr, 'skill', 'cooking');
$this->assertEquals(1, $index);
$obj = TimberHelper::get_object_by_property($arr, 'skill', 'cooking');
$this->assertEquals('austin', $obj->name);
}
示例12: init
protected function init()
{
$this->admin_email = get_bloginfo('admin_email');
$this->name = get_bloginfo('name');
$this->title = $this->name;
$this->description = get_bloginfo('description');
$this->url = get_bloginfo('url');
$this->language = get_bloginfo('language');
$this->charset = get_bloginfo('charset');
$this->pingback_url = get_bloginfo('pingback_url');
$this->theme = new TimberTheme();
$this->language_attributes = TimberHelper::function_wrapper('language_attributes');
$this->multisite = false;
}
示例13: testAgainstFooterFunctionOutput
function testAgainstFooterFunctionOutput()
{
global $wp_scripts;
$wp_scripts = null;
wp_enqueue_script('colorpicker', false, array(), false, true);
wp_enqueue_script('fake-js', 'http://example.org/fake-js.js', array(), false, true);
$wp_footer = TimberHelper::ob_function('wp_footer');
global $wp_scripts;
$wp_scripts = null;
wp_enqueue_script('colorpicker', false, array(), false, true);
wp_enqueue_script('fake-js', 'http://example.org/fake-js.js', array(), false, true);
$str = Timber::compile_string('{{function("wp_footer")}}');
$this->assertEquals($wp_footer, $str);
$this->assertGreaterThan(50, strlen($str));
}
示例14: get_terms
/**
* @param string|array $args
* @param array $maybe_args
* @param string $TermClass
* @return mixed
*/
public static function get_terms($args = null, $maybe_args = array(), $TermClass = 'TimberTerm')
{
if (is_string($maybe_args) && !strstr($maybe_args, '=')) {
//the user is sending the $TermClass in the second argument
$TermClass = $maybe_args;
}
if (is_string($maybe_args) && strstr($maybe_args, '=')) {
parse_str($maybe_args, $maybe_args);
}
if (is_string($args) && strstr($args, '=')) {
//a string and a query string!
$parsed = TimberTermGetter::get_term_query_from_query_string($args);
if (is_array($maybe_args)) {
$parsed->args = array_merge($parsed->args, $maybe_args);
}
return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
} else {
if (is_string($args)) {
//its just a string with a single taxonomy
$parsed = TimberTermGetter::get_term_query_from_string($args);
if (is_array($maybe_args)) {
$parsed->args = array_merge($parsed->args, $maybe_args);
}
return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
} else {
if (is_array($args) && TimberHelper::is_array_assoc($args)) {
//its an associative array, like a good ole query
$parsed = TimberTermGetter::get_term_query_from_assoc_array($args);
return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
} else {
if (is_array($args)) {
//its just an array of strings or IDs (hopefully)
$parsed = TimberTermGetter::get_term_query_from_array($args);
if (is_array($maybe_args)) {
$parsed->args = array_merge($parsed->args, $maybe_args);
}
return self::handle_term_query($parsed->taxonomies, $parsed->args, $TermClass);
} else {
if (is_null($args)) {
return self::handle_term_query(get_taxonomies(), array(), $TermClass);
}
}
}
}
}
return null;
}
示例15: timber_extras
/**
* Timber extras.
*/
function timber_extras($data)
{
// get secondary sidebar
$sidebar_secondary = Timber::get_widgets('sidebar_secondary');
$data['sidebar']['secondary'] = apply_filters('maera/sidebar/secondary', $sidebar_secondary);
$extra_widget_areas = Maera_BS_Widgets::extra_widget_areas_array();
foreach ($extra_widget_areas as $extra_widget_area => $options) {
if (0 != get_theme_mod($extra_widget_area . '_toggle', 0)) {
$data['sidebar'][$extra_widget_area] = Timber::get_widgets($extra_widget_area);
}
}
$comment_form_args = array('comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x('Comment', 'noun', 'maera_bs') . '</label><textarea class="form-control" id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>', 'id_submit' => 'comment-submit');
$data['content_width'] = Maera_BS_Structure::content_width_px();
$data['post_meta'] = Maera_BS_Meta::meta_elements();
$data['comment_form'] = TimberHelper::get_comment_form(null, $comment_form_args);
return $data;
}