Skip to content

Commit

Permalink
Drop compatibility with WordPress versions older than 6.4
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenLundsgaard committed Dec 3, 2024
1 parent 98eab89 commit 648199f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 28 deletions.
5 changes: 1 addition & 4 deletions inc/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ function gtmkit_plugin_activation(): void {
function gtmkit_plugin_deactivation(): void {

if ( function_exists( 'wp_set_option_autoload' ) ) {
wp_set_option_autoload( 'gtmkit', true );
} else {
global $wpdb;
$wpdb->query( "UPDATE $wpdb->options SET autoload = 'no' WHERE option_name = 'gtmkit'" );
wp_set_option_autoload( 'gtmkit', false );
}

wp_clear_scheduled_hook( 'gtmkit_send_anonymous_data' );
Expand Down
3 changes: 0 additions & 3 deletions src/Installation/Activation.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ public function set_autoload_on_options(): void {

if ( function_exists( 'wp_set_option_autoload' ) ) {
wp_set_option_autoload( 'gtmkit', true );
} else {
global $wpdb;
$wpdb->query( "UPDATE $wpdb->options SET autoload = 'yes' WHERE option_name = 'gtmkit'" );
}
}
}
25 changes: 4 additions & 21 deletions src/Integration/WooCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -1027,28 +1027,11 @@ public function cart_item_remove_link( string $woocommerce_cart_item_remove_link
'remove_from_cart'
);

if ( class_exists( 'WP_HTML_Tag_Processor' ) ) {
$link_html = new \WP_HTML_Tag_Processor( $woocommerce_cart_item_remove_link );
$link_html->next_tag();
$link_html->set_attribute( 'data-gtmkit_product_data', esc_attr( wp_json_encode( $item_data ) ) );
$woocommerce_cart_item_remove_link = $link_html->get_updated_html();
} else {
$find_href = ' href="';
$replace_width_product_data = sprintf( ' data-gtmkit_product_data="%s" href="', esc_attr( wp_json_encode( $item_data ) ) );

$substring_pos = strpos( $woocommerce_cart_item_remove_link, $find_href );

if ( $substring_pos !== false ) {
$woocommerce_cart_item_remove_link = substr_replace(
$woocommerce_cart_item_remove_link,
$replace_width_product_data,
$substring_pos,
strlen( $find_href )
);
}
}
$link_html = new \WP_HTML_Tag_Processor( $woocommerce_cart_item_remove_link );
$link_html->next_tag();
$link_html->set_attribute( 'data-gtmkit_product_data', esc_attr( wp_json_encode( $item_data ) ) );

return $woocommerce_cart_item_remove_link;
return $link_html->get_updated_html();
}

/**
Expand Down

0 comments on commit 648199f

Please sign in to comment.