-
Notifications
You must be signed in to change notification settings - Fork 0
/
dessert-display.php
executable file
·190 lines (176 loc) · 6.8 KB
/
dessert-display.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<?php
class WP_Pizzeria_Dessert_Display {
public static function getInstance() {
static $instance = null;
if ( null === $instance ) {
$instance = new static();
}
return $instance;
}
protected function __construct() {
add_shortcode( 'desserts', array( $this, 'display' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );
}
private function __clone() {
}
private function __wakeup() {
}
public function display( $atts ) {
extract( shortcode_atts( array(
'cat' => 'wp_pizzeria_nocat',
), $atts ) );
$output = '';
/* Loop all desserts */
$pizzeria_settings = maybe_unserialize( get_option( 'wp_pizzeria_settings' ) );
if ( ! array( $pizzeria_settings ) ) {
$pizzeria_settings = array();
}
$args = array( 'post_type' => 'wp_pizzeria_dessert',
'posts_per_page' => - 1,
'orderby' => 'menu_order',
'order' => 'ASC'
);
if ( 'wp_pizzeria_nocat' !== $cat ) {
$args['wp_pizzeria_dessert_category'] = $cat;
}
$pizzas = new WP_Query( $args );
$output .= '<table class="wp-pizzeria desserts">' . "\n\t<thead>";
$table_footer_header = "\n\t\t<tr>";
$table_footer_header .= "\n\t\t\t" . '<th class="col1 menu-number">' . esc_html__( '#', 'wp_pizzeria' ) . '</th>';
$table_footer_header .= "\n\t\t\t" . '<th class="col2 title">' . esc_html__( 'Title', 'wp_pizzeria' ) . '</th>';
$table_footer_header .= "\n\t\t\t" . '<th class="col3 description">' . esc_html__( 'Description', 'wp_pizzeria' ) . '</th>';
$table_footer_header .= "\n\t\t\t" . '<th class="col5 price">' . esc_html__( 'Price', 'wp_pizzeria' ) . '</th>';
$table_footer_header .= "\n\t\t</tr>";
$output .= $table_footer_header;
$output .= "\n\t</thead>\n\t<tfoot>";
$output .= $table_footer_header;
$output .= "\n\t</tfoot>\n\t<tbody>";
unset( $table_footer_header );
$even = true;
while ( $pizzas->have_posts() ) {
$pizzas->the_post();
$categories = wp_get_post_terms( get_the_ID(), 'wp_pizzeria_dessert_category' );
if ( true === $even ) {
$class = 'pizza even';
} else {
$class = '$pizza odd';
$even = true;
}
if ( false === empty( $categories ) ) {
foreach ( $categories as $category ) {
$class .= ' ' . $category->slug;
}
}
$output .= "\n\t\t" . '<tr class="' . esc_attr( $class ) . '">';
global $post;
$output .= "\n\t\t\t" . '<td class="col1 menu-number">' . intval( $post->menu_order ) . '</td>';
$output .= "\n\t\t\t" . '<td class="col2 title">';
$output .= '<a href="#" class="pizza-title">' . esc_html( get_the_title() ) . '</a>';
$output .= get_the_post_thumbnail( get_the_ID(), 'wp_pizzeria_thumbnail' );
$output .= '</td>';
$output .= "\n\t\t\t" . '<td class="col3 description"><div class="content">' . wp_kses_post( apply_filters( 'the_content', get_the_content() ) ) . '</div></td>';
if ( false !== get_post_meta( $post->ID, '_wp_pizzeria_price', true ) ) {
$output .= "\n\t\t\t" . '<td class="col5 price">';
if ( true === array_key_exists( 'currency', $pizzeria_settings )
&& true === array_key_exists( 'currency_pos', $pizzeria_settings )
&& 'before' === $pizzeria_settings['currency_pos'] ) {
$output .= esc_html( $pizzeria_settings['currency'] );
}
$output .= get_post_meta( $post->ID, '_wp_pizzeria_price', true );
if ( true === array_key_exists( 'currency', $pizzeria_settings )
&& ( false === array_key_exists( 'currency_pos', $pizzeria_settings )
|| 'after' === $pizzeria_settings['currency_pos'] )
) {
$output .= esc_html( $pizzeria_settings['currency'] );
}
$output .= '</td>';
} else {
$output .= "\n\t\t\t" . '<td class="col5 price"></td>';
}
$output .= "\n\t\t" . '</tr>';
} //endwhile
$output .= "\n\t</tbody>\n";
$output .= '</table>';
wp_reset_postdata();
return $output;
}
public function scripts() {
wp_enqueue_script( 'filter-pizzas', plugins_url( '/js/filter-pizzas.js', __FILE__ ), array( 'jquery' ) );
}
public function loop() {
global $wp_query;
$args = array_merge( $wp_query->query_vars, array( 'orderby' => 'menu_order', 'order' => 'ASC' ) );
query_posts( $args );
if ( true === have_posts() ) {
$pizzeria_settings = maybe_unserialize( get_option( 'wp_pizzeria_settings' ) );
if ( false === is_array( $pizzeria_settings ) ) {
$pizzeria_settings = array();
}
?>
<table class="wp-pizzeria desserts">
<thead>
<tr>
<th class="col1 menu-number">#</th>
<th class="col2 title"><?php esc_html_e( 'Title', 'wp_pizzeria' ); ?></th>
<th class="col3 description hidden"><?php _e( 'Description', 'wp_pizzeria' ); ?></th>
<th class="col5 price"><?php esc_html_e( 'Price', 'wp_pizzeria' ); ?></th>
</tr>
</thead>
<tfoot>
<tr>
<th class="col1 menu-number">#</th>
<th class="col2 title"><?php esc_html_e( 'Title', 'wp_pizzeria' ); ?></th>
<th class="col3 description hidden"><?php esc_html_e( 'Description', 'wp_pizzeria' ); ?></th>
<th class="col5 price"><?php esc_html_e( 'Price', 'wp_pizzeria' ); ?></th>
</tr>
</tfoot>
<tbody>
<?php $odd = true;
while ( have_posts() ) : the_post();
$categories = wp_get_post_terms( get_the_ID(), 'wp_pizzeria_ingredient' ); ?>
<tr class="pizza<?php if ( true === $odd ) {
echo ' odd ';
$odd = false;
} else {
echo ' even';
$odd = true;
}
foreach ( (array) $categories as $category ) {
echo ' ' . esc_attr( $category->slug );
} ?>">
<td class="col1 menu-number"><?php global $post;
echo intval( $post->menu_order ); ?></td>
<td class="col2 title"><a class="pizza-title" href="#"><?php esc_html( get_the_title() ); ?></a></td>
<td class="col3 description hidden">
<div class="content"><?php wp_kses_post( apply_filters( 'the_content', get_the_content() ) ); ?></div>
</td>
<td class="col5 price">
<?php
if ( false !== get_post_meta( get_the_ID(), '_wp_pizzeria_price', true ) ) {
if ( true === array_key_exists( 'currency', $pizzeria_settings )
&& true === array_key_exists( 'currency_pos', $pizzeria_settings )
&& 'before' === $pizzeria_settings['currency_pos']
) {
echo esc_html( $pizzeria_settings['currency'] );
}
echo esc_html( get_post_meta( get_the_ID(), '_wp_pizzeria_price', true ) );
if ( true === array_key_exists( 'currency', $pizzeria_settings )
&& ( false === array_key_exists( 'currency_pos', $pizzeria_settings )
|| 'after' === $pizzeria_settings['currency_pos'] )
) {
echo esc_html( $pizzeria_settings['currency'] );
}
}
?>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
<?php
}
}
}
function desserts_loop() {
WP_Pizzeria_Dessert_Display::getInstance()->loop();
}