تابع wc_get_product_attachment_props دریافت اطلاعات تصویر همچون alt و کپشن

تابع ووکامرسی wc_get_product_attachment_props – دریافت اطلاعات تصویر همچون alt و کپشن
Syntax – سینتکس
(array) wc_get_product_attachment_props( (constant) $attachment_id = null, (bool) $product = false );
Parameters – پارامتر ها (2)
- 1- $attachment_id (constant)
- 2- $product (bool)
Usage – نحوه استفاده
if ( !function_exists( 'wc_get_product_attachment_props' ) ) { require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-product-functions.php'; } // The attachment id. $attachment_id = null; // The product. $product = false; // NOTICE! Understand what this does before running. $result = wc_get_product_attachment_props($attachment_id, $product);
Defined – محل تعریف
/includes/wc-product-functions.php
function wc_get_product_attachment_props( $attachment_id = null, $product = false ) { $props = array( 'title' => '', 'caption' => '', 'url' => '', 'alt' => '', 'src' => '', 'srcset' => false, 'sizes' => false, ); if ( $attachment = get_post( $attachment_id ) ) { $props['title'] = trim( strip_tags( $attachment->post_title ) ); $props['caption'] = trim( strip_tags( $attachment->post_excerpt ) ); $props['url'] = wp_get_attachment_url( $attachment_id ); $props['alt'] = trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) ); // Large version. $src = wp_get_attachment_image_src( $attachment_id, 'full' ); $props['full_src'] = $src[0]; $props['full_src_w'] = $src[1]; $props['full_src_h'] = $src[2]; // Thumbnail version. $src = wp_get_attachment_image_src( $attachment_id, 'shop_thumbnail' ); $props['thumb_src'] = $src[0]; $props['thumb_src_w'] = $src[1]; $props['thumb_src_h'] = $src[2]; // Image source. $src = wp_get_attachment_image_src( $attachment_id, 'shop_single' ); $props['src'] = $src[0]; $props['src_w'] = $src[1]; $props['src_h'] = $src[2]; $props['srcset'] = function_exists( 'wp_get_attachment_image_srcset' ) ? wp_get_attachment_image_srcset( $attachment_id, 'shop_single' ) : false; $props['sizes'] = function_exists( 'wp_get_attachment_image_sizes' ) ? wp_get_attachment_image_sizes( $attachment_id, 'shop_single' ) : false; // Alt text fallbacks $props['alt'] = empty( $props['alt'] ) ? $props['caption'] : $props['alt']; $props['alt'] = empty( $props['alt'] ) ? trim( strip_tags( $attachment->post_title ) ) : $props['alt']; $props['alt'] = empty( $props['alt'] ) && $product ? trim( strip_tags( get_the_title( $product->ID ) ) ) : $props['alt']; } return $props; }
versions – نسخه ها
از نسخه : 2.6.0
نسخه فعلی : 3.0.6
دیگر نسخه ها : 3.0.6 , 3.0.5 , 3.0.4 , 3.0.3 , 3.0.2
ارسال نظر