Essential Content Types - Version 1.8.3

Version Description

(Released: September 21, 2020) == * Bug Fixed: Check if thumbnail exists on templates

Download this release

Release Info

Developer catchthemes
Plugin Icon Essential Content Types
Version 1.8.3
Comparing to
See all releases

Code changes from version 1.8.2 to 1.8.3

README.txt CHANGED
@@ -200,6 +200,9 @@ Not so easy way (via FTP) :
200
  5. Customizer: Services Archive Options
201
 
202
  == Changelog ==
 
 
 
203
  = 1.8.2 (Released: Aug 19, 2020) ==
204
  * Bug Fixed: Issue in add new theme page
205
 
200
  5. Customizer: Services Archive Options
201
 
202
  == Changelog ==
203
+ = 1.8.3 (Released: September 21, 2020) ==
204
+ * Bug Fixed: Check if thumbnail exists on templates
205
+
206
  = 1.8.2 (Released: Aug 19, 2020) ==
207
  * Bug Fixed: Issue in add new theme page
208
 
admin/class-essential-content-types-admin.php CHANGED
@@ -1,259 +1,259 @@
1
- <?php
2
-
3
- /**
4
- * The admin-specific functionality of the plugin.
5
- *
6
- * @link https://catchplugins.com
7
- * @since 1.0.0
8
- *
9
- * @package Essential_Content_Types
10
- * @subpackage Essential_Content_Types/admin
11
- */
12
-
13
- /**
14
- * The admin-specific functionality of the plugin.
15
- *
16
- * Defines the plugin name, version, and two examples hooks for how to
17
- * enqueue the admin-specific stylesheet and JavaScript.
18
- *
19
- * @package Essential_Content_Types
20
- * @subpackage Essential_Content_Types/admin
21
- * @author Catch Plugins <info@catchplugins.com>
22
- */
23
- class Essential_Content_Types_Admin {
24
-
25
- /**
26
- * The ID of this plugin.
27
- *
28
- * @since 1.0.0
29
- * @access private
30
- * @var string $plugin_name The ID of this plugin.
31
- */
32
- private $plugin_name;
33
-
34
- /**
35
- * The version of this plugin.
36
- *
37
- * @since 1.0.0
38
- * @access private
39
- * @var string $version The current version of this plugin.
40
- */
41
- private $version;
42
-
43
- /**
44
- * Initialize the class and set its properties.
45
- *
46
- * @since 1.0.0
47
- * @param string $plugin_name The name of this plugin.
48
- * @param string $version The version of this plugin.
49
- */
50
- public function __construct( $plugin_name, $version ) {
51
-
52
- $this->plugin_name = $plugin_name;
53
- $this->version = $version;
54
-
55
- $this->load_dependencies();
56
-
57
- }
58
-
59
- /**
60
- * Load the required dependencies for this plugin.
61
- *
62
- * Include the following files that make up the plugin:
63
- *
64
- * - Essential_Content_Types_Loader. Orchestrates the hooks of the plugin.
65
- * - Essential_Content_Types_i18n. Defines internationalization functionality.
66
- * - Essential_Content_Types_Admin. Defines all hooks for the admin area.
67
- * - Essential_Content_Types_Public. Defines all hooks for the public side of the site.
68
- *
69
- * Create an instance of the loader which will be used to register the hooks
70
- * with WordPress.
71
- *
72
- * @since 1.0.0
73
- * @access private
74
- */
75
- private function load_dependencies() {
76
-
77
- $portfolio_options = get_option( 'ect_portfolio' );
78
- if ( $portfolio_options['status'] ) {
79
- /**
80
- * Load Portfolio Content Type
81
- */
82
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-portfolio.php';
83
- }
84
-
85
- $testimonial_options = get_option( 'ect_testimonial' );
86
- if ( $testimonial_options['status'] ) {
87
- /**
88
- * Load Testimonial Content Type
89
- */
90
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-testimonial.php';
91
- }
92
-
93
- $featured_content_options = get_option( 'ect_featured_content' );
94
- if ( $featured_content_options['status'] ) {
95
- /**
96
- * Load Featured Content Type
97
- */
98
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-featured-content.php';
99
- }
100
-
101
- $service_options = get_option( 'ect_service' );
102
- if ( $service_options['status'] ) {
103
- /**
104
- * Load Service Type
105
- */
106
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-service.php';
107
- }
108
-
109
- $food_menu_options = get_option( 'ect_food_menu' );
110
- if ( $food_menu_options['status'] ) {
111
- /**
112
- * Load Food Menu Type
113
- */
114
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-food-menu.php';
115
- }
116
-
117
- }
118
-
119
-
120
- /**
121
- * Register the stylesheets for the admin area.
122
- *
123
- * @since 1.0.0
124
- */
125
- public function enqueue_styles( $hook_suffix ) {
126
- $allowed_pages = array(
127
- 'toplevel_page_essential-content-types' => 1,
128
- 'essential-content-types_page_ect-portfolio' => 1,
129
- 'essential-content-types_page_ect-testimonial' => 1,
130
- 'essential-content-types_page_ect-featured-content' => 1,
131
- 'essential-content-types_page_ect-service' => 1,
132
- 'essential-content-types_page_ect-food-menu' => 1,
133
- );
134
-
135
- if ( ! isset( $allowed_pages[ $hook_suffix ] ) ){
136
- return;
137
- }
138
-
139
- wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/essential-content-types-admin.css', array(), $this->version, 'all' );
140
-
141
- wp_enqueue_style( $this->plugin_name.'-tabs', plugin_dir_url( __FILE__ ) . 'css/admin-dashboard.css', array(), $this->version, 'all' );
142
-
143
- }
144
-
145
- /**
146
- * Register the JavaScript for the admin area.
147
- *
148
- * @since 1.0.0
149
- */
150
- public function enqueue_scripts( $hook_suffix ) {
151
- $allowed_pages = array(
152
- 'toplevel_page_essential-content-types' => 1,
153
- 'essential-content-types_page_ect-portfolio' => 1,
154
- 'essential-content-types_page_ect-testimonial' => 1,
155
- 'essential-content-types_page_ect-featured-content' => 1,
156
- 'essential-content-types_page_ect-service' => 1,
157
- 'essential-content-types_page_ect-food-menu' => 1,
158
- );
159
-
160
- if ( ! isset( $allowed_pages[ $hook_suffix ] ) ){
161
- return;
162
- }
163
-
164
- wp_enqueue_script( 'minHeight', plugin_dir_url( __FILE__ ) . 'js/jquery.matchHeight.min.js', array( 'jquery' ), $this->version, false );
165
- wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/essential-content-types-admin.js', array( 'minHeight', 'jquery' ), $this->version, false );
166
-
167
-
168
- }
169
-
170
- /**
171
- * Essential Content Types: action_links
172
- * Essential Content Types Settings Link function callback
173
- *
174
- * @param arrray $links Link url.
175
- *
176
- * @param arrray $file File name.
177
- */
178
- public function action_links( $links, $file ) {
179
- if ( $file === $this->plugin_name . '/' . $this->plugin_name . '.php' ) {
180
- $settings_link = '<a href="' . esc_url( admin_url( 'admin.php?page=essential-content-types' ) ) . '">' . esc_html__( 'Settings', 'essential-content-types' ) . '</a>';
181
-
182
- array_unshift( $links, $settings_link );
183
- }
184
- return $links;
185
- }
186
-
187
- /**
188
- * Add settings menu
189
- */
190
- function settings_menu() {
191
- // Add Main Menu
192
- add_menu_page(
193
- esc_html__( 'Essential Content Types', 'essential-content-types' ), //$page_title
194
- esc_html__( 'Essential Content Types', 'essential-content-types' ), //$menu_title
195
- 'manage_options', //$capability
196
- 'essential-content-types', //$menu_slug
197
- array( $this, 'settings_page' ), //$function
198
- 'dashicons-layout', //$icon_url
199
- '99.01564' //$position
200
- );
201
- }
202
-
203
- /**
204
- * Dashboard Page include
205
- */
206
- function settings_page() {
207
- if ( !current_user_can( 'manage_options' ) ) {
208
- wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
209
- }
210
-
211
- //require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/dashboard-display.php';
212
- require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/essential-content-types-admin-display.php';
213
- }
214
-
215
- function dashboard_switch() {
216
- $value = ( 'true' == $_POST['value'] ) ? 1 : 0;
217
-
218
- $option_name = $_POST['option_name'];
219
-
220
- $option_value = get_option( $option_name );
221
-
222
- $option_value['status'] = $value;
223
-
224
- if( update_option( $option_name, $option_value ) ) {
225
- echo $value;
226
- } else {
227
- esc_html_e( 'Connection Error. Please try again.', 'essential-content-types' );
228
- }
229
-
230
- wp_die(); // this is required to terminate immediately and return a proper response
231
- }
232
- function add_plugin_meta_links( $meta_fields, $file ){
233
-
234
- if( ESSENTIAL_CONTENT_TYPES_BASENAME == $file ) {
235
-
236
- $meta_fields[] = "<a href='https://catchplugins.com/support-forum/forum/essential-content-type/' target='_blank'>Support Forum</a>";
237
- $meta_fields[] = "<a href='https://wordpress.org/support/plugin/essential-content-types/#reviews' target='_blank' title='Rate'>
238
- <i class='ct-rate-stars'>"
239
- . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>"
240
- . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>"
241
- . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>"
242
- . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>"
243
- . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>"
244
- . "</i></a>";
245
-
246
- $stars_color = "#ffb900";
247
-
248
- echo "<style>"
249
- . ".ct-rate-stars{display:inline-block;color:" . $stars_color . ";position:relative;top:3px;}"
250
- . ".ct-rate-stars svg{fill:" . $stars_color . ";}"
251
- . ".ct-rate-stars svg:hover{fill:" . $stars_color . "}"
252
- . ".ct-rate-stars svg:hover ~ svg{fill:none;}"
253
- . "</style>";
254
- }
255
-
256
- return $meta_fields;
257
- }
258
-
259
- }
1
+ <?php
2
+
3
+ /**
4
+ * The admin-specific functionality of the plugin.
5
+ *
6
+ * @link https://catchplugins.com
7
+ * @since 1.0.0
8
+ *
9
+ * @package Essential_Content_Types
10
+ * @subpackage Essential_Content_Types/admin
11
+ */
12
+
13
+ /**
14
+ * The admin-specific functionality of the plugin.
15
+ *
16
+ * Defines the plugin name, version, and two examples hooks for how to
17
+ * enqueue the admin-specific stylesheet and JavaScript.
18
+ *
19
+ * @package Essential_Content_Types
20
+ * @subpackage Essential_Content_Types/admin
21
+ * @author Catch Plugins <info@catchplugins.com>
22
+ */
23
+ class Essential_Content_Types_Admin {
24
+
25
+ /**
26
+ * The ID of this plugin.
27
+ *
28
+ * @since 1.0.0
29
+ * @access private
30
+ * @var string $plugin_name The ID of this plugin.
31
+ */
32
+ private $plugin_name;
33
+
34
+ /**
35
+ * The version of this plugin.
36
+ *
37
+ * @since 1.0.0
38
+ * @access private
39
+ * @var string $version The current version of this plugin.
40
+ */
41
+ private $version;
42
+
43
+ /**
44
+ * Initialize the class and set its properties.
45
+ *
46
+ * @since 1.0.0
47
+ * @param string $plugin_name The name of this plugin.
48
+ * @param string $version The version of this plugin.
49
+ */
50
+ public function __construct( $plugin_name, $version ) {
51
+
52
+ $this->plugin_name = $plugin_name;
53
+ $this->version = $version;
54
+
55
+ $this->load_dependencies();
56
+
57
+ }
58
+
59
+ /**
60
+ * Load the required dependencies for this plugin.
61
+ *
62
+ * Include the following files that make up the plugin:
63
+ *
64
+ * - Essential_Content_Types_Loader. Orchestrates the hooks of the plugin.
65
+ * - Essential_Content_Types_i18n. Defines internationalization functionality.
66
+ * - Essential_Content_Types_Admin. Defines all hooks for the admin area.
67
+ * - Essential_Content_Types_Public. Defines all hooks for the public side of the site.
68
+ *
69
+ * Create an instance of the loader which will be used to register the hooks
70
+ * with WordPress.
71
+ *
72
+ * @since 1.0.0
73
+ * @access private
74
+ */
75
+ private function load_dependencies() {
76
+
77
+ $portfolio_options = get_option( 'ect_portfolio' );
78
+ if ( isset($portfolio_options['status']) && $portfolio_options['status'] ) {
79
+ /**
80
+ * Load Portfolio Content Type
81
+ */
82
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-portfolio.php';
83
+ }
84
+
85
+ $testimonial_options = get_option( 'ect_testimonial' );
86
+ if ( isset($testimonial_options['status']) && $testimonial_options['status'] ) {
87
+ /**
88
+ * Load Testimonial Content Type
89
+ */
90
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-testimonial.php';
91
+ }
92
+
93
+ $featured_content_options = get_option( 'ect_featured_content' );
94
+ if ( isset($featured_content_options['status']) && $featured_content_options['status'] ) {
95
+ /**
96
+ * Load Featured Content Type
97
+ */
98
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-featured-content.php';
99
+ }
100
+
101
+ $service_options = get_option( 'ect_service' );
102
+ if ( isset($service_options['status']) && $service_options['status'] ) {
103
+ /**
104
+ * Load Service Type
105
+ */
106
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-service.php';
107
+ }
108
+
109
+ $food_menu_options = get_option( 'ect_food_menu' );
110
+ if ( isset($food_menu_options['status']) && $food_menu_options['status'] ) {
111
+ /**
112
+ * Load Food Menu Type
113
+ */
114
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-food-menu.php';
115
+ }
116
+
117
+ }
118
+
119
+
120
+ /**
121
+ * Register the stylesheets for the admin area.
122
+ *
123
+ * @since 1.0.0
124
+ */
125
+ public function enqueue_styles( $hook_suffix ) {
126
+ $allowed_pages = array(
127
+ 'toplevel_page_essential-content-types' => 1,
128
+ 'essential-content-types_page_ect-portfolio' => 1,
129
+ 'essential-content-types_page_ect-testimonial' => 1,
130
+ 'essential-content-types_page_ect-featured-content' => 1,
131
+ 'essential-content-types_page_ect-service' => 1,
132
+ 'essential-content-types_page_ect-food-menu' => 1,
133
+ );
134
+
135
+ if ( ! isset( $allowed_pages[ $hook_suffix ] ) ){
136
+ return;
137
+ }
138
+
139
+ wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/essential-content-types-admin.css', array(), $this->version, 'all' );
140
+
141
+ wp_enqueue_style( $this->plugin_name.'-tabs', plugin_dir_url( __FILE__ ) . 'css/admin-dashboard.css', array(), $this->version, 'all' );
142
+
143
+ }
144
+
145
+ /**
146
+ * Register the JavaScript for the admin area.
147
+ *
148
+ * @since 1.0.0
149
+ */
150
+ public function enqueue_scripts( $hook_suffix ) {
151
+ $allowed_pages = array(
152
+ 'toplevel_page_essential-content-types' => 1,
153
+ 'essential-content-types_page_ect-portfolio' => 1,
154
+ 'essential-content-types_page_ect-testimonial' => 1,
155
+ 'essential-content-types_page_ect-featured-content' => 1,
156
+ 'essential-content-types_page_ect-service' => 1,
157
+ 'essential-content-types_page_ect-food-menu' => 1,
158
+ );
159
+
160
+ if ( ! isset( $allowed_pages[ $hook_suffix ] ) ){
161
+ return;
162
+ }
163
+
164
+ wp_enqueue_script( 'minHeight', plugin_dir_url( __FILE__ ) . 'js/jquery.matchHeight.min.js', array( 'jquery' ), $this->version, false );
165
+ wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/essential-content-types-admin.js', array( 'minHeight', 'jquery' ), $this->version, false );
166
+
167
+
168
+ }
169
+
170
+ /**
171
+ * Essential Content Types: action_links
172
+ * Essential Content Types Settings Link function callback
173
+ *
174
+ * @param arrray $links Link url.
175
+ *
176
+ * @param arrray $file File name.
177
+ */
178
+ public function action_links( $links, $file ) {
179
+ if ( $file === $this->plugin_name . '/' . $this->plugin_name . '.php' ) {
180
+ $settings_link = '<a href="' . esc_url( admin_url( 'admin.php?page=essential-content-types' ) ) . '">' . esc_html__( 'Settings', 'essential-content-types' ) . '</a>';
181
+
182
+ array_unshift( $links, $settings_link );
183
+ }
184
+ return $links;
185
+ }
186
+
187
+ /**
188
+ * Add settings menu
189
+ */
190
+ function settings_menu() {
191
+ // Add Main Menu
192
+ add_menu_page(
193
+ esc_html__( 'Essential Content Types', 'essential-content-types' ), //$page_title
194
+ esc_html__( 'Essential Content Types', 'essential-content-types' ), //$menu_title
195
+ 'manage_options', //$capability
196
+ 'essential-content-types', //$menu_slug
197
+ array( $this, 'settings_page' ), //$function
198
+ 'dashicons-layout', //$icon_url
199
+ '99.01564' //$position
200
+ );
201
+ }
202
+
203
+ /**
204
+ * Dashboard Page include
205
+ */
206
+ function settings_page() {
207
+ if ( !current_user_can( 'manage_options' ) ) {
208
+ wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
209
+ }
210
+
211
+ //require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/dashboard-display.php';
212
+ require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/partials/essential-content-types-admin-display.php';
213
+ }
214
+
215
+ function dashboard_switch() {
216
+ $value = ( 'true' == $_POST['value'] ) ? 1 : 0;
217
+
218
+ $option_name = $_POST['option_name'];
219
+
220
+ $option_value = get_option( $option_name );
221
+
222
+ $option_value['status'] = $value;
223
+
224
+ if( update_option( $option_name, $option_value ) ) {
225
+ echo $value;
226
+ } else {
227
+ esc_html_e( 'Connection Error. Please try again.', 'essential-content-types' );
228
+ }
229
+
230
+ wp_die(); // this is required to terminate immediately and return a proper response
231
+ }
232
+ function add_plugin_meta_links( $meta_fields, $file ){
233
+
234
+ if( ESSENTIAL_CONTENT_TYPES_BASENAME == $file ) {
235
+
236
+ $meta_fields[] = "<a href='https://catchplugins.com/support-forum/forum/essential-content-type/' target='_blank'>Support Forum</a>";
237
+ $meta_fields[] = "<a href='https://wordpress.org/support/plugin/essential-content-types/#reviews' target='_blank' title='Rate'>
238
+ <i class='ct-rate-stars'>"
239
+ . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>"
240
+ . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>"
241
+ . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>"
242
+ . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>"
243
+ . "<svg xmlns='http://www.w3.org/2000/svg' width='15' height='15' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round' class='feather feather-star'><polygon points='12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2'/></svg>"
244
+ . "</i></a>";
245
+
246
+ $stars_color = "#ffb900";
247
+
248
+ echo "<style>"
249
+ . ".ct-rate-stars{display:inline-block;color:" . $stars_color . ";position:relative;top:3px;}"
250
+ . ".ct-rate-stars svg{fill:" . $stars_color . ";}"
251
+ . ".ct-rate-stars svg:hover{fill:" . $stars_color . "}"
252
+ . ".ct-rate-stars svg:hover ~ svg{fill:none;}"
253
+ . "</style>";
254
+ }
255
+
256
+ return $meta_fields;
257
+ }
258
+
259
+ }
admin/class-food-menu.php CHANGED
@@ -1,1506 +1,1538 @@
1
- <?php
2
- /*
3
- * Put the following code in your theme's Food Menu Page Template to customize the markup of the menu.
4
-
5
- if ( class_exists( 'Essential_Content_Food_Menu' ) ) {
6
- Essential_Content_Food_Menu::init( array(
7
- 'menu_tag' => 'section',
8
- 'menu_class' => 'menu-items',
9
- 'menu_header_tag' => 'header',
10
- 'menu_header_class' => 'menu-group-header',
11
- 'menu_title_tag' => 'h1',
12
- 'menu_title_class' => 'menu-group-title',
13
- 'menu_description_tag' => 'div',
14
- 'menu_description_class' => 'menu-group-description',
15
- ) );
16
- }
17
-
18
- */
19
-
20
- /* @todo
21
-
22
- Bulk/Quick edit response of Menu Item rows is broken.
23
-
24
- Drag and Drop reordering.
25
- */
26
-
27
- class Essential_Content_Food_Menu {
28
- const MENU_ITEM_POST_TYPE = 'ect_food_menu_item';
29
- const MENU_ITEM_LABEL_TAX = 'ect_food_menu_item_label';
30
- const MENU_TAX = 'ect_food_menu';
31
-
32
- public $version = ESSENTIAL_CONTENT_TYPES_VERSION;
33
-
34
- protected $default_menu_item_loop_markup = array(
35
- 'menu_tag' => 'section',
36
- 'menu_class' => 'menu-items',
37
- 'menu_header_tag' => 'header',
38
- 'menu_header_class' => 'menu-group-header',
39
- 'menu_title_tag' => 'h1',
40
- 'menu_title_class' => 'menu-group-title',
41
- 'menu_description_tag' => 'div',
42
- 'menu_description_class' => 'menu-group-description',
43
- );
44
-
45
- protected $menu_item_loop_markup = array();
46
- protected $menu_item_loop_last_term_id = false;
47
- protected $menu_item_loop_current_term = false;
48
-
49
- static function init( $menu_item_loop_markup = array() ) {
50
- static $instance = false;
51
-
52
- if ( !$instance ) {
53
- $instance = new Essential_Content_Food_Menu;
54
- }
55
-
56
- if ( $menu_item_loop_markup ) {
57
- $instance->menu_item_loop_markup = wp_parse_args( $menu_item_loop_markup, $instance->default_menu_item_loop_markup );
58
- }
59
-
60
- return $instance;
61
- }
62
-
63
- function __construct() {
64
- if ( ! $this->site_supports_food_menu() )
65
- return;
66
-
67
- $this->register_taxonomies();
68
- $this->register_post_types();
69
- add_action( 'admin_menu', array( $this, 'add_admin_menus' ) );
70
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_ect_food_styles' ) );
71
- add_action( 'admin_head', array( $this, 'set_custom_font_icon' ) );
72
-
73
- // Enable Omnisearch for Menu Items.
74
- if ( class_exists( 'Jetpack_Omnisearch_Posts' ) )
75
- new Jetpack_Omnisearch_Posts( self::MENU_ITEM_POST_TYPE );
76
-
77
- // Always sort menu items correctly
78
- add_action( 'parse_query', array( $this, 'sort_menu_item_queries_by_menu_order' ) );
79
- add_filter( 'posts_results', array( $this, 'sort_menu_item_queries_by_menu_taxonomy' ), 10, 2 );
80
-
81
- add_action( 'wp_insert_post', array( $this, 'add_post_meta' ) );
82
-
83
- $this->menu_item_loop_markup = $this->default_menu_item_loop_markup;
84
-
85
- // Only output our Menu Item Loop Markup on a real blog view. Not feeds, XML-RPC, admin, etc.
86
- add_filter( 'template_include', array( $this, 'setup_menu_item_loop_markup__in_filter' ) );
87
-
88
- add_filter( 'enter_title_here', array( $this, 'change_default_title' ) );
89
- add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) );
90
- add_filter( 'dashboard_glance_items', array( $this, 'add_to_dashboard' ) );
91
-
92
- add_filter( 'body_class', array( $this, 'custom_class' ) );
93
-
94
- // register food_menu shortcode (legacy)
95
- add_shortcode( 'food_menu', array( $this, 'ect_food_shortcode' ) );
96
- }
97
-
98
- public function custom_class( $classes ) {
99
- global $post;
100
- if( isset( $post->post_content ) && has_shortcode( $post->post_content, 'food_menu' ) ) {
101
- $classes[] = 'page-template-menu-page';
102
- }
103
- return $classes;
104
- }
105
-
106
- /**
107
- * Should this Custom Post Type be made available?
108
- */
109
- function site_supports_food_menu() {
110
- // If we're on WordPress.com, and it has the menu site vertical.
111
- if ( function_exists( 'site_vertical' ) && 'ect_food_menu' == site_vertical() )
112
- return true;
113
-
114
- // Else, if the current theme requests it.
115
- if ( current_theme_supports( self::MENU_ITEM_POST_TYPE ) )
116
- return true;
117
- }
118
-
119
- /* Setup */
120
-
121
- /**
122
- * Register Taxonomies and Post Type
123
- */
124
- function register_taxonomies() {
125
- if ( ! taxonomy_exists( self::MENU_ITEM_LABEL_TAX ) ) {
126
- register_taxonomy( self::MENU_ITEM_LABEL_TAX, self::MENU_ITEM_POST_TYPE, array(
127
- 'labels' => array(
128
- /* translators: this is about a food menu */
129
- 'name' => __( 'Menu Item Labels', 'essential-content-types' ),
130
- /* translators: this is about a food menu */
131
- 'singular_name' => __( 'Menu Item Label', 'essential-content-types' ),
132
- /* translators: this is about a food menu */
133
- 'search_items' => __( 'Search Menu Item Labels', 'essential-content-types' ),
134
- 'popular_items' => __( 'Popular Labels', 'essential-content-types' ),
135
- /* translators: this is about a food menu */
136
- 'all_items' => __( 'All Menu Item Labels', 'essential-content-types' ),
137
- /* translators: this is about a food menu */
138
- 'edit_item' => __( 'Edit Menu Item Label', 'essential-content-types' ),
139
- /* translators: this is about a food menu */
140
- 'view_item' => __( 'View Menu Item Label', 'essential-content-types' ),
141
- /* translators: this is about a food menu */
142
- 'update_item' => __( 'Update Menu Item Label', 'essential-content-types' ),
143
- /* translators: this is about a food menu */
144
- 'add_new_item' => __( 'Add New Menu Item Label', 'essential-content-types' ),
145
- /* translators: this is about a food menu */
146
- 'new_item_name' => __( 'New Menu Item Label Name', 'essential-content-types' ),
147
- 'separate_items_with_commas' => __( 'For example, spicy, favorite, etc. <br /> Separate Labels with commas', 'essential-content-types' ),
148
- 'add_or_remove_items' => __( 'Add or remove Labels', 'essential-content-types' ),
149
- 'choose_from_most_used' => __( 'Choose from the most used Labels', 'essential-content-types' ),
150
- 'items_list_navigation' => __( 'Menu item label list navigation', 'essential-content-types' ),
151
- 'items_list' => __( 'Menu item labels list', 'essential-content-types' ),
152
- ),
153
- 'no_tagcloud' => __( 'No Labels found', 'essential-content-types' ),
154
- 'hierarchical' => false,
155
- ) );
156
- }
157
-
158
- if ( ! taxonomy_exists( self::MENU_TAX ) ) {
159
- register_taxonomy( self::MENU_TAX, self::MENU_ITEM_POST_TYPE, array(
160
- 'labels' => array(
161
- /* translators: this is about a food menu */
162
- 'name' => __( 'Menu Sections', 'essential-content-types' ),
163
- /* translators: this is about a food menu */
164
- 'singular_name' => __( 'Menu Section', 'essential-content-types' ),
165
- /* translators: this is about a food menu */
166
- 'search_items' => __( 'Search Menu Sections', 'essential-content-types' ),
167
- /* translators: this is about a food menu */
168
- 'all_items' => __( 'All Menu Sections', 'essential-content-types' ),
169
- /* translators: this is about a food menu */
170
- 'parent_item' => __( 'Parent Menu Section', 'essential-content-types' ),
171
- /* translators: this is about a food menu */
172
- 'parent_item_colon' => __( 'Parent Menu Section:', 'essential-content-types' ),
173
- /* translators: this is about a food menu */
174
- 'edit_item' => __( 'Edit Menu Section', 'essential-content-types' ),
175
- /* translators: this is about a food menu */
176
- 'view_item' => __( 'View Menu Section', 'essential-content-types' ),
177
- /* translators: this is about a food menu */
178
- 'update_item' => __( 'Update Menu Section', 'essential-content-types' ),
179
- /* translators: this is about a food menu */
180
- 'add_new_item' => __( 'Add New Menu Section', 'essential-content-types' ),
181
- /* translators: this is about a food menu */
182
- 'new_item_name' => __( 'New Menu Sections Name', 'essential-content-types' ),
183
- 'items_list_navigation' => __( 'Menu section list navigation', 'essential-content-types' ),
184
- 'items_list' => __( 'Menu section list', 'essential-content-types' ),
185
- ),
186
- 'rewrite' => array(
187
- 'slug' => 'menu',
188
- 'with_front' => false,
189
- 'hierarchical' => true,
190
- ),
191
- 'hierarchical' => true,
192
- 'show_tagcloud' => false,
193
- 'query_var' => 'menu',
194
- ) );
195
- }
196
- }
197
-
198
- function register_post_types() {
199
- if ( post_type_exists( self::MENU_ITEM_POST_TYPE ) ) {
200
- return;
201
- }
202
-
203
- register_post_type( self::MENU_ITEM_POST_TYPE, array(
204
- 'description' => __( "Items on your restaurant's menu", 'essential-content-types' ),
205
-
206
- 'labels' => array(
207
- /* translators: this is about a food menu */
208
- 'name' => __( 'Menu Items', 'essential-content-types' ),
209
- /* translators: this is about a food menu */
210
- 'singular_name' => __( 'Menu Item', 'essential-content-types' ),
211
- /* translators: this is about a food menu */
212
- 'menu_name' => __( 'Food Menus', 'essential-content-types' ),
213
- /* translators: this is about a food menu */
214
- 'all_items' => __( 'Menu Items', 'essential-content-types' ),
215
- /* translators: this is about a food menu */
216
- 'add_new' => __( 'Add One Item', 'essential-content-types' ),
217
- /* translators: this is about a food menu */
218
- 'add_new_item' => __( 'Add Menu Item', 'essential-content-types' ),
219
- /* translators: this is about a food menu */
220
- 'edit_item' => __( 'Edit Menu Item', 'essential-content-types' ),
221
- /* translators: this is about a food menu */
222
- 'new_item' => __( 'New Menu Item', 'essential-content-types' ),
223
- /* translators: this is about a food menu */
224
- 'view_item' => __( 'View Menu Item', 'essential-content-types' ),
225
- /* translators: this is about a food menu */
226
- 'search_items' => __( 'Search Menu Items', 'essential-content-types' ),
227
- /* translators: this is about a food menu */
228
- 'not_found' => __( 'No Menu Items found', 'essential-content-types' ),
229
- /* translators: this is about a food menu */
230
- 'not_found_in_trash' => __( 'No Menu Items found in Trash', 'essential-content-types' ),
231
- 'filter_items_list' => __( 'Filter menu items list', 'essential-content-types' ),
232
- 'items_list_navigation' => __( 'Menu item list navigation', 'essential-content-types' ),
233
- 'items_list' => __( 'Menu items list', 'essential-content-types' ),
234
- ),
235
- 'supports' => array(
236
- 'title',
237
- 'editor',
238
- 'excerpt',
239
- ),
240
- 'rewrite' => array(
241
- 'slug' => 'item',
242
- 'with_front' => false,
243
- 'feeds' => false,
244
- 'pages' => false,
245
- ),
246
- 'register_meta_box_cb' => array( $this, 'register_menu_item_meta_boxes' ),
247
-
248
- 'public' => true,
249
- 'show_ui' => true, // set to false to replace with custom UI
250
- 'menu_position' => 20, // below Pages
251
- 'capability_type' => 'page',
252
- 'map_meta_cap' => true,
253
- 'has_archive' => false,
254
- 'query_var' => 'item',
255
- ) );
256
- }
257
-
258
-
259
- /**
260
- * Update messages for the Menu Item admin.
261
- */
262
- function updated_messages( $messages ) {
263
- global $post;
264
-
265
- $messages[self::MENU_ITEM_POST_TYPE] = array(
266
- 0 => '', // Unused. Messages start at index 1.
267
- /* translators: this is about a food menu */
268
- 1 => sprintf( __( 'Menu item updated. <a href="%s">View item</a>', 'essential-content-types' ), esc_url( get_permalink( $post->ID ) ) ),
269
- 2 => esc_html__( 'Custom field updated.', 'essential-content-types' ),
270
- 3 => esc_html__( 'Custom field deleted.', 'essential-content-types' ),
271
- /* translators: this is about a food menu */
272
- 4 => esc_html__( 'Menu item updated.', 'essential-content-types' ),
273
- /* translators: %s: date and time of the revision */
274
- 5 => isset( $_GET['revision'] ) ? sprintf( esc_html__( 'Menu item restored to revision from %s', 'essential-content-types' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
275
- /* translators: this is about a food menu */
276
- 6 => sprintf( __( 'Menu item published. <a href="%s">View item</a>', 'essential-content-types' ), esc_url( get_permalink( $post->ID ) ) ),
277
- /* translators: this is about a food menu */
278
- 7 => esc_html__( 'Menu item saved.', 'essential-content-types' ),
279
- /* translators: this is about a food menu */
280
- 8 => sprintf( __( 'Menu item submitted. <a target="_blank" href="%s">Preview item</a>', 'essential-content-types' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) ),
281
- /* translators: this is about a food menu */
282
- 9 => sprintf( __( 'Menu item scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview item</a>', 'essential-content-types' ),
283
- // translators: Publish box date format, see http://php.net/date
284
- date_i18n( __( 'M j, Y @ G:i', 'essential-content-types' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post->ID) ) ),
285
- /* translators: this is about a food menu */
286
- 10 => sprintf( __( 'Menu item draft updated. <a target="_blank" href="%s">Preview item</a>', 'essential-content-types' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) ),
287
- );
288
-
289
- return $messages;
290
- }
291
-
292
-
293
- /**
294
- * Nova Styles and Scripts
295
- */
296
- function enqueue_ect_food_styles( $hook ) {
297
- global $post_type;
298
- $pages = array( 'edit.php', 'post.php', 'post-new.php' );
299
-
300
- if ( in_array( $hook, $pages ) && $post_type == self::MENU_ITEM_POST_TYPE ) {
301
- wp_enqueue_style( 'ect-food-menu-style', plugins_url( 'css/ect-food-menu.css', __FILE__ ), array(), $this->version );
302
- }
303
-
304
- wp_enqueue_style( 'ect-food-menu-font', plugins_url( 'css/ect-food-menu-font.css', __FILE__ ), array(), $this->version );
305
- }
306
-
307
-
308
- /**
309
- * Change ‘Enter Title Here’ text for the Menu Item.
310
- */
311
- function change_default_title( $title ) {
312
- $screen = get_current_screen();
313
-
314
- if ( self::MENU_ITEM_POST_TYPE == $screen->post_type )
315
- /* translators: this is about a food menu */
316
- $title = esc_html__( "Enter the menu item's name here", 'essential-content-types' );
317
-
318
- return $title;
319
- }
320
-
321
-
322
- /**
323
- * Add to Dashboard At A Glance
324
- */
325
- function add_to_dashboard() {
326
- $number_menu_items = wp_count_posts( self::MENU_ITEM_POST_TYPE );
327
-
328
- if ( current_user_can( 'administrator' ) ) {
329
- $number_menu_items_published = sprintf( '<a href="%1$s">%2$s</a>',
330
- esc_url( get_admin_url( get_current_blog_id(), 'edit.php?post_type=' . self::MENU_ITEM_POST_TYPE ) ),
331
- sprintf( _n( '%1$d Food Menu Item', '%1$d Food Menu Items', intval( $number_menu_items->publish ), 'essential-content-types' ), number_format_i18n( $number_menu_items->publish ) )
332
- );
333
- }
334
- else {
335
- $number_menu_items_published = sprintf( '<span>%1$s</span>',
336
- sprintf( _n( '%1$d Food Menu Item', '%1$d Food Menu Items', intval( $number_menu_items->publish ), 'essential-content-types' ), number_format_i18n( $number_menu_items->publish ) )
337
- );
338
- }
339
-
340
- echo '<li class="ect-food-menu-count">' . $number_menu_items_published . '</li>';
341
- }
342
-
343
-
344
- /**
345
- * Query
346
- */
347
- function is_menu_item_query( $query ) {
348
- if (
349
- ( isset( $query->query_vars['taxonomy'] ) && self::MENU_TAX == $query->query_vars['taxonomy'] )
350
- ||
351
- ( isset( $query->query_vars['post_type'] ) && self::MENU_ITEM_POST_TYPE == $query->query_vars['post_type'] )
352
- ) {
353
- return true;
354
- }
355
-
356
- return false;
357
- }
358
-
359
- function sort_menu_item_queries_by_menu_order( $query ) {
360
- if ( ! $this->is_menu_item_query( $query ) ) {
361
- return;
362
- }
363
-
364
- $query->query_vars['orderby'] = 'menu_order';
365
- $query->query_vars['order'] = 'ASC';
366
-
367
- // For now, just turn off paging so we can sort by taxonmy later
368
- // If we want paging in the future, we'll need to add the taxonomy sort here (or at least before the DB query is made)
369
- $query->query_vars['posts_per_page'] = -1;
370
- }
371
-
372
- function sort_menu_item_queries_by_menu_taxonomy( $posts, $query ) {
373
- if ( !$posts ) {
374
- return $posts;
375
- }
376
-
377
- if ( !$this->is_menu_item_query( $query ) ) {
378
- return $posts;
379
- }
380
-
381
- $grouped_by_term = array();
382
-
383
- foreach ( $posts as $post ) {
384
- $term = $this->get_menu_item_menu_leaf( $post->ID );
385
- if ( !$term || is_wp_error( $term ) ) {
386
- $term_id = 0;
387
- } else {
388
- $term_id = $term->term_id;
389
- }
390
-
391
- if ( !isset( $grouped_by_term["$term_id"] ) ) {
392
- $grouped_by_term["$term_id"] = array();
393
- }
394
-
395
- $grouped_by_term["$term_id"][] = $post;
396
- }
397
-
398
- $term_order = get_option( 'ect_food_menu_order', array() );
399
-
400
- $return = array();
401
- foreach ( $term_order as $term_id ) {
402
- if ( isset( $grouped_by_term["$term_id"] ) ) {
403
- $return = array_merge( $return, $grouped_by_term["$term_id"] );
404
- unset( $grouped_by_term["$term_id"] );
405
- }
406
- }
407
-
408
- foreach ( $grouped_by_term as $term_id => $posts ) {
409
- $return = array_merge( $return, $posts );
410
- }
411
-
412
- return $return;
413
- }
414
-
415
-
416
- /**
417
- * Add Many Items
418
- */
419
- function add_admin_menus() {
420
- $hook = add_submenu_page(
421
- 'edit.php?post_type=' . self::MENU_ITEM_POST_TYPE,
422
- __( 'Add Many Items', 'essential-content-types' ),
423
- __( 'Add Many Items', 'essential-content-types' ),
424
- 'edit_pages',
425
- 'add_many_ect_food_items',
426
- array( $this, 'add_many_new_items_page' )
427
- );
428
-
429
- add_action( "load-$hook", array( $this, 'add_many_new_items_page_load' ) );
430
-
431
- add_action( 'current_screen', array( $this, 'current_screen_load' ) );
432
-
433
- //Adjust 'Add Many Items' submenu position
434
- if ( isset( $GLOBALS['submenu']['edit.php?post_type=' . self::MENU_ITEM_POST_TYPE] ) ) {
435
- $submenu_item = array_pop( $GLOBALS['submenu']['edit.php?post_type=' . self::MENU_ITEM_POST_TYPE] );
436
- $GLOBALS['submenu']['edit.php?post_type=' . self::MENU_ITEM_POST_TYPE][11] = $submenu_item;
437
- ksort( $GLOBALS['submenu']['edit.php?post_type=' . self::MENU_ITEM_POST_TYPE] );
438
- }
439
-
440
-
441
- $this->setup_menu_item_columns();
442
-
443
- wp_register_script(
444
- 'ect-food-menu-checkboxes',
445
- plugin_dir_url( __FILE__ ) . 'js/ect-food-menu-menu-checkboxes.js',
446
- array( 'jquery' ),
447
- $this->version,
448
- false
449
- );
450
- }
451
-
452
-
453
- /**
454
- * Custom Nova Icon CSS
455
- */
456
- function set_custom_font_icon() {
457
- ?>
458
- <style type="text/css">
459
- #menu-posts-ect_food_menu_item .wp-menu-image:before {
460
- font-family: 'nova-font' !important;
461
- content: '\e603' !important;
462
- }
463
- </style>
464
- <?php
465
- }
466
-
467
- function current_screen_load() {
468
- $screen = get_current_screen();
469
- if ( 'edit-ect_food_menu_item' !== $screen->id ) {
470
- return;
471
- }
472
-
473
- $this->edit_menu_items_page_load();
474
- add_filter( 'admin_notices', array( $this, 'admin_notices' ) );
475
- }
476
-
477
- /* Edit Items List */
478
-
479
- function admin_notices() {
480
- if ( isset( $_GET['ect_food_reordered'] ) )
481
- /* translators: this is about a food menu */
482
- printf( '<div class="updated"><p>%s</p></div>', __( 'Menu Items re-ordered.', 'essential-content-types' ) );
483
- }
484
-
485
- function no_title_sorting( $columns ) {
486
- if ( isset( $columns['title'] ) )
487
- unset( $columns['title'] );
488
- return $columns;
489
- }
490
-
491
- function setup_menu_item_columns() {
492
- add_filter( sprintf( 'manage_edit-%s_sortable_columns', self::MENU_ITEM_POST_TYPE ), array( $this, 'no_title_sorting' ) );
493
- add_filter( sprintf( 'manage_%s_posts_columns', self::MENU_ITEM_POST_TYPE ), array( $this, 'menu_item_columns' ) );
494
-
495
- add_action( sprintf( 'manage_%s_posts_custom_column', self::MENU_ITEM_POST_TYPE ), array( $this, 'menu_item_column_callback' ), 10, 2 );
496
- }
497
-
498
- function menu_item_columns( $columns ) {
499
- unset( $columns['date'], $columns['likes'] );
500
-
501
- $columns['thumbnail'] = __( 'Thumbnail', 'essential-content-types' );
502
- $columns['labels'] = __( 'Labels', 'essential-content-types' );
503
- $columns['price'] = __( 'Price', 'essential-content-types' );
504
- $columns['order'] = __( 'Order', 'essential-content-types' );
505
-
506
- return $columns;
507
- }
508
-
509
- function menu_item_column_callback( $column, $post_id ) {
510
- $screen = get_current_screen();
511
-
512
- switch ( $column ) {
513
- case 'thumbnail':
514
- echo get_the_post_thumbnail( $post_id, array( 50, 50 ) );
515
- break;
516
- case 'labels' :
517
- $this->list_admin_labels( $post_id );
518
- break;
519
- case 'price' :
520
- $this->display_price( $post_id );
521
- break;
522
- case 'order' :
523
- $url = admin_url( $screen->parent_file );
524
-
525
- $up_url = add_query_arg( array(
526
- 'action' => 'move-item-up',
527
- 'post_id' => (int) $post_id,
528
- ), wp_nonce_url( $url, 'ect_food_move_item_up_' . $post_id ) );
529
-
530
- $down_url = add_query_arg( array(
531
- 'action' => 'move-item-down',
532
- 'post_id' => (int) $post_id,
533
- ), wp_nonce_url( $url, 'ect_food_move_item_down_' . $post_id ) );
534
- $menu_item = get_post($post_id);
535
- $this->get_menu_by_post_id( $post_id );
536
- if ( $term_id = $this->get_menu_by_post_id( $post_id ) ) {
537
- $term_id = $term_id->term_id;
538
- }
539
- ?>
540
- <input type="hidden" class="menu-order-value" name="ect_food_order[<?php echo (int) $post_id ?>]" value="<?php echo esc_attr( $menu_item->menu_order ) ?>" />
541
- <input type="hidden" class='ect-food-menu-term' name="ect_food_menu_term[<?php echo (int) $post_id ?>]" value="<?php echo esc_attr( $term_id ); ?>">
542
-
543
- <span class="hide-if-js">
544
- &nbsp; &nbsp; &mdash; <a class="ect-food-move-item-up" data-post-id="<?php echo (int) $post_id; ?>" href="<?php echo esc_url( $up_url ); ?>">up</a>
545
- <br />
546
- &nbsp; &nbsp; &mdash; <a class="ect-food-move-item-down" data-post-id="<?php echo (int) $post_id; ?>" href="<?php echo esc_url( $down_url ); ?>">down</a>
547
- </span>
548
- <?php
549
- break;
550
- }
551
- }
552
-
553
- function get_menu_by_post_id( $post_id = null ) {
554
- if ( ! $post_id )
555
- return false;
556
-
557
- $terms = get_the_terms( $post_id, self::MENU_TAX );
558
-
559
- if ( ! is_array( $terms ) )
560
- return false;
561
-
562
- return array_pop( $terms );
563
- }
564
-
565
- /**
566
- * Fires on a menu edit page. We might have drag-n-drop reordered
567
- */
568
- function maybe_reorder_menu_items() {
569
- // make sure we clicked our button
570
- if ( ! ( isset( $_REQUEST['menu_reorder_submit'] ) && $_REQUEST['menu_reorder_submit'] === __( 'Save New Order', 'essential-content-types' ) ) )
571
- return;
572
- ;
573
-
574
- // make sure we have the nonce
575
- if ( ! ( isset( $_REQUEST['drag-drop-reorder'] ) && wp_verify_nonce( $_REQUEST['drag-drop-reorder'], 'drag-drop-reorder' ) ) )
576
- return;
577
-
578
- $term_pairs = array_map( 'absint', $_REQUEST['ect_food_menu_term'] );
579
- $order_pairs = array_map( 'absint', $_REQUEST['ect_food_order'] );
580
-
581
- foreach( $order_pairs as $ID => $menu_order ) {
582
- $ID = absint( $ID );
583
- unset( $order_pairs[$ID] );
584
- if ( $ID < 0 )
585
- continue;
586
-
587
- $post = get_post( $ID );
588
- if ( ! $post )
589
- continue;
590
-
591
- // save a write if the order hasn't changed
592
- if ( $menu_order != $post->menu_order )
593
- wp_update_post( compact( 'ID', 'menu_order' ) );
594
-
595
- // save a write if the term hasn't changed
596
- if ( $term_pairs[$ID] != $this->get_menu_by_post_id( $ID )->term_id )
597
- wp_set_object_terms( $ID, $term_pairs[$ID], self::MENU_TAX );
598
-
599
- }
600
-
601
- $redirect = add_query_arg( array(
602
- 'post_type' => self::MENU_ITEM_POST_TYPE,
603
- 'ect_food_reordered' => '1'
604
- ), admin_url( 'edit.php' ) );
605
- wp_safe_redirect( $redirect );
606
- exit;
607
-
608
- }
609
-
610
- function edit_menu_items_page_load() {
611
- if ( isset( $_GET['action'] ) ) {
612
- $this->handle_menu_item_actions();
613
- }
614
-
615
- $this->maybe_reorder_menu_items();
616
-
617
- wp_enqueue_script(
618
- 'ect-food-drag-drop',
619
- plugin_dir_url( __FILE__ ) . 'js/ect-food-menu-drag-drop.js',
620
- array( 'jquery-ui-sortable' ),
621
- $this->version,
622
- true
623
- );
624
-
625
- wp_localize_script( 'ect-food-drag-drop', '_novaDragDrop', array(
626
- 'nonce' => wp_create_nonce( 'drag-drop-reorder' ),
627
- 'nonceName' => 'drag-drop-reorder',
628
- 'reorder' => __( 'Save New Order', 'essential-content-types' ),
629
- 'reorderName' => 'menu_reorder_submit'
630
- ) );
631
- add_action( 'the_post', array( $this, 'show_menu_titles_in_menu_item_list' ) );
632
- }
633
-
634
- function handle_menu_item_actions() {
635
- $action = (string) $_GET['action'];
636
-
637
- switch ( $action ) {
638
- case 'move-item-up' :
639
- case 'move-item-down' :
640
- $reorder = false;
641
-
642
- $post_id = (int) $_GET['post_id'];
643
-
644
- $term = $this->get_menu_item_menu_leaf( $post_id );
645
-
646
- // Get all posts in that term
647
- $query = new WP_Query( array(
648
- 'taxonomy' => self::MENU_TAX,
649
- 'term' => $term->slug,
650
- ) );
651
-
652
- $order = array();
653
- foreach ( $query->posts as $post ) {
654
- $order[] = $post->ID;
655
- }
656
-
657
- if ( 'move-item-up' == $action ) {
658
- check_admin_referer( 'ect_food_move_item_up_' . $post_id );
659
-
660
- $first_post_id = $order[0];
661
- if ( $post_id == $first_post_id ) {
662
- break;
663
- }
664
-
665
- foreach ( $order as $menu_order => $order_post_id ) {
666
- if ( $post_id != $order_post_id ) {
667
- continue;
668
- }
669
-
670
- $swap_post_id = $order[$menu_order - 1];
671
- $order[$menu_order - 1] = $post_id;
672
- $order[$menu_order] = $swap_post_id;
673
-
674
- $reorder = true;
675
- break;
676
- }
677
- } else {
678
- check_admin_referer( 'ect_food_move_item_down_' . $post_id );
679
-
680
- $last_post_id = end( $order );
681
- if ( $post_id == $last_post_id ) {
682
- break;
683
- }
684
-
685
- foreach ( $order as $menu_order => $order_post_id ) {
686
- if ( $post_id != $order_post_id ) {
687
- continue;
688
- }
689
-
690
- $swap_post_id = $order[$menu_order + 1];
691
- $order[$menu_order + 1] = $post_id;
692
- $order[$menu_order] = $swap_post_id;
693
-
694
- $reorder = true;
695
- }
696
- }
697
-
698
- if ( $reorder ) {
699
- foreach ( $order as $menu_order => $ID ) {
700
- wp_update_post( compact( 'ID', 'menu_order' ) );
701
- }
702
- }
703
-
704
- break;
705
- case 'move-menu-up' :
706
- case 'move-menu-down' :
707
- $reorder = false;
708
-
709
- $term_id = (int) $_GET['term_id'];
710
-
711
- $terms = $this->get_menus();
712
-
713
- $order = array();
714
- foreach ( $terms as $term ) {
715
- $order[] = $term->term_id;
716
- }
717
-
718
- if ( 'move-menu-up' == $action ) {
719
- check_admin_referer( 'ect_food_move_menu_up_' . $term_id );
720
-
721
- $first_term_id = $order[0];
722
- if ( $term_id == $first_term_id ) {
723
- break;
724
- }
725
-
726
- foreach ( $order as $menu_order => $order_term_id ) {
727
- if ( $term_id != $order_term_id ) {
728
- continue;
729
- }
730
-
731
- $swap_term_id = $order[$menu_order - 1];
732
- $order[$menu_order - 1] = $term_id;
733
- $order[$menu_order] = $swap_term_id;
734
-
735
- $reorder = true;
736
- break;
737
- }
738
- } else {
739
- check_admin_referer( 'ect_food_move_menu_down_' . $term_id );
740
-
741
- $last_term_id = end( $order );
742
- if ( $term_id == $last_term_id ) {
743
- break;
744
- }
745
-
746
- foreach ( $order as $menu_order => $order_term_id ) {
747
- if ( $term_id != $order_term_id ) {
748
- continue;
749
- }
750
-
751
- $swap_term_id = $order[$menu_order + 1];
752
- $order[$menu_order + 1] = $term_id;
753
- $order[$menu_order] = $swap_term_id;
754
-
755
- $reorder = true;
756
- }
757
- }
758
-
759
- if ( $reorder ) {
760
- update_option( 'ect_food_menu_order', $order );
761
- }
762
-
763
- break;
764
- default :
765
- return;
766
- }
767
-
768
- $redirect = add_query_arg( array(
769
- 'post_type' => self::MENU_ITEM_POST_TYPE,
770
- 'ect_food_reordered' => '1'
771
- ), admin_url( 'edit.php' ) );
772
- wp_safe_redirect( $redirect );
773
- exit;
774
- }
775
-
776
- /*
777
- * Add menu title rows to the list table
778
- */
779
- function show_menu_titles_in_menu_item_list( $post ) {
780
- global $wp_list_table;
781
-
782
- static $last_term_id = false;
783
-
784
- $term = $this->get_menu_item_menu_leaf( $post->ID );
785
-
786
- $term_id = $term instanceof WP_Term ? $term->term_id : null;
787
-
788
- if ( false !== $last_term_id && $last_term_id === $term_id ) {
789
- return;
790
- }
791
-
792
- if ( is_null( $term_id ) ) {
793
- $last_term_id = null;
794
- $term_name = '';
795
- $parent_count = 0;
796
- } else {
797
- $last_term_id = $term->term_id;
798
- $term_name = $term->name;
799
- $parent_count = 0;
800
- $current_term = $term;
801
- while ( $current_term->parent ) {
802
- $parent_count++;
803
- $current_term = get_term( $current_term->parent, self::MENU_TAX );
804
- }
805
- }
806
-
807
- $non_order_column_count = $wp_list_table->get_column_count() - 1;
808
-
809
- $screen = get_current_screen();
810
-
811
- $url = admin_url( $screen->parent_file );
812
-
813
- $up_url = add_query_arg( array(
814
- 'action' => 'move-menu-up',
815
- 'term_id' => (int) $term_id,
816
- ), wp_nonce_url( $url, 'ect_food_move_menu_up_' . $term_id ) );
817
-
818
- $down_url = add_query_arg( array(
819
- 'action' => 'move-menu-down',
820
- 'term_id' => (int) $term_id,
821
- ), wp_nonce_url( $url, 'ect_food_move_menu_down_' . $term_id ) );
822
-
823
- ?>
824
- <tr class="no-items menu-label-row" data-term_id="<?php echo esc_attr( $term_id ) ?>">
825
- <td class="colspanchange" colspan="<?php echo (int) $non_order_column_count; ?>">
826
- <h3><?php
827
- echo str_repeat( ' &mdash; ', (int) $parent_count );
828
-
829
- if ( $term instanceof WP_Term ) {
830
- echo esc_html( sanitize_term_field( 'name', $term_name, $term_id, self::MENU_TAX, 'display' ) );
831
- edit_term_link( __( 'edit', 'essential-content-types' ), '<span class="edit-ect-food-section"><span class="dashicon dashicon-edit"></span>', '</span>', $term );
832
-
833
- } else {
834
- _e( 'Uncategorized' , 'essential-content-types' );
835
- }
836
- ?></h3>
837
- </td>
838
- <td>
839
- <?php if ( $term instanceof WP_Term ) { ?>
840
- <a class="ect-food-move-menu-up" title="<?php esc_attr_e( 'Move menu section up', 'essential-content-types' ); ?>" href="<?php echo esc_url( $up_url ); ?>"><?php esc_html_e( 'UP', 'essential-content-types' ); ?></a>
841
- <br />
842
- <a class="ect-food-move-menu-down" title="<?php esc_attr_e( 'Move menu section down', 'essential-content-types' ); ?>" href="<?php echo esc_url( $down_url ); ?>"><?php esc_html_e( 'DOWN', 'essential-content-types' ); ?></a>
843
- <?php } ?>
844
- </td>
845
- </tr>
846
- <?php
847
- }
848
-
849
- /* Edit Many Items */
850
-
851
- function add_many_new_items_page_load() {
852
- if ( 'POST' === strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
853
- $this->process_form_request();
854
- exit;
855
- }
856
-
857
- $this->enqueue_many_items_scripts();
858
- }
859
-
860
- function enqueue_many_items_scripts() {
861
- wp_enqueue_script(
862
- 'ect-food-many-items',
863
- plugin_dir_url( __FILE__ ) . 'js/ect-food-menu-many-items.js',
864
- array( 'jquery' ),
865
- $this->version,
866
- true
867
- );
868
- }
869
-
870
- function process_form_request() {
871
- if ( !isset( $_POST['ect_food_title'] ) || !is_array( $_POST['ect_food_title'] ) ) {
872
- return;
873
- }
874
-
875
- $is_ajax = !empty( $_POST['ajax'] );
876
-
877
- if ( $is_ajax ) {
878
- check_ajax_referer( 'ect_food_many_items' );
879
- } else {
880
- check_admin_referer( 'ect_food_many_items' );
881
- }
882
-
883
- foreach ( array_keys( $_POST['ect_food_title'] ) as $key ) :
884
- // $_POST is already slashed
885
- $post_details = array(
886
- 'post_status' => 'publish',
887
- 'post_type' => self::MENU_ITEM_POST_TYPE,
888
- 'post_content' => $_POST['ect_food_content'][$key],
889
- 'post_title' => $_POST['ect_food_title'][$key],
890
- 'tax_input' => array(
891
- self::MENU_ITEM_LABEL_TAX => $_POST['ect_food_labels'][$key],
892
- self::MENU_TAX => isset( $_POST['ect_food_menu_tax'] ) ? $_POST['ect_food_menu_tax'] : null,
893
- ),
894
- );
895
-
896
- $post_id = wp_insert_post( $post_details );
897
- if ( !$post_id || is_wp_error( $post_id ) ) {
898
- continue;
899
- }
900
-
901
- $this->set_price( $post_id, isset( $_POST['ect_food_price'][$key] ) ? stripslashes( $_POST['ect_food_price'][$key] ) : '' );
902
-
903
- if ( $is_ajax ) :
904
- $post = get_post( $post_id );
905
- $GLOBALS['post'] = $post;
906
- setup_postdata( $post );
907
-
908
- ?>
909
- <td><?php the_title(); ?></td>
910
- <td class="ect-food-price"><?php $this->display_price(); ?></td>
911
- <td><?php $this->list_labels( $post_id ); ?></td>
912
- <td><?php the_content(); ?></td>
913
- <?php
914
- endif;
915
-
916
- endforeach;
917
-
918
- if ( $is_ajax ) {
919
- exit;
920
- }
921
-
922
- wp_safe_redirect( admin_url( 'edit.php?post_type=' . self::MENU_ITEM_POST_TYPE ) );
923
- exit;
924
- }
925
-
926
- function add_many_new_items_page() {
927
- ?>
928
- <div class="wrap">
929
- <h2><?php esc_html_e( 'Add Many Items', 'essential-content-types' ); ?></h2>
930
-
931
- <p><?php _e( 'Use the <kbd>TAB</kbd> key on your keyboard to move between colums and the <kbd>ENTER</kbd> or <kbd>RETURN</kbd> key to save each row and move on to the next.', 'essential-content-types' ); ?></p>
932
-
933
- <form method="post" action="" enctype="multipart/form-data">
934
- <p><h3><?php esc_html_e( 'Add to section:', 'essential-content-types' ); ?> <?php wp_dropdown_categories( array(
935
- 'id' => 'ect-food-menu-tax',
936
- 'name' => 'ect_food_menu_tax',
937
- 'taxonomy' => self::MENU_TAX,
938
- 'hide_empty' => false,
939
- 'hierarchical' => true,
940
- ) ); ?></h3></p>
941
-
942
- <table class="many-items-table wp-list-table widefat">
943
- <thead>
944
- <tr>
945
- <th scope="col"><?php esc_html_e( 'Name', 'essential-content-types' ); ?></th>
946
- <th scope="col" class="ect-food-price"><?php esc_html_e( 'Price', 'essential-content-types' ); ?></th>
947
- <th scope="col"><?php _e( 'Labels: <small>spicy, favorite, etc. <em>Separate Labels with commas</em></small>', 'essential-content-types' ); ?></th>
948
- <th scope="col"><?php esc_html_e( 'Description', 'essential-content-types' ); ?></th>
949
- </tr>
950
- </thead>
951
- <tbody>
952
- <tr>
953
- <td><input type="text" name="ect_food_title[]" aria-required="true" /></td>
954
- <td class="ect-food-price"><input type="text" name="ect_food_price[]" /></td>
955
- <td><input type="text" name="ect_food_labels[]" /></td>
956
- <td><textarea name="ect_food_content[]" cols="20" rows="1"></textarea>
957
- </tr>
958
- </tbody>
959
- <tbody>
960
- <tr>
961
- <td><input type="text" name="ect_food_title[]" aria-required="true" /></td>
962
- <td class="ect-food-price"><input type="text" name="ect_food_price[]" /></td>
963
- <td><input type="text" name="ect_food_labels[]" /></td>
964
- <td><textarea name="ect_food_content[]" cols="20" rows="1"></textarea>
965
- </tr>
966
- </tbody>
967
- <tfoot>
968
- <tr>
969
- <th><a class="button button-secondary ect-food-new-row"><span class="dashicon dashicon-plus"></span> <?php esc_html_e( 'New Row' , 'essential-content-types' ); ?></a></th>
970
- <th class="ect-food-price"></th>
971
- <th></th>
972
- <th></th>
973
- </tr>
974
- </tfoot>
975
- </table>
976
-
977
- <p class="submit">
978
- <input type="submit" class="button-primary" value="<?php esc_attr_e( 'Add These New Menu Items', 'essential-content-types' ); ?>" />
979
- <?php wp_nonce_field( 'ect_food_many_items' ); ?>
980
- </p>
981
- </form>
982
- </div>
983
- <?php
984
- }
985
-
986
- /* Edit One Item */
987
-
988
- function register_menu_item_meta_boxes() {
989
- wp_enqueue_script( 'ect-food-menu-checkboxes' );
990
-
991
- add_meta_box( 'menu_item_price', __( 'Price', 'essential-content-types' ), array( $this, 'menu_item_price_meta_box' ), null, 'side', 'high' );
992
- }
993
-
994
- function menu_item_price_meta_box( $post, $meta_box ) {
995
- $price = $this->get_price( $post->ID );
996
- ?>
997
- <label for="ect-food-price-<?php echo (int) $post->ID; ?>" class="screen-reader-text"><?php esc_html_e( 'Price', 'essential-content-types' ); ?></label>
998
- <input type="text" id="ect-food-price-<?php echo (int) $post->ID; ?>" class="widefat" name="ect_food_price[<?php echo (int) $post->ID; ?>]" value="<?php echo esc_attr( $price ); ?>" />
999
- <?php
1000
- }
1001
-
1002
- function add_post_meta( $post_id ) {
1003
- if ( !isset( $_POST['ect_food_price'][$post_id] ) ) {
1004
- return;
1005
- }
1006
-
1007
- $this->set_price( $post_id, stripslashes( $_POST['ect_food_price'][$post_id] ) );
1008
- }
1009
-
1010
- /* Data */
1011
-
1012
- function get_menus( $args = array() ) {
1013
- $args = wp_parse_args( $args, array(
1014
- 'hide_empty' => false,
1015
- ) );
1016
-
1017
- $terms = get_terms( self::MENU_TAX, $args );
1018
- if ( !$terms || is_wp_error( $terms ) ) {
1019
- return array();
1020
- }
1021
-
1022
- $terms_by_id = array();
1023
- foreach ( $terms as $term ) {
1024
- $terms_by_id["{$term->term_id}"] = $term;
1025
- }
1026
-
1027
- $term_order = get_option( 'ect_food_menu_order', array() );
1028
-
1029
- $return = array();
1030
- foreach ( $term_order as $term_id ) {
1031
- if ( isset( $terms_by_id["$term_id"] ) ) {
1032
- $return[] = $terms_by_id["$term_id"];
1033
- unset( $terms_by_id["$term_id"] );
1034
- }
1035
- }
1036
-
1037
- foreach ( $terms_by_id as $term_id => $term ) {
1038
- $return[] = $term;
1039
- }
1040
-
1041
- return $return;
1042
- }
1043
-
1044
- function get_menu_item_menu_leaf( $post_id ) {
1045
- // Get first menu taxonomy "leaf"
1046
- $term_ids = wp_get_object_terms( $post_id, self::MENU_TAX, array( 'fields' => 'ids' ) );
1047
-
1048
- foreach ( $term_ids as $term_id ) {
1049
- $children = get_term_children( $term_id, self::MENU_TAX );
1050
- if ( ! $children ) {
1051
- break;
1052
- }
1053
- }
1054
-
1055
- if ( ! isset( $term_id ) ) {
1056
- return false;
1057
- }
1058
-
1059
- return get_term( $term_id, self::MENU_TAX );
1060
-
1061
- }
1062
-
1063
- function list_labels( $post_id = 0 ) {
1064
- $post = get_post( $post_id );
1065
- echo get_the_term_list( $post->ID, self::MENU_ITEM_LABEL_TAX, '', _x( ', ', 'Nova label separator', 'essential-content-types' ), '' );
1066
- }
1067
-
1068
- function list_admin_labels( $post_id = 0 ) {
1069
- $post = get_post( $post_id );
1070
- $labels = get_the_terms( $post->ID, self::MENU_ITEM_LABEL_TAX );
1071
- if ( !empty( $labels ) ) {
1072
- $out = array();
1073
- foreach ( $labels as $label ) {
1074
- $out[] = sprintf( '<a href="%s">%s</a>',
1075
- esc_url( add_query_arg( array(
1076
- 'post_type' => self::MENU_ITEM_POST_TYPE,
1077
- 'taxonomy' => self::MENU_ITEM_LABEL_TAX,
1078
- 'term' => $label->slug
1079
- ), 'edit.php' ) ),
1080
- esc_html( sanitize_term_field( 'name', $label->name, $label->term_id, self::MENU_ITEM_LABEL_TAX, 'display' ) )
1081
- );
1082
- }
1083
-
1084
- echo join( _x( ', ', 'Nova label separator', 'essential-content-types' ), $out );
1085
- } else {
1086
- esc_html_e( 'No Labels', 'essential-content-types' );
1087
- }
1088
- }
1089
-
1090
- function set_price( $post_id = 0, $price = '' ) {
1091
- $post = get_post( $post_id );
1092
-
1093
- return update_post_meta( $post->ID, 'ect_food_price', $price );
1094
- }
1095
-
1096
- function get_price( $post_id = 0 ) {
1097
- $post = get_post( $post_id );
1098
-
1099
- return get_post_meta( $post->ID, 'ect_food_price', true );
1100
- }
1101
-
1102
- function display_price( $post_id = 0 ) {
1103
- echo esc_html( $this->get_price( $post_id ) );
1104
- }
1105
-
1106
- /* Menu Item Loop Markup */
1107
-
1108
- /* Does not support nested loops */
1109
-
1110
- function get_menu_item_loop_markup( $field = null ) {
1111
- return $this->menu_item_loop_markup;
1112
- }
1113
-
1114
- /**
1115
- * Sets up the loop markup.
1116
- * Attached to the 'template_include' *filter*,
1117
- * which fires only during a real blog view (not in admin, feeds, etc.)
1118
- *
1119
- * @param string Template File
1120
- * @return string Template File. VERY Important.
1121
- */
1122
- function setup_menu_item_loop_markup__in_filter( $template ) {
1123
- add_action( 'loop_start', array( $this, 'start_menu_item_loop' ) );
1124
-
1125
- return $template;
1126
- }
1127
-
1128
- /**
1129
- * If the Query is a Menu Item Query, start outputing the Menu Item Loop Marku
1130
- * Attached to the 'loop_start' action.
1131
- *
1132
- * @param WP_Query
1133
- */
1134
- function start_menu_item_loop( $query ) {
1135
- if ( !$this->is_menu_item_query( $query ) ) {
1136
- return;
1137
- }
1138
-
1139
- $this->menu_item_loop_last_term_id = false;
1140
- $this->menu_item_loop_current_term = false;
1141
-
1142
- add_action( 'the_post', array( $this, 'menu_item_loop_each_post' ) );
1143
- add_action( 'loop_end', array( $this, 'stop_menu_item_loop' ) );
1144
- }
1145
-
1146
- /**
1147
- * Outputs the Menu Item Loop Marku
1148
- * Attached to the 'the_post' action.
1149
- *
1150
- * @param WP_Post
1151
- */
1152
- function menu_item_loop_each_post( $post ) {
1153
- $this->menu_item_loop_current_term = $this->get_menu_item_menu_leaf( $post->ID );
1154
-
1155
- if ( false === $this->menu_item_loop_last_term_id ) {
1156
- // We're at the very beginning of the loop
1157
-
1158
- $this->menu_item_loop_open_element( 'menu' ); // Start a new menu section
1159
- $this->menu_item_loop_header(); // Output the menu's header
1160
- } elseif ( $this->menu_item_loop_last_term_id != $this->menu_item_loop_current_term->term_id ) {
1161
- // We're not at the very beginning but still need to start a new menu section. End the previous menu section first.
1162
-
1163
- $this->menu_item_loop_close_element( 'menu' ); // End the previous menu section
1164
- $this->menu_item_loop_open_element( 'menu' ); // Start a new menu section
1165
- $this->menu_item_loop_header(); // Output the menu's header
1166
- }
1167
-
1168
- $this->menu_item_loop_last_term_id = isset( $this->menu_item_loop_current_term->term_id ) ? $this->menu_item_loop_current_term->term_id : '' ;
1169
- }
1170
-
1171
- /**
1172
- * If the Query is a Menu Item Query, stop outputing the Menu Item Loop Marku
1173
- * Attached to the 'loop_end' action.
1174
- *
1175
- * @param WP_Query
1176
- */
1177
- function stop_menu_item_loop( $query ) {
1178
- if ( !$this->is_menu_item_query( $query ) ) {
1179
- return;
1180
- }
1181
-
1182
- remove_action( 'the_post', array( $this, 'menu_item_loop_each_post' ) );
1183
- remove_action( 'loop_start', array( $this, 'start_menu_item_loop' ) );
1184
- remove_action( 'loop_end', array( $this, 'stop_menu_item_loop' ) );
1185
-
1186
- $this->menu_item_loop_close_element( 'menu' ); // End the last menu section
1187
- }
1188
-
1189
- /**
1190
- * Outputs the Menu Group Header
1191
- */
1192
- function menu_item_loop_header() {
1193
- $this->menu_item_loop_open_element( 'menu_header' );
1194
- $this->menu_item_loop_open_element( 'menu_title' );
1195
- echo isset( $this->menu_item_loop_current_term->name ) ? esc_html( $this->menu_item_loop_current_term->name ) : ''; // @todo tax filter
1196
- $this->menu_item_loop_close_element( 'menu_title' );
1197
- if ( isset( $this->menu_item_loop_current_term->description ) && $this->menu_item_loop_current_term->description ) :
1198
- $this->menu_item_loop_open_element( 'menu_description' );
1199
- echo esc_html( $this->menu_item_loop_current_term->description ); // @todo kses, tax filter
1200
- $this->menu_item_loop_close_element( 'menu_description' );
1201
- endif;
1202
- $this->menu_item_loop_close_element( 'menu_header' );
1203
- }
1204
-
1205
- /**
1206
- * Outputs a Menu Item Markup element opening tag
1207
- *
1208
- * @param string $field - Menu Item Markup settings field.
1209
- */
1210
- function menu_item_loop_open_element( $field ) {
1211
- $markup = $this->get_menu_item_loop_markup();
1212
- /**
1213
- * Filter a menu item's element opening tag.
1214
- *
1215
- * @module custom-content-types
1216
- *
1217
- * @since 4.4.0
1218
- *
1219
- * @param string $tag Menu item's element opening tag.
1220
- * @param string $field Menu Item Markup settings field.
1221
- * @param array $markup Array of markup elements for the menu item.
1222
- * @param false|object $term Taxonomy term for current menu item.
1223
- */
1224
- echo apply_filters(
1225
- 'essential-content-types_ect_food_menu_item_loop_open_element',
1226
- '<' . tag_escape( $markup["{$field}_tag"] ) . $this->menu_item_loop_class( $markup["{$field}_class"] ) . ">\n",
1227
- $field,
1228
- $markup,
1229
- $this->menu_item_loop_current_term
1230
- );
1231
- }
1232
-
1233
- /**
1234
- * Outputs a Menu Item Markup element closing tag
1235
- *
1236
- * @param string $field - Menu Item Markup settings field
1237
- */
1238
- function menu_item_loop_close_element( $field ) {
1239
- $markup = $this->get_menu_item_loop_markup();
1240
- /**
1241
- * Filter a menu item's element closing tag.
1242
- *
1243
- * @module custom-content-types
1244
- *
1245
- * @since 4.4.0
1246
- *
1247
- * @param string $tag Menu item's element closing tag.
1248
- * @param string $field Menu Item Markup settings field.
1249
- * @param array $markup Array of markup elements for the menu item.
1250
- * @param false|object $term Taxonomy term for current menu item.
1251
- */
1252
- echo apply_filters(
1253
- 'essential-content-types_ect_food_menu_item_loop_close_element',
1254
- '</' . tag_escape( $markup["{$field}_tag"] ) . ">\n",
1255
- $field,
1256
- $markup,
1257
- $this->menu_item_loop_current_term
1258
- );
1259
- }
1260
-
1261
- /**
1262
- * Returns a Menu Item Markup element's class attribute.
1263
- *
1264
- * @param string $class Class name.
1265
- * @return string HTML class attribute with leading whitespace.
1266
- */
1267
- function menu_item_loop_class( $class ) {
1268
- if ( ! $class ) {
1269
- return '';
1270
- }
1271
-
1272
- /**
1273
- * Filter a menu Item Markup element's class attribute.
1274
- *
1275
- * @module custom-content-types
1276
- *
1277
- * @since 4.4.0
1278
- *
1279
- * @param string $tag Menu Item Markup element's class attribute.
1280
- * @param string $class Menu Item Class name.
1281
- * @param false|object $term Taxonomy term for current menu item.
1282
- */
1283
- return apply_filters(
1284
- 'essential-content-types_ect_food_menu_item_loop_class',
1285
- ' class="' . esc_attr( $class ) . '"',
1286
- $class,
1287
- $this->menu_item_loop_current_term
1288
- );
1289
- }
1290
-
1291
- /**
1292
- * Our [food_menu] shortcode.
1293
- * Prints Food Menu data styled to look good on *any* theme.
1294
- *
1295
- * @return ect_food_shortcode_html
1296
- */
1297
- static function ect_food_shortcode( $atts ) {
1298
- // Default attributes
1299
- $atts = shortcode_atts( array(
1300
- 'include_type' => false,
1301
- 'include_tag' => false,
1302
- 'showposts' => -1,
1303
- ), $atts, 'food_menu' );
1304
-
1305
- // A little sanitization
1306
- if ( $atts['include_type'] ) {
1307
- $atts['include_type'] = explode( ',', str_replace( ' ', '', $atts['include_type'] ) );
1308
- }
1309
-
1310
- if ( $atts['include_tag'] ) {
1311
- $atts['include_tag'] = explode( ',', str_replace( ' ', '', $atts['include_tag'] ) );
1312
- }
1313
-
1314
- $atts['showposts'] = intval( $atts['showposts'] );
1315
-
1316
- // enqueue shortcode styles when shortcode is used
1317
- wp_enqueue_style( 'ect-food-menu-style', plugins_url( 'css/food-menu-shortcode.css', __FILE__ ), array(), '20140326' );
1318
- wp_enqueue_script( 'ect-food-menu-script', plugins_url( 'js/food-menu-shortcode.js', __FILE__ ) , array( 'jquery' ), '20180530', false );
1319
-
1320
- return self::ect_food_shortcode_html( $atts );
1321
- }
1322
-
1323
- /**
1324
- * Query to retrieve entries from the Food Menu post_type.
1325
- *
1326
- * @return object
1327
- */
1328
- static function ect_food_query( $atts ) {
1329
- // Default query arguments
1330
- $default = array(
1331
- 'posts_per_page' => $atts['showposts'],
1332
- );
1333
-
1334
- $args = wp_parse_args( $atts, $default );
1335
- $args['post_type'] = self::MENU_ITEM_POST_TYPE; // Force this post type
1336
-
1337
- if ( false != $atts['include_type'] || false != $atts['include_tag'] ) {
1338
- $args['tax_query'] = array();
1339
- }
1340
-
1341
- // If 'include_type' has been set use it on the main query
1342
- if ( false != $atts['include_type'] ) {
1343
- array_push( $args['tax_query'], array(
1344
- 'taxonomy' => self::MENU_TAX,
1345
- 'field' => 'slug',
1346
- 'terms' => $atts['include_type'],
1347
- ) );
1348
- }
1349
-
1350
- // If 'include_tag' has been set use it on the main query
1351
- if ( false != $atts['include_tag'] ) {
1352
- array_push( $args['tax_query'], array(
1353
- 'taxonomy' => self::MENU_ITEM_LABEL_TAX,
1354
- 'field' => 'slug',
1355
- 'terms' => $atts['include_tag'],
1356
- ) );
1357
- }
1358
-
1359
- if ( false != $atts['include_type'] && false != $atts['include_tag'] ) {
1360
- $args['tax_query']['relation'] = 'AND';
1361
- }
1362
-
1363
- // Run the query and return
1364
- $query = new WP_Query( $args );
1365
- return $query;
1366
- }
1367
-
1368
- /**
1369
- * The Food Menu shortcode loop.
1370
- *
1371
- * @return html
1372
- */
1373
- static function ect_food_shortcode_html( $atts ) {
1374
-
1375
- $query = self::ect_food_query( $atts );
1376
- ob_start();
1377
-
1378
- // If we have posts, create the html
1379
- // with hect_food markup
1380
- if ( $query->have_posts() ) {
1381
-
1382
- /**
1383
- * Hook: ect_before_food_menu_loop.
1384
- *
1385
- * @hooked ect_food_menu_section
1386
- */
1387
- $layout = ect_get_layout();
1388
- do_action( 'ect_before_food_menu_loop' );
1389
- ?>
1390
- <?php
1391
-
1392
- ect_get_template_part( 'ect', 'menu', $atts );
1393
-
1394
- // If comments are open or we have at least one comment, load up the comment template
1395
- if ( comments_open() || '0' != get_comments_number() ) {
1396
- comments_template( '', true );
1397
- }
1398
- ?>
1399
- <?php
1400
-
1401
- /**
1402
- * Hook: ect_after_food_menu_loop.
1403
- *
1404
- * @hooked
1405
- */
1406
- do_action( 'ect_after_food_menu_loop' );
1407
-
1408
- } else {
1409
- /**
1410
- * Hook: ect_no_food_menu_found.
1411
- *
1412
- * @hooked ect_no_food_menu_found
1413
- */
1414
- do_action( 'ect_no_food_menu_found' );
1415
- }
1416
-
1417
- $html = ob_get_clean();
1418
-
1419
- // If there is a [food-menu] within a [food-menu], remove the shortcode
1420
- if ( has_shortcode( $html, 'food-menu' ) ){
1421
- remove_shortcode( 'food-menu' );
1422
- }
1423
-
1424
- // Return the HTML block
1425
- return $html;
1426
- }
1427
- }
1428
-
1429
- add_action( 'init', array( 'Essential_Content_Food_Menu', 'init' ) );
1430
-
1431
-
1432
- /**
1433
- * Add Food Menu support
1434
- */
1435
- function essential_content_food_menu_support() {
1436
- /*
1437
- * Adding theme support for Food Menu Item CPT.
1438
- */
1439
- add_theme_support( 'ect_food_menu_item' );
1440
- }
1441
- add_action( 'after_setup_theme', 'essential_content_food_menu_support' );
1442
-
1443
-
1444
- if( ! function_exists( 'essential_content_no_food_menu_found' ) ):
1445
- /**
1446
- * No items found text
1447
- *
1448
- * @return html
1449
- */
1450
- function essential_content_no_food_menu_found() {
1451
- echo "<p><em>" . esc_html__( 'Your Food Menu Archive currently has no entries. You can start creating them on your dashboard.', 'essential-content-types-pro' ) . "</em></p>";
1452
- }
1453
- endif;
1454
- add_action( 'ect_no_food_menu_found', 'essential_content_no_food_menu_found', 10 );
1455
-
1456
-
1457
- if( ! function_exists( 'essential_content_food_menu_section_open' ) ):
1458
- /**
1459
- * Open section
1460
- *
1461
- * @return html
1462
- */
1463
- function essential_content_food_menu_section_open() {
1464
- echo '<div class="ect-menu ect-section">';
1465
- echo '<div class="ect-wrapper">';
1466
- }
1467
- endif;
1468
- add_action( 'ect_before_food_menu_loop', 'essential_content_food_menu_section_open', 10, 1 );
1469
-
1470
-
1471
- if( ! function_exists( 'essential_content_food_menu_loop_start' ) ):
1472
- /**
1473
- * open wrapper before loop
1474
- *
1475
- */
1476
- function essential_content_food_menu_loop_start(){
1477
- echo '<div class="section-content-wrapper menu-content-wrapper">';
1478
- }
1479
- endif;
1480
- add_action( 'ect_before_food_menu_loop', 'essential_content_food_menu_loop_start', 30 );
1481
-
1482
-
1483
- if( ! function_exists( 'essential_content_food_menu_loop_end' ) ):
1484
- /**
1485
- * close wrapper after loop
1486
- *
1487
- */
1488
- function essential_content_food_menu_loop_end(){
1489
- echo '</div><!-- .menu-content-wrapper -->';
1490
- }
1491
- endif;
1492
- add_action( 'ect_after_food_menu_loop', 'essential_content_food_menu_loop_end', 10 );
1493
-
1494
-
1495
- if( ! function_exists( 'essential_content_food_menu_section_close' ) ):
1496
- /**
1497
- * Close section
1498
- *
1499
- * @return html
1500
- */
1501
- function essential_content_food_menu_section_close() {
1502
- echo '</div><!-- .ect-wrapper -->';
1503
- echo '</div><!-- .ect-section -->';
1504
- }
1505
- endif;
1506
- add_action( 'ect_after_food_menu_loop', 'essential_content_food_menu_section_close', 20 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ * Put the following code in your theme's Food Menu Page Template to customize the markup of the menu.
4
+
5
+ if ( class_exists( 'Essential_Content_Food_Menu' ) ) {
6
+ Essential_Content_Food_Menu::init( array(
7
+ 'menu_tag' => 'section',
8
+ 'menu_class' => 'menu-items',
9
+ 'menu_header_tag' => 'header',
10
+ 'menu_header_class' => 'menu-group-header',
11
+ 'menu_title_tag' => 'h1',
12
+ 'menu_title_class' => 'menu-group-title',
13
+ 'menu_description_tag' => 'div',
14
+ 'menu_description_class' => 'menu-group-description',
15
+ ) );
16
+ }
17
+
18
+ */
19
+
20
+ /* @todo
21
+
22
+ Bulk/Quick edit response of Menu Item rows is broken.
23
+
24
+ Drag and Drop reordering.
25
+ */
26
+
27
+ class Essential_Content_Food_Menu {
28
+ const MENU_ITEM_POST_TYPE = 'ect_food_menu_item';
29
+ const MENU_ITEM_LABEL_TAX = 'ect_food_menu_item_label';
30
+ const MENU_TAX = 'ect_food_menu';
31
+
32
+ public $version = ESSENTIAL_CONTENT_TYPES_VERSION;
33
+
34
+ protected $default_menu_item_loop_markup = array(
35
+ 'menu_tag' => 'section',
36
+ 'menu_class' => 'menu-items',
37
+ 'menu_header_tag' => 'header',
38
+ 'menu_header_class' => 'menu-group-header',
39
+ 'menu_title_tag' => 'h1',
40
+ 'menu_title_class' => 'menu-group-title',
41
+ 'menu_description_tag' => 'div',
42
+ 'menu_description_class' => 'menu-group-description',
43
+ );
44
+
45
+ protected $menu_item_loop_markup = array();
46
+ protected $menu_item_loop_last_term_id = false;
47
+ protected $menu_item_loop_current_term = false;
48
+
49
+ static function init( $menu_item_loop_markup = array() ) {
50
+ static $instance = false;
51
+
52
+ if ( !$instance ) {
53
+ $instance = new Essential_Content_Food_Menu;
54
+ }
55
+
56
+ if ( $menu_item_loop_markup ) {
57
+ $instance->menu_item_loop_markup = wp_parse_args( $menu_item_loop_markup, $instance->default_menu_item_loop_markup );
58
+ }
59
+
60
+ return $instance;
61
+ }
62
+
63
+ function __construct() {
64
+ if ( ! $this->site_supports_food_menu() )
65
+ return;
66
+
67
+ $this->register_taxonomies();
68
+ $this->register_post_types();
69
+ add_action( 'admin_menu', array( $this, 'add_admin_menus' ) );
70
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_ect_food_styles' ) );
71
+ add_action( 'admin_head', array( $this, 'set_custom_font_icon' ) );
72
+
73
+ // Enable Omnisearch for Menu Items.
74
+ if ( class_exists( 'Jetpack_Omnisearch_Posts' ) )
75
+ new Jetpack_Omnisearch_Posts( self::MENU_ITEM_POST_TYPE );
76
+
77
+ // Always sort menu items correctly
78
+ add_action( 'parse_query', array( $this, 'sort_menu_item_queries_by_menu_order' ) );
79
+ add_filter( 'posts_results', array( $this, 'sort_menu_item_queries_by_menu_taxonomy' ), 10, 2 );
80
+
81
+ add_action( 'wp_insert_post', array( $this, 'add_post_meta' ) );
82
+
83
+ $this->menu_item_loop_markup = $this->default_menu_item_loop_markup;
84
+
85
+ // Only output our Menu Item Loop Markup on a real blog view. Not feeds, XML-RPC, admin, etc.
86
+ add_filter( 'template_include', array( $this, 'setup_menu_item_loop_markup__in_filter' ) );
87
+
88
+ add_filter( 'enter_title_here', array( $this, 'change_default_title' ) );
89
+ add_filter( 'post_updated_messages', array( $this, 'updated_messages' ) );
90
+ add_filter( 'dashboard_glance_items', array( $this, 'add_to_dashboard' ) );
91
+
92
+ add_filter( 'body_class', array( $this, 'custom_class' ) );
93
+
94
+ // register food_menu shortcode (legacy)
95
+ add_shortcode( 'food_menu', array( $this, 'ect_food_shortcode' ) );
96
+ }
97
+
98
+ public function custom_class( $classes ) {
99
+ global $post;
100
+ if( isset( $post->post_content ) && has_shortcode( $post->post_content, 'food_menu' ) ) {
101
+ $classes[] = 'page-template-menu-page';
102
+ }
103
+ return $classes;
104
+ }
105
+
106
+ /**
107
+ * Should this Custom Post Type be made available?
108
+ */
109
+ function site_supports_food_menu() {
110
+ // If we're on WordPress.com, and it has the menu site vertical.
111
+ if ( function_exists( 'site_vertical' ) && 'ect_food_menu' == site_vertical() )
112
+ return true;
113
+
114
+ // Else, if the current theme requests it.
115
+ if ( current_theme_supports( self::MENU_ITEM_POST_TYPE ) )
116
+ return true;
117
+ }
118
+
119
+ /* Setup */
120
+
121
+ /**
122
+ * Register Taxonomies and Post Type
123
+ */
124
+ function register_taxonomies() {
125
+ if ( ! taxonomy_exists( self::MENU_ITEM_LABEL_TAX ) ) {
126
+ register_taxonomy( self::MENU_ITEM_LABEL_TAX, self::MENU_ITEM_POST_TYPE, array(
127
+ 'labels' => array(
128
+ /* translators: this is about a food menu */
129
+ 'name' => __( 'Menu Item Labels', 'essential-content-types' ),
130
+ /* translators: this is about a food menu */
131
+ 'singular_name' => __( 'Menu Item Label', 'essential-content-types' ),
132
+ /* translators: this is about a food menu */
133
+ 'search_items' => __( 'Search Menu Item Labels', 'essential-content-types' ),
134
+ 'popular_items' => __( 'Popular Labels', 'essential-content-types' ),
135
+ /* translators: this is about a food menu */
136
+ 'all_items' => __( 'All Menu Item Labels', 'essential-content-types' ),
137
+ /* translators: this is about a food menu */
138
+ 'edit_item' => __( 'Edit Menu Item Label', 'essential-content-types' ),
139
+ /* translators: this is about a food menu */
140
+ 'view_item' => __( 'View Menu Item Label', 'essential-content-types' ),
141
+ /* translators: this is about a food menu */
142
+ 'update_item' => __( 'Update Menu Item Label', 'essential-content-types' ),
143
+ /* translators: this is about a food menu */
144
+ 'add_new_item' => __( 'Add New Menu Item Label', 'essential-content-types' ),
145
+ /* translators: this is about a food menu */
146
+ 'new_item_name' => __( 'New Menu Item Label Name', 'essential-content-types' ),
147
+ 'separate_items_with_commas' => __( 'For example, spicy, favorite, etc. <br /> Separate Labels with commas', 'essential-content-types' ),
148
+ 'add_or_remove_items' => __( 'Add or remove Labels', 'essential-content-types' ),
149
+ 'choose_from_most_used' => __( 'Choose from the most used Labels', 'essential-content-types' ),
150
+ 'items_list_navigation' => __( 'Menu item label list navigation', 'essential-content-types' ),
151
+ 'items_list' => __( 'Menu item labels list', 'essential-content-types' ),
152
+ ),
153
+ 'no_tagcloud' => __( 'No Labels found', 'essential-content-types' ),
154
+ 'hierarchical' => false,
155
+ ) );
156
+ }
157
+
158
+ if ( ! taxonomy_exists( self::MENU_TAX ) ) {
159
+ register_taxonomy( self::MENU_TAX, self::MENU_ITEM_POST_TYPE, array(
160
+ 'labels' => array(
161
+ /* translators: this is about a food menu */
162
+ 'name' => __( 'Menu Sections', 'essential-content-types' ),
163
+ /* translators: this is about a food menu */
164
+ 'singular_name' => __( 'Menu Section', 'essential-content-types' ),
165
+ /* translators: this is about a food menu */
166
+ 'search_items' => __( 'Search Menu Sections', 'essential-content-types' ),
167
+ /* translators: this is about a food menu */
168
+ 'all_items' => __( 'All Menu Sections', 'essential-content-types' ),
169
+ /* translators: this is about a food menu */
170
+ 'parent_item' => __( 'Parent Menu Section', 'essential-content-types' ),
171
+ /* translators: this is about a food menu */
172
+ 'parent_item_colon' => __( 'Parent Menu Section:', 'essential-content-types' ),
173
+ /* translators: this is about a food menu */
174
+ 'edit_item' => __( 'Edit Menu Section', 'essential-content-types' ),
175
+ /* translators: this is about a food menu */
176
+ 'view_item' => __( 'View Menu Section', 'essential-content-types' ),
177
+ /* translators: this is about a food menu */
178
+ 'update_item' => __( 'Update Menu Section', 'essential-content-types' ),
179
+ /* translators: this is about a food menu */
180
+ 'add_new_item' => __( 'Add New Menu Section', 'essential-content-types' ),
181
+ /* translators: this is about a food menu */
182
+ 'new_item_name' => __( 'New Menu Sections Name', 'essential-content-types' ),
183
+ 'items_list_navigation' => __( 'Menu section list navigation', 'essential-content-types' ),
184
+ 'items_list' => __( 'Menu section list', 'essential-content-types' ),
185
+ ),
186
+ 'rewrite' => array(
187
+ 'slug' => 'menu',
188
+ 'with_front' => false,
189
+ 'hierarchical' => true,
190
+ ),
191
+ 'hierarchical' => true,
192
+ 'show_tagcloud' => false,
193
+ 'query_var' => 'menu',
194
+ ) );
195
+ }
196
+ }
197
+
198
+ function register_post_types() {
199
+ if ( post_type_exists( self::MENU_ITEM_POST_TYPE ) ) {
200
+ return;
201
+ }
202
+
203
+ register_post_type( self::MENU_ITEM_POST_TYPE, array(
204
+ 'description' => __( "Items on your restaurant's menu", 'essential-content-types' ),
205
+
206
+ 'labels' => array(
207
+ /* translators: this is about a food menu */
208
+ 'name' => __( 'Menu Items', 'essential-content-types' ),
209
+ /* translators: this is about a food menu */
210
+ 'singular_name' => __( 'Menu Item', 'essential-content-types' ),
211
+ /* translators: this is about a food menu */
212
+ 'menu_name' => __( 'Food Menus', 'essential-content-types' ),
213
+ /* translators: this is about a food menu */
214
+ 'all_items' => __( 'Menu Items', 'essential-content-types' ),
215
+ /* translators: this is about a food menu */
216
+ 'add_new' => __( 'Add One Item', 'essential-content-types' ),
217
+ /* translators: this is about a food menu */
218
+ 'add_new_item' => __( 'Add Menu Item', 'essential-content-types' ),
219
+ /* translators: this is about a food menu */
220
+ 'edit_item' => __( 'Edit Menu Item', 'essential-content-types' ),
221
+ /* translators: this is about a food menu */
222
+ 'new_item' => __( 'New Menu Item', 'essential-content-types' ),
223
+ /* translators: this is about a food menu */
224
+ 'view_item' => __( 'View Menu Item', 'essential-content-types' ),
225
+ /* translators: this is about a food menu */
226
+ 'search_items' => __( 'Search Menu Items', 'essential-content-types' ),
227
+ /* translators: this is about a food menu */
228
+ 'not_found' => __( 'No Menu Items found', 'essential-content-types' ),
229
+ /* translators: this is about a food menu */
230
+ 'not_found_in_trash' => __( 'No Menu Items found in Trash', 'essential-content-types' ),
231
+ 'filter_items_list' => __( 'Filter menu items list', 'essential-content-types' ),
232
+ 'items_list_navigation' => __( 'Menu item list navigation', 'essential-content-types' ),
233
+ 'items_list' => __( 'Menu items list', 'essential-content-types' ),
234
+ ),
235
+ 'supports' => array(
236
+ 'title',
237
+ 'editor',
238
+ 'excerpt',
239
+ ),
240
+ 'rewrite' => array(
241
+ 'slug' => 'item',
242
+ 'with_front' => false,
243
+ 'feeds' => false,
244
+ 'pages' => false,
245
+ ),
246
+ 'register_meta_box_cb' => array( $this, 'register_menu_item_meta_boxes' ),
247
+
248
+ 'public' => true,
249
+ 'show_ui' => true, // set to false to replace with custom UI
250
+ 'menu_position' => 20, // below Pages
251
+ 'capability_type' => 'page',
252
+ 'map_meta_cap' => true,
253
+ 'has_archive' => false,
254
+ 'query_var' => 'item',
255
+ ) );
256
+ }
257
+
258
+
259
+ /**
260
+ * Update messages for the Menu Item admin.
261
+ */
262
+ function updated_messages( $messages ) {
263
+ global $post;
264
+
265
+ $messages[self::MENU_ITEM_POST_TYPE] = array(
266
+ 0 => '', // Unused. Messages start at index 1.
267
+ /* translators: this is about a food menu */
268
+ 1 => sprintf( __( 'Menu item updated. <a href="%s">View item</a>', 'essential-content-types' ), esc_url( get_permalink( $post->ID ) ) ),
269
+ 2 => esc_html__( 'Custom field updated.', 'essential-content-types' ),
270
+ 3 => esc_html__( 'Custom field deleted.', 'essential-content-types' ),
271
+ /* translators: this is about a food menu */
272
+ 4 => esc_html__( 'Menu item updated.', 'essential-content-types' ),
273
+ /* translators: %s: date and time of the revision */
274
+ 5 => isset( $_GET['revision'] ) ? sprintf( esc_html__( 'Menu item restored to revision from %s', 'essential-content-types' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
275
+ /* translators: this is about a food menu */
276
+ 6 => sprintf( __( 'Menu item published. <a href="%s">View item</a>', 'essential-content-types' ), esc_url( get_permalink( $post->ID ) ) ),
277
+ /* translators: this is about a food menu */
278
+ 7 => esc_html__( 'Menu item saved.', 'essential-content-types' ),
279
+ /* translators: this is about a food menu */
280
+ 8 => sprintf( __( 'Menu item submitted. <a target="_blank" href="%s">Preview item</a>', 'essential-content-types' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) ),
281
+ /* translators: this is about a food menu */
282
+ 9 => sprintf( __( 'Menu item scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview item</a>', 'essential-content-types' ),
283
+ // translators: Publish box date format, see http://php.net/date
284
+ date_i18n( __( 'M j, Y @ G:i', 'essential-content-types' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post->ID) ) ),
285
+ /* translators: this is about a food menu */
286
+ 10 => sprintf( __( 'Menu item draft updated. <a target="_blank" href="%s">Preview item</a>', 'essential-content-types' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post->ID ) ) ) ),
287
+ );
288
+
289
+ return $messages;
290
+ }
291
+
292
+
293
+ /**
294
+ * Nova Styles and Scripts
295
+ */
296
+ function enqueue_ect_food_styles( $hook ) {
297
+ global $post_type;
298
+ $pages = array( 'edit.php', 'post.php', 'post-new.php' );
299
+
300
+ if ( in_array( $hook, $pages ) && $post_type == self::MENU_ITEM_POST_TYPE ) {
301
+ wp_enqueue_style( 'ect-food-menu-style', plugins_url( 'css/ect-food-menu.css', __FILE__ ), array(), $this->version );
302
+ }
303
+
304
+ wp_enqueue_style( 'ect-food-menu-font', plugins_url( 'css/ect-food-menu-font.css', __FILE__ ), array(), $this->version );
305
+ }
306
+
307
+
308
+ /**
309
+ * Change ‘Enter Title Here’ text for the Menu Item.
310
+ */
311
+ function change_default_title( $title ) {
312
+ $screen = get_current_screen();
313
+
314
+ if ( self::MENU_ITEM_POST_TYPE == $screen->post_type )
315
+ /* translators: this is about a food menu */
316
+ $title = esc_html__( "Enter the menu item's name here", 'essential-content-types' );
317
+
318
+ return $title;
319
+ }
320
+
321
+
322
+ /**
323
+ * Add to Dashboard At A Glance
324
+ */
325
+ function add_to_dashboard() {
326
+ $number_menu_items = wp_count_posts( self::MENU_ITEM_POST_TYPE );
327
+
328
+ if ( current_user_can( 'administrator' ) ) {
329
+ $number_menu_items_published = sprintf( '<a href="%1$s">%2$s</a>',
330
+ esc_url( get_admin_url( get_current_blog_id(), 'edit.php?post_type=' . self::MENU_ITEM_POST_TYPE ) ),
331
+ sprintf( _n( '%1$d Food Menu Item', '%1$d Food Menu Items', intval( $number_menu_items->publish ), 'essential-content-types' ), number_format_i18n( $number_menu_items->publish ) )
332
+ );
333
+ }
334
+ else {
335
+ $number_menu_items_published = sprintf( '<span>%1$s</span>',
336
+ sprintf( _n( '%1$d Food Menu Item', '%1$d Food Menu Items', intval( $number_menu_items->publish ), 'essential-content-types' ), number_format_i18n( $number_menu_items->publish ) )
337
+ );
338
+ }
339
+
340
+ echo '<li class="ect-food-menu-count">' . $number_menu_items_published . '</li>';
341
+ }
342
+
343
+
344
+ /**
345
+ * Query
346
+ */
347
+ function is_menu_item_query( $query ) {
348
+ if (
349
+ ( isset( $query->query_vars['taxonomy'] ) && self::MENU_TAX == $query->query_vars['taxonomy'] )
350
+ ||
351
+ ( isset( $query->query_vars['post_type'] ) && self::MENU_ITEM_POST_TYPE == $query->query_vars['post_type'] )
352
+ ) {
353
+ return true;
354
+ }
355
+
356
+ return false;
357
+ }
358
+
359
+ function sort_menu_item_queries_by_menu_order( $query ) {
360
+ if ( ! $this->is_menu_item_query( $query ) ) {
361
+ return;
362
+ }
363
+
364
+ $query->query_vars['orderby'] = 'menu_order';
365
+ $query->query_vars['order'] = 'ASC';
366
+
367
+ // For now, just turn off paging so we can sort by taxonmy later
368
+ // If we want paging in the future, we'll need to add the taxonomy sort here (or at least before the DB query is made)
369
+ $query->query_vars['posts_per_page'] = -1;
370
+ }
371
+
372
+ function sort_menu_item_queries_by_menu_taxonomy( $posts, $query ) {
373
+ if ( !$posts ) {
374
+ return $posts;
375
+ }
376
+
377
+ if ( !$this->is_menu_item_query( $query ) ) {
378
+ return $posts;
379
+ }
380
+
381
+ $grouped_by_term = array();
382
+
383
+ foreach ( $posts as $post ) {
384
+ $term = $this->get_menu_item_menu_leaf( $post->ID );
385
+ if ( !$term || is_wp_error( $term ) ) {
386
+ $term_id = 0;
387
+ } else {
388
+ $term_id = $term->term_id;
389
+ }
390
+
391
+ if ( !isset( $grouped_by_term["$term_id"] ) ) {
392
+ $grouped_by_term["$term_id"] = array();
393
+ }
394
+
395
+ $grouped_by_term["$term_id"][] = $post;
396
+ }
397
+
398
+ $term_order = get_option( 'ect_food_menu_order', array() );
399
+
400
+ $return = array();
401
+ foreach ( $term_order as $term_id ) {
402
+ if ( isset( $grouped_by_term["$term_id"] ) ) {
403
+ $return = array_merge( $return, $grouped_by_term["$term_id"] );
404
+ unset( $grouped_by_term["$term_id"] );
405
+ }
406
+ }
407
+
408
+ foreach ( $grouped_by_term as $term_id => $posts ) {
409
+ $return = array_merge( $return, $posts );
410
+ }
411
+
412
+ return $return;
413
+ }
414
+
415
+
416
+ /**
417
+ * Add Many Items
418
+ */
419
+ function add_admin_menus() {
420
+ $hook = add_submenu_page(
421
+ 'edit.php?post_type=' . self::MENU_ITEM_POST_TYPE,
422
+ __( 'Add Many Items', 'essential-content-types' ),
423
+ __( 'Add Many Items', 'essential-content-types' ),
424
+ 'edit_pages',
425
+ 'add_many_ect_food_items',
426
+ array( $this, 'add_many_new_items_page' )
427
+ );
428
+
429
+ add_action( "load-$hook", array( $this, 'add_many_new_items_page_load' ) );
430
+
431
+ add_action( 'current_screen', array( $this, 'current_screen_load' ) );
432
+
433
+ //Adjust 'Add Many Items' submenu position
434
+ if ( isset( $GLOBALS['submenu']['edit.php?post_type=' . self::MENU_ITEM_POST_TYPE] ) ) {
435
+ $submenu_item = array_pop( $GLOBALS['submenu']['edit.php?post_type=' . self::MENU_ITEM_POST_TYPE] );
436
+ $GLOBALS['submenu']['edit.php?post_type=' . self::MENU_ITEM_POST_TYPE][11] = $submenu_item;
437
+ ksort( $GLOBALS['submenu']['edit.php?post_type=' . self::MENU_ITEM_POST_TYPE] );
438
+ }
439
+
440
+
441
+ $this->setup_menu_item_columns();
442
+
443
+ wp_register_script(
444
+ 'ect-food-menu-checkboxes',
445
+ plugin_dir_url( __FILE__ ) . 'js/ect-food-menu-menu-checkboxes.js',
446
+ array( 'jquery' ),
447
+ $this->version,
448
+ false
449
+ );
450
+ }
451
+
452
+
453
+ /**
454
+ * Custom Nova Icon CSS
455
+ */
456
+ function set_custom_font_icon() {
457
+ ?>
458
+ <style type="text/css">
459
+ #menu-posts-ect_food_menu_item .wp-menu-image:before {
460
+ font-family: 'nova-font' !important;
461
+ content: '\e603' !important;
462
+ }
463
+ </style>
464
+ <?php
465
+ }
466
+
467
+ function current_screen_load() {
468
+ $screen = get_current_screen();
469
+ if ( 'edit-ect_food_menu_item' !== $screen->id ) {
470
+ return;
471
+ }
472
+
473
+ $this->edit_menu_items_page_load();
474
+ add_filter( 'admin_notices', array( $this, 'admin_notices' ) );
475
+ }
476
+
477
+ /* Edit Items List */
478
+
479
+ function admin_notices() {
480
+ if ( isset( $_GET['ect_food_reordered'] ) )
481
+ /* translators: this is about a food menu */
482
+ printf( '<div class="updated"><p>%s</p></div>', __( 'Menu Items re-ordered.', 'essential-content-types' ) );
483
+ }
484
+
485
+ function no_title_sorting( $columns ) {
486
+ if ( isset( $columns['title'] ) )
487
+ unset( $columns['title'] );
488
+ return $columns;
489
+ }
490
+
491
+ function setup_menu_item_columns() {
492
+ add_filter( sprintf( 'manage_edit-%s_sortable_columns', self::MENU_ITEM_POST_TYPE ), array( $this, 'no_title_sorting' ) );
493
+ add_filter( sprintf( 'manage_%s_posts_columns', self::MENU_ITEM_POST_TYPE ), array( $this, 'menu_item_columns' ) );
494
+
495
+ add_action( sprintf( 'manage_%s_posts_custom_column', self::MENU_ITEM_POST_TYPE ), array( $this, 'menu_item_column_callback' ), 10, 2 );
496
+ }
497
+
498
+ function menu_item_columns( $columns ) {
499
+ unset( $columns['date'], $columns['likes'] );
500
+
501
+ $columns['thumbnail'] = __( 'Thumbnail', 'essential-content-types' );
502
+ $columns['labels'] = __( 'Labels', 'essential-content-types' );
503
+ $columns['price'] = __( 'Price', 'essential-content-types' );
504
+ $columns['order'] = __( 'Order', 'essential-content-types' );
505
+
506
+ return $columns;
507
+ }
508
+
509
+ function menu_item_column_callback( $column, $post_id ) {
510
+ $screen = get_current_screen();
511
+
512
+ switch ( $column ) {
513
+ case 'thumbnail':
514
+ echo get_the_post_thumbnail( $post_id, array( 50, 50 ) );
515
+ break;
516
+ case 'labels' :
517
+ $this->list_admin_labels( $post_id );
518
+ break;
519
+ case 'price' :
520
+ $this->display_price( $post_id );
521
+ break;
522
+ case 'order' :
523
+ $url = admin_url( $screen->parent_file );
524
+
525
+ $up_url = add_query_arg( array(
526
+ 'action' => 'move-item-up',
527
+ 'post_id' => (int) $post_id,
528
+ ), wp_nonce_url( $url, 'ect_food_move_item_up_' . $post_id ) );
529
+
530
+ $down_url = add_query_arg( array(
531
+ 'action' => 'move-item-down',
532
+ 'post_id' => (int) $post_id,
533
+ ), wp_nonce_url( $url, 'ect_food_move_item_down_' . $post_id ) );
534
+ $menu_item = get_post($post_id);
535
+ $this->get_menu_by_post_id( $post_id );
536
+ if ( $term_id = $this->get_menu_by_post_id( $post_id ) ) {
537
+ $term_id = $term_id->term_id;
538
+ }
539
+ ?>
540
+ <input type="hidden" class="menu-order-value" name="ect_food_order[<?php echo (int) $post_id ?>]" value="<?php echo esc_attr( $menu_item->menu_order ) ?>" />
541
+ <input type="hidden" class='ect-food-menu-term' name="ect_food_menu_term[<?php echo (int) $post_id ?>]" value="<?php echo esc_attr( $term_id ); ?>">
542
+
543
+ <span class="hide-if-js">
544
+ &nbsp; &nbsp; &mdash; <a class="ect-food-move-item-up" data-post-id="<?php echo (int) $post_id; ?>" href="<?php echo esc_url( $up_url ); ?>">up</a>
545
+ <br />
546
+ &nbsp; &nbsp; &mdash; <a class="ect-food-move-item-down" data-post-id="<?php echo (int) $post_id; ?>" href="<?php echo esc_url( $down_url ); ?>">down</a>
547
+ </span>
548
+ <?php
549
+ break;
550
+ }
551
+ }
552
+
553
+ function get_menu_by_post_id( $post_id = null ) {
554
+ if ( ! $post_id )
555
+ return false;
556
+
557
+ $terms = get_the_terms( $post_id, self::MENU_TAX );
558
+
559
+ if ( ! is_array( $terms ) )
560
+ return false;
561
+
562
+ return array_pop( $terms );
563
+ }
564
+
565
+ /**
566
+ * Fires on a menu edit page. We might have drag-n-drop reordered
567
+ */
568
+ function maybe_reorder_menu_items() {
569
+ // make sure we clicked our button
570
+ if ( ! ( isset( $_REQUEST['menu_reorder_submit'] ) && $_REQUEST['menu_reorder_submit'] === __( 'Save New Order', 'essential-content-types' ) ) )
571
+ return;
572
+ ;
573
+
574
+ // make sure we have the nonce
575
+ if ( ! ( isset( $_REQUEST['drag-drop-reorder'] ) && wp_verify_nonce( $_REQUEST['drag-drop-reorder'], 'drag-drop-reorder' ) ) )
576
+ return;
577
+
578
+ $term_pairs = array_map( 'absint', $_REQUEST['ect_food_menu_term'] );
579
+ $order_pairs = array_map( 'absint', $_REQUEST['ect_food_order'] );
580
+
581
+ foreach( $order_pairs as $ID => $menu_order ) {
582
+ $ID = absint( $ID );
583
+ unset( $order_pairs[$ID] );
584
+ if ( $ID < 0 )
585
+ continue;
586
+
587
+ $post = get_post( $ID );
588
+ if ( ! $post )
589
+ continue;
590
+
591
+ // save a write if the order hasn't changed
592
+ if ( $menu_order != $post->menu_order )
593
+ wp_update_post( compact( 'ID', 'menu_order' ) );
594
+
595
+ // save a write if the term hasn't changed
596
+ if ( $term_pairs[$ID] != $this->get_menu_by_post_id( $ID )->term_id )
597
+ wp_set_object_terms( $ID, $term_pairs[$ID], self::MENU_TAX );
598
+
599
+ }
600
+
601
+ $redirect = add_query_arg( array(
602
+ 'post_type' => self::MENU_ITEM_POST_TYPE,
603
+ 'ect_food_reordered' => '1'
604
+ ), admin_url( 'edit.php' ) );
605
+ wp_safe_redirect( $redirect );
606
+ exit;
607
+
608
+ }
609
+
610
+ function edit_menu_items_page_load() {
611
+ if ( isset( $_GET['action'] ) ) {
612
+ $this->handle_menu_item_actions();
613
+ }
614
+
615
+ $this->maybe_reorder_menu_items();
616
+
617
+ wp_enqueue_script(
618
+ 'ect-food-drag-drop',
619
+ plugin_dir_url( __FILE__ ) . 'js/ect-food-menu-drag-drop.js',
620
+ array( 'jquery-ui-sortable' ),
621
+ $this->version,
622
+ true
623
+ );
624
+
625
+ wp_localize_script( 'ect-food-drag-drop', '_novaDragDrop', array(
626
+ 'nonce' => wp_create_nonce( 'drag-drop-reorder' ),
627
+ 'nonceName' => 'drag-drop-reorder',
628
+ 'reorder' => __( 'Save New Order', 'essential-content-types' ),
629
+ 'reorderName' => 'menu_reorder_submit'
630
+ ) );
631
+ add_action( 'the_post', array( $this, 'show_menu_titles_in_menu_item_list' ) );
632
+ }
633
+
634
+ function handle_menu_item_actions() {
635
+ $action = (string) $_GET['action'];
636
+
637
+ switch ( $action ) {
638
+ case 'move-item-up' :
639
+ case 'move-item-down' :
640
+ $reorder = false;
641
+
642
+ $post_id = (int) $_GET['post_id'];
643
+
644
+ $term = $this->get_menu_item_menu_leaf( $post_id );
645
+
646
+ // Get all posts in that term
647
+ $query = new WP_Query( array(
648
+ 'taxonomy' => self::MENU_TAX,
649
+ 'term' => $term->slug,
650
+ ) );
651
+
652
+ $order = array();
653
+ foreach ( $query->posts as $post ) {
654
+ $order[] = $post->ID;
655
+ }
656
+
657
+ if ( 'move-item-up' == $action ) {
658
+ check_admin_referer( 'ect_food_move_item_up_' . $post_id );
659
+
660
+ $first_post_id = $order[0];
661
+ if ( $post_id == $first_post_id ) {
662
+ break;
663
+ }
664
+
665
+ foreach ( $order as $menu_order => $order_post_id ) {
666
+ if ( $post_id != $order_post_id ) {
667
+ continue;
668
+ }
669
+
670
+ $swap_post_id = $order[$menu_order - 1];
671
+ $order[$menu_order - 1] = $post_id;
672
+ $order[$menu_order] = $swap_post_id;
673
+
674
+ $reorder = true;
675
+ break;
676
+ }
677
+ } else {
678
+ check_admin_referer( 'ect_food_move_item_down_' . $post_id );
679
+
680
+ $last_post_id = end( $order );
681
+ if ( $post_id == $last_post_id ) {
682
+ break;
683
+ }
684
+
685
+ foreach ( $order as $menu_order => $order_post_id ) {
686
+ if ( $post_id != $order_post_id ) {
687
+ continue;
688
+ }
689
+
690
+ $swap_post_id = $order[$menu_order + 1];
691
+ $order[$menu_order + 1] = $post_id;
692
+ $order[$menu_order] = $swap_post_id;
693
+
694
+ $reorder = true;
695
+ }
696
+ }
697
+
698
+ if ( $reorder ) {
699
+ foreach ( $order as $menu_order => $ID ) {
700
+ wp_update_post( compact( 'ID', 'menu_order' ) );
701
+ }
702
+ }
703
+
704
+ break;
705
+ case 'move-menu-up' :
706
+ case 'move-menu-down' :
707
+ $reorder = false;
708
+
709
+ $term_id = (int) $_GET['term_id'];
710
+
711
+ $terms = $this->get_menus();
712
+
713
+ $order = array();
714
+ foreach ( $terms as $term ) {
715
+ $order[] = $term->term_id;
716
+ }
717
+
718
+ if ( 'move-menu-up' == $action ) {
719
+ check_admin_referer( 'ect_food_move_menu_up_' . $term_id );
720
+
721
+ $first_term_id = $order[0];
722
+ if ( $term_id == $first_term_id ) {
723
+ break;
724
+ }
725
+
726
+ foreach ( $order as $menu_order => $order_term_id ) {
727
+ if ( $term_id != $order_term_id ) {
728
+ continue;
729
+ }
730
+
731
+ $swap_term_id = $order[$menu_order - 1];
732
+ $order[$menu_order - 1] = $term_id;
733
+ $order[$menu_order] = $swap_term_id;
734
+
735
+ $reorder = true;
736
+ break;
737
+ }
738
+ } else {
739
+ check_admin_referer( 'ect_food_move_menu_down_' . $term_id );
740
+
741
+ $last_term_id = end( $order );
742
+ if ( $term_id == $last_term_id ) {
743
+ break;
744
+ }
745
+
746
+ foreach ( $order as $menu_order => $order_term_id ) {
747
+ if ( $term_id != $order_term_id ) {
748
+ continue;
749
+ }
750
+
751
+ $swap_term_id = $order[$menu_order + 1];
752
+ $order[$menu_order + 1] = $term_id;
753
+ $order[$menu_order] = $swap_term_id;
754
+
755
+ $reorder = true;
756
+ }
757
+ }
758
+
759
+ if ( $reorder ) {
760
+ update_option( 'ect_food_menu_order', $order );
761
+ }
762
+
763
+ break;
764
+ default :
765
+ return;
766
+ }
767
+
768
+ $redirect = add_query_arg( array(
769
+ 'post_type' => self::MENU_ITEM_POST_TYPE,
770
+ 'ect_food_reordered' => '1'
771
+ ), admin_url( 'edit.php' ) );
772
+ wp_safe_redirect( $redirect );
773
+ exit;
774
+ }
775
+
776
+ /*
777
+ * Add menu title rows to the list table
778
+ */
779
+ function show_menu_titles_in_menu_item_list( $post ) {
780
+ global $wp_list_table;
781
+
782
+ static $last_term_id = false;
783
+
784
+ $term = $this->get_menu_item_menu_leaf( $post->ID );
785
+
786
+ $term_id = $term instanceof WP_Term ? $term->term_id : null;
787
+
788
+ if ( false !== $last_term_id && $last_term_id === $term_id ) {
789
+ return;
790
+ }
791
+
792
+ if ( is_null( $term_id ) ) {
793
+ $last_term_id = null;
794
+ $term_name = '';
795
+ $parent_count = 0;
796
+ } else {
797
+ $last_term_id = $term->term_id;
798
+ $term_name = $term->name;
799
+ $parent_count = 0;
800
+ $current_term = $term;
801
+ while ( $current_term->parent ) {
802
+ $parent_count++;
803
+ $current_term = get_term( $current_term->parent, self::MENU_TAX );
804
+ }
805
+ }
806
+
807
+ $non_order_column_count = $wp_list_table->get_column_count() - 1;
808
+
809
+ $screen = get_current_screen();
810
+
811
+ $url = admin_url( $screen->parent_file );
812
+
813
+ $up_url = add_query_arg( array(
814
+ 'action' => 'move-menu-up',
815
+ 'term_id' => (int) $term_id,
816
+ ), wp_nonce_url( $url, 'ect_food_move_menu_up_' . $term_id ) );
817
+
818
+ $down_url = add_query_arg( array(
819
+ 'action' => 'move-menu-down',
820
+ 'term_id' => (int) $term_id,
821
+ ), wp_nonce_url( $url, 'ect_food_move_menu_down_' . $term_id ) );
822
+
823
+ ?>
824
+ <tr class="no-items menu-label-row" data-term_id="<?php echo esc_attr( $term_id ) ?>">
825
+ <td class="colspanchange" colspan="<?php echo (int) $non_order_column_count; ?>">
826
+ <h3><?php
827
+ echo str_repeat( ' &mdash; ', (int) $parent_count );
828
+
829
+ if ( $term instanceof WP_Term ) {
830
+ echo esc_html( sanitize_term_field( 'name', $term_name, $term_id, self::MENU_TAX, 'display' ) );
831
+ edit_term_link( __( 'edit', 'essential-content-types' ), '<span class="edit-ect-food-section"><span class="dashicon dashicon-edit"></span>', '</span>', $term );
832
+
833
+ } else {
834
+ _e( 'Uncategorized' , 'essential-content-types' );
835
+ }
836
+ ?></h3>
837
+ </td>
838
+ <td>
839
+ <?php if ( $term instanceof WP_Term ) { ?>
840
+ <a class="ect-food-move-menu-up" title="<?php esc_attr_e( 'Move menu section up', 'essential-content-types' ); ?>" href="<?php echo esc_url( $up_url ); ?>"><?php esc_html_e( 'UP', 'essential-content-types' ); ?></a>
841
+ <br />
842
+ <a class="ect-food-move-menu-down" title="<?php esc_attr_e( 'Move menu section down', 'essential-content-types' ); ?>" href="<?php echo esc_url( $down_url ); ?>"><?php esc_html_e( 'DOWN', 'essential-content-types' ); ?></a>
843
+ <?php } ?>
844
+ </td>
845
+ </tr>
846
+ <?php
847
+ }
848
+
849
+ /* Edit Many Items */
850
+
851
+ function add_many_new_items_page_load() {
852
+ if ( 'POST' === strtoupper( $_SERVER['REQUEST_METHOD'] ) ) {
853
+ $this->process_form_request();
854
+ exit;
855
+ }
856
+
857
+ $this->enqueue_many_items_scripts();
858
+ }
859
+
860
+ function enqueue_many_items_scripts() {
861
+ wp_enqueue_script(
862
+ 'ect-food-many-items',
863
+ plugin_dir_url( __FILE__ ) . 'js/ect-food-menu-many-items.js',
864
+ array( 'jquery' ),
865
+ $this->version,
866
+ true
867
+ );
868
+ }
869
+
870
+ function process_form_request() {
871
+ if ( !isset( $_POST['ect_food_title'] ) || !is_array( $_POST['ect_food_title'] ) ) {
872
+ return;
873
+ }
874
+
875
+ $is_ajax = !empty( $_POST['ajax'] );
876
+
877
+ if ( $is_ajax ) {
878
+ check_ajax_referer( 'ect_food_many_items' );
879
+ } else {
880
+ check_admin_referer( 'ect_food_many_items' );
881
+ }
882
+
883
+ foreach ( array_keys( $_POST['ect_food_title'] ) as $key ) :
884
+ // $_POST is already slashed
885
+ $post_details = array(
886
+ 'post_status' => 'publish',
887
+ 'post_type' => self::MENU_ITEM_POST_TYPE,
888
+ 'post_content' => $_POST['ect_food_content'][$key],
889
+ 'post_title' => $_POST['ect_food_title'][$key],
890
+ 'tax_input' => array(
891
+ self::MENU_ITEM_LABEL_TAX => $_POST['ect_food_labels'][$key],
892
+ self::MENU_TAX => isset( $_POST['ect_food_menu_tax'] ) ? $_POST['ect_food_menu_tax'] : null,
893
+ ),
894
+ );
895
+
896
+ $post_id = wp_insert_post( $post_details );
897
+ if ( !$post_id || is_wp_error( $post_id ) ) {
898
+ continue;
899
+ }
900
+
901
+ $this->set_price( $post_id, isset( $_POST['ect_food_price'][$key] ) ? stripslashes( $_POST['ect_food_price'][$key] ) : '' );
902
+
903
+ if ( $is_ajax ) :
904
+ $post = get_post( $post_id );
905
+ $GLOBALS['post'] = $post;
906
+ setup_postdata( $post );
907
+
908
+ ?>
909
+ <td><?php the_title(); ?></td>
910
+ <td class="ect-food-price"><?php $this->display_price(); ?></td>
911
+ <td><?php $this->list_labels( $post_id ); ?></td>
912
+ <td><?php the_content(); ?></td>
913
+ <?php
914
+ endif;
915
+
916
+ endforeach;
917
+
918
+ if ( $is_ajax ) {
919
+ exit;
920
+ }
921
+
922
+ wp_safe_redirect( admin_url( 'edit.php?post_type=' . self::MENU_ITEM_POST_TYPE ) );
923
+ exit;
924
+ }
925
+
926
+ function add_many_new_items_page() {
927
+ ?>
928
+ <div class="wrap">
929
+ <h2><?php esc_html_e( 'Add Many Items', 'essential-content-types' ); ?></h2>
930
+
931
+ <p><?php _e( 'Use the <kbd>TAB</kbd> key on your keyboard to move between colums and the <kbd>ENTER</kbd> or <kbd>RETURN</kbd> key to save each row and move on to the next.', 'essential-content-types' ); ?></p>
932
+
933
+ <form method="post" action="" enctype="multipart/form-data">
934
+ <p><h3><?php esc_html_e( 'Add to section:', 'essential-content-types' ); ?> <?php wp_dropdown_categories( array(
935
+ 'id' => 'ect-food-menu-tax',
936
+ 'name' => 'ect_food_menu_tax',
937
+ 'taxonomy' => self::MENU_TAX,
938
+ 'hide_empty' => false,
939
+ 'hierarchical' => true,
940
+ ) ); ?></h3></p>
941
+
942
+ <table class="many-items-table wp-list-table widefat">
943
+ <thead>
944
+ <tr>
945
+ <th scope="col"><?php esc_html_e( 'Name', 'essential-content-types' ); ?></th>
946
+ <th scope="col" class="ect-food-price"><?php esc_html_e( 'Price', 'essential-content-types' ); ?></th>
947
+ <th scope="col"><?php _e( 'Labels: <small>spicy, favorite, etc. <em>Separate Labels with commas</em></small>', 'essential-content-types' ); ?></th>
948
+ <th scope="col"><?php esc_html_e( 'Description', 'essential-content-types' ); ?></th>
949
+ </tr>
950
+ </thead>
951
+ <tbody>
952
+ <tr>
953
+ <td><input type="text" name="ect_food_title[]" aria-required="true" /></td>
954
+ <td class="ect-food-price"><input type="text" name="ect_food_price[]" /></td>
955
+ <td><input type="text" name="ect_food_labels[]" /></td>
956
+ <td><textarea name="ect_food_content[]" cols="20" rows="1"></textarea>
957
+ </tr>
958
+ </tbody>
959
+ <tbody>
960
+ <tr>
961
+ <td><input type="text" name="ect_food_title[]" aria-required="true" /></td>
962
+ <td class="ect-food-price"><input type="text" name="ect_food_price[]" /></td>
963
+ <td><input type="text" name="ect_food_labels[]" /></td>
964
+ <td><textarea name="ect_food_content[]" cols="20" rows="1"></textarea>
965
+ </tr>
966
+ </tbody>
967
+ <tfoot>
968
+ <tr>
969
+ <th><a class="button button-secondary ect-food-new-row"><span class="dashicon dashicon-plus"></span> <?php esc_html_e( 'New Row' , 'essential-content-types' ); ?></a></th>
970
+ <th class="ect-food-price"></th>
971
+ <th></th>
972
+ <th></th>
973
+ </tr>
974
+ </tfoot>
975
+ </table>
976
+
977
+ <p class="submit">
978
+ <input type="submit" class="button-primary" value="<?php esc_attr_e( 'Add These New Menu Items', 'essential-content-types' ); ?>" />
979
+ <?php wp_nonce_field( 'ect_food_many_items' ); ?>
980
+ </p>
981
+ </form>
982
+ </div>
983
+ <?php
984
+ }
985
+
986
+ /* Edit One Item */
987
+
988
+ function register_menu_item_meta_boxes() {
989
+ wp_enqueue_script( 'ect-food-menu-checkboxes' );
990
+
991
+ add_meta_box( 'menu_item_price', __( 'Price', 'essential-content-types' ), array( $this, 'menu_item_price_meta_box' ), null, 'side', 'high' );
992
+ }
993
+
994
+ function menu_item_price_meta_box( $post, $meta_box ) {
995
+ $price = $this->get_price( $post->ID );
996
+ ?>
997
+ <label for="ect-food-price-<?php echo (int) $post->ID; ?>" class="screen-reader-text"><?php esc_html_e( 'Price', 'essential-content-types' ); ?></label>
998
+ <input type="text" id="ect-food-price-<?php echo (int) $post->ID; ?>" class="widefat" name="ect_food_price[<?php echo (int) $post->ID; ?>]" value="<?php echo esc_attr( $price ); ?>" />
999
+ <?php
1000
+ }
1001
+
1002
+ function add_post_meta( $post_id ) {
1003
+ if ( !isset( $_POST['ect_food_price'][$post_id] ) ) {
1004
+ return;
1005
+ }
1006
+
1007
+ $this->set_price( $post_id, stripslashes( $_POST['ect_food_price'][$post_id] ) );
1008
+ }
1009
+
1010
+ /* Data */
1011
+
1012
+ function get_menus( $args = array() ) {
1013
+ $args = wp_parse_args( $args, array(
1014
+ 'hide_empty' => false,
1015
+ ) );
1016
+
1017
+ $terms = get_terms( self::MENU_TAX, $args );
1018
+ if ( !$terms || is_wp_error( $terms ) ) {
1019
+ return array();
1020
+ }
1021
+
1022
+ $terms_by_id = array();
1023
+ foreach ( $terms as $term ) {
1024
+ $terms_by_id["{$term->term_id}"] = $term;
1025
+ }
1026
+
1027
+ $term_order = get_option( 'ect_food_menu_order', array() );
1028
+
1029
+ $return = array();
1030
+ foreach ( $term_order as $term_id ) {
1031
+ if ( isset( $terms_by_id["$term_id"] ) ) {
1032
+ $return[] = $terms_by_id["$term_id"];
1033
+ unset( $terms_by_id["$term_id"] );
1034
+ }
1035
+ }
1036
+
1037
+ foreach ( $terms_by_id as $term_id => $term ) {
1038
+ $return[] = $term;
1039
+ }
1040
+
1041
+ return $return;
1042
+ }
1043
+
1044
+ function get_menu_item_menu_leaf( $post_id ) {
1045
+ // Get first menu taxonomy "leaf"
1046
+ $term_ids = wp_get_object_terms( $post_id, self::MENU_TAX, array( 'fields' => 'ids' ) );
1047
+
1048
+ foreach ( $term_ids as $term_id ) {
1049
+ $children = get_term_children( $term_id, self::MENU_TAX );
1050
+ if ( ! $children ) {
1051
+ break;
1052
+ }
1053
+ }
1054
+
1055
+ if ( ! isset( $term_id ) ) {
1056
+ return false;
1057
+ }
1058
+
1059
+ return get_term( $term_id, self::MENU_TAX );
1060
+
1061
+ }
1062
+
1063
+ function list_labels( $post_id = 0 ) {
1064
+ $post = get_post( $post_id );
1065
+ echo get_the_term_list( $post->ID, self::MENU_ITEM_LABEL_TAX, '', _x( ', ', 'Nova label separator', 'essential-content-types' ), '' );
1066
+ }
1067
+
1068
+ function list_admin_labels( $post_id = 0 ) {
1069
+ $post = get_post( $post_id );
1070
+ $labels = get_the_terms( $post->ID, self::MENU_ITEM_LABEL_TAX );
1071
+ if ( !empty( $labels ) ) {
1072
+ $out = array();
1073
+ foreach ( $labels as $label ) {
1074
+ $out[] = sprintf( '<a href="%s">%s</a>',
1075
+ esc_url( add_query_arg( array(
1076
+ 'post_type' => self::MENU_ITEM_POST_TYPE,
1077
+ 'taxonomy' => self::MENU_ITEM_LABEL_TAX,
1078
+ 'term' => $label->slug
1079
+ ), 'edit.php' ) ),
1080
+ esc_html( sanitize_term_field( 'name', $label->name, $label->term_id, self::MENU_ITEM_LABEL_TAX, 'display' ) )
1081
+ );
1082
+ }
1083
+
1084
+ echo join( _x( ', ', 'Nova label separator', 'essential-content-types' ), $out );
1085
+ } else {
1086
+ esc_html_e( 'No Labels', 'essential-content-types' );
1087
+ }
1088
+ }
1089
+
1090
+ function set_price( $post_id = 0, $price = '' ) {
1091
+ $post = get_post( $post_id );
1092
+
1093
+ return update_post_meta( $post->ID, 'ect_food_price', $price );
1094
+ }
1095
+
1096
+ function get_price( $post_id = 0 ) {
1097
+ $post = get_post( $post_id );
1098
+
1099
+ return get_post_meta( $post->ID, 'ect_food_price', true );
1100
+ }
1101
+
1102
+ function display_price( $post_id = 0 ) {
1103
+ echo esc_html( $this->get_price( $post_id ) );
1104
+ }
1105
+
1106
+ /* Menu Item Loop Markup */
1107
+
1108
+ /* Does not support nested loops */
1109
+
1110
+ function get_menu_item_loop_markup( $field = null ) {
1111
+ return $this->menu_item_loop_markup;
1112
+ }
1113
+
1114
+ /**
1115
+ * Sets up the loop markup.
1116
+ * Attached to the 'template_include' *filter*,
1117
+ * which fires only during a real blog view (not in admin, feeds, etc.)
1118
+ *
1119
+ * @param string Template File
1120
+ * @return string Template File. VERY Important.
1121
+ */
1122
+ function setup_menu_item_loop_markup__in_filter( $template ) {
1123
+ add_action( 'loop_start', array( $this, 'start_menu_item_loop' ) );
1124
+
1125
+ return $template;
1126
+ }
1127
+
1128
+ /**
1129
+ * If the Query is a Menu Item Query, start outputing the Menu Item Loop Marku
1130
+ * Attached to the 'loop_start' action.
1131
+ *
1132
+ * @param WP_Query
1133
+ */
1134
+ function start_menu_item_loop( $query ) {
1135
+ if ( !$this->is_menu_item_query( $query ) ) {
1136
+ return;
1137
+ }
1138
+
1139
+ $this->menu_item_loop_last_term_id = false;
1140
+ $this->menu_item_loop_current_term = false;
1141
+
1142
+ add_action( 'the_post', array( $this, 'menu_item_loop_each_post' ) );
1143
+ add_action( 'loop_end', array( $this, 'stop_menu_item_loop' ) );
1144
+ }
1145
+
1146
+ /**
1147
+ * Outputs the Menu Item Loop Marku
1148
+ * Attached to the 'the_post' action.
1149
+ *
1150
+ * @param WP_Post
1151
+ */
1152
+ function menu_item_loop_each_post( $post ) {
1153
+ $this->menu_item_loop_current_term = $this->get_menu_item_menu_leaf( $post->ID );
1154
+
1155
+ if ( false === $this->menu_item_loop_last_term_id ) {
1156
+ // We're at the very beginning of the loop
1157
+
1158
+ $this->menu_item_loop_open_element( 'menu' ); // Start a new menu section
1159
+ $this->menu_item_loop_header(); // Output the menu's header
1160
+ } elseif ( $this->menu_item_loop_last_term_id != $this->menu_item_loop_current_term->term_id ) {
1161
+ // We're not at the very beginning but still need to start a new menu section. End the previous menu section first.
1162
+
1163
+ $this->menu_item_loop_close_element( 'menu' ); // End the previous menu section
1164
+ $this->menu_item_loop_open_element( 'menu' ); // Start a new menu section
1165
+ $this->menu_item_loop_header(); // Output the menu's header
1166
+ }
1167
+
1168
+ $this->menu_item_loop_last_term_id = isset( $this->menu_item_loop_current_term->term_id ) ? $this->menu_item_loop_current_term->term_id : '' ;
1169
+ }
1170
+
1171
+ /**
1172
+ * If the Query is a Menu Item Query, stop outputing the Menu Item Loop Marku
1173
+ * Attached to the 'loop_end' action.
1174
+ *
1175
+ * @param WP_Query
1176
+ */
1177
+ function stop_menu_item_loop( $query ) {
1178
+ if ( !$this->is_menu_item_query( $query ) ) {
1179
+ return;
1180
+ }
1181
+
1182
+ remove_action( 'the_post', array( $this, 'menu_item_loop_each_post' ) );
1183
+ remove_action( 'loop_start', array( $this, 'start_menu_item_loop' ) );
1184
+ remove_action( 'loop_end', array( $this, 'stop_menu_item_loop' ) );
1185
+
1186
+ $this->menu_item_loop_close_element( 'menu' ); // End the last menu section
1187
+ }
1188
+
1189
+ /**
1190
+ * Outputs the Menu Group Header
1191
+ */
1192
+ function menu_item_loop_header() {
1193
+ $this->menu_item_loop_open_element( 'menu_header' );
1194
+ $this->menu_item_loop_open_element( 'menu_title' );
1195
+ echo isset( $this->menu_item_loop_current_term->name ) ? esc_html( $this->menu_item_loop_current_term->name ) : ''; // @todo tax filter
1196
+ $this->menu_item_loop_close_element( 'menu_title' );
1197
+ if ( isset( $this->menu_item_loop_current_term->description ) && $this->menu_item_loop_current_term->description ) :
1198
+ $this->menu_item_loop_open_element( 'menu_description' );
1199
+ echo esc_html( $this->menu_item_loop_current_term->description ); // @todo kses, tax filter
1200
+ $this->menu_item_loop_close_element( 'menu_description' );
1201
+ endif;
1202
+ $this->menu_item_loop_close_element( 'menu_header' );
1203
+ }
1204
+
1205
+ /**
1206
+ * Outputs a Menu Item Markup element opening tag
1207
+ *
1208
+ * @param string $field - Menu Item Markup settings field.
1209
+ */
1210
+ function menu_item_loop_open_element( $field ) {
1211
+ $markup = $this->get_menu_item_loop_markup();
1212
+ /**
1213
+ * Filter a menu item's element opening tag.
1214
+ *
1215
+ * @module custom-content-types
1216
+ *
1217
+ * @since 4.4.0
1218
+ *
1219
+ * @param string $tag Menu item's element opening tag.
1220
+ * @param string $field Menu Item Markup settings field.
1221
+ * @param array $markup Array of markup elements for the menu item.
1222
+ * @param false|object $term Taxonomy term for current menu item.
1223
+ */
1224
+ echo apply_filters(
1225
+ 'essential-content-types_ect_food_menu_item_loop_open_element',
1226
+ '<' . tag_escape( $markup["{$field}_tag"] ) . $this->menu_item_loop_class( $markup["{$field}_class"] ) . ">\n",
1227
+ $field,
1228
+ $markup,
1229
+ $this->menu_item_loop_current_term
1230
+ );
1231
+ }
1232
+
1233
+ /**
1234
+ * Outputs a Menu Item Markup element closing tag
1235
+ *
1236
+ * @param string $field - Menu Item Markup settings field
1237
+ */
1238
+ function menu_item_loop_close_element( $field ) {
1239
+ $markup = $this->get_menu_item_loop_markup();
1240
+ /**
1241
+ * Filter a menu item's element closing tag.
1242
+ *
1243
+ * @module custom-content-types
1244
+ *
1245
+ * @since 4.4.0
1246
+ *
1247
+ * @param string $tag Menu item's element closing tag.
1248
+ * @param string $field Menu Item Markup settings field.
1249
+ * @param array $markup Array of markup elements for the menu item.
1250
+ * @param false|object $term Taxonomy term for current menu item.
1251
+ */
1252
+ echo apply_filters(
1253
+ 'essential-content-types_ect_food_menu_item_loop_close_element',
1254
+ '</' . tag_escape( $markup["{$field}_tag"] ) . ">\n",
1255
+ $field,
1256
+ $markup,
1257
+ $this->menu_item_loop_current_term
1258
+ );
1259
+ }
1260
+
1261
+ /**
1262
+ * Returns a Menu Item Markup element's class attribute.
1263
+ *
1264
+ * @param string $class Class name.
1265
+ * @return string HTML class attribute with leading whitespace.
1266
+ */
1267
+ function menu_item_loop_class( $class ) {
1268
+ if ( ! $class ) {
1269
+ return '';
1270
+ }
1271
+
1272
+ /**
1273
+ * Filter a menu Item Markup element's class attribute.
1274
+ *
1275
+ * @module custom-content-types
1276
+ *
1277
+ * @since 4.4.0
1278
+ *
1279
+ * @param string $tag Menu Item Markup element's class attribute.
1280
+ * @param string $class Menu Item Class name.
1281
+ * @param false|object $term Taxonomy term for current menu item.
1282
+ */
1283
+ return apply_filters(
1284
+ 'essential-content-types_ect_food_menu_item_loop_class',
1285
+ ' class="' . esc_attr( $class ) . '"',
1286
+ $class,
1287
+ $this->menu_item_loop_current_term
1288
+ );
1289
+ }
1290
+
1291
+ /**
1292
+ * Our [food_menu] shortcode.
1293
+ * Prints Food Menu data styled to look good on *any* theme.
1294
+ *
1295
+ * @return ect_food_shortcode_html
1296
+ */
1297
+ static function ect_food_shortcode( $atts ) {
1298
+ // Default attributes
1299
+ $atts = shortcode_atts( array(
1300
+ 'include_type' => false,
1301
+ 'include_tag' => false,
1302
+ 'showposts' => -1,
1303
+ ), $atts, 'food_menu' );
1304
+
1305
+ // A little sanitization
1306
+ if ( $atts['include_type'] ) {
1307
+ $atts['include_type'] = explode( ',', str_replace( ' ', '', $atts['include_type'] ) );
1308
+ }
1309
+
1310
+ if ( $atts['include_tag'] ) {
1311
+ $atts['include_tag'] = explode( ',', str_replace( ' ', '', $atts['include_tag'] ) );
1312
+ }
1313
+
1314
+ $atts['showposts'] = intval( $atts['showposts'] );
1315
+
1316
+ // enqueue shortcode styles when shortcode is used
1317
+ wp_enqueue_style( 'ect-food-menu-style', plugins_url( 'css/food-menu-shortcode.css', __FILE__ ), array(), '20140326' );
1318
+ wp_enqueue_script( 'ect-food-menu-script', plugins_url( 'js/food-menu-shortcode.js', __FILE__ ) , array( 'jquery' ), '20180530', false );
1319
+
1320
+ return self::ect_food_shortcode_html( $atts );
1321
+ }
1322
+
1323
+ /**
1324
+ * Query to retrieve entries from the Food Menu post_type.
1325
+ *
1326
+ * @return object
1327
+ */
1328
+ static function ect_food_query( $atts ) {
1329
+ // Default query arguments
1330
+ $default = array(
1331
+ 'posts_per_page' => $atts['showposts'],
1332
+ );
1333
+
1334
+ $args = wp_parse_args( $atts, $default );
1335
+ $args['post_type'] = self::MENU_ITEM_POST_TYPE; // Force this post type
1336
+
1337
+ if ( false != $atts['include_type'] || false != $atts['include_tag'] ) {
1338
+ $args['tax_query'] = array();
1339
+ }
1340
+
1341
+ // If 'include_type' has been set use it on the main query
1342
+ if ( false != $atts['include_type'] ) {
1343
+ array_push( $args['tax_query'], array(
1344
+ 'taxonomy' => self::MENU_TAX,
1345
+ 'field' => 'slug',
1346
+ 'terms' => $atts['include_type'],
1347
+ ) );
1348
+ }
1349
+
1350
+ // If 'include_tag' has been set use it on the main query
1351
+ if ( false != $atts['include_tag'] ) {
1352
+ array_push( $args['tax_query'], array(
1353
+ 'taxonomy' => self::MENU_ITEM_LABEL_TAX,
1354
+ 'field' => 'slug',
1355
+ 'terms' => $atts['include_tag'],
1356
+ ) );
1357
+ }
1358
+
1359
+ if ( false != $atts['include_type'] && false != $atts['include_tag'] ) {
1360
+ $args['tax_query']['relation'] = 'AND';
1361
+ }
1362
+
1363
+ // Run the query and return
1364
+ $query = new WP_Query( $args );
1365
+ return $query;
1366
+ }
1367
+
1368
+ /**
1369
+ * The Food Menu shortcode loop.
1370
+ *
1371
+ * @return html
1372
+ */
1373
+ static function ect_food_shortcode_html( $atts ) {
1374
+
1375
+ $query = self::ect_food_query( $atts );
1376
+ ob_start();
1377
+
1378
+ // If we have posts, create the html
1379
+ // with hect_food markup
1380
+ if ( $query->have_posts() ) {
1381
+
1382
+ /**
1383
+ * Hook: ect_before_food_menu_loop.
1384
+ *
1385
+ * @hooked ect_food_menu_section
1386
+ */
1387
+ $layout = ect_get_layout();
1388
+ do_action( 'ect_before_food_menu_loop' );
1389
+ ?>
1390
+ <?php
1391
+
1392
+ ect_get_template_part( 'ect', 'menu', $atts );
1393
+
1394
+ // If comments are open or we have at least one comment, load up the comment template
1395
+ if ( comments_open() || '0' != get_comments_number() ) {
1396
+ comments_template( '', true );
1397
+ }
1398
+ ?>
1399
+ <?php
1400
+
1401
+ /**
1402
+ * Hook: ect_after_food_menu_loop.
1403
+ *
1404
+ * @hooked
1405
+ */
1406
+ do_action( 'ect_after_food_menu_loop' );
1407
+
1408
+ } else {
1409
+ /**
1410
+ * Hook: ect_no_food_menu_found.
1411
+ *
1412
+ * @hooked ect_no_food_menu_found
1413
+ */
1414
+ do_action( 'ect_no_food_menu_found' );
1415
+ }
1416
+
1417
+ $html = ob_get_clean();
1418
+
1419
+ // If there is a [food-menu] within a [food-menu], remove the shortcode
1420
+ if ( has_shortcode( $html, 'food-menu' ) ){
1421
+ remove_shortcode( 'food-menu' );
1422
+ }
1423
+
1424
+ // Return the HTML block
1425
+ return $html;
1426
+ }
1427
+ }
1428
+
1429
+ add_action( 'init', array( 'Essential_Content_Food_Menu', 'init' ) );
1430
+
1431
+
1432
+ /**
1433
+ * Add Food Menu support
1434
+ */
1435
+ function essential_content_food_menu_support() {
1436
+ /*
1437
+ * Adding theme support for Food Menu Item CPT.
1438
+ */
1439
+ add_theme_support( 'ect_food_menu_item' );
1440
+ }
1441
+ add_action( 'after_setup_theme', 'essential_content_food_menu_support' );
1442
+
1443
+
1444
+ if( ! function_exists( 'essential_content_no_food_menu_found' ) ):
1445
+ /**
1446
+ * No items found text
1447
+ *
1448
+ * @return html
1449
+ */
1450
+ function essential_content_no_food_menu_found() {
1451
+ echo "<p><em>" . esc_html__( 'Your Food Menu Archive currently has no entries. You can start creating them on your dashboard.', 'essential-content-types-pro' ) . "</em></p>";
1452
+ }
1453
+ endif;
1454
+ add_action( 'ect_no_food_menu_found', 'essential_content_no_food_menu_found', 10 );
1455
+
1456
+
1457
+ if( ! function_exists( 'essential_content_food_menu_section_open' ) ):
1458
+ /**
1459
+ * Open section
1460
+ *
1461
+ * @return html
1462
+ */
1463
+ function essential_content_food_menu_section_open() {
1464
+ echo '<div class="ect-menu ect-section">';
1465
+ echo '<div class="ect-wrapper">';
1466
+ }
1467
+ endif;
1468
+ add_action( 'ect_before_food_menu_loop', 'essential_content_food_menu_section_open', 10, 1 );
1469
+
1470
+
1471
+ if( ! function_exists( 'essential_content_food_menu_loop_start' ) ):
1472
+ /**
1473
+ * open wrapper before loop
1474
+ *
1475
+ */
1476
+ function essential_content_food_menu_loop_start(){
1477
+ echo '<div class="section-content-wrapper menu-content-wrapper">';
1478
+ }
1479
+ endif;
1480
+ add_action( 'ect_before_food_menu_loop', 'essential_content_food_menu_loop_start', 30 );
1481
+
1482
+
1483
+ if( ! function_exists( 'essential_content_food_menu_loop_end' ) ):
1484
+ /**
1485
+ * close wrapper after loop
1486
+ *
1487
+ */
1488
+ function essential_content_food_menu_loop_end(){
1489
+ echo '</div><!-- .menu-content-wrapper -->';
1490
+ }
1491
+ endif;
1492
+ add_action( 'ect_after_food_menu_loop', 'essential_content_food_menu_loop_end', 10 );
1493
+
1494
+
1495
+ if( ! function_exists( 'essential_content_food_menu_section_close' ) ):
1496
+ /**
1497
+ * Close section
1498
+ *
1499
+ * @return html
1500
+ */
1501
+ function essential_content_food_menu_section_close() {
1502
+ echo '</div><!-- .ect-wrapper -->';
1503
+ echo '</div><!-- .ect-section -->';
1504
+ }
1505
+ endif;
1506
+ add_action( 'ect_after_food_menu_loop', 'essential_content_food_menu_section_close', 20 );
1507
+
1508
+ function essential_content_food_menu_get_menus( $args = array() ) {
1509
+ $args = wp_parse_args( $args, array(
1510
+ 'hide_empty' => false,
1511
+ ) );
1512
+
1513
+ $terms = get_terms( 'ect_food_menu', $args );
1514
+ if ( !$terms || is_wp_error( $terms ) ) {
1515
+ return array();
1516
+ }
1517
+
1518
+ $terms_by_id = array();
1519
+ foreach ( $terms as $term ) {
1520
+ $terms_by_id["{$term->term_id}"] = $term;
1521
+ }
1522
+
1523
+ $term_order = get_option( 'ect_food_menu_order', array() );
1524
+
1525
+ $return = array();
1526
+ foreach ( $term_order as $term_id ) {
1527
+ if ( isset( $terms_by_id["$term_id"] ) ) {
1528
+ $return[] = $terms_by_id["$term_id"];
1529
+ unset( $terms_by_id["$term_id"] );
1530
+ }
1531
+ }
1532
+
1533
+ foreach ( $terms_by_id as $term_id => $term ) {
1534
+ $return[] = $term;
1535
+ }
1536
+
1537
+ return $return;
1538
+ }
admin/css/food-menu-shortcode.css CHANGED
@@ -1,156 +1,160 @@
1
- /*--------------------------------------------------------------
2
- # Food Menu
3
- --------------------------------------------------------------*/
4
-
5
- /*--------------------------------------------------------------
6
- # Element
7
- --------------------------------------------------------------*/
8
- html {
9
- -webkit-box-sizing: border-box;
10
- -moz-box-sizing: border-box;
11
- box-sizing: border-box;
12
- }
13
-
14
- *,
15
- *:before,
16
- *:after {
17
- /* Inherit box-sizing to make it easier to change the property for components that leverage other behavior; see http://css-tricks.com/inheriting-box-sizing-probably-slightly-better-best-practice/ */
18
- -webkit-box-sizing: inherit;
19
- -moz-box-sizing: inherit;
20
- box-sizing: inherit;
21
- }
22
-
23
- .menu-content-wrapper {
24
- max-width: 1080px;
25
- margin: 0 auto;
26
- }
27
-
28
- .menu-content-wrapper .ui-nav-collapse {
29
- margin: 0;
30
- margin-bottom: 21px;
31
- }
32
-
33
-
34
- .menu-content-wrapper .ui-nav-collapse,
35
- .menu-content-wrapper .ui-tabs-anchor {
36
- display: block;
37
- font-size: 20px;
38
- font-size: 1.25rem;
39
- font-weight: 500;
40
- text-transform: capitalize;
41
- }
42
-
43
- .menu-content-wrapper .tabs-nav,
44
- .menu-content-wrapper .ui-tabs-panel {
45
- display: none;
46
- }
47
-
48
- .menu-content-wrapper .ui-tabs-panel.active-tab {
49
- display: block;
50
- }
51
-
52
- .menu-content-wrapper .hentry {
53
- margin-bottom: 21px;
54
- }
55
-
56
- .menu-content-wrapper .hentry-inner {
57
- border-bottom: 3px solid #eee;
58
- padding-bottom: 21px;
59
- }
60
-
61
- .menu-content-wrapper .entry-container {
62
- display: table;
63
- position: relative;
64
- table-layout: fixed;
65
- width: 100%;
66
- }
67
-
68
- .menu-content-wrapper .entry-description, .entry-price {
69
- display: table-cell;
70
- vertical-align: top;
71
- }
72
-
73
- .menu-content-wrapper .entry-description {
74
- width: 70%;
75
- }
76
-
77
- .entry-price {
78
- padding-top: 4px;
79
- width: 30%;
80
- text-align: right;
81
- }
82
-
83
- .menu-group-header {
84
- display: none;
85
- }
86
-
87
- /*--------------------------------------------------------------
88
- # >= 667px
89
- --------------------------------------------------------------*/
90
-
91
- @media screen and (min-width: 41.6875em) {
92
-
93
- /*menu-content-wrapper*/
94
- .menu-content-wrapper .tabs-nav {
95
- display: block;
96
- margin-bottom: 35px;
97
- }
98
-
99
- .menu-content-wrapper .ui-tabs-nav {
100
- margin: 0;
101
- padding: 0;
102
- text-align: center;
103
- }
104
-
105
- .menu-content-wrapper .ui-tabs-nav li {
106
- display: inline-block;
107
- list-style: none;
108
- }
109
-
110
- .menu-content-wrapper .ui-tabs-anchor {
111
- display: inline-block;
112
- padding: 14px 25px;
113
- }
114
-
115
- .menu-content-wrapper .ui-nav-collapse {
116
- display: none;
117
- }
118
-
119
- .menu-content-wrapper .hentry-inner {
120
- padding-bottom: 28px;
121
- }
122
-
123
- .entry-price {
124
- font-size: 18px;
125
- font-size: 1.125rem;
126
- }
127
- }
128
-
129
- .menu-content-wrapper a {
130
- text-decoration: none;
131
- }
132
-
133
- .menu-content-wrapper .entry-title,
134
- .menu-content-wrapper .entry-header {
135
- margin-bottom: 0;
136
- padding: 0;
137
- }
138
-
139
- .menu-content-wrapper .entry-title {
140
- margin-bottom: 7px;
141
- }
142
-
143
- body.ect-post .content-area .singular-content-wrap .menu-content-wrapper .entry-content {
144
- padding-top: 0;
145
- margin-top: 21px;
146
- }
147
-
148
- .ect-post .menu-content-wrapper .more-button {
149
- text-align: left;
150
- }
151
-
152
- .ect-post .singular-content-wrap .entry-content .entry-header,
153
- .ect-post .entry-content,
154
- .ect-post .ect-menu .menu-content-wrapper .entry-header {
155
- text-align: left;
156
- }
 
 
 
 
1
+ /*--------------------------------------------------------------
2
+ # Food Menu
3
+ --------------------------------------------------------------*/
4
+
5
+ /*--------------------------------------------------------------
6
+ # Element
7
+ --------------------------------------------------------------*/
8
+ html {
9
+ -webkit-box-sizing: border-box;
10
+ -moz-box-sizing: border-box;
11
+ box-sizing: border-box;
12
+ }
13
+
14
+ *,
15
+ *:before,
16
+ *:after {
17
+ /* Inherit box-sizing to make it easier to change the property for components that leverage other behavior; see http://css-tricks.com/inheriting-box-sizing-probably-slightly-better-best-practice/ */
18
+ -webkit-box-sizing: inherit;
19
+ -moz-box-sizing: inherit;
20
+ box-sizing: inherit;
21
+ }
22
+
23
+ .menu-content-wrapper {
24
+ max-width: 1080px;
25
+ margin: 0 auto;
26
+ }
27
+
28
+ .menu-content-wrapper .ui-nav-collapse {
29
+ margin: 0;
30
+ margin-bottom: 21px;
31
+ }
32
+
33
+
34
+ .menu-content-wrapper .ui-nav-collapse,
35
+ .menu-content-wrapper .ui-tabs-anchor {
36
+ display: block;
37
+ font-size: 20px;
38
+ font-size: 1.25rem;
39
+ font-weight: 500;
40
+ text-transform: capitalize;
41
+ }
42
+
43
+ .menu-content-wrapper .tabs-nav,
44
+ .menu-content-wrapper .ui-tabs-panel {
45
+ display: none;
46
+ }
47
+
48
+ .menu-content-wrapper .ui-tabs-panel.active-tab {
49
+ display: block;
50
+ }
51
+
52
+ .menu-content-wrapper .hentry {
53
+ margin-bottom: 21px;
54
+ }
55
+
56
+ .menu-content-wrapper .hentry-inner {
57
+ border-bottom: 3px solid #eee;
58
+ padding-bottom: 21px;
59
+ }
60
+
61
+ .menu-content-wrapper .entry-container {
62
+ display: table;
63
+ position: relative;
64
+ table-layout: fixed;
65
+ width: 100%;
66
+ }
67
+
68
+ .menu-content-wrapper .entry-description, .entry-price {
69
+ display: table-cell;
70
+ vertical-align: top;
71
+ }
72
+
73
+ .menu-content-wrapper .entry-description {
74
+ width: 70%;
75
+ }
76
+
77
+ .entry-price {
78
+ padding-top: 4px;
79
+ width: 30%;
80
+ text-align: right;
81
+ }
82
+
83
+ .menu-group-header {
84
+ display: none;
85
+ }
86
+
87
+ /*--------------------------------------------------------------
88
+ # >= 667px
89
+ --------------------------------------------------------------*/
90
+
91
+ @media screen and (min-width: 41.6875em) {
92
+
93
+ /*menu-content-wrapper*/
94
+ .menu-content-wrapper .tabs-nav {
95
+ display: block;
96
+ margin-bottom: 35px;
97
+ }
98
+
99
+ .menu-content-wrapper .ui-tabs-nav {
100
+ margin: 0;
101
+ padding: 0;
102
+ text-align: center;
103
+ }
104
+
105
+ .menu-content-wrapper .ui-tabs-nav li {
106
+ display: inline-block;
107
+ list-style: none;
108
+ }
109
+
110
+ .menu-content-wrapper .ui-tabs-anchor {
111
+ display: inline-block;
112
+ padding: 14px 25px;
113
+ }
114
+
115
+ .menu-content-wrapper .ui-nav-collapse {
116
+ display: none;
117
+ }
118
+
119
+ .menu-content-wrapper .hentry-inner {
120
+ padding-bottom: 28px;
121
+ }
122
+
123
+ .entry-price {
124
+ font-size: 18px;
125
+ font-size: 1.125rem;
126
+ }
127
+ }
128
+
129
+ .menu-content-wrapper a {
130
+ text-decoration: none;
131
+ }
132
+
133
+ .menu-content-wrapper .entry-title,
134
+ .menu-content-wrapper .entry-header {
135
+ margin-bottom: 0;
136
+ padding: 0;
137
+ }
138
+
139
+ .menu-content-wrapper .entry-title {
140
+ margin-bottom: 7px;
141
+ }
142
+
143
+ body.ect-post .content-area .singular-content-wrap .menu-content-wrapper .entry-content {
144
+ padding-top: 0;
145
+ margin-top: 21px;
146
+ }
147
+
148
+ .ect-post .menu-content-wrapper .more-button {
149
+ text-align: left;
150
+ }
151
+
152
+ .ect-post .singular-content-wrap .entry-content .entry-header,
153
+ .ect-post .entry-content,
154
+ .ect-post .ect-menu .menu-content-wrapper .entry-header {
155
+ text-align: left;
156
+ }
157
+
158
+ .ect-post .menu-content-wrapper .ect_food_menu_item .entry-header .entry-title {
159
+ font-size: 24px;
160
+ }
ect-templates/content-menu.php CHANGED
@@ -1,26 +1,36 @@
1
- <?php
2
-
3
- if ( ! defined( 'ABSPATH' ) ) {
4
- exit; // Exit if accessed directly
5
- }
6
-
7
- ?>
8
- <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
9
- <div class="hentry-inner">
10
- <div class="entry-container">
11
- <div class="entry-description">
12
- <header class="entry-header">
13
- <?php the_title( '<h2 class="entry-title"><a href="' . esc_url( get_the_permalink() ) . '">', '</a></h2>' ); ?>
14
- </header>
15
-
16
- <div class="entry-content">
17
- <?php the_excerpt(); ?>
18
- </div>
19
- </div>
20
-
21
- <div class="entry-price">
22
- <p class="item-price"><?php echo esc_html( get_post_meta( get_the_ID(), 'ect_food_price', true ) ); ?></p>
23
- </div>
24
- </div>
25
- </div><!-- .hentry-inner -->
26
- </article><!-- .hentry -->
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ if ( ! defined( 'ABSPATH' ) ) {
4
+ exit; // Exit if accessed directly
5
+ }
6
+
7
+ ?>
8
+ <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
9
+ <div class="hentry-inner">
10
+ <?php
11
+ // Check if has thumbnail
12
+ if ( has_post_thumbnail( get_the_ID() ) ) :
13
+ ?>
14
+ <div class="food-menu-thumbnail post-thumbnail">
15
+ <a href="<?php echo get_the_permalink(); ?>">
16
+ <?php echo get_the_post_thumbnail( get_the_ID(), array( 50, 50 ) ); ?>
17
+ </a>
18
+ </div>
19
+ <?php endif; ?>
20
+ <div class="entry-container">
21
+ <div class="entry-description">
22
+ <header class="entry-header">
23
+ <?php the_title( '<h2 class="entry-title"><a href="' . get_the_permalink() . '">', '</a></h2>' ); ?>
24
+ </header>
25
+
26
+ <div class="entry-content">
27
+ <?php the_excerpt(); ?>
28
+ </div>
29
+ </div>
30
+
31
+ <div class="entry-price">
32
+ <p class="item-price"><?php echo esc_html( get_post_meta( get_the_ID(), 'ect_food_price', true ) ); ?></p>
33
+ </div>
34
+ </div>
35
+ </div><!-- .hentry-inner -->
36
+ </article><!-- .hentry -->
ect-templates/ect-menu.php CHANGED
@@ -1,107 +1,108 @@
1
- <?php
2
- /**
3
- * The template for displaying food_menu items
4
- *
5
- * @package Foodie_World
6
- */
7
- ?>
8
-
9
- <?php
10
- $cat_list = array();
11
-
12
- $args['taxonomy'] = 'ect_food_menu';
13
-
14
- $menu_categories = get_categories( $args );
15
-
16
- foreach( $menu_categories as $category ) {
17
- if( false != $atts['include_type'] ) {
18
- if ( in_array( $category->slug, $atts['include_type'] ) ) {
19
- $cat_list[] = $category->term_id;
20
- }
21
- } else {
22
- $cat_list[] = $category->term_id;
23
- }
24
- }
25
- ?>
26
- <div id="tabs" class="tabs">
27
- <div class="tabs-nav">
28
- <ul class="ui-tabs-nav menu-tabs-nav">
29
- <?php
30
- $taxonomy = 'ect_food_menu';
31
-
32
- $i = 0;
33
- foreach ( $cat_list as $cat ) :
34
- $term_obj = get_term_by( 'id', absint( $cat ), $taxonomy );
35
- if( $term_obj ) {
36
- $term_name = $cat_name[] = $term_obj->name;
37
-
38
- $class = 'ui-tabs-tab menu-tabs-tab';
39
-
40
- if ( 0 === $i ) {
41
- $class .= ' ui-state-active';
42
- }
43
-
44
- ?>
45
- <li class="<?php echo $class; ?>"><a href="#tab-<?php echo esc_attr( $i + 1 ); ?>" class="ui-tabs-anchor"><?php echo esc_html( $term_obj->name ) ?></a></li>
46
- <?php
47
- }
48
- $i++;
49
- endforeach;
50
- ?>
51
- </ul>
52
- </div><!-- .tabs-nav -->
53
-
54
- <?php
55
- $i = 0;
56
- foreach ( $cat_list as $cat ) :
57
- if( isset( $cat_name ) ) {
58
- ?>
59
-
60
- <div class="ui-tabs-panel-wrap">
61
- <h4 class="menu-nav-collapse ui-nav-collapse<?php echo ( 0 === $i ) ? ' ui-state-active' : ''; ?>"><a href="#tab-<?php echo esc_attr( $i + 1 ); ?>" class="ui-tabs-anchor"><?php echo esc_html( $cat_name[ $i ] ); ?></a></h4>
62
- <div id="tab-<?php echo esc_attr( $i + 1 ); ?>" class="menu-tabs-panel ui-tabs-panel<?php echo ( 0 === $i ) ? ' active-tab' : ''; ?>">
63
- <?php
64
-
65
- $args = array();
66
- $args['post_type'] = Essential_Content_Food_Menu::MENU_ITEM_POST_TYPE;
67
-
68
- $tax_query = array(
69
- array(
70
- 'taxonomy' => Essential_Content_Food_Menu::MENU_TAX,
71
- 'terms' => absint( $cat ),
72
- 'field' => 'term_id',
73
- ),
74
- );
75
-
76
- $args['tax_query'] = $tax_query;
77
-
78
- if ( false != $atts['include_tag'] ) {
79
- array_push( $args['tax_query'], array(
80
- 'taxonomy' => Essential_Content_Food_Menu::MENU_ITEM_LABEL_TAX,
81
- 'field' => 'slug',
82
- 'terms' => $atts['include_tag'],
83
- ) );
84
- }
85
-
86
- if ( false != $atts['include_type'] && false != $atts['include_tag'] ) {
87
- $args['tax_query']['relation'] = 'AND';
88
- }
89
-
90
- $loop = new WP_Query( $args );
91
- if ( $loop->have_posts() ) :
92
- while ( $loop->have_posts() ) :
93
- $loop->the_post();
94
- ect_get_template_part( 'content', 'menu', $atts );
95
- endwhile;
96
- endif;
97
- wp_reset_postdata();
98
- ?>
99
- </div><!-- #tab-1 -->
100
- </div><!-- .ui-tabs-panel-wrap -->
101
-
102
- <?php
103
- }
104
- $i++;
105
- endforeach;
106
- ?>
107
- </div><!-- .tabs -->
 
