class-tracking-settings-data.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <?php
  2. /**
  3. * WPSEO plugin file.
  4. *
  5. * @package WPSEO\Admin\Tracking
  6. */
  7. /**
  8. * Collects anonymized settings data.
  9. */
  10. class WPSEO_Tracking_Settings_Data implements WPSEO_Collection {
  11. /**
  12. * @var array $anonymous_settings contains all of the option_names which need to be
  13. * anonimized before they can be sent elsewhere.
  14. */
  15. private $anonymous_settings = [
  16. 'baiduverify',
  17. 'googleverify',
  18. 'msverify',
  19. 'yandexverify',
  20. 'myyoast-oauth',
  21. 'website_name',
  22. 'alternate_website_name',
  23. 'company_logo',
  24. 'company_name',
  25. 'person_name',
  26. 'person_logo',
  27. 'person_logo_id',
  28. 'company_logo_id',
  29. 'facebook_site',
  30. 'instagram_url',
  31. 'linkedin_url',
  32. 'myspace_url',
  33. 'og_default_image',
  34. 'og_default_image_id',
  35. 'og_frontpage_title',
  36. 'og_frontpage_desc',
  37. 'og_frontpage_image',
  38. 'og_frontpage_image_id',
  39. 'pinterest_url',
  40. 'pinterestverify',
  41. 'twitter_site',
  42. 'youtube_url',
  43. 'wikipedia_url',
  44. 'fbadminapp',
  45. ];
  46. /**
  47. * @var array $include_list contains the option_names for the options we want to track.
  48. */
  49. private $include_list = [
  50. 'ms_defaults_set',
  51. 'version',
  52. 'disableadvanced_meta',
  53. 'onpage_indexability',
  54. 'baiduverify',
  55. 'googleverify',
  56. 'msverify',
  57. 'yandexverify',
  58. 'site_type',
  59. 'has_multiple_authors',
  60. 'environment_type',
  61. 'content_analysis_active',
  62. 'keyword_analysis_active',
  63. 'enable_admin_bar_menu',
  64. 'enable_cornerstone_content',
  65. 'enable_xml_sitemap',
  66. 'enable_text_link_counter',
  67. 'show_onboarding_notice',
  68. 'first_activated_on',
  69. 'myyoast-oauth',
  70. 'website_name',
  71. 'alternate_website_name',
  72. 'company_logo',
  73. 'company_name',
  74. 'company_or_person',
  75. 'person_name',
  76. 'title_test',
  77. 'forcerewritetitle',
  78. 'separator',
  79. 'title-home-wpseo',
  80. 'title-author-wpseo',
  81. 'title-archive-wpseo',
  82. 'title-search-wpseo',
  83. 'title-404-wpseo',
  84. 'metadesc-home-wpseo',
  85. 'metadesc-author-wpseo',
  86. 'metadesc-archive-wpseo',
  87. 'rssbefore',
  88. 'rssafter',
  89. 'noindex-author-wpseo',
  90. 'noindex-author-noposts-wpseo',
  91. 'noindex-archive-wpseo',
  92. 'disable-author',
  93. 'disable-date',
  94. 'disable-post_format',
  95. 'disable-attachment',
  96. 'is-media-purge-relevant',
  97. 'breadcrumbs-404crumb',
  98. 'breadcrumbs-display-blog-page',
  99. 'breadcrumbs-boldlast',
  100. 'breadcrumbs-archiveprefix',
  101. 'breadcrumbs-enable',
  102. 'breadcrumbs-home',
  103. 'breadcrumbs-prefix',
  104. 'breadcrumbs-searchprefix',
  105. 'breadcrumbs-sep',
  106. 'person_logo',
  107. 'person_logo_id',
  108. 'company_logo_id',
  109. 'company_or_person_user_id',
  110. 'stripcategorybase',
  111. 'noindex-post',
  112. 'showdate-post',
  113. 'display-metabox-pt-post',
  114. 'noindex-page',
  115. 'showdate-page',
  116. 'display-metabox-pt-page',
  117. 'noindex-attachment',
  118. 'showdate-attachment',
  119. 'display-metabox-pt-attachment',
  120. 'display-metabox-tax-category',
  121. 'noindex-tax-category',
  122. 'display-metabox-tax-post_tag',
  123. 'noindex-tax-post_tag',
  124. 'display-metabox-tax-post_format',
  125. 'noindex-tax-post_format',
  126. 'taxonomy-category-ptparent',
  127. 'taxonomy-post_tag-ptparent',
  128. 'taxonomy-post_format-ptparent',
  129. 'breadcrumbs-blog-remove',
  130. 'hideeditbox-post',
  131. 'hideeditbox-page',
  132. 'hideeditbox-attachment',
  133. 'hideeditbox-tax-category',
  134. 'hideeditbox-tax-post_tag',
  135. 'hideeditbox-tax-post_format',
  136. 'facebook_site',
  137. 'instagram_url',
  138. 'linkedin_url',
  139. 'myspace_url',
  140. 'og_default_image',
  141. 'og_default_image_id',
  142. 'og_frontpage_title',
  143. 'og_frontpage_desc',
  144. 'og_frontpage_image',
  145. 'og_frontpage_image_id',
  146. 'opengraph',
  147. 'pinterest_url',
  148. 'pinterestverify',
  149. 'twitter',
  150. 'twitter_site',
  151. 'twitter_card_type',
  152. 'youtube_url',
  153. 'wikipedia_url',
  154. 'fbadminapp',
  155. ];
  156. /**
  157. * Returns the collection data.
  158. *
  159. * @return array The collection data.
  160. */
  161. public function get() {
  162. /**
  163. * Filter: 'wpseo_tracking_settings_include_list' - Allow filtering the settings included in tracking.
  164. *
  165. * @api string $include_list the list with included setting names.
  166. */
  167. $this->include_list = apply_filters( 'wpseo_tracking_settings_include_list', $this->include_list );
  168. $options = WPSEO_Options::get_all();
  169. // Returns the settings of which the keys intersect with the values of the include list.
  170. $options = array_intersect_key( $options, array_flip( $this->include_list ) );
  171. return [
  172. 'settings' => $this->anonymize_settings( $options ),
  173. ];
  174. }
  175. /**
  176. * Anonimizes the WPSEO_Options array by replacing all $anonymous_settings values to 'used'.
  177. *
  178. * @param array $settings The settings.
  179. * @return array The anonymized settings.
  180. */
  181. private function anonymize_settings( $settings ) {
  182. foreach ( $this->anonymous_settings as $setting ) {
  183. if ( ! empty( $settings[ $setting ] ) ) {
  184. $settings[ $setting ] = 'used';
  185. }
  186. }
  187. return $settings;
  188. }
  189. }