Changeset 3218193
- Timestamp:
- 01/07/2025 08:54:29 AM (15 months ago)
- Location:
- acf-galerie-4/trunk
- Files:
-
- 2 added
- 3 edited
-
acf-galerie-4.php (modified) (3 diffs)
-
assets/css/admin-style.css (added)
-
assets/js/admin-script.js (added)
-
class-acfg4-register-field-type.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
acf-galerie-4/trunk/acf-galerie-4.php
r3197857 r3218193 9 9 * License: GPL v2 or later 10 10 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 11 * Version: 1.3. 111 * Version: 1.3.2 12 12 * Domain Path: /lang 13 13 * Requires PHP: 7.4 … … 19 19 } 20 20 21 define( 'ACFG4_VERSION', '1.3. 1' );21 define( 'ACFG4_VERSION', '1.3.2' ); 22 22 define( 'ACFG4_PLUGIN', __FILE__ ); 23 23 define( 'ACFG4_PLUGIN_BASENAME', plugin_basename( ACFG4_PLUGIN ) ); … … 80 80 new acfg4_wpgraphql(); 81 81 }); 82 83 add_action('admin_head', 'acfg4_start_migration_nonce'); 84 function acfg4_start_migration_nonce() { 85 if ( !is_admin() ) return; 86 $nonce = wp_create_nonce('acfg4_start_migration_nonce'); 87 ?> 88 <script type="text/javascript"> 89 const acfg4_start_migration_nonce = "<?php echo $nonce; ?>"; 90 </script> 91 <?php 92 } 93 94 add_action('admin_enqueue_scripts', 'enqueue_plugin_admin_scripts'); 95 function enqueue_plugin_admin_scripts() { 96 wp_enqueue_script( 97 'acfg4-admin-script', 98 plugin_dir_url(__FILE__) . 'assets/js/admin-script.js', 99 ['jquery'], 100 '1.0.0', 101 true 102 ); 103 } 104 105 add_action('admin_enqueue_scripts', 'enqueue_plugin_admin_styles'); 106 function enqueue_plugin_admin_styles() { 107 wp_enqueue_style( 108 'acfg4-admin-css', 109 plugin_dir_url(__FILE__) . 'assets/css/admin-style.css', 110 [], 111 '1.0.0' 112 ); 113 } 114 115 add_action('wp_ajax_acfg4_start_migration', 'acfg4_start_migration'); 116 function acfg4_start_migration() { 117 global $wpdb; 118 $wpdb->query('START TRANSACTION'); 119 120 try { 121 $migrate_from = $_POST['migrate_from']; 122 123 if ( 124 isset( $_POST['nonce'] ) && 125 !wp_verify_nonce( $_POST['nonce'], 'acfg4_start_migration_nonce') ) 126 { 127 wp_send_json_error(['message' => "Nonce verification failed. Please try again."], 400); 128 } 129 130 if( !in_array( $migrate_from, [1, 2] ) ){ 131 wp_send_json_error(['message' => "Choose which plugin you want to migrate from."], 400); 132 } 133 134 $fields = $wpdb->get_results("SELECT * FROM {$wpdb->posts} WHERE post_type = 'acf-field'"); 135 136 foreach( $fields as $field ){ 137 $field_name = $field->post_excerpt; 138 $field_metadata = unserialize( $field->post_content ); 139 $field_type = $field_metadata['type']; 140 141 if( in_array( $field_type, ['photo_gallery', 'gallery'])){ 142 $field_metadata['type'] = 'galerie-4'; 143 $updated_content = serialize($field_metadata); 144 145 $wpdb->update( 146 $wpdb->posts, 147 array( 'post_content' => $updated_content ), 148 array( 'ID' => $field->ID ) 149 ); 150 151 //If ACF Photo Gallery Field, we want the ID's to be serialized. 152 if( $migrate_from == 1 ){ 153 $meta_fields = $wpdb->get_results( 154 $wpdb->prepare("SELECT * FROM {$wpdb->postmeta} WHERE meta_key = %s", $field_name ) 155 ); 156 157 foreach( $meta_fields as $meta){ 158 $meta_value = array_filter( explode(',', $meta->meta_value) ); 159 $meta_value_serialized = serialize( $meta_value ); 160 161 $wpdb->update( 162 $wpdb->postmeta, 163 array( 'meta_value' => $meta_value_serialized ), 164 array( 'meta_id' => $meta->meta_id ) 165 ); 166 } 167 } 168 } 169 } 170 171 $wpdb->query('COMMIT'); 172 173 wp_send_json_success([ 174 'message' => 'Migration has successfully completed.' 175 ]); 176 } catch (Exception $e) { 177 $wpdb->query('ROLLBACK'); 178 wp_send_json_error(['message' => $e->getMessage()], 500); 179 } 180 181 die(); 182 } -
acf-galerie-4/trunk/class-acfg4-register-field-type.php
r3197857 r3218193 88 88 89 89 parent::__construct(); 90 91 add_filter('plugin_action_links_acf-galerie-4/acf-galerie-4.php', array($this, 'add_custom_action_link')); 92 } 93 94 /** 95 * Add a custom action link next to "Deactivate" on the plugins page. 96 * 97 * @param array $links An array of existing action links. 98 * @return array Modified array of action links. 99 */ 100 function add_custom_action_link($links) { 101 // Add your custom link 102 $custom_link = '<a href="#" id="acfg4-migrate">Migrate</a>'; 103 104 // Append the custom link to the end of the array 105 $links[] = $custom_link; 106 107 return $links; 90 108 } 91 109 … … 220 238 */ 221 239 function format_value( $value, $post_id, $field ) { 240 if( empty( $value ) ) return array(); 241 222 242 $attachment_ids = array_map( 'intval', $value ); 223 243 224 if( empty( $attachment_ids ) ){ 225 return array(); 226 } 244 if( empty( $attachment_ids ) ) return array(); 227 245 228 246 return $this->transform( $attachment_ids ); -
acf-galerie-4/trunk/readme.txt
r3197857 r3218193 5 5 Requires at least: 5.8 6 6 Tested up to: 6.7 7 Stable tag: 1.3. 17 Stable tag: 1.3.2 8 8 Requires PHP: 7.0 9 9 License: GPLv2 or later … … 39 39 40 40 == Changelog == 41 = 1.3.2 = 42 * [Added] Migrate from ACF Gallery Field or ACF Gallery Pro to ACF Galerie 4. 43 41 44 = 1.3.1 = 42 45 * [Fixed] WordPress media library not opening in user edit screen
Note: See TracChangeset
for help on using the changeset viewer.