Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.31 KB | None | 0 0
  1. <?php
  2. add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
  3. function theme_enqueue_styles() {
  4. wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
  5. wp_enqueue_style( 'child-style',
  6. get_stylesheet_directory_uri() . '/style.css',
  7. array('parent-style')
  8. );
  9. }
  10.  
  11. function custom_post_name () {
  12. return array(
  13. 'feeds' => true,
  14. 'slug' => 'tenants',
  15. 'with_front' => false,
  16. );
  17. }
  18. add_filter( 'et_project_posttype_rewrite_args', 'custom_post_name' );
  19.  
  20.  
  21. function child_et_pb_register_posttypes() { $labels = array( 'add_new' => __( 'Add New', 'Divi' ),
  22. 'add_new_item' => __( 'Add New Tenant', 'Divi' ),
  23. 'all_items' => __( 'All Tenants', 'Divi' ),
  24. 'edit_item' => __( 'Edit Tenant', 'Divi' ),
  25. 'menu_name' => __( 'Tenants', 'Divi' ),
  26. 'name' => __( 'Tenants', 'Divi' ),
  27. 'new_item' => __( 'New Tenant', 'Divi' ),
  28. 'not_found' => __( 'Nothing found', 'Divi' ),
  29. 'not_found_in_trash' => __( 'Nothing found in Trash', 'Divi' ),
  30. 'parent_item_colon' => '',
  31. 'search_items' => __( 'Search Tenants', 'Divi' ),
  32. 'singular_name' => __( 'Tenant', 'Divi' ),
  33. 'view_item' => __( 'View Tenant', 'Divi' ),
  34. );
  35.  
  36. $args = array(
  37. 'can_export' => true,
  38. 'capability_type' => 'post',
  39. 'has_archive' => true,
  40. 'hierarchical' => false,
  41. 'labels' => $labels,
  42. 'menu_icon' => 'dashicons-admin-home',
  43. // 'menu_position' => 100,
  44. 'public' => true,
  45. 'publicly_queryable' => true,
  46. 'query_var' => true,
  47. 'show_in_nav_menus' => true,
  48. 'show_ui' => true,
  49. 'rewrite' => apply_filters( 'et_project_posttype_rewrite_args', array(
  50. 'feeds' => true,
  51. 'slug' => 'tenants',
  52. 'with_front' => false,
  53. )),
  54. 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments', 'revisions', 'custom-fields' ),
  55. );
  56.  
  57. register_post_type( 'project', apply_filters( 'et_project_posttype_args', $args ) );
  58.  
  59. $labels = array(
  60. 'name' => _x( 'Categories', 'Tenant category name', 'Divi' ),
  61. 'singular_name' => _x( 'Category', 'Tenant category singular name', 'Divi' ),
  62. 'search_items' => __( 'Search Categories', 'Divi' ),
  63. 'all_items' => __( 'All Categories', 'Divi' ),
  64. 'parent_item' => __( 'Parent Category', 'Divi' ),
  65. 'parent_item_colon' => __( 'Parent Category:', 'Divi' ),
  66. 'edit_item' => __( 'Edit Category', 'Divi' ),
  67. 'update_item' => __( 'Update Category', 'Divi' ),
  68. 'add_new_item' => __( 'Add New Category', 'Divi' ),
  69. 'new_item_name' => __( 'New Category Name', 'Divi' ),
  70. 'menu_name' => __( 'Categories', 'Divi' ),
  71. );
  72.  
  73. register_taxonomy( 'project_category', array( 'project' ), array(
  74. 'hierarchical' => true,
  75. 'labels' => $labels,
  76. 'show_ui' => true,
  77. 'show_admin_column' => true,
  78. 'query_var' => true,
  79. ) );
  80.  
  81. $labels = array(
  82. 'name' => _x( 'Tags', 'Tenant Tag name', 'Divi' ),
  83. 'singular_name' => _x( 'Tag', 'Tenant tag singular name', 'Divi' ),
  84. 'search_items' => __( 'Search Tags', 'Divi' ),
  85. 'all_items' => __( 'All Tags', 'Divi' ),
  86. 'parent_item' => __( 'Parent Tag', 'Divi' ),
  87. 'parent_item_colon' => __( 'Parent Tag:', 'Divi' ),
  88. 'edit_item' => __( 'Edit Tag', 'Divi' ),
  89. 'update_item' => __( 'Update Tag', 'Divi' ),
  90. 'add_new_item' => __( 'Add New Tag', 'Divi' ),
  91. 'new_item_name' => __( 'New Tag Name', 'Divi' ),
  92. 'menu_name' => __( 'Tags', 'Divi' ),
  93. );
  94.  
  95. register_taxonomy( 'project_tag', array( 'project' ), array(
  96. 'hierarchical' => false,
  97. 'labels' => $labels,
  98. 'show_ui' => true,
  99. 'show_admin_column' => true,
  100. 'query_var' => true,
  101. ) );
  102.  
  103.  
  104. }
  105.  
  106. function remove_et_pb_actions() {
  107. remove_action( 'init', 'et_pb_register_posttypes', 15 );
  108. }
  109.  
  110. add_action( 'init', 'remove_et_pb_actions');
  111. add_action( 'init', 'child_et_pb_register_posttypes', 20 );
  112.  
  113. function format_hours_table($content) {
  114. $items = array_filter(explode("\r\n", $content));
  115.  
  116. $html = '<div class="hours-table-wrapper"><table class="hours-table"><tbody>';
  117.  
  118. // Get current day of week
  119. $current_day = current_time('l');
  120. $current_day_index = -1;
  121.  
  122. // Explode the items and find the current day index
  123. foreach ($items as $idx => $item) {
  124. $items[$idx] = explode(';', $item);
  125. array_unshift($items[$idx], '&nbsp;');
  126.  
  127. if ($items[$idx][1] === $current_day) {
  128. $current_day_index = $idx;
  129. }
  130. }
  131.  
  132. // Reorder table based on current day
  133. if ($current_day_index > -1) {
  134. $first = array_slice($items, $current_day_index);
  135. $second = array_slice($items, 0, $current_day_index);
  136. $items = array_merge($first, $second);
  137. }
  138.  
  139. // Set label of first cell
  140. $items[0][0] = "Hours:";
  141.  
  142. // Iterate cells
  143. foreach ($items as $item) {
  144. $html .= '<tr><td>' . implode('</td><td>', $item) . '</td></tr>';
  145. }
  146. $html .= '</tbody></table></div><div class="clear"></div>';
  147. return $html;
  148. }
  149.  
  150. function tenant_info_shortcode( $atts, $content = "" ) {
  151. $info = array();
  152.  
  153. if ($phone = get_post_custom_values('phone')[0]) array_push($info, "<p><a href=\"tel:" . $phone . "\">" . $phone . "</a></p>");
  154. if ($hours = get_post_custom_values('hours')[0]) array_push($info, "<p>" . $hours . "</p>");
  155. if ($hours_table = get_post_custom_values('hours-table')[0]) array_push($info, format_hours_table($hours_table));
  156. if ($website = get_post_custom_values('website')[0]) array_push($info, "<p><a href=\"" . $website . "\" target=\"_blank\">Visit website</a></p>");
  157.  
  158. return "<div style=\"text-align: right;\">" . join("\n", $info) . "</div>";
  159. }
  160. add_shortcode( 'tenant_info', 'tenant_info_shortcode' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement