| 1 |
<?php |
| 2 |
/** |
| 3 |
* Main ActionHooks class. |
| 4 |
* |
| 5 |
* @package RadiusTheme\SB |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace RadiusTheme\SB\Controllers\Hooks; |
| 9 |
|
| 10 |
use RadiusTheme\SB\Elementor\Render\Render; |
| 11 |
use RadiusTheme\SB\Helpers\Fns; |
| 12 |
use RadiusTheme\SB\Models\GeneralList; |
| 13 |
|
| 14 |
defined( 'ABSPATH' ) || exit(); |
| 15 |
|
| 16 |
/** |
| 17 |
* Main ActionHooks class. |
| 18 |
*/ |
| 19 |
class ActionHooks { |
| 20 |
/** |
| 21 |
* Init Hooks. |
| 22 |
* |
| 23 |
* @return void |
| 24 |
*/ |
| 25 |
public static function init_hooks() { |
| 26 |
add_action( 'wp_head', [ __CLASS__, 'og_metatags_for_sharing' ], 1 ); |
| 27 |
add_action( 'woocommerce_share', [ __CLASS__, 'shopbuilder_share' ], 20 ); |
| 28 |
add_action( 'rtsb/wcqv/product/summary', [ __CLASS__, 'shopbuilder_share' ], 40 ); |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Meta tags for social sharing. |
| 33 |
* |
| 34 |
* @return void |
| 35 |
*/ |
| 36 |
public static function shopbuilder_share() { |
| 37 |
|
| 38 |
$generalList = GeneralList::instance()->get_data(); |
| 39 |
|
| 40 |
if ( |
| 41 |
empty( $generalList['social_share']['share_platforms_to_product_page'] ) || |
| 42 |
'on' !== $generalList['social_share']['share_platforms_to_product_page'] || |
| 43 |
empty( $generalList['social_share']['share_platforms'] ) |
| 44 |
) { |
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
$share_platforms = []; |
| 49 |
foreach ( $generalList['social_share']['share_platforms'] as $value ) { |
| 50 |
$share_platforms[ $value ] = [ |
| 51 |
'share_items' => $value, |
| 52 |
'share_text' => ucwords( $value ), |
| 53 |
]; |
| 54 |
} |
| 55 |
$settings['share_platforms'] = $share_platforms; |
| 56 |
$settings['layout'] = ! empty( $generalList['social_share']['share_icon_layout'] ) ? $generalList['social_share']['share_icon_layout'] : 1; |
| 57 |
$settings['show_share_icon'] = 1; |
| 58 |
// TODO:: Implement Later ! empty( $generalList['social_share']['share_icon_show_to_product_page'] ) && 'on' === $generalList['social_share']['share_icon_show_to_product_page']; |
| 59 |
Fns::print_html( Render::instance()->social_share_view( 'elementor/general/social-share', $settings ), true ); |
| 60 |
|
| 61 |
} |
| 62 |
/** |
| 63 |
* Meta tags for social sharing. |
| 64 |
* |
| 65 |
* @return void |
| 66 |
*/ |
| 67 |
public static function og_metatags_for_sharing() { |
| 68 |
global $post; |
| 69 |
|
| 70 |
if ( ! isset( $post ) ) { |
| 71 |
return; |
| 72 |
} |
| 73 |
|
| 74 |
if ( ! is_singular( 'product' ) ) { |
| 75 |
return; |
| 76 |
} |
| 77 |
|
| 78 |
Fns::print_html( '<meta property="og:url" content="' . get_the_permalink() . '" />', true ); |
| 79 |
Fns::print_html( '<meta property="og:type" content="article" />', true ); |
| 80 |
Fns::print_html( '<meta property="og:title" content="' . $post->post_title . '" />', true ); |
| 81 |
Fns::print_html( '<meta property="og:description" content="' . wp_trim_words( $post->post_content, 150 ) . '" />' ); |
| 82 |
|
| 83 |
$attachment = get_the_post_thumbnail_url(); |
| 84 |
|
| 85 |
if ( ! empty( $attachment ) ) { |
| 86 |
Fns::print_html( '<meta property="og:image" content="' . $attachment . '" />', true ); |
| 87 |
} |
| 88 |
|
| 89 |
Fns::print_html( '<meta property="og:site_name" content="' . get_bloginfo( 'name' ) . '" />', true ); |
| 90 |
Fns::print_html( '<meta name="twitter:card" content="summary" />', true ); |
| 91 |
} |
| 92 |
} |
| 93 |
|