generated from pascalmartineau/wp-skeleton
feat: imageCenter field
This commit is contained in:
22
wp-content/themes/ccat/includes/graphql/image-center.php
Normal file
22
wp-content/themes/ccat/includes/graphql/image-center.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
// Add 'imageCenter' field to MediaItem type
|
||||
add_action( 'graphql_register_types', 'ccat_register_image_center_graphql_field' );
|
||||
function ccat_register_image_center_graphql_field() {
|
||||
register_graphql_field(
|
||||
'MediaItem',
|
||||
'imageCenter',
|
||||
array(
|
||||
'type' => 'String',
|
||||
'description' => 'Image center point for cropping (e.g., "50% 50%")',
|
||||
'resolve' => function ( $source, $args, $context, $info ) {
|
||||
if ( empty( $position = get_post_meta( $source->databaseId, 'theiaSmartThumbnails_position', true ) ) ) {
|
||||
return null;
|
||||
}
|
||||
$x = round( $position[0], 4 );
|
||||
$y = round( $position[1], 4 );
|
||||
return "$x% $y%";
|
||||
},
|
||||
)
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user