• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Yoast / wordpress-seo / 5066322038

pending completion
5066322038

push

github

GitHub
Merge pull request #20316 from Yoast/JRF/ghactions-run-more-selectively

2550 of 29012 relevant lines covered (8.79%)

0.32 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/integrations/third-party/woocommerce-permalinks.php
1
<?php
2

3
namespace Yoast\WP\SEO\Integrations\Third_Party;
4

5
use Yoast\WP\SEO\Conditionals\Migrations_Conditional;
6
use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional;
7
use Yoast\WP\SEO\Helpers\Indexable_Helper;
8
use Yoast\WP\SEO\Integrations\Integration_Interface;
9

10
/**
11
 * The permalink watcher.
12
 */
13
class Woocommerce_Permalinks implements Integration_Interface {
14

15
        /**
16
         * Represents the indexable helper.
17
         *
18
         * @var Indexable_Helper
19
         */
20
        protected $indexable_helper;
21

22
        /**
23
         * Returns the conditionals based in which this loadable should be active.
24
         *
25
         * @return array
26
         */
27
        public static function get_conditionals() {
28
                return [ WooCommerce_Conditional::class, Migrations_Conditional::class ];
×
29
        }
30

31
        /**
32
         * Constructor.
33
         *
34
         * @param Indexable_Helper $indexable_helper Indexable Helper.
35
         */
36
        public function __construct( Indexable_Helper $indexable_helper ) {
37
                $this->indexable_helper = $indexable_helper;
×
38
        }
39

40
        /**
41
         * Registers the hooks.
42
         *
43
         * @codeCoverageIgnore
44
         */
45
        public function register_hooks() {
46
                \add_filter( 'wpseo_post_types_reset_permalinks', [ $this, 'filter_product_from_post_types' ] );
47
                \add_action( 'update_option_woocommerce_permalinks', [ $this, 'reset_woocommerce_permalinks' ], 10, 2 );
48
        }
49

50
        /**
51
         * Filters the product post type from the post type.
52
         *
53
         * @param array $post_types The post types to filter.
54
         *
55
         * @return array The filtered post types.
56
         */
57
        public function filter_product_from_post_types( $post_types ) {
58
                unset( $post_types['product'] );
×
59

60
                return $post_types;
×
61
        }
62

63
        /**
64
         * Resets the indexables for WooCommerce based on the changed permalink fields.
65
         *
66
         * @param array $old_value The old value.
67
         * @param array $new_value The new value.
68
         */
69
        public function reset_woocommerce_permalinks( $old_value, $new_value ) {
70
                $changed_options = \array_diff( $old_value, $new_value );
×
71

72
                if ( \array_key_exists( 'product_base', $changed_options ) ) {
×
73
                        $this->indexable_helper->reset_permalink_indexables( 'post', 'product' );
×
74
                }
75

76
                if ( \array_key_exists( 'attribute_base', $changed_options ) ) {
×
77
                        $attribute_taxonomies = $this->get_attribute_taxonomies();
×
78

79
                        foreach ( $attribute_taxonomies as $attribute_name ) {
×
80
                                $this->indexable_helper->reset_permalink_indexables( 'term', $attribute_name );
×
81
                        }
82
                }
83

84
                if ( \array_key_exists( 'category_base', $changed_options ) ) {
×
85
                        $this->indexable_helper->reset_permalink_indexables( 'term', 'product_cat' );
×
86
                }
87

88
                if ( \array_key_exists( 'tag_base', $changed_options ) ) {
×
89
                        $this->indexable_helper->reset_permalink_indexables( 'term', 'product_tag' );
×
90
                }
91
        }
92

93
        /**
94
         * Retrieves the taxonomies based on the attributes.
95
         *
96
         * @return array The taxonomies.
97
         */
98
        protected function get_attribute_taxonomies() {
99
                $taxonomies = [];
×
100
                foreach ( \wc_get_attribute_taxonomies() as $attribute_taxonomy ) {
×
101
                        $taxonomies[] = \wc_attribute_taxonomy_name( $attribute_taxonomy->attribute_name );
×
102
                }
103

104
                $taxonomies = \array_filter( $taxonomies );
×
105

106
                return $taxonomies;
×
107
        }
108
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc