Plugin Directory

Changeset 3016263


Ignore:
Timestamp:
01/02/2024 04:42:10 AM (2 years ago)
Author:
alexusblack
Message:

added ability to cast field data to post_id

Location:
post-update-addon-gravity-forms
Files:
2 edited
5 copied

Legend:

Unmodified
Added
Removed
  • post-update-addon-gravity-forms/tags/1.1.4/class-post-update-addon.php

    r2662026 r3016263  
    143143    $metaMap = $this->get_dynamic_field_map_fields($feed, 'meta_field_map');
    144144    foreach($metaMap as $target_meta_key => $source_field_id) {
     145      // target meta key can contain "type" like <post_id>, extracting it
     146      if(strpos($target_meta_key, '<') !== false) {
     147        $target_meta_key_name = substr($target_meta_key, 0, strpos($target_meta_key, '<'));
     148        $target_meta_key_type = substr($target_meta_key, strpos($target_meta_key, '<') + 1, -1);
     149      } else {
     150        $target_meta_key_name = $target_meta_key;
     151        $target_meta_key_type = 'string';
     152      }
    145153      $form_field_value = '';
    146154      if(array_key_exists($source_field_id . '.1', $entry)) {
     
    155163        // this is just a plain value
    156164        $form_field_value = rgar($entry, $source_field_id);
     165        // type matching
     166        if($target_meta_key_type === 'post_id' && !is_numeric($form_field_value)) {
     167          if(filter_var($form_field_value, FILTER_VALIDATE_URL) !== false) {
     168            $attachment_id = attachment_url_to_postid($form_field_value);
     169            if($attachment_id) $form_field_value = $attachment_id;
     170          }
     171        }
    157172      }
    158173      if($update_non_empty_meta_fields_only && $form_field_value === '') continue;
    159       update_post_meta($post_id, $target_meta_key, $form_field_value);
     174      update_post_meta($post_id, $target_meta_key_name, $form_field_value);
    160175    }
    161176  }
  • post-update-addon-gravity-forms/tags/1.1.4/readme.txt

    r2662026 r3016263  
    33Tags: gravity forms, post update, update post, post edit, edit post, change post, post change
    44Requires at least: 5.4.0
    5 Tested up to: 5.8.2
    6 Stable tag: 1.1.3
     5Tested up to: 6.3.0
     6Stable tag: 1.1.4
    77Requires PHP: 7.0
    88License: GPLv2 or later
     
    5050== Changelog ==
    5151
     52= 1.1.4 =
     53- Added support for data type casting. Example: logo<post_id> in key for custom field. This would make sure that uploaded images saved as a post_id.
     54
    5255= 1.1.3 =
    5356- Support for custom taxonomies
  • post-update-addon-gravity-forms/trunk/class-post-update-addon.php

    r2662026 r3016263  
    143143    $metaMap = $this->get_dynamic_field_map_fields($feed, 'meta_field_map');
    144144    foreach($metaMap as $target_meta_key => $source_field_id) {
     145      // target meta key can contain "type" like <post_id>, extracting it
     146      if(strpos($target_meta_key, '<') !== false) {
     147        $target_meta_key_name = substr($target_meta_key, 0, strpos($target_meta_key, '<'));
     148        $target_meta_key_type = substr($target_meta_key, strpos($target_meta_key, '<') + 1, -1);
     149      } else {
     150        $target_meta_key_name = $target_meta_key;
     151        $target_meta_key_type = 'string';
     152      }
    145153      $form_field_value = '';
    146154      if(array_key_exists($source_field_id . '.1', $entry)) {
     
    155163        // this is just a plain value
    156164        $form_field_value = rgar($entry, $source_field_id);
     165        // type matching
     166        if($target_meta_key_type === 'post_id' && !is_numeric($form_field_value)) {
     167          if(filter_var($form_field_value, FILTER_VALIDATE_URL) !== false) {
     168            $attachment_id = attachment_url_to_postid($form_field_value);
     169            if($attachment_id) $form_field_value = $attachment_id;
     170          }
     171        }
    157172      }
    158173      if($update_non_empty_meta_fields_only && $form_field_value === '') continue;
    159       update_post_meta($post_id, $target_meta_key, $form_field_value);
     174      update_post_meta($post_id, $target_meta_key_name, $form_field_value);
    160175    }
    161176  }
  • post-update-addon-gravity-forms/trunk/readme.txt

    r2662026 r3016263  
    33Tags: gravity forms, post update, update post, post edit, edit post, change post, post change
    44Requires at least: 5.4.0
    5 Tested up to: 5.8.2
    6 Stable tag: 1.1.3
     5Tested up to: 6.3.0
     6Stable tag: 1.1.4
    77Requires PHP: 7.0
    88License: GPLv2 or later
     
    5050== Changelog ==
    5151
     52= 1.1.4 =
     53- Added support for data type casting. Example: logo<post_id> in key for custom field. This would make sure that uploaded images saved as a post_id.
     54
    5255= 1.1.3 =
    5356- Support for custom taxonomies
Note: See TracChangeset for help on using the changeset viewer.