Changeset 3237616
- Timestamp:
- 02/10/2025 06:44:00 AM (10 months ago)
- Location:
- acf-galerie-4/trunk
- Files:
-
- 2 added
- 1 deleted
- 3 edited
-
acf-galerie-4.php (modified) (2 diffs)
-
assets/js/admin-script.js (modified) (1 diff)
-
class-acfg4-register-field-type.php (deleted)
-
providers/class.migration.php (added)
-
providers/class.register-field-type.php (added)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
acf-galerie-4/trunk/acf-galerie-4.php
r3218193 r3237616 9 9 * License: GPL v2 or later 10 10 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 11 * Version: 1. 3.211 * Version: 1.4.0 12 12 * Domain Path: /lang 13 13 * Requires PHP: 7.4 … … 19 19 } 20 20 21 define( 'ACFG4_VERSION', '1.3.2' ); 22 define( 'ACFG4_PLUGIN', __FILE__ ); 23 define( 'ACFG4_PLUGIN_BASENAME', plugin_basename( ACFG4_PLUGIN ) ); 24 define( 'ACFG4_PLUGIN_NAME', trim( dirname( ACFG4_PLUGIN_BASENAME ), '/' ) ); 25 define( 'ACFG4_PLUGIN_DIR', untrailingslashit( dirname( ACFG4_PLUGIN ) ) ); 21 if ( ! class_exists( 'ACFG4' ) ) { 26 22 27 /** 28 * Loads the text domain for translation in the plugin. 29 * 30 * Hooks into the `init` action to: 31 * - Load the plugin's text domain for translation, allowing the plugin to support 32 * multiple languages. 33 * - Specifies the path to the translation files, located in the `lang` directory. 34 * - The `acf-galerie-4` text domain is used for translation strings within the plugin. 35 * 36 * This ensures that any text strings in the plugin can be translated according 37 * to the user's WordPress language settings. 38 * 39 * @return void 40 */ 41 add_action('init', 'acfg4_textdomain'); 42 function acfg4_textdomain() { 43 load_plugin_textdomain( 'acf-galerie-4', false, basename( dirname( __FILE__ ) ) . '/lang' ); 23 class ACFG4 { 24 25 public function initialize() { 26 $this->define( 'ACFG4_VERSION', '1.4.0' ); 27 $this->define( 'ACFG4_PLUGIN', __FILE__ ); 28 $this->define( 'ACFG4_PLUGIN_BASENAME', plugin_basename( ACFG4_PLUGIN ) ); 29 $this->define( 'ACFG4_PLUGIN_NAME', trim( dirname( ACFG4_PLUGIN_BASENAME ), '/' ) ); 30 $this->define( 'ACFG4_PLUGIN_DIR', untrailingslashit( dirname( ACFG4_PLUGIN ) ) ); 31 $this->define( 'ACFG4_PLUGIN_URL', plugin_dir_url( ACFG4_PLUGIN ) ); 32 $this->define( 'ACFG4_PLUGIN_TYPE', 'galerie-4'); 33 34 add_action('init', array($this, 'init')); 35 add_action( 'wpgraphql/acf/registry_init', array($this, 'wpgraphql')); 36 } 37 38 public function init() { 39 // Load the text domain for translation 40 $this->load_text_domain(); 41 42 // Include and instantiate the Migration class 43 $this->initialize_migration(); 44 45 // Register custom ACF field type 46 $this->register_acf_field_type(); 47 } 48 49 /** 50 * Loads the text domain for translation in the plugin. 51 * 52 * Hooks into the `init` action to: 53 * - Load the plugin's text domain for translation, allowing the plugin to support 54 * multiple languages. 55 * - Specifies the path to the translation files, located in the `lang` directory. 56 * - The `acf-galerie-4` text domain is used for translation strings within the plugin. 57 * 58 * This ensures that any text strings in the plugin can be translated according 59 * to the user's WordPress language settings. 60 * 61 * @return void 62 */ 63 public function load_text_domain() { 64 load_plugin_textdomain( 'acf-galerie-4', false, basename( dirname( __FILE__ ) ) . '/lang' ); 65 } 66 67 /** 68 * Includes and instantiates the Migration class to handle database migrations or other related tasks. 69 * 70 * @return void 71 */ 72 public function initialize_migration() { 73 require_once __DIR__ . '/providers/class.migration.php'; 74 new acfg4_migration(); 75 } 76 77 /** 78 * Registers the custom ACF field type during WordPress initialization. 79 * 80 * Hooks into the `init` action to: 81 * - Check if the `acf_register_field_type` function is available. 82 * This ensures compatibility with ACF Pro 5.0 or higher. 83 * - Require the file that defines the `acfg4_register_field_type` class. 84 * - Register the custom field type (`acfg4_register_field_type`) with ACF. 85 * 86 * This setup ensures that the `galerie-4` custom field type is properly 87 * initialized and available for use in ACF field groups. 88 * 89 * @return void 90 */ 91 public function register_acf_field_type() { 92 if ( ! function_exists( 'acf_register_field_type' ) ) return; 93 require_once __DIR__ . '/providers/class.register-field-type.php'; 94 acf_register_field_type( 'acfg4_register_field_type' ); 95 } 96 97 public function wpgraphql(){ 98 require_once __DIR__ . '/providers/class.wpgraphql.php'; 99 new acfg4_wpgraphql(); 100 } 101 102 /** 103 * Helper method to define constants. 104 */ 105 private function define( $name, $value ) { 106 if ( ! defined( $name ) ) { 107 define( $name, $value ); 108 } 109 } 110 } 111 112 // Instantiate. 113 $acfg4 = new ACFG4(); 114 $acfg4->initialize(); 44 115 } 45 46 /**47 * Registers the custom ACF field type during WordPress initialization.48 *49 * Hooks into the `init` action to:50 * - Check if the `acf_register_field_type` function is available.51 * This ensures compatibility with ACF Pro 5.0 or higher.52 * - Require the file that defines the `acfg4_register_field_type` class.53 * - Register the custom field type (`acfg4_register_field_type`) with ACF.54 *55 * This setup ensures that the `galerie-4` custom field type is properly56 * initialized and available for use in ACF field groups.57 *58 * @return void59 */60 add_action( 'init', 'acfg4_init_register_type' );61 function acfg4_init_register_type() {62 if ( ! function_exists( 'acf_register_field_type' ) ) return;63 require_once __DIR__ . '/class-acfg4-register-field-type.php';64 acf_register_field_type( 'acfg4_register_field_type' );65 }66 67 /**68 * Registers the custom ACF field type with WPGraphQL.69 *70 * Hooks into the `wpgraphql/acf/registry_init` action to initialize71 * support for the custom `galerie-4` ACF field type in WPGraphQL.72 *73 * The function:74 * - Requires the WPGraphQL integration class file.75 * - Instantiates the `acfg4_wpgraphql` class to register and configure76 * the field type within the WPGraphQL schema.77 */78 add_action( 'wpgraphql/acf/registry_init', function() {79 require_once __DIR__ . '/providers/class.wpgraphql.php';80 new acfg4_wpgraphql();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 <?php92 }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 true102 );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/assets/js/admin-script.js
r3218193 r3237616 117 117 } 118 118 ); 119 120 $(document).ready(function () { 121 if ( 122 typeof acf_gallery_4_pro_localize !== "undefined" && 123 acf_gallery_4_pro_localize?.license_activate === "1" 124 ) { 125 return; 126 } 127 128 $( 129 "body.acf-admin-page #wpcontent .acf-admin-toolbar .acf-nav-upgrade-wrap" 130 ).prepend( 131 `<a target="_blank" href="https://galerie4.com/" class="btn-upgrade acf-admin-toolbar-upgrade-btn" style="margin-right:15px;"> 132 <p>Upgrade to ACF Galerie 4 Pro</p> 133 </a>` 134 ); 135 }); 119 136 })(jQuery); -
acf-galerie-4/trunk/readme.txt
r3218195 r3237616 5 5 Requires at least: 5.8 6 6 Tested up to: 6.7 7 Stable tag: 1. 3.27 Stable tag: 1.4.0 8 8 Requires PHP: 7.0 9 9 License: GPLv2 or later … … 25 25 6. **GraphQL Support**: Unlock powerful and flexible queries for your custom galleries with [WPGraphQL](https://wordpress.org/plugins/wp-graphql/) and [WPGraphQL for ACF](https://wordpress.org/plugins/wpgraphql-acf/) integration. 26 26 27 === How to use? === 28 1. Using "Advanced Custom Fields (ACF)", create a "Field Group". 29 2. Create a new field and choose the field type as "Galerie 4". 30 3. After saving, go to the post/page where the field group is showing. 31 4. You'll see the ACF field group, click on the "Add Media" button, choose media you want to add. 32 5. Save the post/page. 33 6. To show the media gallery on the front-end, use ACF's built-in function [get_field()](https://www.advancedcustomfields.com/resources/get_field/). 27 === Links === 28 * [Website](https://galerie4.com/?utm_source=wordpress.org&utm_medium=free) 29 * [Support](https://galerie4.com/support) 30 * [ACF Galerie 4 Pro](https://galerie4.com/?utm_source=wordpress.org&utm_medium=free&utm_campaign=upgrade) 31 32 = PRO = 33 The ACF Galerie 4 plugin is also available in a professional version, offering more features, enhanced functionality, and greater flexibility. ACF Galerie 4 Pro includes: 34 35 * Support for Elemetor 36 * Support for Bricks Builder 37 * Lifetime updates 38 * Priority Support 39 40 [Upgrade to ACF Galerie 4 Pro 🚀](https://galerie4.com/?utm_source=wordpress.org&utm_medium=free&utm_campaign=upgrade) 34 41 35 42 == Installation == … … 39 46 40 47 == Changelog == 48 = 1.4.0 = 49 * [Added] Wrapped the main function inside a class to prevent conflicts with other WordPress functions. 50 * [Added] Added upgrade links to ACF Galerie 4 Pro for better user experience and visibility. 51 41 52 = 1.3.2 = 42 53 * [Added] Migrate from ACF Photo Gallery Field or ACF Gallery Pro to ACF Galerie 4.
Note: See TracChangeset
for help on using the changeset viewer.