921d7660 by Jeff Balicki

added filters

Signed-off-by: Jeff <jeff@gotenzing.com>
1 parent 9d48efc0
...@@ -66,7 +66,7 @@ class ExportMediaURLsAdmin ...@@ -66,7 +66,7 @@ class ExportMediaURLsAdmin
66 public function enqueue_scripts($hook_suffix) 66 public function enqueue_scripts($hook_suffix)
67 { 67 {
68 68
69 if($hook_suffix !== Constants::PLUGIN_HOOK_SUFFIX) { 69 if ($hook_suffix !== Constants::PLUGIN_HOOK_SUFFIX) {
70 return; 70 return;
71 } 71 }
72 72
...@@ -101,7 +101,7 @@ class ExportMediaURLsAdmin ...@@ -101,7 +101,7 @@ class ExportMediaURLsAdmin
101 $user_names[] = $user->data->user_login; 101 $user_names[] = $user->data->user_login;
102 } 102 }
103 103
104 ?> 104 ?>
105 105
106 <div class="wrap"> 106 <div class="wrap">
107 107
...@@ -121,11 +121,11 @@ class ExportMediaURLsAdmin ...@@ -121,11 +121,11 @@ class ExportMediaURLsAdmin
121 121
122 <td> 122 <td>
123 123
124 <label><input type="checkbox" name="additional-data[]" value="id" checked/> 124 <label><input type="checkbox" name="additional-data[]" value="id" checked />
125 ID</label><br /> 125 ID</label><br />
126 <label><input type="checkbox" name="additional-data[]" value="title" checked/> 126 <label><input type="checkbox" name="additional-data[]" value="title" checked />
127 Title</label><br /> 127 Title</label><br />
128 <label><input type="checkbox" name="additional-data[]" value="file_name" checked/> 128 <label><input type="checkbox" name="additional-data[]" value="file_name" checked />
129 File Name</label><br /> 129 File Name</label><br />
130 <label><input type="checkbox" name="additional-data[]" value="caption" /> 130 <label><input type="checkbox" name="additional-data[]" value="caption" />
131 Caption</label><br /> 131 Caption</label><br />
...@@ -135,10 +135,14 @@ class ExportMediaURLsAdmin ...@@ -135,10 +135,14 @@ class ExportMediaURLsAdmin
135 Description</label><br /> 135 Description</label><br />
136 <label><input type="checkbox" name="additional-data[]" value="url" checked /> 136 <label><input type="checkbox" name="additional-data[]" value="url" checked />
137 URL</label><br /> 137 URL</label><br />
138 <label><input type="checkbox" name="additional-data[]" value="date" checked/> Date Uploaded</label><br /> 138 <label><input type="checkbox" name="additional-data[]" value="date" checked /> Date
139 Uploaded</label><br />
140
141 <label><input type="checkbox" name="additional-data[]" value="type" checked />
142 Type</label><br />
143 <label><input type="checkbox" name="additional-data[]" value="category" checked />
144 Category & filters</label><br />
139 145
140 <label><input type="checkbox" name="additional-data[]" value="type" checked/> Type</label><br />
141 <label><input type="checkbox" name="additional-data[]" value="category" checked/> Category</label><br />
142 146
143 </td> 147 </td>
144 148
...@@ -147,7 +151,8 @@ class ExportMediaURLsAdmin ...@@ -147,7 +151,8 @@ class ExportMediaURLsAdmin
147 <tr> 151 <tr>
148 <th><label for="post-author">By Author:</label></th> 152 <th><label for="post-author">By Author:</label></th>
149 <td> 153 <td>
150 <select id="post-author" class="select2" name="post-author" required="required" style="width: 40%;"> 154 <select id="post-author" class="select2" name="post-author" required="required"
155 style="width: 40%;">
151 <option value="all" selected>All</option> 156 <option value="all" selected>All</option>
152 <?php 157 <?php
153 if (!empty($user_ids) && !empty($user_names)) { 158 if (!empty($user_ids) && !empty($user_names)) {
...@@ -167,7 +172,8 @@ class ExportMediaURLsAdmin ...@@ -167,7 +172,8 @@ class ExportMediaURLsAdmin
167 172
168 <td> 173 <td>
169 174
170 <label><input type="radio" name="export-type" value="csv" required="required" checked/> CSV File</label><br /> 175 <label><input type="radio" name="export-type" value="csv" required="required" checked />
176 CSV File</label><br />
171 <label><input type="radio" name="export-type" value="dashboard" required="required" /> 177 <label><input type="radio" name="export-type" value="dashboard" required="required" />
172 Output here</label><br /> 178 Output here</label><br />
173 179
...@@ -201,7 +207,7 @@ class ExportMediaURLsAdmin ...@@ -201,7 +207,7 @@ class ExportMediaURLsAdmin
201 207
202 </div> 208 </div>
203 209
204 <?php 210 <?php
205 211
206 if (isset($_POST['export'])) { 212 if (isset($_POST['export'])) {
207 213
...@@ -292,7 +298,7 @@ class ExportMediaURLsAdmin ...@@ -292,7 +298,7 @@ class ExportMediaURLsAdmin
292 $counter = 0; 298 $counter = 0;
293 while ($query_urls->have_posts()) { 299 while ($query_urls->have_posts()) {
294 $query_urls->the_post(); 300 $query_urls->the_post();
295 301 $used_categories = array();
296 if (!isset($data[$data_type][$counter])) { 302 if (!isset($data[$data_type][$counter])) {
297 $data[$data_type][$counter] = null; 303 $data[$data_type][$counter] = null;
298 } 304 }
...@@ -337,9 +343,48 @@ class ExportMediaURLsAdmin ...@@ -337,9 +343,48 @@ class ExportMediaURLsAdmin
337 $data[$data_type][$counter] .= get_post_mime_type() . $line_break; 343 $data[$data_type][$counter] .= get_post_mime_type() . $line_break;
338 break; 344 break;
339 case 'category': 345 case 'category':
340 $categories = wp_get_post_terms(get_the_ID(), 'mlo-category', array('fields' => 'names')); 346 $categories = wp_get_post_terms(get_the_ID(), 'mlo-category', array('fields' => 'all'));
341 $data['category'][$counter] .= implode(', ', $categories) . $line_break; 347 $used_categories = array();
348 $category_terms = array();
349 $sub_category_terms = array();
350
351 foreach ($categories as $category) {
352 if ($category->parent == 0) {
353 // Add to category array and mark as used
354 $category_terms[] = $category->name;
355 $used_categories[] = $category->term_id;
356 }
357 }
358
359 foreach ($categories as $category) {
360 if ($category->parent != 0 && !in_array($category->term_id, $used_categories)) {
361 // Add to sub-category array if not already used
362 $sub_category_terms[] = $category->name;
363 }
364 }
365 if (empty($category_terms) && !empty($sub_category_terms)) {
366 // Get the parent term of one of the sub-category terms
367 $first_sub_category = reset($sub_category_terms);
368 foreach ($categories as $category) {
369 if ($category->name == $first_sub_category) {
370 $parent_term = get_term($category->parent, 'mlo-category');
371 if (!is_wp_error($parent_term) && $parent_term) {
372 $category_terms[] = $parent_term->name;
373 }
374 break;
375 }
376 }
377 }
378
379 if (!empty($category_terms)) {
380 $data['category'][$counter] .= implode(', ', $category_terms) . $line_break;
381 }
382
383 if (!empty($sub_category_terms)) {
384 $data['sub-category'][$counter] .= implode(', ', $sub_category_terms) . $line_break;
385 }
342 break; 386 break;
387
343 default: 388 default:
344 break; 389 break;
345 390
...@@ -372,6 +417,7 @@ class ExportMediaURLsAdmin ...@@ -372,6 +417,7 @@ class ExportMediaURLsAdmin
372 'date' => 'Date Uploaded', 417 'date' => 'Date Uploaded',
373 'type' => 'Type', 418 'type' => 'Type',
374 'category' => 'Categories', 419 'category' => 'Categories',
420 'sub-category' => 'Filters',
375 ]; 421 ];
376 422
377 foreach ($headers as $key => $name) { 423 foreach ($headers as $key => $name) {
......