class-fl-builder-privacy.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Helper class for working with privacy.
  4. *
  5. * @since 2.1
  6. */
  7. final class FLBuilderPrivacy {
  8. static public function init() {
  9. add_action( 'admin_init', array( 'FLBuilderPrivacy', 'admin_init' ) );
  10. }
  11. static public function admin_init() {
  12. if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) {
  13. return false;
  14. }
  15. add_filter( 'wp_privacy_personal_data_exporters', array( 'FLBuilderPrivacy', 'register_exporter' ) );
  16. self::register_policy();
  17. }
  18. static public function register_exporter( $exporters ) {
  19. $exporters[] = array(
  20. 'exporter_friendly_name' => __( 'Beaver Builder Plugin' ),
  21. 'callback' => array( 'FLBuilderPrivacy', 'exporter' ),
  22. );
  23. return $exporters;
  24. }
  25. static public function exporter( $email, $page = 1 ) {
  26. $export_items = array();
  27. $data = array();
  28. $user = get_user_by( 'email', $email );
  29. $meta = (array) get_user_meta( $user->ID, 'fl_builder_user_settings', true );
  30. $result = self::array_flatten( $meta );
  31. foreach ( $result as $key => $setting ) {
  32. if ( ! $key ) {
  33. continue;
  34. }
  35. if ( ! is_array( $setting ) ) {
  36. if ( '' == $setting ) {
  37. $setting = 'false';
  38. }
  39. $data[] = array(
  40. 'name' => $key,
  41. 'value' => $setting,
  42. );
  43. }
  44. }
  45. if ( empty( $data ) ) {
  46. return array(
  47. 'data' => array(),
  48. 'done' => true,
  49. );
  50. }
  51. $export_items[] = array(
  52. 'group_id' => 'bb-settings',
  53. 'group_label' => 'Beaver Builder Settings',
  54. 'item_id' => 'bb-settings',
  55. 'data' => $data,
  56. );
  57. return array(
  58. 'data' => $export_items,
  59. 'done' => true,
  60. );
  61. }
  62. static public function array_flatten( $array ) {
  63. $return = array();
  64. foreach ( $array as $key => $value ) {
  65. if ( is_array( $value ) ) {
  66. $return = array_merge( $return, self::array_flatten( $value ) );
  67. } else {
  68. $return[ $key ] = $value;
  69. }
  70. }
  71. return $return;
  72. }
  73. static public function register_policy() {
  74. wp_add_privacy_policy_content( 'Beaver Builder', __( '<p>In terms of GDPR, Beaver Builder products do not collect any personal information from your users. However some modules such as videos and maps might need you to update your privacy policy accordingly.</p>', 'fl-builder' ) );
  75. }
  76. }
  77. FLBuilderPrivacy::init();