Media Library Assistant - Version 2.93

Version Description

  • New: The "MLA Simple Mapping Hooks Example" plugin has been updated so it will run when attachments are uploaded or updated by the WP/LR Sync plugin.
  • New: For the "Smart Media Categories" example plugin, support has been added for the "Postie" plugin chron job that creates posts and attachments from an email.
  • Fix: Correct defect in parsing request: substitution parameters containing compound names to access array elements, e.g., tax_input.
  • Fix: For [mla_gallery] pagination shortcodes, correct defects in handling substitution parameters containing array values, e.g., tax_input.
  • Fix: For the "Smart Media Categories" example plugin, term synchronization now works when multiple attachments are added to a parent in the same page load.
Download this release

Release Info

Developer dglingren
Plugin Icon 128x128 Media Library Assistant
Version 2.93
Comparing to
See all releases

Code changes from version 2.92 to 2.93

examples/plugins/mla-simple-mapping-hooks-example.php CHANGED
@@ -21,8 +21,12 @@
21
  * opened on 8/4/2016 by "ciano":
22
  * https://wordpress.org/support/topic/replacing-sort-order-attribute
23
  *
 
 
 
 
24
  * @package MLA Simple Mapping Hooks Example
25
- * @version 1.03
26
  */
27
 
28
  /*
@@ -30,10 +34,10 @@ Plugin Name: MLA Simple Mapping Hooks Example
30
  Plugin URI: http://davidlingren.com/
31
  Description: Populates custom fields based on a regular expression; updates menu_order; cleans up Title and ALT Text
32
  Author: David Lingren
33
- Version: 1.03
34
  Author URI: http://davidlingren.com/
35
 
36
- Copyright 2014 - 2016 David Lingren
37
 
38
  This program is free software; you can redistribute it and/or modify
39
  it under the terms of the GNU General Public License as published by
@@ -69,17 +73,17 @@ class MLASimpleMappingHooksExample {
69
  * @return void
70
  */
71
  public static function initialize() {
72
- /*
73
- * The filters are only useful in the admin section; exit if in the "front-end" posts/pages.
74
- */
75
- if ( ! is_admin() )
76
- return;
77
 
78
- /*
79
- * This filter is applied in class-mla-options.php functions
80
- * mla_evaluate_iptc_exif_mapping and mla_evaluate_custom_field_mapping
81
- */
82
- add_filter( 'mla_mapping_updates', 'MLASimpleMappingHooksExample::mla_mapping_updates', 10, 5 );
 
 
 
83
  }
84
 
85
  /**
21
  * opened on 8/4/2016 by "ciano":
22
  * https://wordpress.org/support/topic/replacing-sort-order-attribute
23
  *
24
+ * Enhanced for support topic "Plugin ‘MLA Simple Mapping Hooks Example’"
25
+ * opened on 12/7/2020 by "ernstwg":
26
+ * https://wordpress.org/support/topic/plugin-mla-simple-mapping-hooks-example/
27
+ *
28
  * @package MLA Simple Mapping Hooks Example
29
+ * @version 1.04
30
  */
31
 
32
  /*
34
  Plugin URI: http://davidlingren.com/
35
  Description: Populates custom fields based on a regular expression; updates menu_order; cleans up Title and ALT Text
36
  Author: David Lingren
37
+ Version: 1.04
38
  Author URI: http://davidlingren.com/
39
 
40
+ Copyright 2014 - 2020 David Lingren
41
 
42
  This program is free software; you can redistribute it and/or modify
43
  it under the terms of the GNU General Public License as published by
73
  * @return void
74
  */
75
  public static function initialize() {
76
+ // WP/LR Sync plugin has its own protocol to process uploads
77
+ $is_wplr_sync = isset( $_SERVER['REQUEST_URI'] ) && false !== strpos( $_SERVER['REQUEST_URI'], '/?wplr-sync-api' ); // phpcs:ignore
 
 
 
78
 
79
+ // The filters are only useful in the admin section or during WP/LR Sync; exit if in the "front-end" posts/pages.
80
+ if ( is_admin() || $is_wplr_sync ) {
81
+ /*
82
+ * This filter is applied in class-mla-options.php functions
83
+ * mla_evaluate_iptc_exif_mapping and mla_evaluate_custom_field_mapping
84
+ */
85
+ add_filter( 'mla_mapping_updates', 'MLASimpleMappingHooksExample::mla_mapping_updates', 10, 5 );
86
+ }
87
  }
88
 
89
  /**
examples/plugins/smart-media-categories/admin/class-smart-media-categories-admin.php CHANGED
@@ -3,9 +3,9 @@
3
  * The Smart Media Categories (SMC) Plugin, Admin Mode.
4
  *
5
  * @package Smart_Media_Categories_Admin
6
- * @author David Lingren <dlingren@comcast.net>
7
  * @license GPL-2.0+
8
- * @link @TODO http://example.com
9
  * @copyright 2014 David Lingren
10
  */
11
 
@@ -23,7 +23,7 @@ SMC_Automatic_Support::initialize();
23
  * administrative-side of the WordPress site.
24
  *
25
  * @package Smart_Media_Categories_Admin
26
- * @author David Lingren <dlingren@comcast.net>
27
  */
