<?php /*-----------------------------------------------------------------------*/ // Match Custom Post /*-----------------------------------------------------------------------*/ $match = PostType::make('slhb_match', 'Les matchs', 'match')->set(array('public' => true, 'menu_position' => 20, 'supports' => false, 'rewrite' => false, 'query_var' => false, 'labels' => ['add_new' => 'Ajouter un nouveau match', 'add_item' => 'Ajouter un match', 'all_items' => 'Tous les matchs', 'edit_item' => 'Modifier un match'])); /*-----------------------------------------------------------------------*/ // Match informations /*-----------------------------------------------------------------------*/ $infos = Metabox::make('Informations du match', $match->get('name'))->set(array(Field::date('match_date', ['title' => 'Date du match']), Field::select('match_team_dom', TeamModel::getTeamsArray()), Field::text('match_team_ext', ['title' => 'Equipe à l\'exterieur']), Field::number('score_dom', ['title' => 'Score de l\'équipe à domicile']), Field::number('score_ext', ['title' => 'Score de l\'équipe extérieur']))); /*-----------------------------------------------------------------------*/ // Match Defaults Values /*-----------------------------------------------------------------------*/ function slhb_set_title($post_id, $post, $update) { $dateStr = Meta::get($post_id, 'match_date'); $title = $dateStr . ' - ' . Meta::get($post_id, 'match_team_dom') . ' - ' . Meta::get($post_id, 'match_team_ext'); $date = date($dateStr); //This temporarily removes filter to prevent infinite loops remove_action('save_post_slhb_match', __FUNCTION__); wp_update_post(array('ID' => $post_id, 'post_title' => $title, 'match_date' => $date)); //redo filter add_action('save_post_slhb_match', __FUNCTION__, 10, 3); } add_action('save_post_slhb_match', 'slhb_set_title', 10, 3);
<?php $cat = Taxonomy::make('gallery-category', 'galleries', __('Gallery Categories', THEME_TEXT_DOMAIN), __('Gallery Category', THEME_TEXT_DOMAIN))->set(['public' => true, 'show_in_nav_menus' => true, 'hierarchical' => true, 'show_tagcloud' => true, 'show_in_quick_edit' => true]); $tag = Taxonomy::make('gallery-tag', 'galleries', __('Gallery Tags', THEME_TEXT_DOMAIN), __('Gallery Tag', THEME_TEXT_DOMAIN))->set(['public' => true, 'show_in_nav_menus' => true, 'hierarchical' => true, 'show_tagcloud' => true, 'show_in_quick_edit' => true]); $galleries = PostType::make('galleries', __('Galleries', THEME_TEXT_DOMAIN), __('Gallery', THEME_TEXT_DOMAIN))->set(['public' => true, 'labels' => ['add_item' => __('Add', THEMOSIS_TEXTDOMAIN)], 'supports' => array('title', 'excerpt', 'thumbnail', 'revisions'), 'taxonomies' => ['gallery-category', 'gallery-tag']]); $infos = Metabox::make('Informations', $galleries->getSlug())->set(array(Field::collection('images', ['type' => 'images']))); /*-----------------------------------------------------------------------*/ // Book info validation /*-----------------------------------------------------------------------*/ //$infos->validate(array( // 'title' => array('textfield', 'min:5') //));
<?php /* * Add layout metabox for all post type */ foreach (get_post_types(['public' => true], 'names') as $post_type) { Metabox::make(__('Layouts', THEME_TEXT_DOMAIN), $post_type)->set([\Themosis\Facades\Field::select('layout', [['layouts.rightsidebar' => __('Right Sidebar', THEME_TEXT_DOMAIN), 'layouts.leftsidebar' => __('Left Sidebar', THEME_TEXT_DOMAIN), 'layouts.default' => __('Full width', THEME_TEXT_DOMAIN)]], ['title' => __('Choose a layout:', THEME_TEXT_DOMAIN), 'value' => 2])])->validate(['layout']); } foreach (get_post_types(['public' => true], 'names') as $post_type) { Metabox::make('loopType', $post_type)->set([\Themosis\Facades\Field::select('loopType', [['partials.unique.unique1' => __('Right Sidebar', THEME_TEXT_DOMAIN), 'partials.unique.unique2' => __('Left Sidebar', THEME_TEXT_DOMAIN), 'partials.unique.unique3' => __('Full width', THEME_TEXT_DOMAIN)]], ['title' => __('Choose a loop type:', THEME_TEXT_DOMAIN), 'value' => 1])])->validate(['loopType']); } function get_post_view($ID) { $count = Meta::get($ID, 'post_views_count'); if (empty($count)) { $count = 0; add_post_meta($ID, 'post_views_count', 0); } return $count; } function set_post_view($ID) { $count = Meta::get($ID, 'post_views_count'); if (empty($count)) { add_post_meta($ID, 'post_views_count', 1); } else { update_post_meta($ID, 'post_views_count', $count++); } }
<?php $infosPratiques = get_page_by_path('infos-pratiques'); if (themosis_is_post($infosPratiques->ID)) { /*-----------------------------------------------------------------------*/ // TEAM METABOX /*-----------------------------------------------------------------------*/ Metabox::make('Team', 'page')->set(array(Field::infinite('collaborators', array(Field::text('full-name', array('title' => 'Full name')), Field::text('job'), Field::media('pic')), array('title' => 'Collaborateurs')))); }
<?php /* * Add layout metabox for all post type */ foreach (get_post_types(['public' => true], 'names') as $post_type) { Metabox::make(__('Layouts', THEME_TEXT_DOMAIN), $post_type)->set([\Themosis\Facades\Field::select('layout', [['layouts.rightsidebar' => __('Right Sidebar', THEME_TEXT_DOMAIN), 'layouts.leftsidebar' => __('Left Sidebar', THEME_TEXT_DOMAIN), 'layouts.default' => __('Full width', THEME_TEXT_DOMAIN)]], ['title' => __('Choose a layout:', THEME_TEXT_DOMAIN), 'value' => 2])])->validate(['layout']); } function get_post_view($ID) { $count = Meta::get($ID, 'post_views_count'); if (empty($count)) { $count = 0; add_post_meta($ID, 'post_views_count', 0); } return $count; } function set_post_view($ID) { $count = Meta::get($ID, 'post_views_count'); if (empty($count)) { add_post_meta($ID, 'post_views_count', 1); } else { update_post_meta($ID, 'post_views_count', $count++); } }
<?php $cat = Taxonomy::make('product-category', 'products', __('Product Categories', THEME_TEXT_DOMAIN), __('Product Category', THEME_TEXT_DOMAIN))->set(['public' => true, 'show_in_nav_menus' => true, 'hierarchical' => true, 'show_tagcloud' => true, 'show_in_quick_edit' => true]); $tag = Taxonomy::make('product-tag', 'products', __('Product Tags', THEME_TEXT_DOMAIN), __('Product Tag', THEME_TEXT_DOMAIN))->set(['public' => true, 'show_in_nav_menus' => true, 'hierarchical' => true, 'show_tagcloud' => true, 'show_in_quick_edit' => true]); $products = PostType::make('products', __('Products', THEME_TEXT_DOMAIN), __('Product', THEME_TEXT_DOMAIN))->set(['public' => true, 'labels' => ['add_item' => __('Add', THEME_TEXT_DOMAIN)], 'supports' => array('title', 'excerpt', 'thumbnail', 'revisions'), 'taxonomies' => array('product-category', 'product-tag')]); $infos = Metabox::make('Informations', $products->getSlug())->set(array(Field::textarea('description'), Field::collection('images', ['type' => 'images']), Field::infinite('info', [Field::text('title'), Field::textarea('value')]))); /*-----------------------------------------------------------------------*/ // Book info validation /*-----------------------------------------------------------------------*/ $infos->validate(array());
<?php /*-----------------------------------------------------------------------*/ // Custom post type - bks-books /*-----------------------------------------------------------------------*/ $books = PostType::make('bks-books', 'Books', 'Book')->set(array('public' => true, 'rewrite' => array('slug' => 'books'), 'supports' => array('title', 'editor', 'excerpt', 'thumbnail'))); /*-----------------------------------------------------------------------*/ // Book informations /*-----------------------------------------------------------------------*/ $infos = Metabox::make('Informations', $books->getSlug())->set(array(Field::text('author'), Field::media('promo-image', array('title' => 'Image promotion', 'info' => 'Image used on home page in order to promote the book.')), Field::text('color', array('info' => 'Insert a hexadecimal color value: <b>#cdcdcd</b>')))); /*-----------------------------------------------------------------------*/ // Book info validation /*-----------------------------------------------------------------------*/ $infos->validate(array('author' => array('textfield', 'min:5'), 'color' => array('color')));
/** * Set up timeslot custom post type * * @private */ private static function _set_up_timeslot() { PostType::make('timeslot', 'Time Slots', 'Time Slot')->set(); $fields = array(Field::select('timeslot_venue', array(array('none' => __('- None -')) + VenueModel::venueSelection()), array('title' => __('Venue'))), Field::select('timeslot_user', array(array('none' => __('- None -')) + UserModel::userSelection()), array('title' => __('User'))), Field::date('date', array('title' => 'Date')), Field::select('time_from', array(Config::get('application.timeslots')), array('title' => __('Start at'))), Field::select('time_to', array(Config::get('application.timeslots')), array('title' => __('Finish at')))); Metabox::make('Options', 'timeslot')->set($fields); }
<?php /*-----------------------------------------------------------------------*/ // Home/Front page. /*-----------------------------------------------------------------------*/ $home = (int) get_option('page_on_front'); if (themosis_is_post($home)) { $books = new Books(); // Metabox for the front page. Metabox::make('Book promo', 'page')->set(array(Field::select('book-promo', array($books->published()), false, array('title' => 'Book', 'info' => 'Choose a book to promote on the home page.')))); } /*-----------------------------------------------------------------------*/ // Remove editor from home page. /*-----------------------------------------------------------------------*/ add_action('init', function () use($home) { if (themosis_is_post($home)) { remove_post_type_support('page', 'editor'); } });
<?php $team = PostType::make('slhb_team', 'Les équipes', 'équipe')->set(array('public' => true, 'menu_position' => 20, 'supports' => array('title', 'editor'), 'rewrite' => false, 'query_var' => false, 'labels' => ['add_new_item' => 'Ajouter une nouvelle équipe', 'add_new' => 'Ajouter une équipe', 'add_item' => 'Ajouter une équipe', 'all_items' => 'Toutes les équipes', 'edit_item' => 'Modifier une équipe'])); /*-----------------------------------------------------------------------*/ // Team informations /*-----------------------------------------------------------------------*/ $infos = Metabox::make('Informations sur l\'équipe', $team->get('name'))->set(array(Field::media('profile', ['title' => 'Photo de groupe de l\'équipe ']), Field::select('Niveau', [['Excellence Région', 'Honneur Région', 'Pré-Région', 'Deuxième division']], ['title' => 'Quelle division? ']), Field::collection('gallery')));