1
+ <?php
2
+ /**
3
+ * The template for displaying food_menu items
4
+ *
5
+ * @package Foodie_World
6
+ */
7
+ ?>
8
+
9
+ <?php
10
+ $cat_list = array();
11
+
12
+ $menu_categories = essential_content_food_menu_get_menus();
13
+
14
+ foreach ( $menu_categories as $category ) {
15
+ if ( false != $atts['include_type'] ) {
16
+ if ( in_array( $category->slug, $atts['include_type'] ) ) {
17
+ $cat_list[] = $category->term_id;
18
+ }
19
+ } else {
20
+ $cat_list[] = $category->term_id;
21
+ }
22
+ }
23
+ ?>
24
+ <div id="tabs" class="tabs">
25
+ <div class="tabs-nav">
26
+ <ul class="ui-tabs-nav menu-tabs-nav">
27
+ <?php
28
+ $taxonomy = 'ect_food_menu';
29
+
30
+ $i = 0;
31
+ foreach ( $cat_list as $cat ) :
32
+ $term_obj = get_term_by( 'id', absint( $cat ), $taxonomy );
33
+ if ( $term_obj ) {
34
+ $term_name = $cat_name[] = $term_obj->name;
35
+
36
+ $class = 'ui-tabs-tab menu-tabs-tab';
37
+
38
+ if ( 0 === $i ) {
39
+ $class .= ' ui-state-active';
40
+ }
41
+
42
+ ?>
43
+ <li class="<?php echo $class; ?>"><a href="#tab-<?php echo esc_attr( $i + 1 ); ?>" class="ui-tabs-anchor"><?php echo esc_html( $term_obj->name ); ?></a></li>
44
+ <?php
45
+ }
46
+ $i++;
47
+ endforeach;
48
+ ?>
49
+ </ul>
50
+ </div><!-- .tabs-nav -->
51
+
52
+ <?php
53
+ $i = 0;
54
+ foreach ( $cat_list as $cat ) :
55
+ if ( isset( $cat_name ) ) {
56
+ ?>
57
+
58
+ <div class="ui-tabs-panel-wrap">
59
+ <h4 class="menu-nav-collapse ui-nav-collapse<?php echo ( 0 === $i ) ? ' ui-state-active' : ''; ?>"><a href="#tab-<?php echo esc_attr( $i + 1 ); ?>" class="ui-tabs-anchor"><?php echo esc_html( $cat_name[ $i ] ); ?></a></h4>
60
+ <div id="tab-<?php echo esc_attr( $i + 1 ); ?>" class="menu-tabs-panel ui-tabs-panel<?php echo ( 0 === $i ) ? ' active-tab' : ''; ?>">
61
+ <?php
62
+
63
+ $args = array();
64
+ $args['post_type'] = Essential_Content_Food_Menu::MENU_ITEM_POST_TYPE;
65
+
66
+ $tax_query = array(
67
+ array(
68
+ 'taxonomy' => Essential_Content_Food_Menu::MENU_TAX,
69
+ 'terms' => absint( $cat ),
70
+ 'field' => 'term_id',
71
+ ),
72
+ );
73
+
74
+ $args['tax_query'] = $tax_query;
75
+
76
+ if ( false != $atts['include_tag'] ) {
77
+ array_push(
78
+ $args['tax_query'],
79
+ array(
80
+ 'taxonomy' => Essential_Content_Food_Menu::MENU_ITEM_LABEL_TAX,
81
+ 'field' => 'slug',
82
+ 'terms' => $atts['include_tag'],
83
+ )
84
+ );
85
+ }
86
+
87
+ if ( false != $atts['include_type'] && false != $atts['include_tag'] ) {
88
+ $args['tax_query']['relation'] = 'AND';
89
+ }
90
+
91
+ $loop = new WP_Query( $args );
92
+ if ( $loop->have_posts() ) :
93
+ while ( $loop->have_posts() ) :
94
+ $loop->the_post();
95
+ ect_get_template_part( 'content', 'menu', $atts );
96
+ endwhile;
97
+ endif;
98
+ wp_reset_postdata();
99
+ ?>
100
+ </div><!-- #tab-1 -->
101
+ </div><!-- .ui-tabs-panel-wrap -->
102
+
103
+ <?php
104
+ }
105
+ $i++;
106
+ endforeach;
107
+ ?>
108
+ </div><!-- .tabs -->
essential-content-types.php CHANGED
@@ -16,7 +16,7 @@
16
  * Plugin Name: Essential Content Types