28
  class Smart_Media_Categories_Admin {
29
 
@@ -622,7 +622,7 @@ if ( 'heartbeat' != $_REQUEST['action'] ) {
622
  * @return void echoes HTML markup for the column content
623
  */
624
  public function action_manage_posts_custom_column( $column_name, $post_id ) {
625
- // global $wp, $wp_query, $wp_the_query;
626
  global $post;
627
  static $smc_status = NULL;
628
  //error_log( __LINE__ . " Smart_Media_Categories_Admin::action_manage_posts_custom_column( {$column_name}, {$post_id} )", 0 );
3
  * The Smart Media Categories (SMC) Plugin, Admin Mode.
4
  *
5
  * @package Smart_Media_Categories_Admin
6
+ * @author David Lingren <david@davidlingren.com>
7
  * @license GPL-2.0+
8
+ * @link http://davidlingren.com
9
  * @copyright 2014 David Lingren
10
  */
11
 
23
  * administrative-side of the WordPress site.
24
  *
25
  * @package Smart_Media_Categories_Admin
26
+ * @author David Lingren <david@davidlingren.com>
27
  */
28
  class Smart_Media_Categories_Admin {
29
 
622
  * @return void echoes HTML markup for the column content
623
  */
624
  public function action_manage_posts_custom_column( $column_name, $post_id ) {
625
+ // global $wp, $wp_query, $wp_the_query; // for error_log debug only
626
  global $post;
627
  static $smc_status = NULL;
628
  //error_log( __LINE__ . " Smart_Media_Categories_Admin::action_manage_posts_custom_column( {$column_name}, {$post_id} )", 0 );
examples/plugins/smart-media-categories/admin/includes/class-smc-automatic-support.php CHANGED
@@ -3,9 +3,9 @@
3
  * Support functions for the SMC automatic actions.
4
  *
5
  * @package Smart_Media_Categories_Admin
6
- * @author David Lingren <dlingren@comcast.net>
7
  * @license GPL-2.0+
8
- * @link @TODO http://example.com
9
  * @copyright 2014 David Lingren
10
  */
11
 
@@ -16,7 +16,7 @@
16
  * no need to create a new instance of the class.
17
  *
18
  * @package Smart_Media_Categories_Admin
19
- * @author David Lingren <dlingren@comcast.net>
20
  */
21
  class SMC_Automatic_Support {
22
  /**
@@ -169,6 +169,9 @@ class SMC_Automatic_Support {
169
  public static function action_add_attachment( $post_id ) {
170
  //error_log( __LINE__ . ' SMC_Automatic_Support::action_add_attachment $post_id = ' . var_export( $post_id, true), 0 );
171
  //error_log( __LINE__ . ' SMC_Automatic_Support::action_add_attachment $post = ' . var_export( get_post( $post_id ), true), 0 );
 
 
 
172
 
173
  if ( (boolean) SMC_Settings_Support::get_option( 'upload_item' ) ) {
174
  SMC_Automatic_support::rule_upload_item( $post_id );
@@ -591,7 +594,7 @@ class SMC_Automatic_Support {
591
  $sql = "UPDATE $wpdb->posts SET post_parent = {$parent_id}
592
  WHERE ID = {$insert_id}";
593
  $results = $wpdb->query( $sql );
594
- //error_log( "rule_insert_orphan SET post_parent({$insert_id}) $results = " . var_export( $results, true), 0 );
595
  clean_attachment_cache( $insert_id );
596
  } // each insert
597
 
@@ -652,7 +655,7 @@ class SMC_Automatic_Support {
652
  $sql = "UPDATE $wpdb->posts SET post_parent = {$parent_id}
653
  WHERE ID = {$insert_id}";
654
  $results = $wpdb->query( $sql );
655
- //error_log( "rule_insert_attached SET post_parent({$insert_id}) $results = " . var_export( $results, true), 0 );
656
  clean_attachment_cache( $insert_id );
657
  } // each insert
658
 
@@ -718,7 +721,7 @@ class SMC_Automatic_Support {
718
  }
719
 
720
  // tt_ids are strings on input, old_tt_ids are integers
721
- $tt_ids = array_map( absint, $tt_ids );
722
  //error_log( __LINE__ . ' SMC_Automatic_Support::rule_update_post_terms mapped $tt_ids = ' . var_export( $tt_ids, true), 0 );
723
  if ( $tt_ids != $old_tt_ids ) {
724
  $terms_changed = true;
3
  * Support functions for the SMC automatic actions.
4
  *
5
  * @package Smart_Media_Categories_Admin
6
+ * @author David Lingren <david@davidlingren.com>
7
  * @license GPL-2.0+
8
+ * @link http://davidlingren.com
9
  * @copyright 2014 David Lingren
10
  */
11
 
16
  * no need to create a new instance of the class.
17
  *
18
  * @package Smart_Media_Categories_Admin
19
+ * @author David Lingren <david@davidlingren.com>
20
  */
21
  class SMC_Automatic_Support {
22
  /**
169
  public static function action_add_attachment( $post_id ) {
170
  //error_log( __LINE__ . ' SMC_Automatic_Support::action_add_attachment $post_id = ' . var_export( $post_id, true), 0 );
171
  //error_log( __LINE__ . ' SMC_Automatic_Support::action_add_attachment $post = ' . var_export( get_post( $post_id ), true), 0 );
172
+
173
+ // Flush the cache of parent/child term assignments toforce resynch
174
+ SMC_Sync_Support::get_posts_per_view( NULL, true );
175
 
176
  if ( (boolean) SMC_Settings_Support::get_option( 'upload_item' ) ) {
177
  SMC_Automatic_support::rule_upload_item( $post_id );
594
  $sql = "UPDATE $wpdb->posts SET post_parent = {$parent_id}
595
  WHERE ID = {$insert_id}";
596
  $results = $wpdb->query( $sql );
597
+ //error_log( __LINE__ . " SMC_Automatic_Support::rule_insert_orphan SET post_parent({$insert_id}) $results = " . var_export( $results, true), 0 );
598
  clean_attachment_cache( $insert_id );
599
  } // each insert
600
 
655
  $sql = "UPDATE $wpdb->posts SET post_parent = {$parent_id}
656
  WHERE ID = {$insert_id}";
657
  $results = $wpdb->query( $sql );
658
+ //error_log( __LINE__ . " SMC_Automatic_Support::rule_insert_attached SET post_parent({$insert_id}) $results = " . var_export( $results, true), 0 );
659
  clean_attachment_cache( $insert_id );
660
  } // each insert
661
 
721
  }
722
 
723
  // tt_ids are strings on input, old_tt_ids are integers
724
+ $tt_ids = array_map( 'absint', $tt_ids );
725
  //error_log( __LINE__ . ' SMC_Automatic_Support::rule_update_post_terms mapped $tt_ids = ' . var_export( $tt_ids, true), 0 );
726
  if ( $tt_ids != $old_tt_ids ) {
727
  $terms_changed = true;
examples/plugins/smart-media-categories/admin/includes/class-smc-settings-support.php CHANGED
@@ -3,9 +3,9 @@
3
  * Support functions for the SMC Settings page.
4
  *
5
  * @package Smart_Media_Categories_Admin
6
- * @author David Lingren <dlingren@comcast.net>
7
  * @license GPL-2.0+
8
- * @link @TODO http://example.com
9
  * @copyright 2014 David Lingren
10
  */
11
 
@@ -16,7 +16,7 @@
16
  * no need to create a new instance of the class.
17
  *
18
  * @package Smart_Media_Categories_Admin
19
- * @author David Lingren <dlingren@comcast.net>
20
  */
21
  class SMC_Settings_Support {
22
  /**
@@ -370,12 +370,12 @@ class SMC_Settings_Support {
370
  * @return void
371
  */
372
  public static function validate_automatic_options( $input ) {
373
- //error_log( __LINE__ ."' SMC_Settings_Support::validate_automatic_options input = " . var_export( $input, true ), 0 );
374
  $output = array();
375
  $updates = 0;
376
 
377
  foreach( SMC_Settings_Support::$option_definitions['smc_automatic_options'] as $key => $value ) {
378
- //error_log( __LINE__ ."' SMC_Settings_Support::validate_automatic_options {$key} = " . var_export( $value, true ), 0 );
379
 
380
  $update = NULL;
381
  switch ( $value['type'] ) {
@@ -419,7 +419,7 @@ class SMC_Settings_Support {
419
  );
420
  }
421
 
422
- //error_log( __LINE__ ."' SMC_Settings_Support::validate_automatic_options output = " . var_export( $output, true ), 0 );
423
  update_option( 'smc_automatic_options', $output );
424
  }
425
 
3
  * Support functions for the SMC Settings page.
4
  *
5
  * @package Smart_Media_Categories_Admin
6
+ * @author David Lingren <david@davidlingren.com>
7
  * @license GPL-2.0+
8
+ * @link http://davidlingren.com
9
  * @copyright 2014 David Lingren
10
  */
11
 
16
  * no need to create a new instance of the class.
17
  *
18
  * @package Smart_Media_Categories_Admin
19
+ * @author David Lingren <david@davidlingren.com>
20
  */
21
  class SMC_Settings_Support {
22
  /**
370
  * @return void
371
  */
372
  public static function validate_automatic_options( $input ) {
373
+ //error_log( __LINE__ ." SMC_Settings_Support::validate_automatic_options input = " . var_export( $input, true ), 0 );
374
  $output = array();
375
  $updates = 0;
376
 
377
  foreach( SMC_Settings_Support::$option_definitions['smc_automatic_options'] as $key => $value ) {
378
+ //error_log( __LINE__ ." SMC_Settings_Support::validate_automatic_options {$key} = " . var_export( $value, true ), 0 );
379
 
380
  $update = NULL;
381
  switch ( $value['type'] ) {
419
  );
420
  }
421
 
422
+ //error_log( __LINE__ ." SMC_Settings_Support::validate_automatic_options output = " . var_export( $output, true ), 0 );
423
  update_option( 'smc_automatic_options', $output );
424
  }
425
 
examples/plugins/smart-media-categories/admin/includes/class-smc-sync-support.php CHANGED
@@ -3,9 +3,9 @@
3
  * Manages synchronization between a parent post and its children.
4
  *
5
  * @package Smart_Media_Categories_Admin
6
- * @author David Lingren <dlingren@comcast.net>
7
  * @license GPL-2.0+
8
- * @link @TODO http://example.com
9
  * @copyright 2014 David Lingren
10
  */
11
 
@@ -17,7 +17,7 @@
17
  * no need to create a new instance of the class.
18
  *
19
  * @package Smart_Media_Categories_Admin
20
- * @author David Lingren <dlingren@comcast.net>
21
  */
22
  class SMC_Sync_Support {
23
  /**
@@ -54,26 +54,29 @@ class SMC_Sync_Support {
54
  *
55
  * @since 1.0.2
56
  *
57
- * @param array Optional; ('smc_status', 'post_parents', 'fields')
 
58
  *
59
  * @return array ( 'sync' => Synced posts, 'unsync' => Unsynced posts )
60
  */
61
- public static function get_posts_per_view( $attr = NULL ) {
62
  global $wpdb;
63
  static $save_attr = NULL, $posts_per_view = NULL;
64
 
65
- /*
66
- * Make sure $attr is an array, even if it's empty
67
- */
 
 
 
 
68
  if ( empty( $attr ) ) {
69
  $attr = array();
70
  } elseif ( is_string( $attr ) ) {
71
  $attr = shortcode_parse_atts( $attr );
72
  }
73
 
74
- /*
75
- * Create the PHP variables we need
76
- */
77
  extract( shortcode_atts( array(
78
  'post_type' => 'post',
79
  'smc_status' => NULL, // 'sync', 'unsync'
@@ -283,7 +286,7 @@ class SMC_Sync_Support {
283
 
284
  // Compute sync status
285
  foreach ( $assignments as $parent_id => $assignment ) {
286
- //error_log( __LINE__ ."' SMC_Sync_Support::get_posts_per_view (parent {$parent_id}) assignment = " . var_export( $assignment, true ), 0 );
287
  $parent_terms = $assignment['ttids'];
288
  unset( $assignment['ttids'] );
289
  unset( $assignment['terms'] );
@@ -393,7 +396,7 @@ class SMC_Sync_Support {
393
  } else {
394
  $parent_terms = $results[ $parent_id ][ $taxonomy ] = array();
395
  }
396
- //error_log( __LINE__ ."' SMC_Sync_Support::get_terms ({$taxonomy}) \$parent_terms = " . var_export( $parent_terms, true ), 0 );
397
 
398
  foreach( $children as $child ) {
399
  if ( ! isset( $results[ $child ][ $taxonomy ] ) ) {
@@ -408,7 +411,7 @@ class SMC_Sync_Support {
408
  } else {
409
  $results[ $child ]['smc_sync'] = $results[ $child ][ $taxonomy ]['smc_sync'];
410
  }
411
- //error_log( __LINE__ ."' SMC_Sync_Support::get_terms ({$child}) \$results = " . var_export( $results, true ), 0 );
412
  }
413
  }
414
 
@@ -471,7 +474,7 @@ class SMC_Sync_Support {
471
  //error_log( __LINE__ . ' SMC_Sync_Support::sync_all $tax_action = ' . var_export( $tax_action, true ), 0 );
472
 
473
  $results = SMC_Sync_Support::sync_terms( $parent_id, $children, $tax_input, $tax_action );
474
- //error_log( __LINE__ ."' SMC_Sync_Support::sync_all {$parent_id} results = " . var_export( $results, true ), 0 );
475
  if ( $results['updated'] ) {
476
  $parent_count++;
477
  $children_count += $results['updated'];
@@ -558,14 +561,17 @@ class SMC_Sync_Support {
558
  }
559
 
560
  $taxonomy_obj = get_taxonomy( $taxonomy );
561
- //error_log( __LINE__ ."' SMC_Sync_Support::sync_terms \$taxonomy_obj = " . var_export( $taxonomy_obj, true ), 0 );
562
- if ( ! current_user_can( $taxonomy_obj->cap->assign_terms ) ) {
563
- continue;
 
 
 
 
 
564
  }
565
 
566
- /*
567
- * Arrays are term-ids, strings are slugs
568
- */
569
  $terms = $tax_inputs[ $taxonomy ];
570
  if ( is_array( $terms ) ) {
571
  $terms = array_filter( array_map( 'absint', $terms ) );
@@ -578,9 +584,7 @@ class SMC_Sync_Support {
578
  $terms = array_filter( array_map( 'trim', explode(',', $terms ) ) );
579
  }
580
 
581
- /*
582
- * Get the parent terms, compare for changes, update as necessary
583
- */
584
  $terms_before = array();
585
  if ( isset( $term_assignments[ $parent_id ][ $taxonomy ] ) ) {
586
  foreach( $term_assignments[ $parent_id ][ $taxonomy ] as $term_taxonomy_id => $term ) {
@@ -596,12 +600,10 @@ class SMC_Sync_Support {
596
  if ( $terms_after != $terms_before ) {
597
  $parent_changed = true;
598
  }
599
-
600
- //error_log( __LINE__ ."' SMC_Sync_Support::sync_terms \$terms[{$taxonomy}] = " . var_export( $terms, true ), 0 );
601
- //error_log( __LINE__ ."' SMC_Sync_Support::sync_terms \$parent_changed = " . var_export( $parent_changed, true ), 0 );
602
- /*
603
- * For each child, get the terms, compare for changes, update as necessary
604
- */
605
  foreach( $children as $child ) {
606
  $terms_before = array();
607
  if ( isset( $term_assignments[ $child ][ $taxonomy ] ) ) {
@@ -618,9 +620,9 @@ class SMC_Sync_Support {
618
  if ( $terms_after != $terms_before ) {
619
  $children_changed[ $child ] = $child;
620
  }
621
- //error_log( __LINE__ ."' SMC_Sync_Support::sync_terms \$terms_before[{$child}] = " . var_export( $terms_before, true ), 0 );
622
- //error_log( __LINE__ ."' SMC_Sync_Support::sync_terms \$terms_after = " . var_export( $terms_after, true ), 0 );
623
- //error_log( __LINE__ ."' SMC_Sync_Support::sync_terms \$children_changed = " . var_export( $children_changed, true ), 0 );
624
  }
625
  }
626
 
3
  * Manages synchronization between a parent post and its children.
4
  *
5
  * @package Smart_Media_Categories_Admin
6
+ * @author David Lingren <david@davidlingren.com>
7
  * @license GPL-2.0+
8
+ * @link http://davidlingren.com
9
  * @copyright 2014 David Lingren
10
  */
11
 
17
  * no need to create a new instance of the class.
18
  *
19
  * @package Smart_Media_Categories_Admin
20
+ * @author David Lingren <david@davidlingren.com>
21
  */
22
  class SMC_Sync_Support {
23
  /**
54
  *
55
  * @since 1.0.2
56
  *
57
+ * @param array Optional; ('post_type', 'smc_status', 'post_parents', 'fields')
58
+ * @param boolean Optional; true to flush the cache, e.g., when adding attachments
59
  *
60
  * @return array ( 'sync' => Synced posts, 'unsync' => Unsynced posts )
61
  */
62
+ public static function get_posts_per_view( $attr = NULL, $flush_cache = false ) {
63
  global $wpdb;
64
  static $save_attr = NULL, $posts_per_view = NULL;
65
 
66
+ if ( $flush_cache ) {
67
+ $save_attr = NULL;
68
+ $posts_per_view = NULL;
69
+ return array();
70
+ }
71
+
72
+ // Make sure $attr is an array, even if it's empty
73
  if ( empty( $attr ) ) {
74
  $attr = array();
75
  } elseif ( is_string( $attr ) ) {
76
  $attr = shortcode_parse_atts( $attr );
77
  }
78
 
79
+ // Create the PHP variables we need
 
 
80
  extract( shortcode_atts( array(
81
  'post_type' => 'post',
82
  'smc_status' => NULL, // 'sync', 'unsync'
286
 
287
  // Compute sync status
288
  foreach ( $assignments as $parent_id => $assignment ) {
289
+ //error_log( __LINE__ ." SMC_Sync_Support::get_posts_per_view (parent {$parent_id}) assignment = " . var_export( $assignment, true ), 0 );
290
  $parent_terms = $assignment['ttids'];
291
  unset( $assignment['ttids'] );
292
  unset( $assignment['terms'] );
396
  } else {
397
  $parent_terms = $results[ $parent_id ][ $taxonomy ] = array();
398
  }
399
+ //error_log( __LINE__ ." SMC_Sync_Support::get_terms ({$taxonomy}) \$parent_terms = " . var_export( $parent_terms, true ), 0 );
400
 
401
  foreach( $children as $child ) {
402
  if ( ! isset( $results[ $child ][ $taxonomy ] ) ) {
411
  } else {
412
  $results[ $child ]['smc_sync'] = $results[ $child ][ $taxonomy ]['smc_sync'];
413
  }
414
+ //error_log( __LINE__ ." SMC_Sync_Support::get_terms ({$child}) \$results = " . var_export( $results, true ), 0 );
415
  }
416
  }
417
 
474
  //error_log( __LINE__ . ' SMC_Sync_Support::sync_all $tax_action = ' . var_export( $tax_action, true ), 0 );
475
 
476
  $results = SMC_Sync_Support::sync_terms( $parent_id, $children, $tax_input, $tax_action );
477
+ //error_log( __LINE__ ." SMC_Sync_Support::sync_all {$parent_id} results = " . var_export( $results, true ), 0 );
478
  if ( $results['updated'] ) {
479
  $parent_count++;
480
  $children_count += $results['updated'];
561
  }
562
 
563
  $taxonomy_obj = get_taxonomy( $taxonomy );
564
+ //error_log( __LINE__ ." SMC_Sync_Support::sync_terms \$taxonomy_obj = " . var_export( $taxonomy_obj, true ), 0 );
565
+
566
+ // Check if logged-in user can assign terms
567
+ $current_user = wp_get_current_user();
568
+ if ( $current_user->ID ) {
569
+ if ( ! current_user_can( $taxonomy_obj->cap->assign_terms ) ) {
570
+ continue;
571
+ }
572
  }
573
 
574
+ // Arrays are term-ids, strings are slugs
 
 
575
  $terms = $tax_inputs[ $taxonomy ];
576
  if ( is_array( $terms ) ) {
577
  $terms = array_filter( array_map( 'absint', $terms ) );
584
  $terms = array_filter( array_map( 'trim', explode(',', $terms ) ) );
585
  }
586
 
587
+ // Get the parent terms, compare for changes, update as necessary
 
 
588
  $terms_before = array();
589
  if ( isset( $term_assignments[ $parent_id ][ $taxonomy ] ) ) {
590
  foreach( $term_assignments[ $parent_id ][ $taxonomy ] as $term_taxonomy_id => $term ) {
600
  if ( $terms_after != $terms_before ) {
601
  $parent_changed = true;
602
  }
603
+ //error_log( __LINE__ ." SMC_Sync_Support::sync_terms \$terms[{$taxonomy}] = " . var_export( $terms, true ), 0 );
604
+ //error_log( __LINE__ ." SMC_Sync_Support::sync_terms \$parent_changed = " . var_export( $parent_changed, true ), 0 );
605
+
606
+ // For each child, get the terms, compare for changes, update as necessary
 
 
607
  foreach( $children as $child ) {
608
  $terms_before = array();
609
  if ( isset( $term_assignments[ $child ][ $taxonomy ] ) ) {
620
  if ( $terms_after != $terms_before ) {
621
  $children_changed[ $child ] = $child;
622
  }
623
+ //error_log( __LINE__ ." SMC_Sync_Support::sync_terms \$terms_before[{$child}] = " . var_export( $terms_before, true ), 0 );
624
+ //error_log( __LINE__ ." SMC_Sync_Support::sync_terms \$terms_after = " . var_export( $terms_after, true ), 0 );
625
+ //error_log( __LINE__ ." SMC_Sync_Support::sync_terms \$children_changed = " . var_export( $children_changed, true ), 0 );
626
  }
627
  }
628
 
examples/plugins/smart-media-categories/admin/views/smc-admin.php CHANGED
@@ -6,9 +6,9 @@
6
  * The User Interface to the end user.
7
  *
8
  * @package Smart_Media_Categories_Admin
9
- * @author David Lingren <dlingren@comcast.net>
10
  * @license GPL-2.0+
11
- * @link @TODO http://example.com
12
  * @copyright 2014 David Lingren
13
  */
14
  ?>
6
  * The User Interface to the end user.
7
  *
8
  * @package Smart_Media_Categories_Admin
9
+ * @author David Lingren <david@davidlingren.com>
10
  * @license GPL-2.0+
11
+ * @link http://davidlingren.com
12
  * @copyright 2014 David Lingren
13
  */
14
  ?>
examples/plugins/smart-media-categories/public/class-smart-media-categories.php CHANGED
@@ -3,9 +3,9 @@
3
  * The Smart Media Categories (SMC) Plugin.
4
  *
5
  * @package Smart_Media_Categories
6
- * @author David Lingren <dlingren@comcast.net>
7
  * @license GPL-2.0+
8
- * @link @TODO http://example.com
9
  * @copyright 2014 David Lingren
10
  */
11
 
@@ -14,7 +14,7 @@
14
  * public-facing side of the WordPress site.
15
  *
16
  * @package Smart_Media_Categories
17
- * @author David Lingren <dlingren@comcast.net>
18
  */
19
  class Smart_Media_Categories {
20
 
@@ -25,7 +25,7 @@ class Smart_Media_Categories {
25
  *
26
  * @var string
27
  */
28
- const VERSION = '1.1.3';
29
 
30
  /**
31
  * Unique identifier for your plugin.
3
  * The Smart Media Categories (SMC) Plugin.
4
  *
5
  * @package Smart_Media_Categories
6
+ * @author David Lingren <david@davidlingren.com>
7
  * @license GPL-2.0+
8
+ * @link http://davidlingren.com
9
  * @copyright 2014 David Lingren
10
  */
11
 
14
  * public-facing side of the WordPress site.
15
  *
16
  * @package Smart_Media_Categories
17
+ * @author David Lingren <david@davidlingren.com>
18
  */
19
  class Smart_Media_Categories {
20
 
25
  *
26
  * @var string
27
  */
28
+ const VERSION = '1.1.5';
29
 
30
  /**
31
  * Unique identifier for your plugin.
examples/plugins/smart-media-categories/public/views/public.php CHANGED
@@ -6,9 +6,9 @@
6
  * frontend of the theme when the plugin is activated.
7
  *
8
  * @package Smart_Media_Categories
9
- * @author David Lingren <dlingren@comcast.net>
10
  * @license GPL-2.0+
11
- * @link @TODO http://example.com
12
  * @copyright 2014 David Lingren
13
  */
14
  ?>
6
  * frontend of the theme when the plugin is activated.
7
  *
8
  * @package Smart_Media_Categories
9
+ * @author David Lingren <david@davidlingren.com>
10
  * @license GPL-2.0+
11
+ * @link http://davidlingren.com
12
  * @copyright 2014 David Lingren
13
  */
14
  ?>
examples/plugins/smart-media-categories/smart-media-categories.php CHANGED
@@ -6,7 +6,7 @@
6
  * the terms of their parent post/page.
7
  *
8
  * @package Smart_Media_Categories
9
- * @author David Lingren <dlingren@comcast.net>
10
  * @license GPL-2.0+
11
  * @copyright 2014-2017 David Lingren
12
  *
@@ -14,7 +14,7 @@
14
  * Plugin Name: Smart Media Categories
15
  * Plugin URI: http://davidlingren.com/
16
  * Description: Assigns taxonomy terms to Media Library items based on the terms of their parent post/page.
17
- * Version: 1.1.3
18
  * Author: David Lingren
19
  * Author URI: http://davidlingren.com/
20
  * Text Domain: smart-media-categories
@@ -86,4 +86,12 @@ if ( is_admin() /* && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) */ ) {
86
  require_once( plugin_dir_path( __FILE__ ) . 'admin/class-smart-media-categories-admin.php' );
87
  add_action( 'plugins_loaded', array( 'Smart_Media_Categories_Admin', 'get_instance' ) );
88
  }
 
 
 
 
 
 
 
 
89
  ?>
6
  * the terms of their parent post/page.
7
  *
8
  * @package Smart_Media_Categories
9
+ * @author David Lingren <david@davidlingren.com>
10
  * @license GPL-2.0+
11
  * @copyright 2014-2017 David Lingren
12
  *
14
  * Plugin Name: Smart Media Categories
15
  * Plugin URI: http://davidlingren.com/
16
  * Description: Assigns taxonomy terms to Media Library items based on the terms of their parent post/page.
17
+ * Version: 1.1.5
18
  * Author: David Lingren
19
  * Author URI: http://davidlingren.com/
20
  * Text Domain: smart-media-categories
86
  require_once( plugin_dir_path( __FILE__ ) . 'admin/class-smart-media-categories-admin.php' );
87
  add_action( 'plugins_loaded', array( 'Smart_Media_Categories_Admin', 'get_instance' ) );
88
  }
89
+
90
+ // Look for Postie chron job
91
+ if ( isset( $_REQUEST['doing_wp_cron'] ) && class_exists( 'Postie', false ) ) {
92
+ require_once( plugin_dir_path( __FILE__ ) . 'admin/class-smart-media-categories-admin.php' );
93
+ add_action( 'postie_session_start', array( 'Smart_Media_Categories_Admin', 'get_instance' ) );
94
+ //error_log( __LINE__ . ' smart-media-categories.php performed postie add_action', 0 );
95
+ }
96
+
97
  ?>
examples/plugins/smart-media-categories/uninstall.php CHANGED
@@ -3,9 +3,9 @@
3
  * Fired when the plugin is uninstalled.
4
  *
5
  * @package Smart_Media_Categories
6
- * @author David Lingren <dlingren@comcast.net>
7
  * @license GPL-2.0+
8
- * @link @TODO http://example.com
9
  * @copyright 2014 David Lingren
10
  */
11
 
3
  * Fired when the plugin is uninstalled.
4
  *
5
  * @package Smart_Media_Categories
6
+ * @author David Lingren <david@davidlingren.com>
7
  * @license GPL-2.0+
8
+ * @link http://davidlingren.com
9
  * @copyright 2014 David Lingren
10
  */
11
 
includes/class-mla-core.php CHANGED
@@ -21,7 +21,7 @@ class MLACore {
21
  *
22
  * @var string
23
  */
24
- const CURRENT_MLA_VERSION = '2.92';
25
 
26
  /**
27
  * Slug for registering and enqueueing plugin style sheets (moved from class-mla-main.php)
21
  *
22
  * @var string
23
  */
24
+ const CURRENT_MLA_VERSION = '2.93';
25
 
26
  /**
27
  * Slug for registering and enqueueing plugin style sheets (moved from class-mla-main.php)
includes/class-mla-data.php CHANGED
@@ -1285,12 +1285,12 @@ class MLAData {
1285
  break;
1286
  case 'request':
1287
  if ( isset( $_REQUEST[ $value['value'] ] ) ) {
1288
- $record = sanitize_text_field( wp_unslash( $_REQUEST[ $value['value'] ] ) );
1289
  } else {
1290
  // Look for compound names, e.g., tax_input.attachment_category
1291
  $key_array = explode( '.', $value['value'] );
1292
  if ( 1 < count( $key_array ) && isset( $_REQUEST[ $key_array[0] ] ) ) {
1293
- $array_value = array( $key_array[0] => sanitize_text_field( wp_unslash( $_REQUEST[ $key_array[0] ] ) ) );
1294
  $record = MLAData::mla_find_array_element( $value['value'], $array_value, $value['option'], false, ',' );
1295
  } else {
1296
  $record = '';
1285
  break;
1286
  case 'request':
1287
  if ( isset( $_REQUEST[ $value['value'] ] ) ) {
1288
+ $record = wp_kses( wp_unslash( $_REQUEST[ $value['value'] ] ), 'post' );
1289
  } else {
1290
  // Look for compound names, e.g., tax_input.attachment_category
1291
  $key_array = explode( '.', $value['value'] );
1292
  if ( 1 < count( $key_array ) && isset( $_REQUEST[ $key_array[0] ] ) ) {
1293
+ $array_value = array( $key_array[0] => wp_unslash( $_REQUEST[ $key_array[0] ] ) ); // phpcs:ignore
1294
  $record = MLAData::mla_find_array_element( $value['value'], $array_value, $value['option'], false, ',' );
1295
  } else {
1296
  $record = '';
includes/class-mla-shortcode-support.php CHANGED
@@ -385,6 +385,7 @@ class MLAShortcode_Support {
385
  public static function mla_gallery_shortcode( $attr, $content = NULL ) {
386
  //error_log( __LINE__ . " mla_gallery_shortcode() _REQUEST = " . var_export( $_REQUEST, true ), 0 );
387
  //error_log( __LINE__ . " mla_gallery_shortcode() attr = " . var_export( $attr, true ), 0 );
 
388
  global $post;
389
 
390
  // Some do_shortcode callers may not have a specific post in mind
@@ -564,7 +565,9 @@ class MLAShortcode_Support {
564
  }
565
 
566
  $attr_value = str_replace( '{+', '[+', str_replace( '+}', '+]', $attr_value ) );
 
567
  $replacement_values = MLAData::mla_expand_field_level_parameters( $attr_value, $attr, $page_values );
 
568
  $attr[ $attr_key ] = MLAData::mla_parse_template( $attr_value, $replacement_values );
569
  }
570
  //error_log( __LINE__ . " mla_gallery_shortcode() attr = " . var_export( $attr, true ), 0 );
@@ -3933,16 +3936,15 @@ class MLAShortcode_Support {
3933
  $parts['path'] = '';
3934
  }
3935
 
3936
- $clean_query = '';
3937
  if ( empty( $parts['query'] ) ) {
3938
  // No existing query arguments; create query if requested
3939
  if ( false !== $value ) {
3940
- $clean_query = '?' . urlencode( $key ) . '=' . urlencode( $value );
3941
  }
3942
  } else {
3943
  parse_str( $parts['query'], $query );
3944
 
3945
- $query_prefix = '?';
3946
  $add_it = true;
3947
  foreach ( $query as $query_key => $query_value ) {
3948
  // Query argument names cannot have URL special characters
@@ -3957,17 +3959,23 @@ class MLAShortcode_Support {
3957
  $query_value = $value;
3958
  }
3959
 
3960
- $clean_query .= $query_prefix . urlencode( $query_key ) . '=' . urlencode( $query_value );
3961
- $query_prefix = '&';
3962
  }
3963
  }
3964
 
3965
  if ( $add_it && ( false !== $value ) ) {
3966
- $clean_query .= $query_prefix . urlencode( $key ) . '=' . urlencode( $value );
3967
  }
3968
  }
3969
 
3970
- return $parts['scheme'] . '://' . $parts['host'] . $parts['path'] . $clean_query;
 
 
 
 
 
 
 
3971
  }
3972
 
3973
  /**
@@ -4251,19 +4259,25 @@ class MLAShortcode_Support {
4251
  // Validate the query arguments to prevent cross-site scripting (reflection) attacks
4252
  $test_query = array();
4253
  parse_str( strval( $uri_query ), $test_query );
4254
-
4255
- $clean_query = '';
4256
- $query_prefix = '?';
4257
  foreach ( $test_query as $test_key => $test_value ) {
4258
  // Query argument names cannot have URL special characters
4259
  if ( $test_key === urldecode( $test_key ) ) {
4260
- $clean_query .= $query_prefix . urlencode( $test_key ) . '=' . urlencode( $test_value );
4261
- $query_prefix = '&';
4262
  }
4263
  }
4264
 
 
 
4265
  $markup_values['query_string'] = $clean_query;
4266
- $markup_values['request_uri'] = $uri_path . $markup_values['query_string'];
 
 
 
 
 
 
4267
  $markup_values['new_url'] = set_url_scheme( $markup_values['scheme'] . $markup_values['http_host'] . $markup_values['request_uri'] );
4268
  $markup_values = apply_filters( 'mla_gallery_pagination_values', $markup_values );
4269
 
385
  public static function mla_gallery_shortcode( $attr, $content = NULL ) {
386
  //error_log( __LINE__ . " mla_gallery_shortcode() _REQUEST = " . var_export( $_REQUEST, true ), 0 );
387
  //error_log( __LINE__ . " mla_gallery_shortcode() attr = " . var_export( $attr, true ), 0 );
388
+ //error_log( __LINE__ . " mla_gallery_shortcode() content = " . var_export( $content, true ), 0 );
389
  global $post;
390
 
391
  // Some do_shortcode callers may not have a specific post in mind
565
  }
566
 
567
  $attr_value = str_replace( '{+', '[+', str_replace( '+}', '+]', $attr_value ) );
568
+ //error_log( __LINE__ . " mla_gallery_shortcode() attr_value = " . var_export( $attr_value, true ), 0 );
569
  $replacement_values = MLAData::mla_expand_field_level_parameters( $attr_value, $attr, $page_values );
570
+ //error_log( __LINE__ . " mla_gallery_shortcode() replacement_values = " . var_export( $replacement_values, true ), 0 );
571
  $attr[ $attr_key ] = MLAData::mla_parse_template( $attr_value, $replacement_values );
572
  }
573
  //error_log( __LINE__ . " mla_gallery_shortcode() attr = " . var_export( $attr, true ), 0 );
3936
  $parts['path'] = '';
3937
  }
3938
 
3939
+ $clean_query = array();
3940
  if ( empty( $parts['query'] ) ) {
3941
  // No existing query arguments; create query if requested
3942
  if ( false !== $value ) {
3943
+ $clean_query[ $key ] = $value;
3944
  }
3945
  } else {
3946
  parse_str( $parts['query'], $query );
3947
 
 
3948
  $add_it = true;
3949
  foreach ( $query as $query_key => $query_value ) {
3950
  // Query argument names cannot have URL special characters
3959
  $query_value = $value;
3960
  }
3961
 
3962
+ $clean_query[ $query_key ] = $query_value;
 
3963
  }
3964
  }
3965
 
3966
  if ( $add_it && ( false !== $value ) ) {
3967
+ $clean_query[ $key ] = $value;
3968
  }
3969
  }
3970
 
3971
+ $clean_query = urlencode_deep( $clean_query );
3972
+ $clean_query = build_query( $clean_query );
3973
+
3974
+ if ( !empty( $clean_query ) ) {
3975
+ return $parts['scheme'] . '://' . $parts['host'] . $parts['path'] . '?' . $clean_query;
3976
+ } else {
3977
+ return $parts['scheme'] . '://' . $parts['host'] . $parts['path'];
3978
+ }
3979
  }
3980
 
3981
  /**
4259
  // Validate the query arguments to prevent cross-site scripting (reflection) attacks
4260
  $test_query = array();
4261
  parse_str( strval( $uri_query ), $test_query );
4262
+
4263
+ $clean_query = array();
 
4264
  foreach ( $test_query as $test_key => $test_value ) {
4265
  // Query argument names cannot have URL special characters
4266
  if ( $test_key === urldecode( $test_key ) ) {
4267
+ $clean_query[ $test_key ] = $test_value;
 
4268
  }
4269
  }
4270
 
4271
+ $clean_query = urlencode_deep( $clean_query );
4272
+ $clean_query = build_query( $clean_query );
4273
  $markup_values['query_string'] = $clean_query;
4274
+
4275
+ if ( !empty( $clean_query ) ) {
4276
+ $markup_values['request_uri'] = $uri_path . '?' . $clean_query;
4277
+ } else {
4278
+ $markup_values['request_uri'] = $uri_path;
4279
+ }
4280
+
4281
  $markup_values['new_url'] = set_url_scheme( $markup_values['scheme'] . $markup_values['http_host'] . $markup_values['request_uri'] );
4282
  $markup_values = apply_filters( 'mla_gallery_pagination_values', $markup_values );
4283
 
index.php CHANGED
@@ -6,17 +6,17 @@
6
  * will the rest of the plugin be loaded and run.
7
  *
8
  * @package Media Library Assistant
9
- * @version 2.92
10
  */
11
 
12
  /*
13
  Plugin Name: Media Library Assistant
14
  Plugin URI: http://davidlingren.com/#two
15
- Description: 20201124 Enhances the Media Library; powerful [mla_gallery] [mla_tag_cloud] [mla_term_list], taxonomy support, IPTC/EXIF/XMP/PDF processing, bulk/quick edit.
16
  Author: David Lingren
17
  Text Domain: media-library-assistant
18
  Domain Path: /languages
19
- Version: 2.92
20
  Author URI: http://davidlingren.com/
21
 
22
  Copyright 2011-2020 David Lingren
6
  * will the rest of the plugin be loaded and run.
7
  *
8
  * @package Media Library Assistant
9
+ * @version 2.93
10
  */
11
 
12
  /*
13
  Plugin Name: Media Library Assistant
14
  Plugin URI: http://davidlingren.com/#two
15
+ Description: Enhances the Media Library; powerful [mla_gallery] [mla_tag_cloud] [mla_term_list], taxonomy support, IPTC/EXIF/XMP/PDF processing, bulk/quick edit.
16
  Author: David Lingren
17
  Text Domain: media-library-assistant
18
  Domain Path: /languages
19
+ Version: 2.93
20
  Author URI: http://davidlingren.com/
21
 
22
  Copyright 2011-2020 David Lingren
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: media, media library, gallery, images, categories, tags, attachments, IPTC
5
  Requires at least: 3.5.0
6
  Tested up to: 5.6
7
  Requires PHP: 5.3
8
- Stable tag: 2.92
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -181,6 +181,13 @@ All of the MLA source code has been annotated with "DocBlocks", a special type o
181
 
182
  == Changelog ==
183
 
 
 
 
 
 
 
 
184
  = 2.92 =
185
  * Fix: Correct Media/Assistant Quick Edit error that deleted term assignments in the WordPress Categories taxonomy.
186
 
@@ -314,8 +321,8 @@ All of the MLA source code has been annotated with "DocBlocks", a special type o
314
 
315
  == Upgrade Notice ==
316
 
317
- = 2.92 =
318
- Correct Media/Assistant Quick Edit error that deleted term assignments in the WordPress Categories taxonomy.
319
 
320
  == Other Notes ==
321
 
5
  Requires at least: 3.5.0
6
  Tested up to: 5.6
7
  Requires PHP: 5.3
8
+ Stable tag: 2.93
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
181
 
182
  == Changelog ==
183
 
184
+ = 2.93 =
185
+ * New: The "MLA Simple Mapping Hooks Example" plugin has been updated so it will run when attachments are uploaded or updated by the WP/LR Sync plugin.
186
+ * New: For the "Smart Media Categories" example plugin, support has been added for the "Postie" plugin chron job that creates posts and attachments from an email.
187
+ * Fix: <strong>Correct defect in parsing `request:` substitution parameters containing compound names to access array elements, e.g., `tax_input`.</strong>
188
+ * Fix: <strong>For `[mla_gallery]` pagination shortcodes, correct defects in handling substitution parameters containing array values, e.g., `tax_input`.</strong>
189
+ * Fix: For the "Smart Media Categories" example plugin, term synchronization now works when multiple attachments are added to a parent in the same page load.
190
+
191
  = 2.92 =
192
  * Fix: Correct Media/Assistant Quick Edit error that deleted term assignments in the WordPress Categories taxonomy.
193
 
321
 
322
  == Upgrade Notice ==
323
 
324
+ = 2.93 =
325
+ IMPORTANT: Correct defects in handling array values, e.g., tax_input, in request: parameters and pagination controls. Example plugin enhancements. Two enhancements in all, three fixes.
326
 
327
  == Other Notes ==
328