Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
- function theme_enqueue_styles() {
- wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
- wp_enqueue_style( 'child-style',
- get_stylesheet_directory_uri() . '/style.css',
- array('parent-style')
- );
- }
- function custom_post_name () {
- return array(
- 'feeds' => true,
- 'slug' => 'tenants',
- 'with_front' => false,
- );
- }
- add_filter( 'et_project_posttype_rewrite_args', 'custom_post_name' );
- function child_et_pb_register_posttypes() { $labels = array( 'add_new' => __( 'Add New', 'Divi' ),
- 'add_new_item' => __( 'Add New Tenant', 'Divi' ),
- 'all_items' => __( 'All Tenants', 'Divi' ),
- 'edit_item' => __( 'Edit Tenant', 'Divi' ),
- 'menu_name' => __( 'Tenants', 'Divi' ),
- 'name' => __( 'Tenants', 'Divi' ),
- 'new_item' => __( 'New Tenant', 'Divi' ),
- 'not_found' => __( 'Nothing found', 'Divi' ),
- 'not_found_in_trash' => __( 'Nothing found in Trash', 'Divi' ),
- 'parent_item_colon' => '',
- 'search_items' => __( 'Search Tenants', 'Divi' ),
- 'singular_name' => __( 'Tenant', 'Divi' ),
- 'view_item' => __( 'View Tenant', 'Divi' ),
- );
- $args = array(
- 'can_export' => true,
- 'capability_type' => 'post',
- 'has_archive' => true,
- 'hierarchical' => false,
- 'labels' => $labels,
- 'menu_icon' => 'dashicons-admin-home',
- // 'menu_position' => 100,
- 'public' => true,
- 'publicly_queryable' => true,
- 'query_var' => true,
- 'show_in_nav_menus' => true,
- 'show_ui' => true,
- 'rewrite' => apply_filters( 'et_project_posttype_rewrite_args', array(
- 'feeds' => true,
- 'slug' => 'tenants',
- 'with_front' => false,
- )),
- 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments', 'revisions', 'custom-fields' ),
- );
- register_post_type( 'project', apply_filters( 'et_project_posttype_args', $args ) );
- $labels = array(
- 'name' => _x( 'Categories', 'Tenant category name', 'Divi' ),
- 'singular_name' => _x( 'Category', 'Tenant category singular name', 'Divi' ),
- 'search_items' => __( 'Search Categories', 'Divi' ),
- 'all_items' => __( 'All Categories', 'Divi' ),
- 'parent_item' => __( 'Parent Category', 'Divi' ),
- 'parent_item_colon' => __( 'Parent Category:', 'Divi' ),
- 'edit_item' => __( 'Edit Category', 'Divi' ),
- 'update_item' => __( 'Update Category', 'Divi' ),
- 'add_new_item' => __( 'Add New Category', 'Divi' ),
- 'new_item_name' => __( 'New Category Name', 'Divi' ),
- 'menu_name' => __( 'Categories', 'Divi' ),
- );
- register_taxonomy( 'project_category', array( 'project' ), array(
- 'hierarchical' => true,
- 'labels' => $labels,
- 'show_ui' => true,
- 'show_admin_column' => true,
- 'query_var' => true,
- ) );
- $labels = array(
- 'name' => _x( 'Tags', 'Tenant Tag name', 'Divi' ),
- 'singular_name' => _x( 'Tag', 'Tenant tag singular name', 'Divi' ),
- 'search_items' => __( 'Search Tags', 'Divi' ),
- 'all_items' => __( 'All Tags', 'Divi' ),
- 'parent_item' => __( 'Parent Tag', 'Divi' ),
- 'parent_item_colon' => __( 'Parent Tag:', 'Divi' ),
- 'edit_item' => __( 'Edit Tag', 'Divi' ),
- 'update_item' => __( 'Update Tag', 'Divi' ),
- 'add_new_item' => __( 'Add New Tag', 'Divi' ),
- 'new_item_name' => __( 'New Tag Name', 'Divi' ),
- 'menu_name' => __( 'Tags', 'Divi' ),
- );
- register_taxonomy( 'project_tag', array( 'project' ), array(
- 'hierarchical' => false,
- 'labels' => $labels,
- 'show_ui' => true,
- 'show_admin_column' => true,
- 'query_var' => true,
- ) );
- }
- function remove_et_pb_actions() {
- remove_action( 'init', 'et_pb_register_posttypes', 15 );
- }
- add_action( 'init', 'remove_et_pb_actions');
- add_action( 'init', 'child_et_pb_register_posttypes', 20 );
- function format_hours_table($content) {
- $items = array_filter(explode("\r\n", $content));
- $html = '<div class="hours-table-wrapper"><table class="hours-table"><tbody>';
- // Get current day of week
- $current_day = current_time('l');
- $current_day_index = -1;
- // Explode the items and find the current day index
- foreach ($items as $idx => $item) {
- $items[$idx] = explode(';', $item);
- array_unshift($items[$idx], ' ');
- if ($items[$idx][1] === $current_day) {
- $current_day_index = $idx;
- }
- }
- // Reorder table based on current day
- if ($current_day_index > -1) {
- $first = array_slice($items, $current_day_index);
- $second = array_slice($items, 0, $current_day_index);
- $items = array_merge($first, $second);
- }
- // Set label of first cell
- $items[0][0] = "Hours:";
- // Iterate cells
- foreach ($items as $item) {
- $html .= '<tr><td>' . implode('</td><td>', $item) . '</td></tr>';
- }
- $html .= '</tbody></table></div><div class="clear"></div>';
- return $html;
- }
- function tenant_info_shortcode( $atts, $content = "" ) {
- $info = array();
- if ($phone = get_post_custom_values('phone')[0]) array_push($info, "<p><a href=\"tel:" . $phone . "\">" . $phone . "</a></p>");
- if ($hours = get_post_custom_values('hours')[0]) array_push($info, "<p>" . $hours . "</p>");
- if ($hours_table = get_post_custom_values('hours-table')[0]) array_push($info, format_hours_table($hours_table));
- if ($website = get_post_custom_values('website')[0]) array_push($info, "<p><a href=\"" . $website . "\" target=\"_blank\">Visit website</a></p>");
- return "<div style=\"text-align: right;\">" . join("\n", $info) . "</div>";
- }
- add_shortcode( 'tenant_info', 'tenant_info_shortcode' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement