PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.16
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.16
1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 1.10.0 1.9.17 1.9.15 1.9.16 1.9.14 1.9.13 All 162 releases
woocommerce-pos / includes / Services / Store_Logo_Resolver.php

Store_Logo_Resolver.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.16, at includes/Services/Store_Logo_Resolver.php

86 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Shared store/site logo resolution.
4 *
5 * @package WCPOS\WooCommercePOS\Services
6 */
7
8 namespace WCPOS\WooCommercePOS\Services;
9
10 /**
11 * Store_Logo_Resolver class.
12 *
13 * Resolves the display logo for a POS store using explicit-store-logo
14 * precedence then an optional site-logo fallback.
15 */
16 class Store_Logo_Resolver {
17 /**
18 * Resolve the logo URL for the given POS store.
19 *
20 * Precedence:
21 * 1. Explicit store logo (post thumbnail on the store CPT).
22 * 2. WordPress site logo (theme `custom_logo`) – unless the store opts out.
23 * 3. null when nothing matches.
24 *
25 * @param object $pos_store Active POS store object.
26 *
27 * @return string|null
28 */
29 public static function resolve( $pos_store ): ?string {
30 $store_id = method_exists( $pos_store, 'get_id' ) ? (int) $pos_store->get_id() : 0;
31 $use_site_logo = true;
32 if ( $store_id > 0 ) {
33 $use_site_logo = 'no' !== get_post_meta( $store_id, '_use_site_logo', true );
34 }
35
36 $explicit_logo_url = self::get_explicit_store_logo_url( $store_id );
37 if ( null !== $explicit_logo_url ) {
38 return $explicit_logo_url;
39 }
40
41 if ( ! $use_site_logo ) {
42 return null;
43 }
44
45 return self::get_site_logo_url();
46 }
47
48 /**
49 * Get explicit store logo URL from the store post thumbnail.
50 *
51 * @param int $store_id Active POS store ID.
52 *
53 * @return string|null
54 */
55 private static function get_explicit_store_logo_url( int $store_id ): ?string {
56 if ( $store_id <= 0 ) {
57 return null;
58 }
59
60 $thumbnail_id = (int) get_post_thumbnail_id( $store_id );
61 if ( $thumbnail_id <= 0 ) {
62 return null;
63 }
64
65 $logo_src = wp_get_attachment_image_src( $thumbnail_id, 'full' );
66
67 return ( is_array( $logo_src ) && ! empty( $logo_src[0] ) ) ? $logo_src[0] : null;
68 }
69
70 /**
71 * Get the WordPress site logo URL.
72 *
73 * @return string|null
74 */
75 private static function get_site_logo_url(): ?string {
76 $custom_logo_id = (int) get_theme_mod( 'custom_logo' );
77 if ( $custom_logo_id <= 0 ) {
78 return null;
79 }
80
81 $site_logo_src = wp_get_attachment_image_src( $custom_logo_id, 'full' );
82
83 return ( is_array( $site_logo_src ) && ! empty( $site_logo_src[0] ) ) ? $site_logo_src[0] : null;
84 }
85 }
86