@@ -1030,63 +1030,14 @@ private function get_image_size_within_tags( $tags, $relation ) {
10301030
10311031 // If this tag's post ID matches our relation's post ID, get the size from the slug and return it.
10321032 if ( $ post_id === $ set ['id ' ] ) {
1033- $ size = $ this ->get_size_from_slug ( $ set ['atts ' ]['data-size-slug ' ] );
1033+ $ size = $ this ->media -> get_size_from_slug ( $ set ['atts ' ]['data-size-slug ' ] );
10341034 return ( empty ( $ size ) ) ? array () : $ size ; // Return the size if found, otherwise return empty array.
10351035 }
10361036 }
10371037
10381038 return array ();
10391039 }
10401040
1041- /**
1042- * Get the size dimensions based on the size slug.
1043- *
1044- * @param string $size_slug The WordPress size slug (e.g., 'thumbnail', 'medium', 'large').
1045- *
1046- * @return array|null An array with width and height, or null if not found.
1047- */
1048- private function get_size_from_slug ( $ size_slug ) {
1049-
1050- // Get the dimensions of the WordPress size from options.
1051- $ size_width = get_option ( $ size_slug . '_size_w ' );
1052- $ size_height = get_option ( $ size_slug . '_size_h ' );
1053-
1054- // Check if we have valid dimensions. If not, return null to indicate no specific size.
1055- if ( empty ( $ size_width ) || empty ( $ size_height ) ) {
1056- return null ;
1057- }
1058-
1059- return array ( (int ) $ size_width , (int ) $ size_height );
1060- }
1061-
1062- /**
1063- * Extract WordPress image size from parent figure element.
1064- *
1065- * @param string $element The img tag element.
1066- * @param string $content The full HTML content.
1067- *
1068- * @return string|null The WordPress size slug (e.g., 'thumbnail', 'medium'), or null if not found.
1069- */
1070- private function get_size_slug_from_parent_figure_class ( $ element , $ content ) {
1071- // If content is empty, we can't find a parent figure, so return null.
1072- if ( empty ( $ content ) ) {
1073- return null ;
1074- }
1075-
1076- // Escape the element for use in regex.
1077- $ escaped_element = preg_quote ( $ element , '# ' );
1078-
1079- // Pattern: <figure class="...size-{size}...">...img element...[optional figcaption]</figure> .
1080- $ pattern = '#<figure\s+[^>]*class="[^"]*\bsize-(\w+)\b[^"]*"[^>]*>.*? ' . $ escaped_element . '.*?</figure>#is ' ;
1081-
1082- // Look for the parent figure tag that contains this img element.
1083- if ( preg_match ( $ pattern , $ content , $ matches ) ) {
1084- return $ matches [1 ];
1085- }
1086-
1087- return null ;
1088- }
1089-
10901041 /**
10911042 * Convert media tags from Local to Cloudinary, and register with String_Replace.
10921043 *
@@ -1311,7 +1262,7 @@ protected function standardize_tag( $tag_element ) {
13111262
13121263 // Retrieve size from the parent figure class of the image if it exists.
13131264 if ( ! empty ( $ tag_element ['atts ' ]['data-size-slug ' ] ) && 'img ' === $ tag_element ['tag ' ] ) {
1314- $ slug_size = $ this ->get_size_from_slug ( $ tag_element ['atts ' ]['data-size-slug ' ] );
1265+ $ slug_size = $ this ->media -> get_size_from_slug ( $ tag_element ['atts ' ]['data-size-slug ' ] );
13151266 if ( ! empty ( $ slug_size ) ) {
13161267 $ size = $ slug_size ;
13171268 }
@@ -1652,15 +1603,14 @@ public function parse_element( $element, $content = '' ) {
16521603
16531604 // If no size found in URL, try to extract from parent figure element so we can apply cropping if needed.
16541605 if ( empty ( $ has_size ) && $ has_sized_transformation ) {
1655- $ size_slug = $ this ->get_size_slug_from_parent_figure_class ( $ tag_element ['original ' ], $ content );
1606+ $ size_slug = $ this ->media -> get_size_slug_from_parent_figure_class ( $ tag_element ['original ' ], $ content );
16561607
16571608 if ( ! empty ( $ size_slug ) ) {
1658- $ has_size = $ this ->get_size_from_slug ( $ size_slug );
1609+ $ has_size = $ this ->media -> get_size_from_slug ( $ size_slug );
16591610 if ( ! empty ( $ has_size ) ) {
16601611 $ attributes ['data-size-slug ' ] = $ size_slug ;
16611612 $ tag_element ['width ' ] = $ has_size [0 ];
16621613 $ tag_element ['height ' ] = $ has_size [1 ];
1663-
16641614 }
16651615 }
16661616 }
0 commit comments