Changeset 2630300
- Timestamp:
- 11/16/2021 01:59:43 AM (4 years ago)
- Location:
- post-update-addon-gravity-forms
- Files:
-
- 6 edited
- 1 copied
-
tags/1.1.0 (copied) (copied from post-update-addon-gravity-forms/trunk)
-
tags/1.1.0/class-post-update-addon.php (modified) (1 diff)
-
tags/1.1.0/post-update-addon-gravity-forms.php (modified) (1 diff)
-
tags/1.1.0/readme.txt (modified) (4 diffs)
-
trunk/class-post-update-addon.php (modified) (1 diff)
-
trunk/post-update-addon-gravity-forms.php (modified) (1 diff)
-
trunk/readme.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
post-update-addon-gravity-forms/tags/1.1.0/class-post-update-addon.php
r2626503 r2630300 1 1 <?php 2 require_once('feed-settings.php'); 3 2 4 GFForms::include_feed_addon_framework(); 3 5 4 6 class ACGF_PostUpdateAddOn extends GFFeedAddOn { 5 protected $_version = ACGF_POST_UPDATE_ADDON_VERSION; 6 // Earlier versions maybe supported but not tested 7 protected $_min_gravityforms_version = '2.5'; 8 protected $_slug = 'post-update-addon-gravity-forms'; 9 protected $_path = 'post-update-addon-gravity-forms/post-update-addon-gravity-forms.php'; 10 protected $_full_path = __FILE__; 11 protected $_title = 'Post Update Add-On'; 12 protected $_short_title = 'Post Update'; 13 14 private static $_instance = null; 15 16 public static function get_instance() { 17 if(self::$_instance == null) { 18 self::$_instance = new ACGF_PostUpdateAddOn(); 19 } 20 return self::$_instance; 7 use ACGF_PostUpdateAddon_FeedSettings; 8 9 protected $_version = ACGF_POST_UPDATE_ADDON_VERSION; 10 // Earlier versions maybe supported but not tested 11 protected $_min_gravityforms_version = '2.5'; 12 protected $_slug = 'post-update-addon-gravity-forms'; 13 protected $_path = 'post-update-addon-gravity-forms/post-update-addon-gravity-forms.php'; 14 protected $_full_path = __FILE__; 15 protected $_title = 'Post Update Add-On'; 16 protected $_short_title = 'Post Update'; 17 18 private static $_instance = null; 19 20 public static function get_instance() { 21 if(self::$_instance == null) { 22 self::$_instance = new ACGF_PostUpdateAddOn(); 23 } 24 return self::$_instance; 25 } 26 27 public function init() { 28 parent::init(); 29 } 30 31 public function feed_list_columns() { 32 return array( 33 'feedName' => __('Name', $this->_slug) 34 ); 35 } 36 37 public function get_menu_icon() { 38 return 'dashicons-welcome-write-blog'; 39 } 40 41 public function process_feed($feed, $entry, $form) { 42 $this->log_debug(__METHOD__ . '(): Start feed processing'); 43 44 $raw_post_id = rgars($feed, 'meta/post_id'); 45 $raw_post_id = trim($raw_post_id); 46 47 // get current post id 48 $current_post_id = get_the_ID(); 49 if($current_post_id !== false) { 50 $raw_post_id = str_replace('{current_post_id}', $current_post_id, $raw_post_id); 51 } 52 53 // replacing merge tags 54 $raw_post_id = GFCommon::replace_variables($raw_post_id, $form, $entry, false, false, false); 55 if($raw_post_id == '') { 56 $this->log_debug(__METHOD__ . sprintf('(): After processing merge tags Post ID is an empty string. Cancelling feed processing.')); 57 return; 58 } 59 60 $post_id = intval($raw_post_id); 61 $this->log_debug(__METHOD__ . sprintf('(): Provided Post ID "%d"', $post_id)); 62 63 $postarr = array( 64 'ID' => $post_id 65 ); 66 67 // Preparing standard post fields 68 $this->prepare_author_id($feed, $entry, $form, $postarr); 69 $this->prepare_post_status($feed, $entry, $form, $postarr); 70 $this->prepare_post_title($feed, $entry, $form, $postarr); 71 $this->prepare_post_content($feed, $entry, $form, $postarr); 72 73 // Updating standard post fields 74 $this->process_standard_post_fields($postarr); 75 $this->process_featured_image($feed, $entry, $post_id); 76 77 // Updating taxonomies 78 $this->process_taxonomy($feed, $entry, 'category', $post_id); 79 $this->process_taxonomy($feed, $entry, 'post_tag', $post_id); 80 81 // Updating meta fields 82 $this->process_meta_fields($feed, $entry, $post_id); 83 } 84 85 function process_standard_post_fields($postarr) { 86 $this->log_debug(__METHOD__ . sprintf('(): Starting post update')); 87 $result = wp_update_post($postarr, $wp_error = true); 88 if(is_wp_error($result)) { 89 $this->log_debug(__METHOD__ . sprintf('(): ERROR: Can\'t update the post - "%s"', $result->get_error_message())); 90 return; 91 } 92 } 93 94 function process_featured_image($feed, $entry, $post_id) { 95 $this->log_debug(__METHOD__ . sprintf('(): Starting featured image update')); 96 $featured_image_field_id = rgars($feed, 'meta/featured_image_field'); 97 $featured_image_allow_empty = rgars($feed, 'meta/allow_empty_featured_image'); 98 //var_dump($featured_image_allow_empty); 99 if($featured_image_field_id === '') return; 100 101 $new_featured_image = rgar($entry, $featured_image_field_id); 102 //var_dump($new_featured_image); 103 if($new_featured_image === '') { 104 if($featured_image_allow_empty !== '1') return; 105 delete_post_thumbnail($post_id); 106 return; 107 } 108 $file = str_replace(get_site_url() . '/', ABSPATH, $new_featured_image); 109 //var_dump($file); 110 $filename = basename($file); 111 //var_dump($filename); 112 113 $upload_file = wp_upload_bits($filename, null, file_get_contents($file)); 114 if(!$upload_file['error']) { 115 $wp_filetype = wp_check_filetype($filename, null ); 116 $attachment = array( 117 'post_mime_type' => $wp_filetype['type'], 118 'post_parent' => $post_id, 119 'post_title' => preg_replace('/\.[^.]+$/', '', $filename), 120 'post_content' => '', 121 'post_status' => 'inherit' 122 ); 123 124 $attachment_id = wp_insert_attachment($attachment, $upload_file['file'], $post_id); 125 if(!is_wp_error($attachment_id)) { 126 $this->log_debug(__METHOD__ . sprintf('(): New featured image id: %d', $attachment_id)); 127 require_once(ABSPATH . 'wp-admin' . '/includes/image.php'); 128 $attachment_data = wp_generate_attachment_metadata($attachment_id, $upload_file['file']); 129 wp_update_attachment_metadata($attachment_id, $attachment_data); 130 131 set_post_thumbnail($post_id, $attachment_id); 21 132 } 22 23 public function init() { 24 parent::init(); 25 } 26 27 public function feed_settings_fields() { 28 return array( 29 array( 30 'title' => __('Post Update Settings', $this->_slug), 31 'fields' => array( 32 array( 33 'name' => 'feedName', 34 'label' => __('Name', $this->_slug), 35 'type' => 'text', 36 'required' => true, 37 'class' => 'medium', 38 ), 39 array( 40 'name' => 'post_id', 41 'label' => __('Post ID', $this->_slug), 42 'type' => 'text', 43 'required' => true, 44 'class' => 'medium merge-tag-support mt-position-right', 45 'tooltip' => __('Post ID, custom post ID or a merge tag that contains such id', $this->_slug) 46 ), 47 ), 48 ), 49 50 array( 51 'title' => __('Post Settings', $this->_slug), 52 'tooltip' => __('Empty value means - no change', $this->_slug), 53 'fields' => array( 54 array( 55 'name' => 'author_id', 56 'label' => __('Author ID', $this->_slug), 57 'type' => 'text', 58 'class' => 'medium merge-tag-support mt-position-right', 59 ), 60 array( 61 'name' => 'post_status', 62 'label' => __('Status', $this->_slug), 63 'type' => 'select', 64 'choices' => array( 65 array( 66 'label' => esc_html__('No Change', $this->_slug), 67 'value' => '' 68 ), 69 array( 70 'label' => esc_html__('Published', $this->_slug), 71 'value' => 'publish' 72 ), 73 array( 74 'label' => esc_html__('Draft', $this->_slug), 75 'value' => 'draft' 76 ), 77 array( 78 'label' => esc_html__('Pending', $this->_slug), 79 'value' => 'pending' 80 ), 81 array( 82 'label' => esc_html__('Private', $this->_slug), 83 'value' => 'private' 84 ), 85 array( 86 'label' => esc_html__('Trash', $this->_slug), 87 'value' => 'trash' 88 ) 89 ) 90 ), 91 92 ) 93 ), 94 95 array( 96 'title' => __('Post Content', $this->_slug), 97 'tooltip' => __('Empty value means - no change', $this->_slug), 98 'fields' => array( 99 array( 100 'name' => 'post_title', 101 'label' => __('Title', $this->_slug), 102 'type' => 'text', 103 'class' => 'medium merge-tag-support mt-position-right', 104 ), 105 array( 106 'name' => 'post_content', 107 'label' => __('Content', $this->_slug), 108 'type' => 'textarea', 109 'class' => 'merge-tag-support mt-position-right', 110 ), 111 array( 112 'name' => 'meta_field_map', 113 'label' => __('Custom Fields', $this->_slug), 114 'type' => 'dynamic_field_map', 115 'tooltip' => __('Enter custom field name and then select for field with value for it', $this->_slug) 116 ), 117 ) 118 ), 119 120 array( 121 'fields' => array( 122 array( 123 'name' => 'feed_condition', 124 'label' => __('Conditional Logic', $this->_slug), 125 'type' => 'feed_condition', 126 ) 127 ) 128 ), 129 130 ); 131 } 132 133 public function feed_list_columns() { 134 return array( 135 'feedName' => __('Name', $this->_slug) 136 ); 137 } 138 139 public function get_menu_icon() { 140 return 'dashicons-welcome-write-blog'; 141 } 142 143 public function process_feed($feed, $entry, $form) { 144 $this->log_debug(__METHOD__ . '(): Start feed processing'); 145 $raw_post_id = rgars($feed, 'meta/post_id'); 146 $raw_post_id = trim($raw_post_id); 147 $raw_post_id = GFCommon::replace_variables($raw_post_id, $form, $entry, false, false, false); 148 if($raw_post_id == '') { 149 $this->log_debug(__METHOD__ . sprintf('(): After processing merge tags Post ID is an empty string. Cancelling feed processing.')); 150 return; 151 } 152 $post_id = intval($raw_post_id); 153 154 $this->log_debug(__METHOD__ . sprintf('(): Provided Post ID "%d"', $post_id)); 155 156 $postarr = array( 157 'ID' => $post_id 158 ); 159 160 $author_id = rgars($feed, 'meta/author_id'); 161 $author_id = trim($author_id); 162 $author_id = GFCommon::replace_variables($author_id, $form, $entry, false, false, false); 163 if($author_id !== '') { 164 $postarr['post_author'] = $author_id; 165 $this->log_debug(__METHOD__ . sprintf('(): Provided Author ID "%d"', $author_id)); 166 } 167 168 $post_status = rgars($feed, 'meta/post_status'); 169 $post_status = trim($post_status); 170 $post_status = GFCommon::replace_variables($post_status, $form, $entry, false, false, false); 171 if($post_status !== '') { 172 $postarr['post_status'] = $post_status; 173 $this->log_debug(__METHOD__ . sprintf('(): Provided Post Status "%s"', $post_status)); 174 } 175 176 $post_title = rgars($feed, 'meta/post_title'); 177 $post_title = trim($post_title); 178 $post_title = GFCommon::replace_variables($post_title, $form, $entry, false, false, false); 179 if($post_title !== '') { 180 $postarr['post_title'] = $post_title; 181 $this->log_debug(__METHOD__ . sprintf('(): Provided Post Title "%s"', $post_title)); 182 } 183 184 $post_content = rgars($feed, 'meta/post_content'); 185 $post_content = trim($post_content); 186 $post_content = GFCommon::replace_variables($post_content, $form, $entry, false, false, false); 187 if($post_content !== '') { 188 $postarr['post_content'] = $post_content; 189 $this->log_debug(__METHOD__ . sprintf('(): Provided Post Content "%s"', $post_content)); 190 } 191 // Updating base post fields 192 $this->log_debug(__METHOD__ . sprintf('(): Starting post update')); 193 $result = wp_update_post($postarr, $wp_error = true); 194 if(is_wp_error($result)) { 195 $this->log_debug(__METHOD__ . sprintf('(): ERROR: Can\'t update the post - "%s"', $result->get_error_message())); 196 return; 197 } 198 199 // Updating meta fields 200 $this->log_debug(__METHOD__ . sprintf('(): Starting meta fields (custom fields) update')); 201 $metaMap = $this->get_dynamic_field_map_fields($feed, 'meta_field_map'); 202 foreach($metaMap as $target_meta_key => $source_field_id) { 203 $form_field_value = rgar($entry, $source_field_id); 204 update_post_meta($post_id, $target_meta_key, $form_field_value); 205 } 206 } 133 } else { 134 $this->log_debug(__METHOD__ . '(): Can\'t add new featured image: ' . $upload_file['error']); 135 } 136 } 137 138 function process_meta_fields($feed, $entry, $post_id) { 139 $this->log_debug(__METHOD__ . sprintf('(): Starting meta fields (custom fields) update')); 140 $metaMap = $this->get_dynamic_field_map_fields($feed, 'meta_field_map'); 141 foreach($metaMap as $target_meta_key => $source_field_id) { 142 $form_field_value = rgar($entry, $source_field_id); 143 update_post_meta($post_id, $target_meta_key, $form_field_value); 144 } 145 } 146 147 function process_taxonomy($feed, $entry, $taxonomy_name, $post_id) { 148 $tax_field_id = rgars($feed, 'meta/' . $taxonomy_name . '_tax_settings_field'); 149 // Checking if the field configured 150 if($tax_field_id === '') return; 151 152 $tax_mode = rgars($feed, 'meta/' . $taxonomy_name . '_tax_settings_mode'); 153 $new_tax_value = trim(rgar($entry, $tax_field_id)); 154 if($new_tax_value === '' && $tax_mode === 'override_not_empty') return; 155 156 wp_set_object_terms($post_id, explode(',', $new_tax_value), $taxonomy_name, $tax_mode === 'append'); 157 } 158 159 function prepare_author_id($feed, $entry, $form, &$postarr) { 160 $author_id = rgars($feed, 'meta/author_id'); 161 $author_id = trim($author_id); 162 $author_id = GFCommon::replace_variables($author_id, $form, $entry, false, false, false); 163 if($author_id !== '') { 164 $postarr['post_author'] = $author_id; 165 $this->log_debug(__METHOD__ . sprintf('(): Provided Author ID "%d"', $author_id)); 166 } 167 } 168 169 function prepare_post_status($feed, $entry, $form, &$postarr) { 170 $post_status = rgars($feed, 'meta/post_status'); 171 $post_status = trim($post_status); 172 $post_status = GFCommon::replace_variables($post_status, $form, $entry, false, false, false); 173 if($post_status !== '') { 174 $postarr['post_status'] = $post_status; 175 $this->log_debug(__METHOD__ . sprintf('(): Provided Post Status "%s"', $post_status)); 176 } 177 } 178 179 function prepare_post_title($feed, $entry, $form, &$postarr) { 180 $post_title = rgars($feed, 'meta/post_title'); 181 $post_title = trim($post_title); 182 $post_title = GFCommon::replace_variables($post_title, $form, $entry, false, false, false); 183 if($post_title !== '') { 184 $postarr['post_title'] = $post_title; 185 $this->log_debug(__METHOD__ . sprintf('(): Provided Post Title "%s"', $post_title)); 186 } 187 } 188 189 function prepare_post_content($feed, $entry, $form, &$postarr) { 190 $post_content = rgars($feed, 'meta/post_content'); 191 $post_content = trim($post_content); 192 $post_content = GFCommon::replace_variables($post_content, $form, $entry, false, false, false); 193 $allow_empty_content = rgars($feed, 'meta/allow_empty_content'); 194 if($allow_empty_content === '1' || $post_content !== '') { 195 $postarr['post_content'] = $post_content; 196 $this->log_debug(__METHOD__ . sprintf('(): Provided Post Content "%s"', $post_content)); 197 } 198 } 207 199 } 208 200 ?> -
post-update-addon-gravity-forms/tags/1.1.0/post-update-addon-gravity-forms.php
r2626503 r2630300 3 3 Plugin Name: Post Update Addon - Gravity Forms 4 4 Description: Update/Edit a post or a custom post type with Gravity Forms. 5 Version: 1. 0.15 Version: 1.1.0 6 6 Author: Alex Chernov 7 7 Author URI: https://alexchernov.com 8 8 Text Domain: post-update-addon-gravity-forms 9 9 */ 10 define('ACGF_POST_UPDATE_ADDON_VERSION', '1. 0.1');10 define('ACGF_POST_UPDATE_ADDON_VERSION', '1.1.0'); 11 11 12 12 add_action('gform_loaded', array('ACGF_PostUpdate_AddOn_Bootstrap', 'load'), 5); -
post-update-addon-gravity-forms/tags/1.1.0/readme.txt
r2626503 r2630300 4 4 Requires at least: 5.4.0 5 5 Tested up to: 5.8.1 6 Stable tag: 1. 0.16 Stable tag: 1.1.0 7 7 Requires PHP: 7.0 8 8 License: GPLv2 or later … … 19 19 - In form settings open "Post Update" 20 20 - Press "Add New" 21 - (Required) Enter "Post ID" number (OR insert a merge tag that will contain the ID)21 - (Required) Configure "Post ID" manually, from merge tag or use current page/post id 22 22 - Configure new Author ID 23 23 - Configure new Post Status 24 - Configure Featured Image 25 - Configure Tags & Categories 24 26 - Configure Post title and desctiption manually or insert merge tags 25 27 - Leave any of above empty to avoid changes … … 34 36 * Update "Post Title" 35 37 * Update "Post Content" 38 * Update "Featured Image" 39 * Update "Tags" and "Categories" 36 40 * Update "Post Custom Fields" 37 41 * Merge tags support … … 49 53 == Changelog == 50 54 55 = 1.1.0 = 56 - Current post target feature 57 - Update tags feature 58 - Update categories feature 59 - Update featured image feature 60 - Allow empty page content feature 61 - Allow empty featured image feature 62 - Code refactoring 63 - Minor UI improvements 64 51 65 = 1.0.1 = 52 66 * Making the plugin fully translatable -
post-update-addon-gravity-forms/trunk/class-post-update-addon.php
r2626503 r2630300 1 1 <?php 2 require_once('feed-settings.php'); 3 2 4 GFForms::include_feed_addon_framework(); 3 5 4 6 class ACGF_PostUpdateAddOn extends GFFeedAddOn { 5 protected $_version = ACGF_POST_UPDATE_ADDON_VERSION; 6 // Earlier versions maybe supported but not tested 7 protected $_min_gravityforms_version = '2.5'; 8 protected $_slug = 'post-update-addon-gravity-forms'; 9 protected $_path = 'post-update-addon-gravity-forms/post-update-addon-gravity-forms.php'; 10 protected $_full_path = __FILE__; 11 protected $_title = 'Post Update Add-On'; 12 protected $_short_title = 'Post Update'; 13 14 private static $_instance = null; 15 16 public static function get_instance() { 17 if(self::$_instance == null) { 18 self::$_instance = new ACGF_PostUpdateAddOn(); 19 } 20 return self::$_instance; 7 use ACGF_PostUpdateAddon_FeedSettings; 8 9 protected $_version = ACGF_POST_UPDATE_ADDON_VERSION; 10 // Earlier versions maybe supported but not tested 11 protected $_min_gravityforms_version = '2.5'; 12 protected $_slug = 'post-update-addon-gravity-forms'; 13 protected $_path = 'post-update-addon-gravity-forms/post-update-addon-gravity-forms.php'; 14 protected $_full_path = __FILE__; 15 protected $_title = 'Post Update Add-On'; 16 protected $_short_title = 'Post Update'; 17 18 private static $_instance = null; 19 20 public static function get_instance() { 21 if(self::$_instance == null) { 22 self::$_instance = new ACGF_PostUpdateAddOn(); 23 } 24 return self::$_instance; 25 } 26 27 public function init() { 28 parent::init(); 29 } 30 31 public function feed_list_columns() { 32 return array( 33 'feedName' => __('Name', $this->_slug) 34 ); 35 } 36 37 public function get_menu_icon() { 38 return 'dashicons-welcome-write-blog'; 39 } 40 41 public function process_feed($feed, $entry, $form) { 42 $this->log_debug(__METHOD__ . '(): Start feed processing'); 43 44 $raw_post_id = rgars($feed, 'meta/post_id'); 45 $raw_post_id = trim($raw_post_id); 46 47 // get current post id 48 $current_post_id = get_the_ID(); 49 if($current_post_id !== false) { 50 $raw_post_id = str_replace('{current_post_id}', $current_post_id, $raw_post_id); 51 } 52 53 // replacing merge tags 54 $raw_post_id = GFCommon::replace_variables($raw_post_id, $form, $entry, false, false, false); 55 if($raw_post_id == '') { 56 $this->log_debug(__METHOD__ . sprintf('(): After processing merge tags Post ID is an empty string. Cancelling feed processing.')); 57 return; 58 } 59 60 $post_id = intval($raw_post_id); 61 $this->log_debug(__METHOD__ . sprintf('(): Provided Post ID "%d"', $post_id)); 62 63 $postarr = array( 64 'ID' => $post_id 65 ); 66 67 // Preparing standard post fields 68 $this->prepare_author_id($feed, $entry, $form, $postarr); 69 $this->prepare_post_status($feed, $entry, $form, $postarr); 70 $this->prepare_post_title($feed, $entry, $form, $postarr); 71 $this->prepare_post_content($feed, $entry, $form, $postarr); 72 73 // Updating standard post fields 74 $this->process_standard_post_fields($postarr); 75 $this->process_featured_image($feed, $entry, $post_id); 76 77 // Updating taxonomies 78 $this->process_taxonomy($feed, $entry, 'category', $post_id); 79 $this->process_taxonomy($feed, $entry, 'post_tag', $post_id); 80 81 // Updating meta fields 82 $this->process_meta_fields($feed, $entry, $post_id); 83 } 84 85 function process_standard_post_fields($postarr) { 86 $this->log_debug(__METHOD__ . sprintf('(): Starting post update')); 87 $result = wp_update_post($postarr, $wp_error = true); 88 if(is_wp_error($result)) { 89 $this->log_debug(__METHOD__ . sprintf('(): ERROR: Can\'t update the post - "%s"', $result->get_error_message())); 90 return; 91 } 92 } 93 94 function process_featured_image($feed, $entry, $post_id) { 95 $this->log_debug(__METHOD__ . sprintf('(): Starting featured image update')); 96 $featured_image_field_id = rgars($feed, 'meta/featured_image_field'); 97 $featured_image_allow_empty = rgars($feed, 'meta/allow_empty_featured_image'); 98 //var_dump($featured_image_allow_empty); 99 if($featured_image_field_id === '') return; 100 101 $new_featured_image = rgar($entry, $featured_image_field_id); 102 //var_dump($new_featured_image); 103 if($new_featured_image === '') { 104 if($featured_image_allow_empty !== '1') return; 105 delete_post_thumbnail($post_id); 106 return; 107 } 108 $file = str_replace(get_site_url() . '/', ABSPATH, $new_featured_image); 109 //var_dump($file); 110 $filename = basename($file); 111 //var_dump($filename); 112 113 $upload_file = wp_upload_bits($filename, null, file_get_contents($file)); 114 if(!$upload_file['error']) { 115 $wp_filetype = wp_check_filetype($filename, null ); 116 $attachment = array( 117 'post_mime_type' => $wp_filetype['type'], 118 'post_parent' => $post_id, 119 'post_title' => preg_replace('/\.[^.]+$/', '', $filename), 120 'post_content' => '', 121 'post_status' => 'inherit' 122 ); 123 124 $attachment_id = wp_insert_attachment($attachment, $upload_file['file'], $post_id); 125 if(!is_wp_error($attachment_id)) { 126 $this->log_debug(__METHOD__ . sprintf('(): New featured image id: %d', $attachment_id)); 127 require_once(ABSPATH . 'wp-admin' . '/includes/image.php'); 128 $attachment_data = wp_generate_attachment_metadata($attachment_id, $upload_file['file']); 129 wp_update_attachment_metadata($attachment_id, $attachment_data); 130 131 set_post_thumbnail($post_id, $attachment_id); 21 132 } 22 23 public function init() { 24 parent::init(); 25 } 26 27 public function feed_settings_fields() { 28 return array( 29 array( 30 'title' => __('Post Update Settings', $this->_slug), 31 'fields' => array( 32 array( 33 'name' => 'feedName', 34 'label' => __('Name', $this->_slug), 35 'type' => 'text', 36 'required' => true, 37 'class' => 'medium', 38 ), 39 array( 40 'name' => 'post_id', 41 'label' => __('Post ID', $this->_slug), 42 'type' => 'text', 43 'required' => true, 44 'class' => 'medium merge-tag-support mt-position-right', 45 'tooltip' => __('Post ID, custom post ID or a merge tag that contains such id', $this->_slug) 46 ), 47 ), 48 ), 49 50 array( 51 'title' => __('Post Settings', $this->_slug), 52 'tooltip' => __('Empty value means - no change', $this->_slug), 53 'fields' => array( 54 array( 55 'name' => 'author_id', 56 'label' => __('Author ID', $this->_slug), 57 'type' => 'text', 58 'class' => 'medium merge-tag-support mt-position-right', 59 ), 60 array( 61 'name' => 'post_status', 62 'label' => __('Status', $this->_slug), 63 'type' => 'select', 64 'choices' => array( 65 array( 66 'label' => esc_html__('No Change', $this->_slug), 67 'value' => '' 68 ), 69 array( 70 'label' => esc_html__('Published', $this->_slug), 71 'value' => 'publish' 72 ), 73 array( 74 'label' => esc_html__('Draft', $this->_slug), 75 'value' => 'draft' 76 ), 77 array( 78 'label' => esc_html__('Pending', $this->_slug), 79 'value' => 'pending' 80 ), 81 array( 82 'label' => esc_html__('Private', $this->_slug), 83 'value' => 'private' 84 ), 85 array( 86 'label' => esc_html__('Trash', $this->_slug), 87 'value' => 'trash' 88 ) 89 ) 90 ), 91 92 ) 93 ), 94 95 array( 96 'title' => __('Post Content', $this->_slug), 97 'tooltip' => __('Empty value means - no change', $this->_slug), 98 'fields' => array( 99 array( 100 'name' => 'post_title', 101 'label' => __('Title', $this->_slug), 102 'type' => 'text', 103 'class' => 'medium merge-tag-support mt-position-right', 104 ), 105 array( 106 'name' => 'post_content', 107 'label' => __('Content', $this->_slug), 108 'type' => 'textarea', 109 'class' => 'merge-tag-support mt-position-right', 110 ), 111 array( 112 'name' => 'meta_field_map', 113 'label' => __('Custom Fields', $this->_slug), 114 'type' => 'dynamic_field_map', 115 'tooltip' => __('Enter custom field name and then select for field with value for it', $this->_slug) 116 ), 117 ) 118 ), 119 120 array( 121 'fields' => array( 122 array( 123 'name' => 'feed_condition', 124 'label' => __('Conditional Logic', $this->_slug), 125 'type' => 'feed_condition', 126 ) 127 ) 128 ), 129 130 ); 131 } 132 133 public function feed_list_columns() { 134 return array( 135 'feedName' => __('Name', $this->_slug) 136 ); 137 } 138 139 public function get_menu_icon() { 140 return 'dashicons-welcome-write-blog'; 141 } 142 143 public function process_feed($feed, $entry, $form) { 144 $this->log_debug(__METHOD__ . '(): Start feed processing'); 145 $raw_post_id = rgars($feed, 'meta/post_id'); 146 $raw_post_id = trim($raw_post_id); 147 $raw_post_id = GFCommon::replace_variables($raw_post_id, $form, $entry, false, false, false); 148 if($raw_post_id == '') { 149 $this->log_debug(__METHOD__ . sprintf('(): After processing merge tags Post ID is an empty string. Cancelling feed processing.')); 150 return; 151 } 152 $post_id = intval($raw_post_id); 153 154 $this->log_debug(__METHOD__ . sprintf('(): Provided Post ID "%d"', $post_id)); 155 156 $postarr = array( 157 'ID' => $post_id 158 ); 159 160 $author_id = rgars($feed, 'meta/author_id'); 161 $author_id = trim($author_id); 162 $author_id = GFCommon::replace_variables($author_id, $form, $entry, false, false, false); 163 if($author_id !== '') { 164 $postarr['post_author'] = $author_id; 165 $this->log_debug(__METHOD__ . sprintf('(): Provided Author ID "%d"', $author_id)); 166 } 167 168 $post_status = rgars($feed, 'meta/post_status'); 169 $post_status = trim($post_status); 170 $post_status = GFCommon::replace_variables($post_status, $form, $entry, false, false, false); 171 if($post_status !== '') { 172 $postarr['post_status'] = $post_status; 173 $this->log_debug(__METHOD__ . sprintf('(): Provided Post Status "%s"', $post_status)); 174 } 175 176 $post_title = rgars($feed, 'meta/post_title'); 177 $post_title = trim($post_title); 178 $post_title = GFCommon::replace_variables($post_title, $form, $entry, false, false, false); 179 if($post_title !== '') { 180 $postarr['post_title'] = $post_title; 181 $this->log_debug(__METHOD__ . sprintf('(): Provided Post Title "%s"', $post_title)); 182 } 183 184 $post_content = rgars($feed, 'meta/post_content'); 185 $post_content = trim($post_content); 186 $post_content = GFCommon::replace_variables($post_content, $form, $entry, false, false, false); 187 if($post_content !== '') { 188 $postarr['post_content'] = $post_content; 189 $this->log_debug(__METHOD__ . sprintf('(): Provided Post Content "%s"', $post_content)); 190 } 191 // Updating base post fields 192 $this->log_debug(__METHOD__ . sprintf('(): Starting post update')); 193 $result = wp_update_post($postarr, $wp_error = true); 194 if(is_wp_error($result)) { 195 $this->log_debug(__METHOD__ . sprintf('(): ERROR: Can\'t update the post - "%s"', $result->get_error_message())); 196 return; 197 } 198 199 // Updating meta fields 200 $this->log_debug(__METHOD__ . sprintf('(): Starting meta fields (custom fields) update')); 201 $metaMap = $this->get_dynamic_field_map_fields($feed, 'meta_field_map'); 202 foreach($metaMap as $target_meta_key => $source_field_id) { 203 $form_field_value = rgar($entry, $source_field_id); 204 update_post_meta($post_id, $target_meta_key, $form_field_value); 205 } 206 } 133 } else { 134 $this->log_debug(__METHOD__ . '(): Can\'t add new featured image: ' . $upload_file['error']); 135 } 136 } 137 138 function process_meta_fields($feed, $entry, $post_id) { 139 $this->log_debug(__METHOD__ . sprintf('(): Starting meta fields (custom fields) update')); 140 $metaMap = $this->get_dynamic_field_map_fields($feed, 'meta_field_map'); 141 foreach($metaMap as $target_meta_key => $source_field_id) { 142 $form_field_value = rgar($entry, $source_field_id); 143 update_post_meta($post_id, $target_meta_key, $form_field_value); 144 } 145 } 146 147 function process_taxonomy($feed, $entry, $taxonomy_name, $post_id) { 148 $tax_field_id = rgars($feed, 'meta/' . $taxonomy_name . '_tax_settings_field'); 149 // Checking if the field configured 150 if($tax_field_id === '') return; 151 152 $tax_mode = rgars($feed, 'meta/' . $taxonomy_name . '_tax_settings_mode'); 153 $new_tax_value = trim(rgar($entry, $tax_field_id)); 154 if($new_tax_value === '' && $tax_mode === 'override_not_empty') return; 155 156 wp_set_object_terms($post_id, explode(',', $new_tax_value), $taxonomy_name, $tax_mode === 'append'); 157 } 158 159 function prepare_author_id($feed, $entry, $form, &$postarr) { 160 $author_id = rgars($feed, 'meta/author_id'); 161 $author_id = trim($author_id); 162 $author_id = GFCommon::replace_variables($author_id, $form, $entry, false, false, false); 163 if($author_id !== '') { 164 $postarr['post_author'] = $author_id; 165 $this->log_debug(__METHOD__ . sprintf('(): Provided Author ID "%d"', $author_id)); 166 } 167 } 168 169 function prepare_post_status($feed, $entry, $form, &$postarr) { 170 $post_status = rgars($feed, 'meta/post_status'); 171 $post_status = trim($post_status); 172 $post_status = GFCommon::replace_variables($post_status, $form, $entry, false, false, false); 173 if($post_status !== '') { 174 $postarr['post_status'] = $post_status; 175 $this->log_debug(__METHOD__ . sprintf('(): Provided Post Status "%s"', $post_status)); 176 } 177 } 178 179 function prepare_post_title($feed, $entry, $form, &$postarr) { 180 $post_title = rgars($feed, 'meta/post_title'); 181 $post_title = trim($post_title); 182 $post_title = GFCommon::replace_variables($post_title, $form, $entry, false, false, false); 183 if($post_title !== '') { 184 $postarr['post_title'] = $post_title; 185 $this->log_debug(__METHOD__ . sprintf('(): Provided Post Title "%s"', $post_title)); 186 } 187 } 188 189 function prepare_post_content($feed, $entry, $form, &$postarr) { 190 $post_content = rgars($feed, 'meta/post_content'); 191 $post_content = trim($post_content); 192 $post_content = GFCommon::replace_variables($post_content, $form, $entry, false, false, false); 193 $allow_empty_content = rgars($feed, 'meta/allow_empty_content'); 194 if($allow_empty_content === '1' || $post_content !== '') { 195 $postarr['post_content'] = $post_content; 196 $this->log_debug(__METHOD__ . sprintf('(): Provided Post Content "%s"', $post_content)); 197 } 198 } 207 199 } 208 200 ?> -
post-update-addon-gravity-forms/trunk/post-update-addon-gravity-forms.php
r2626503 r2630300 3 3 Plugin Name: Post Update Addon - Gravity Forms 4 4 Description: Update/Edit a post or a custom post type with Gravity Forms. 5 Version: 1. 0.15 Version: 1.1.0 6 6 Author: Alex Chernov 7 7 Author URI: https://alexchernov.com 8 8 Text Domain: post-update-addon-gravity-forms 9 9 */ 10 define('ACGF_POST_UPDATE_ADDON_VERSION', '1. 0.1');10 define('ACGF_POST_UPDATE_ADDON_VERSION', '1.1.0'); 11 11 12 12 add_action('gform_loaded', array('ACGF_PostUpdate_AddOn_Bootstrap', 'load'), 5); -
post-update-addon-gravity-forms/trunk/readme.txt
r2626503 r2630300 4 4 Requires at least: 5.4.0 5 5 Tested up to: 5.8.1 6 Stable tag: 1. 0.16 Stable tag: 1.1.0 7 7 Requires PHP: 7.0 8 8 License: GPLv2 or later … … 19 19 - In form settings open "Post Update" 20 20 - Press "Add New" 21 - (Required) Enter "Post ID" number (OR insert a merge tag that will contain the ID)21 - (Required) Configure "Post ID" manually, from merge tag or use current page/post id 22 22 - Configure new Author ID 23 23 - Configure new Post Status 24 - Configure Featured Image 25 - Configure Tags & Categories 24 26 - Configure Post title and desctiption manually or insert merge tags 25 27 - Leave any of above empty to avoid changes … … 34 36 * Update "Post Title" 35 37 * Update "Post Content" 38 * Update "Featured Image" 39 * Update "Tags" and "Categories" 36 40 * Update "Post Custom Fields" 37 41 * Merge tags support … … 49 53 == Changelog == 50 54 55 = 1.1.0 = 56 - Current post target feature 57 - Update tags feature 58 - Update categories feature 59 - Update featured image feature 60 - Allow empty page content feature 61 - Allow empty featured image feature 62 - Code refactoring 63 - Minor UI improvements 64 51 65 = 1.0.1 = 52 66 * Making the plugin fully translatable
Note: See TracChangeset
for help on using the changeset viewer.