added filters
Signed-off-by: Jeff <jeff@gotenzing.com>
Showing
1 changed file
with
80 additions
and
34 deletions
| ... | @@ -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 | ||
| ... | @@ -81,7 +81,7 @@ class ExportMediaURLsAdmin | ... | @@ -81,7 +81,7 @@ class ExportMediaURLsAdmin |
| 81 | wp_enqueue_script('select2'); | 81 | wp_enqueue_script('select2'); |
| 82 | wp_enqueue_style('select2css'); | 82 | wp_enqueue_style('select2css'); |
| 83 | } | 83 | } |
| 84 | 84 | ||
| 85 | wp_enqueue_script('emu_script', plugin_dir_url(__FILE__) . '../assets/js/script.js', array('jquery', 'select2'), '2.1', true); | 85 | wp_enqueue_script('emu_script', plugin_dir_url(__FILE__) . '../assets/js/script.js', array('jquery', 'select2'), '2.1', true); |
| 86 | } | 86 | } |
| 87 | 87 | ||
| ... | @@ -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 | ||
| ... | @@ -195,13 +201,13 @@ class ExportMediaURLsAdmin | ... | @@ -195,13 +201,13 @@ class ExportMediaURLsAdmin |
| 195 | </div> | 201 | </div> |
| 196 | </div> | 202 | </div> |
| 197 | <div class="EMU-Side-Container"> | 203 | <div class="EMU-Side-Container"> |
| 198 | 204 | ||
| 199 | </div> | 205 | </div> |
| 200 | </div> | 206 | </div> |
| 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 | ||
| ... | @@ -274,10 +280,10 @@ class ExportMediaURLsAdmin | ... | @@ -274,10 +280,10 @@ class ExportMediaURLsAdmin |
| 274 | $line_break = $export_type == 'dashboard' ? "<br/>" : ""; | 280 | $line_break = $export_type == 'dashboard' ? "<br/>" : ""; |
| 275 | 281 | ||
| 276 | $query_media_urls = array( | 282 | $query_media_urls = array( |
| 277 | 'post_type' => 'attachment', | 283 | 'post_type' => 'attachment', |
| 278 | 'author' => $post_author != 'all' ? $post_author : "", | 284 | 'author' => $post_author != 'all' ? $post_author : "", |
| 279 | 'post_status' => 'inherit', | 285 | 'post_status' => 'inherit', |
| 280 | 'posts_per_page' => -1, | 286 | 'posts_per_page' => -1, |
| 281 | ); | 287 | ); |
| 282 | 288 | ||
| 283 | $query_urls = new \WP_Query($query_media_urls); | 289 | $query_urls = new \WP_Query($query_media_urls); |
| ... | @@ -292,12 +298,12 @@ class ExportMediaURLsAdmin | ... | @@ -292,12 +298,12 @@ 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 | } |
| 299 | 305 | ||
| 300 | 306 | ||
| 301 | switch ($data_type) { | 307 | switch ($data_type) { |
| 302 | case 'id': | 308 | case 'id': |
| 303 | $data[$data_type][$counter] .= get_the_ID() . $line_break; | 309 | $data[$data_type][$counter] .= get_the_ID() . $line_break; |
| ... | @@ -337,15 +343,54 @@ class ExportMediaURLsAdmin | ... | @@ -337,15 +343,54 @@ 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; |
| 343 | default: | 387 | |
| 388 | default: | ||
| 344 | break; | 389 | break; |
| 345 | 390 | ||
| 346 | } | 391 | } |
| 347 | 392 | ||
| 348 | 393 | ||
| 349 | 394 | ||
| 350 | $counter++; | 395 | $counter++; |
| 351 | } | 396 | } |
| ... | @@ -362,16 +407,17 @@ class ExportMediaURLsAdmin | ... | @@ -362,16 +407,17 @@ class ExportMediaURLsAdmin |
| 362 | $filtered_headers = []; | 407 | $filtered_headers = []; |
| 363 | 408 | ||
| 364 | $headers = [ | 409 | $headers = [ |
| 365 | 'id' => 'ID', | 410 | 'id' => 'ID', |
| 366 | 'title' => 'Title', | 411 | 'title' => 'Title', |
| 367 | 'file_name' => 'File Name', | 412 | 'file_name' => 'File Name', |
| 368 | 'caption' => 'Caption', | 413 | 'caption' => 'Caption', |
| 369 | 'alt' => 'Alt Text', | 414 | 'alt' => 'Alt Text', |
| 370 | 'description' => 'Description', | 415 | 'description' => 'Description', |
| 371 | 'url' => 'URLs', | 416 | 'url' => 'URLs', |
| 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) { | ... | ... |
-
Please register or sign in to post a comment