Example #1
0
 public function taxonomy($taxonomy)
 {
     $this->taxonomy = $taxonomy;
     if (!is_array($this->taxonomy)) {
         $this->model = Yare::config("register.taxonomies.{$this->taxonomy}.model", 'Term');
     }
     return $this;
 }
Example #2
0
function add_to_context($data)
{
    //$class = class_exists('\Natty\Model\Globals') ? '\Natty\Model\Globals' : '\WPSW\Core\Model\Globals';
    //$data['globals'] = new \Yare\Yare('WP_Option');
    //pc($data, 'globals');
    $data['request'] = Yare::request();
    return $data;
}
Example #3
0
 public function view()
 {
     if (!$this->data->layout) {
         throw new Exception("layout not set.");
     }
     $context = Timber::get_context();
     $context['globals'] = Yare::globals();
     $context[$this->data->name] = $this->data;
     Timber::render($this->data->layout, $context);
 }
Example #4
0
 public function type($type = 'post')
 {
     if (func_num_args() > 1) {
         $this->post_type = func_get_args();
     } else {
         $this->post_type = $type ?: 'post';
     }
     if (!is_array($this->post_type)) {
         $this->model = Yare::config("register.post_types.{$this->post_type}.model", 'Post');
     }
     return $this;
 }
Example #5
0
 public function __construct(array $args)
 {
     if (!isset($args['table'])) {
         throw new Exception("Error Processing Request", 1);
     }
     $table = array_pull($args, 'table');
     if (!in_array($table, array('posts', 'terms', 'comments', 'users'))) {
         throw new Exception("Error Processing Request", 1);
     }
     $fn = "get_{$table}";
     $this->model = array_pull($args, 'model', 'Model');
     $this->args = $args;
     $this->results = $this->{$fn}();
     $this->request = Yare::request();
 }
Example #6
0
 public function __get($name)
 {
     if (isset($this->computed[$name])) {
         return $this->computed[$name];
     }
     if ('response' == $name) {
         $response = Yare::response();
         $response->data($this);
         return $this->response = $response;
     }
     if (method_exists('Yare\\Yare', $name)) {
         return Yare::$name();
     }
     if (method_exists($this, $name) && !in_array($name, static::$actions)) {
         return $this->computed[$name] = $this->{$name}();
     }
     if ($value = $this->data[$name]) {
         return $value;
     }
     return $this->{$name} = '';
 }
Example #7
0
function theme_page_templates($page_templates, $theme, $post)
{
    foreach (Yare::config('register.page_templates', array()) as $value => $label) {
        $page_templates[$value] = $label;
    }
    return $page_templates;
}
Example #8
0
function remove_post_type_supports()
{
    $default_supports = array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes', 'post-formats');
    $default_types = array('post', 'page', 'attachment', 'revision', 'nav_menu_item');
    $post_types = Yare::config('register.post_types', array());
    foreach ($post_types as $post_type => $args) {
        if (!in_array($post_type, $default_types) or !array_key_exists('supports', $args)) {
            return;
        }
        $supports = array_diff($default_supports, (array) $args['supports']);
        foreach ($supports as $support) {
            remove_post_type_support($post_type, $support);
            //remove_meta_box( 'commentstatusdiv', $post_type, 'nomral' );
            remove_meta_box($support . 'div', $post_type, 'nomral');
        }
    }
}
Example #9
0
<?php

namespace Yare\ThemeSetup\ACF;

use Yare\Yare;
if (function_exists('acf_add_options_page')) {
    if (!class_exists('acf_pro_options_page')) {
        acf_include('pro/admin/options-page.php');
    }
    foreach ((array) Yare::config('register.options_page') as $slug => $option) {
        if (is_numeric($slug)) {
            acf_add_options_page($option);
            continue;
        }
        $args = array('capability' => 'edit_posts', 'redirect' => false, 'menu_slug' => $slug);
        if (is_string($option)) {
            $args['page_title'] = $option;
            $args['menu_title'] = $option;
            acf_add_options_page($args);
        } elseif (is_array($option)) {
            if (isset($option['page_title'])) {
                $args = array_merge($args, $option);
            } elseif (isset($option['main_page'])) {
                if (!is_array($option['main_page'])) {
                    $args['page_title'] = $option['main_page'];
                    $args['menu_title'] = $option['main_page'];
                } else {
                    $args = array_merge($args, $option['main_page']);
                }
            }
        }
Example #10
0
 function hooks()
 {
     foreach ((array) Yare::config('theme.hooks') as $key => $hooks) {
         if (!is_array($hooks)) {
             continue;
         }
         foreach ($hooks as $args) {
             $added = $key === 'remove' && is_numeric($args[1]) ? '_all_filters' : '_filter';
             call_user_func_array($key . $added, $args);
         }
     }
 }
Example #11
0
 protected function args_prepare(&$args)
 {
     $args = is_array($args) ? $args : array('src' => $args);
     if (!Yare::is_url($src = array_get($args, 'src')) && array_get($args, 'ver') == 'filemtime') {
         if (file_exists($filename = Yare::path($src, 'static'))) {
             $args['ver'] = @filemtime($filename);
         } else {
             $args['ver'] = null;
         }
     }
     $args['ver'] = isset($args['ver']) ? $args['ver'] : null;
     $args['deps'] = isset($args['deps']) ? is_string($args['deps']) ? array($args['deps']) : $args['deps'] : array();
     $args['src'] = isset($args['src']) ? Yare::url($args['src'], 'static') : null;
     if ($this->is_style()) {
         $args['media'] = isset($args['media']) ? $args['media'] : 'all';
     }
 }
Example #12
0
/**
 * Get a config item from config files using "dot" notation.
 *
 * @param string $key
 * @param mixed $default
 *
 * @return mixed
 */
function wpsw_get_config($key, $default = null)
{
    return Yare::config($key, $default);
}
 public function register_menu_pages()
 {
     $admin_menu = Yare::config('register.admin_menus', array());
     foreach ((array) $admin_menu as $menu_slug => $menu_args) {
         //if (isset($menu_args['link'])) {
         //    continue;
         //}
         if (isset($menu_args['parent_slug'])) {
             $args = array('parent_slug' => 'options-general.php', 'page_title' => '', 'menu_title' => '', 'capability' => 'manage_options', 'menu_slug' => '', 'function' => '');
             if (isset($menu_args['view'])) {
                 $sub_view = array_get($menu_args, 'view', 'Admin');
                 $function = str_replace('\\', '_', $sub_view);
                 //$parent_slug = array_get($menu_args, 'parent_slug', '');
                 $menu_args['menu_slug'] = $menu_slug;
                 $menu_args['function'] = array($this, $function);
             }
             if (isset($menu_args['link'])) {
                 $this->highlight_files[$menu_args['link']] = $menu_args['parent_slug'];
                 $menu_args['menu_slug'] = $menu_args['link'];
             }
             foreach ($args as $key => $value) {
                 $args[$key] = array_get($menu_args, $key, $value);
             }
             pc($args, 'add_submenu_page');
             call_user_func_array('add_submenu_page', $args);
             continue;
         }
         $args = array('page_title' => '', 'menu_title' => '', 'capability' => 'manage_options', 'menu_slug' => '', 'function' => '', 'icon_url' => '', 'position' => 6);
         if (isset($menu_args['view'])) {
             $view = array_get($menu_args, 'view', 'Admin');
             $function = str_replace('\\', '_', $view);
             $menu_args['menu_slug'] = $menu_slug;
             $menu_args['function'] = array($this, $function);
         }
         if (isset($menu_args['link'])) {
             //$this->highlight_files[$menu_args['link']] = $menu_args['parent_slug'];
             $menu_args['menu_slug'] = $menu_args['link'];
         }
         foreach ($args as $key => $value) {
             $args[$key] = array_get($menu_args, $key, $value);
         }
         pc($args, 'add_menu_page');
         call_user_func_array('add_menu_page', $args);
         if ($sub_menu = array_get($menu_args, 'sub_menu')) {
             foreach ($sub_menu as $sub_menu_slug => $sub_menu_args) {
                 //if (isset($sub_menu_args['link'])) {
                 //    continue;
                 //}
                 $args = array('parent_slug' => $menu_slug, 'page_title' => '', 'menu_title' => '', 'capability' => 'manage_options', 'menu_slug' => '', 'function' => '');
                 if (isset($sub_menu_args['view'])) {
                     $sub_view = array_get($sub_menu_args, 'view', 'Admin');
                     $function = str_replace('\\', '_', $sub_view);
                     $sub_menu_args['menu_slug'] = $menu_slug . '-' . $sub_menu_slug;
                     $sub_menu_args['function'] = array($this, $function);
                 }
                 if (isset($sub_menu_args['link'])) {
                     remove_menu_page($sub_menu_args['link']);
                     $this->highlight_files[$sub_menu_args['link']] = $menu_slug;
                     $sub_menu_args['menu_slug'] = $sub_menu_args['link'];
                 }
                 foreach ($args as $key => $value) {
                     $args[$key] = array_get($sub_menu_args, $key, $value);
                 }
                 pc($args, 'add_submenu_page');
                 call_user_func_array('add_submenu_page', $args);
             }
         }
     }
 }