Esempio n. 1
0
 private static function getModel()
 {
     $models = Store::get('models');
     foreach ($models as $serialized) {
         $model = unserialize($serialized);
         if ($model['post_type'] == strtolower(get_called_class())) {
             return $model;
         }
     }
 }
Esempio n. 2
0
 private function findPostType($tax)
 {
     $models = Store::get('models');
     foreach ($models as $serialized) {
         $model = unserialize($serialized);
         if (in_array($tax->slug, $model['taxonomies'])) {
             $this->do_register($tax, $model['post_type']);
         }
     }
 }
Esempio n. 3
0
 private static function post_type($model)
 {
     $labels = self::callStatic($model, 'getLabels');
     $icon = self::callStatic($model, 'getIcon');
     $sizes = self::callStatic($model, 'getSizes');
     foreach ($sizes as $key => $value) {
         add_image_size($key, $value[0], $value[1], empty($value[2]) ? false : $value[2]);
     }
     Store::push('models', self::callStatic($model, '_serialize'));
     $singular = empty($labels[0]) ? ucfirst($model) : $labels[0];
     $plural = empty($labels[1]) ? ucfirst($model . 's') : $labels[1];
     $icon = empty($icon) ? 'dashicons-admin-post' : $icon;
     $tax = self::callStatic($model, 'getTaxonomies');
     $fields = self::callStatic($model, 'getFields');
     $capabilities = self::callStatic($model, 'getCapabilities');
     $supports = array();
     $wp_fields = array('title', 'editor', 'thumbnail', 'excerpt', 'comments', 'revisions', 'trackbacks', 'page-attributes');
     if (!empty($fields)) {
         foreach ($fields as $key => $value) {
             if (in_array($key, $wp_fields) && $value) {
                 array_push($supports, $key);
             }
         }
     }
     if (count($supports) == 0) {
         $supports = false;
     }
     $capability_type = 'page';
     $capabilities = array();
     $capability_type = 'page';
     $capabilities = [];
     if ($capabilities) {
         $theCapabilities = get_post_type_object('post');
         $capability_type = strtolower($model);
         $capabilities = [];
         foreach ($theCapabilities->cap as $key) {
             $capabilities[$key] = str_replace('post', $capability_type, $key);
         }
     }
     $labels = array('name' => \__($plural), 'singular_name' => \__($singular), 'menu_name' => \__($plural), 'parent_item_colon' => \__('Parent Item:'), 'all_items' => \__($plural), 'view_item' => \__('View') . ' ' . \__($plural), 'add_new_item' => \__('Add') . ' ' . \__($singular), 'add_new' => \__('Add') . ' ' . \__($singular), 'edit_item' => \__('Edit') . ' ' . \__($singular), 'update_item' => \__('Update') . ' ' . \__($singular), 'search_items' => \__('Search') . ' ' . \__($singular), 'not_found' => \__('Not found'), 'not_found_in_trash' => \__('Not found in Trash'));
     $args = array('label' => __($model, 'text_domain'), 'description' => __('', 'text_domain'), 'labels' => $labels, 'supports' => $supports, 'taxonomies' => $tax, 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'show_in_nav_menus' => true, 'show_in_admin_bar' => true, 'menu_position' => 5, 'menu_icon' => $icon, 'can_export' => true, 'has_archive' => true, 'exclude_from_search' => false, 'publicly_queryable' => true, 'capability_type' => $capability_type, 'capabilities' => $capabilities, 'rewrite' => array('slug' => 'hero_' . self::getType($model), 'with_front' => true));
     if (self::getType($model) != 'page' && self::getType($model) != 'post') {
         register_post_type(self::getType($model), $args);
     }
 }
Esempio n. 4
0
 private function registerRelation($model, $relation)
 {
     Store::pushIfNotPresent('relation_' . $relation, ['model' => strtolower(get_class($this)), 'target' => $model]);
     $type = $relation == 'belongs_to' ? 'list' : 'checkbox_list';
     return ['type' => $type, 'label' => ucfirst($model), 'options' => function () use($model) {
         $arr = [];
         $items = call_user_func(ucfirst($model) . '::find');
         foreach ($items as $item) {
             $arr[$item->ID] = $item->title;
         }
         return $arr;
     }];
 }