Changeset 3197083
- Timestamp:
- 11/26/2024 06:52:59 AM (13 months ago)
- Location:
- acf-galerie-4/trunk
- Files:
-
- 4 added
- 3 edited
-
LICENSE (added)
-
acf-galerie-4.php (modified) (5 diffs)
-
class-acfg4-register-field-type.php (modified) (8 diffs)
-
providers (added)
-
providers/class.wpgraphql.php (added)
-
providers/index.php (added)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
acf-galerie-4/trunk/acf-galerie-4.php
r3179670 r3197083 9 9 * License: GPL v2 or later 10 10 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 11 * Version: 1. 2.011 * Version: 1.3.0 12 12 * Domain Path: /lang 13 13 * Requires PHP: 7.4 … … 19 19 } 20 20 21 define( 'ACFG4_VERSION', '1. 2.0' );21 define( 'ACFG4_VERSION', '1.3.0' ); 22 22 define( 'ACFG4_PLUGIN', __FILE__ ); 23 23 define( 'ACFG4_PLUGIN_BASENAME', plugin_basename( ACFG4_PLUGIN ) ); … … 25 25 define( 'ACFG4_PLUGIN_DIR', untrailingslashit( dirname( ACFG4_PLUGIN ) ) ); 26 26 27 //Load the text domain 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 */ 28 41 add_action('init', 'acfg4_textdomain'); 29 42 function acfg4_textdomain() { … … 31 44 } 32 45 33 //Registers the ACF field type. 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 properly 56 * initialized and available for use in ACF field groups. 57 * 58 * @return void 59 */ 34 60 add_action( 'init', 'acfg4_init_register_type' ); 35 61 function acfg4_init_register_type() { … … 38 64 acf_register_field_type( 'acfg4_register_field_type' ); 39 65 } 66 67 /** 68 * Registers the custom ACF field type with WPGraphQL. 69 * 70 * Hooks into the `wpgraphql/acf/registry_init` action to initialize 71 * 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 configure 76 * 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 }); -
acf-galerie-4/trunk/class-acfg4-register-field-type.php
r3179670 r3197083 24 24 25 25 /** 26 * Constructor. 26 * Initializes the custom field type with its properties and defaults. 27 * 28 * This constructor sets up the essential information and configurations 29 * for the custom ACF field type `galerie-4`. It defines: 30 * - Name and label for identification and display in the UI. 31 * - Category under which the field type is listed in the picker. 32 * - Description for the field type, displayed in field settings. 33 * - Links to documentation and tutorial resources for user guidance. 34 * - Default settings specific to this field type. 35 * - Environment settings, including the plugin version. 36 * 37 * Inherits functionality from the parent field type class. 27 38 */ 28 39 public function __construct() { … … 44 55 * The category the field appears within in the field type picker. 45 56 */ 46 $this->category = 'content'; // basic | content | choice | relational | jquery | layout | CUSTOM GROUP NAME57 $this->category = 'content'; 47 58 48 59 /** … … 75 86 'version' => ACFG4_VERSION, 76 87 ); 77 88 78 89 parent::__construct(); 79 90 } … … 103 114 if ( !empty( $field ) and !empty( $field['value'] ) ) { 104 115 $attachment_ids = array_map( 'intval', $field['value'] ); 105 $attachments = $this-> get_attachments( $attachment_ids );116 $attachments = $this->transform( $attachment_ids ); 106 117 } 107 118 ?> … … 154 165 } 155 166 167 /** 168 * Validates and processes the submitted field value before saving it. 169 * 170 * This function performs the following tasks: 171 * - Verifies the nonce for security to ensure the request is valid. 172 * - Checks the presence of the required POST data for the field. 173 * - Sanitizes and processes the input value into an array of integers. 174 * 175 * If the nonce validation fails or required data is missing, the function 176 * terminates execution to prevent further processing. 177 * 178 * @param mixed $value The raw value submitted for the field. 179 * @param int $post_id The ID of the post where the field is being updated. 180 * @param array $field The field configuration array, containing metadata about the field. 181 * 182 * @return array An array of sanitized integer values representing the field's data. 183 */ 156 184 function update_value( $value, $post_id, $field ) { 157 185 $field_type = $field['type']; … … 176 204 } 177 205 206 /** 207 * Formats the field value into a structured attachment data array. 208 * 209 * Converts raw attachment IDs into integer values, validates them, and 210 * transforms the data into a detailed structure with attachment metadata. 211 * 212 * - If the input `$value` is empty, an empty array is returned. 213 * - Valid attachment IDs are passed to the `transform` method for processing. 214 * 215 * @param mixed $value The raw field value, typically an array of attachment IDs. 216 * @param int $post_id The ID of the post where the field is being used. 217 * @param array $field The field configuration array. 218 * 219 * @return array Structured attachment data generated by the `transform` method. 220 */ 178 221 function format_value( $value, $post_id, $field ) { 179 if ( empty($value) ) die();180 181 222 $attachment_ids = array_map( 'intval', $value ); 182 223 183 return $this->get_attachments( $attachment_ids ); 184 } 185 186 function get_attachments( $attachment_ids ){ 187 $attachments = get_posts( 188 array( 189 'post_type' => 'attachment', 190 'post__in' => $attachment_ids, 191 'post_status' => 'inherit', 192 'orderby' => 'post__in', 193 'order' => 'ASC', 194 'numberposts' => -1 195 ) 196 ); 197 224 if( empty( $attachment_ids ) ){ 225 return array(); 226 } 227 228 return $this->transform( $attachment_ids ); 229 } 230 231 /** 232 * Transforms attachment IDs into structured attachment and metadata information. 233 * 234 * Fetches attachment data for the provided IDs and formats the output 235 * to include detailed metadata such as file information, dimensions, 236 * MIME types, and URLs for different image sizes. 237 * 238 * - Non-image attachments include basic file metadata such as MIME type and file size. 239 * - Image attachments include metadata for the full image as well as additional sizes. 240 * 241 * Sensitive fields like `post_password` and `guid` are removed from the attachment object. 242 * 243 * @param array $attachment_ids List of attachment IDs to retrieve and transform. 244 * 245 * @return array A structured array containing attachment data and metadata. 246 * Each element includes: 247 * - 'attachment': The sanitized attachment object. 248 * - 'metadata': An array of metadata details (e.g., file size, URLs). 249 */ 250 public function transform( $attachment_ids ){ 198 251 $attachment_data = array(); 252 $attachments = $this->get_attachments( $attachment_ids ); 199 253 200 254 if ( !empty( $attachments ) ) { … … 247 301 } 248 302 303 /** 304 * Generates a sanitized CSS class name for an ACF field. 305 * 306 * Prepends a prefix to the provided class name and ensures it is properly escaped. 307 * 308 * @param string $class The class name to be prefixed and sanitized. 309 * 310 * @return string The sanitized and prefixed CSS class name. 311 */ 249 312 function add_class($class){ 250 313 return esc_attr("acf-galerie-4-{$class}"); 251 314 } 252 315 316 /** 317 * Prepares an array of HTML attributes for an ACF field. 318 * 319 * Generates attributes including an ID, a nonce for security, 320 * and a CSS class for the ACF field. 321 * 322 * @param array $field The field configuration array containing field details. 323 * 324 * @return array Associative array of sanitized HTML attributes for the field. 325 */ 253 326 function add_attrs($field){ 254 327 return array( … … 295 368 } 296 369 } 370 371 /** 372 * Retrieves attachment posts based on the provided attachment IDs. 373 * 374 * Fetches attachment posts matching the given IDs in their original order, 375 * with a post type of 'attachment' and a status of 'inherit'. 376 * 377 * @param array $attachment_ids List of attachment post IDs to retrieve. 378 * 379 * @return array List of attachment posts that match the criteria. 380 */ 381 public function get_attachments( $attachment_ids ){ 382 return get_posts( 383 array( 384 'post_type' => 'attachment', 385 'post__in' => $attachment_ids, 386 'post_status' => 'inherit', 387 'orderby' => 'post__in', 388 'order' => 'ASC', 389 'numberposts' => -1 390 ) 391 ); 392 } 393 297 394 } -
acf-galerie-4/trunk/readme.txt
r3179670 r3197083 4 4 Tags: acf, gallery, images, videos, media 5 5 Requires at least: 5.8 6 Tested up to: 6. 67 Stable tag: 1. 2.06 Tested up to: 6.7 7 Stable tag: 1.3.0 8 8 Requires PHP: 7.0 9 9 License: GPLv2 or later … … 36 36 37 37 == Changelog == 38 = 1.3.0 = 39 * [Added] support for GraphQL 40 * [Fixed] issue with get_fields() 41 38 42 = 1.2.0 = 39 43 * [Added] support for taxonomy
Note: See TracChangeset
for help on using the changeset viewer.