class-tracking-addon-data.php
2 years ago
class-tracking-default-data.php
3 years ago
class-tracking-plugin-data.php
2 years ago
class-tracking-server-data.php
3 years ago
class-tracking-settings-data.php
3 months ago
class-tracking-theme-data.php
4 years ago
class-tracking.php
1 year ago
class-tracking-addon-data.php
127 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WPSEO plugin file. |
| 4 | * |
| 5 | * @package WPSEO\Admin\Tracking |
| 6 | */ |
| 7 | |
| 8 | use Yoast\WP\SEO\Conditionals\WooCommerce_Conditional; |
| 9 | |
| 10 | /** |
| 11 | * Represents the addon option data. |
| 12 | */ |
| 13 | class WPSEO_Tracking_Addon_Data implements WPSEO_Collection { |
| 14 | |
| 15 | /** |
| 16 | * The local options we want to track. |
| 17 | * |
| 18 | * @var string[] The option_names for the options we want to track. |
| 19 | */ |
| 20 | private $local_include_list = [ |
| 21 | 'use_multiple_locations', |
| 22 | 'multiple_locations_same_organization', |
| 23 | 'business_type', |
| 24 | 'woocommerce_local_pickup_setting', |
| 25 | ]; |
| 26 | |
| 27 | /** |
| 28 | * The woo options we want to track. |
| 29 | * |
| 30 | * @var string[] The option_names for the options we want to track. |
| 31 | */ |
| 32 | private $woo_include_list = []; |
| 33 | |
| 34 | /** |
| 35 | * The news options we want to track. |
| 36 | * |
| 37 | * @var string[] The option_names for the options we want to track. |
| 38 | */ |
| 39 | private $news_include_list = []; |
| 40 | |
| 41 | /** |
| 42 | * The video options we want to track. |
| 43 | * |
| 44 | * @var string[] The option_names for the options we want to track. |
| 45 | */ |
| 46 | private $video_include_list = []; |
| 47 | |
| 48 | /** |
| 49 | * Returns the collection data. |
| 50 | * |
| 51 | * @return array The collection data. |
| 52 | */ |
| 53 | public function get() { |
| 54 | |
| 55 | $addon_settings = []; |
| 56 | $addon_manager = new WPSEO_Addon_Manager(); |
| 57 | |
| 58 | if ( $addon_manager->is_installed( WPSEO_Addon_Manager::LOCAL_SLUG ) ) { |
| 59 | $addon_settings = $this->get_local_addon_settings( $addon_settings, 'wpseo_local', WPSEO_Addon_Manager::LOCAL_SLUG, $this->local_include_list ); |
| 60 | } |
| 61 | |
| 62 | if ( $addon_manager->is_installed( WPSEO_Addon_Manager::WOOCOMMERCE_SLUG ) ) { |
| 63 | $addon_settings = $this->get_addon_settings( $addon_settings, 'wpseo_woo', WPSEO_Addon_Manager::WOOCOMMERCE_SLUG, $this->woo_include_list ); |
| 64 | } |
| 65 | |
| 66 | if ( $addon_manager->is_installed( WPSEO_Addon_Manager::NEWS_SLUG ) ) { |
| 67 | $addon_settings = $this->get_addon_settings( $addon_settings, 'wpseo_news', WPSEO_Addon_Manager::NEWS_SLUG, $this->news_include_list ); |
| 68 | } |
| 69 | |
| 70 | if ( $addon_manager->is_installed( WPSEO_Addon_Manager::VIDEO_SLUG ) ) { |
| 71 | $addon_settings = $this->get_addon_settings( $addon_settings, 'wpseo_video', WPSEO_Addon_Manager::VIDEO_SLUG, $this->video_include_list ); |
| 72 | } |
| 73 | |
| 74 | return $addon_settings; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Gets the tracked options from the addon |
| 79 | * |
| 80 | * @param array $addon_settings The current list of addon settings. |
| 81 | * @param string $source_name The option key of the addon. |
| 82 | * @param string $slug The addon slug. |
| 83 | * @param array $option_include_list All the options to be included in tracking. |
| 84 | * |
| 85 | * @return array |
| 86 | */ |
| 87 | public function get_addon_settings( array $addon_settings, $source_name, $slug, $option_include_list ) { |
| 88 | $source_options = get_option( $source_name, [] ); |
| 89 | if ( ! is_array( $source_options ) || empty( $source_options ) ) { |
| 90 | return $addon_settings; |
| 91 | } |
| 92 | $addon_settings[ $slug ] = array_intersect_key( $source_options, array_flip( $option_include_list ) ); |
| 93 | |
| 94 | return $addon_settings; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Filter business_type in local addon settings. |
| 99 | * |
| 100 | * Remove the business_type setting when 'multiple_locations_shared_business_info' setting is turned off. |
| 101 | * |
| 102 | * @param array $addon_settings The current list of addon settings. |
| 103 | * @param string $source_name The option key of the addon. |
| 104 | * @param string $slug The addon slug. |
| 105 | * @param array $option_include_list All the options to be included in tracking. |
| 106 | * |
| 107 | * @return array |
| 108 | */ |
| 109 | public function get_local_addon_settings( array $addon_settings, $source_name, $slug, $option_include_list ) { |
| 110 | $source_options = get_option( $source_name, [] ); |
| 111 | if ( ! is_array( $source_options ) || empty( $source_options ) ) { |
| 112 | return $addon_settings; |
| 113 | } |
| 114 | $addon_settings[ $slug ] = array_intersect_key( $source_options, array_flip( $option_include_list ) ); |
| 115 | |
| 116 | if ( array_key_exists( 'use_multiple_locations', $source_options ) && array_key_exists( 'business_type', $addon_settings[ $slug ] ) && $source_options['use_multiple_locations'] === 'on' && $source_options['multiple_locations_shared_business_info'] === 'off' ) { |
| 117 | $addon_settings[ $slug ]['business_type'] = 'multiple_locations'; |
| 118 | } |
| 119 | |
| 120 | if ( ! ( new WooCommerce_Conditional() )->is_met() ) { |
| 121 | unset( $addon_settings[ $slug ]['woocommerce_local_pickup_setting'] ); |
| 122 | } |
| 123 | |
| 124 | return $addon_settings; |
| 125 | } |
| 126 | } |
| 127 |