WP_Privacy_Policy_Content::get_suggested_policy_text(): array

In this article

Checks for updated, added or removed privacy policy information from plugins.

Description

Caches the current info in post_meta of the policy page.

Return

array The privacy policy text/information added by core and plugins.

Source

public static function get_suggested_policy_text() {
	$policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
	$checked        = array();
	$time           = time();
	$update_cache   = false;
	$new            = self::$policy_content;
	$old            = array();

	if ( $policy_page_id ) {
		$old = (array) get_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' );
	}

	// Check for no-changes and updates.
	foreach ( $new as $new_key => $new_data ) {
		foreach ( $old as $old_key => $old_data ) {
			$found = false;

			if ( $new_data['policy_text'] === $old_data['policy_text'] ) {
				// Use the new plugin name in case it was changed, translated, etc.
				if ( $old_data['plugin_name'] !== $new_data['plugin_name'] ) {
					$old_data['plugin_name'] = $new_data['plugin_name'];
					$update_cache            = true;
				}

				// A plugin was re-activated.
				if ( ! empty( $old_data['removed'] ) ) {
					unset( $old_data['removed'] );
					$old_data['added'] = $time;
					$update_cache      = true;
				}

				$checked[] = $old_data;
				$found     = true;
			} elseif ( $new_data['plugin_name'] === $old_data['plugin_name'] ) {
				// The info for the policy was updated.
				$checked[]    = array(
					'plugin_name' => $new_data['plugin_name'],
					'policy_text' => $new_data['policy_text'],
					'updated'     => $time,
				);
				$found        = true;
				$update_cache = true;
			}

			if ( $found ) {
				unset( $new[ $new_key ], $old[ $old_key ] );
				continue 2;
			}
		}
	}

	if ( ! empty( $new ) ) {
		// A plugin was activated.
		foreach ( $new as $new_data ) {
			if ( ! empty( $new_data['plugin_name'] ) && ! empty( $new_data['policy_text'] ) ) {
				$new_data['added'] = $time;
				$checked[]         = $new_data;
			}
		}
		$update_cache = true;
	}

	if ( ! empty( $old ) ) {
		// A plugin was deactivated.
		foreach ( $old as $old_data ) {
			if ( ! empty( $old_data['plugin_name'] ) && ! empty( $old_data['policy_text'] ) ) {
				$data = array(
					'plugin_name' => $old_data['plugin_name'],
					'policy_text' => $old_data['policy_text'],
					'removed'     => $time,
				);

				$checked[] = $data;
			}
		}
		$update_cache = true;
	}

	if ( $update_cache && $policy_page_id ) {
		delete_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content' );
		// Update the cache.
		foreach ( $checked as $data ) {
			add_post_meta( $policy_page_id, '_wp_suggested_privacy_policy_content', $data );
		}
	}

	return $checked;
}

Changelog

VersionDescription
4.9.6Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.