17
  * Plugin URI: https://catchplugins.com/plugins/essential-content-types/
18
  * Description: Essential Content Types allows you to feature the impressive content through different content/post types on your website just the way you want it. These content/post types are missed by the themes in WordPress Theme Directory as the feature falls more towards the plugins’ territory.
19
- * Version: 1.8.2
20
  * Author: Catch Plugins
21
  * Author URI: https://catchplugins.com
22
  * License: GPL-3.0+
@@ -31,7 +31,7 @@ if ( ! defined( 'WPINC' ) ) {
31
  }
32
 
33
  // Define Version
34
- define( 'ESSENTIAL_CONTENT_TYPES_VERSION', '1.8.2' );
35
 
36
  /**
37
  * The code that runs during plugin activation.
16
  * Plugin Name: Essential Content Types
17
  * Plugin URI: https://catchplugins.com/plugins/essential-content-types/
18
  * Description: Essential Content Types allows you to feature the impressive content through different content/post types on your website just the way you want it. These content/post types are missed by the themes in WordPress Theme Directory as the feature falls more towards the plugins’ territory.
19
+ * Version: 1.8.3
20
  * Author: Catch Plugins
21
  * Author URI: https://catchplugins.com
22
  * License: GPL-3.0+
31
  }
32
 
33
  // Define Version
34
+ define( 'ESSENTIAL_CONTENT_TYPES_VERSION', '1.8.3' );
35
 
36
  /**
37
  * The code that runs during plugin activation.
languages/essential-content-types-fr_FR.mo CHANGED
Binary file
languages/essential-content-types-fr_FR.po CHANGED
@@ -4,8 +4,8 @@ msgid ""
4
  msgstr ""
5
  "Project-Id-Version: Essential Content Types\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/tags/_s\n"
7
- "POT-Creation-Date: 2020-08-19 14:29-0400\n"
8
- "PO-Revision-Date: 2020-08-19 14:29-0400\n"
9
  "Last-Translator: Charles Girardin <girardin.charles.57@gmail.com>\n"
10
  "Language-Team: Catch Plugins <info@catchplugins.com>\n"
11
  "Language: fr_FR\n"
4
  msgstr ""
5
  "Project-Id-Version: Essential Content Types\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/tags/_s\n"
7
+ "POT-Creation-Date: 2020-09-21 08:20-0400\n"
8
+ "PO-Revision-Date: 2020-09-21 08:20-0400\n"
9
  "Last-Translator: Charles Girardin <girardin.charles.57@gmail.com>\n"
10
  "Language-Team: Catch Plugins <info@catchplugins.com>\n"
11
  "Language: fr_FR\n"
languages/essential-content-types.pot CHANGED
@@ -5,7 +5,7 @@ msgid ""
5
  msgstr ""
6
  "Project-Id-Version: Essential Content Types\n"
7
  "Report-Msgid-Bugs-To: https://wordpress.org/tags/_s\n"
8
- "POT-Creation-Date: 2020-08-19 14:29-0400\n"
9
  "PO-Revision-Date: 2016-12-12 09:23-0500\n"
10
  "Last-Translator: Sakin Shrestha <info@catchplugins.com>\n"
11
  "Language-Team: Catch Plugins <info@catchplugins.com>\n"
5
  msgstr ""
6
  "Project-Id-Version: Essential Content Types\n"
7
  "Report-Msgid-Bugs-To: https://wordpress.org/tags/_s\n"
8
+ "POT-Creation-Date: 2020-09-21 08:20-0400\n"
9
  "PO-Revision-Date: 2016-12-12 09:23-0500\n"
10
  "Last-Translator: Sakin Shrestha <info@catchplugins.com>\n"
11
  "Language-Team: Catch Plugins <info@catchplugins.com>\n"