v1.1.0
This commit is contained in:
parent
9b856d1c3d
commit
ddaaff71ad
23 changed files with 879 additions and 798 deletions
|
|
@ -136,6 +136,10 @@ class Robotstxt_OG_Image_Fallback {
|
|||
add_action( 'updated_post_meta', array( $this, 'handle_thumbnail_change' ), 10, 4 );
|
||||
add_action( 'deleted_post_meta', array( $this, 'handle_thumbnail_change' ), 10, 4 );
|
||||
|
||||
// Register GDPR privacy data handlers.
|
||||
add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'register_privacy_exporter' ) );
|
||||
add_filter( 'wp_privacy_personal_data_erasers', array( $this, 'register_privacy_eraser' ) );
|
||||
|
||||
// Register activation and deactivation hooks.
|
||||
register_activation_hook( ROBOTSTXT_OG_PATH . 'robotstxt-og.php', array( $this, 'activate' ) );
|
||||
register_deactivation_hook( ROBOTSTXT_OG_PATH . 'robotstxt-og.php', array( $this, 'deactivate' ) );
|
||||
|
|
@ -209,13 +213,13 @@ class Robotstxt_OG_Image_Fallback {
|
|||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param int $meta_id ID of the meta data entry.
|
||||
* @param int $post_id Post ID.
|
||||
* @param string $meta_key Meta key being updated.
|
||||
* @param mixed $meta_value New meta value (unused).
|
||||
* @param int|int[] $meta_id ID or array of IDs of the meta data entry.
|
||||
* @param int $post_id Post ID.
|
||||
* @param string $meta_key Meta key being updated.
|
||||
* @param mixed $meta_value New meta value (unused).
|
||||
* @return void
|
||||
*/
|
||||
public function handle_thumbnail_change( int $meta_id, int $post_id, string $meta_key, $meta_value = null ): void { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
|
||||
public function handle_thumbnail_change( int|array $meta_id, int $post_id, string $meta_key, $meta_value = null ): void { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
|
||||
if ( '_thumbnail_id' !== $meta_key ) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -223,6 +227,171 @@ class Robotstxt_OG_Image_Fallback {
|
|||
$this->resolver->clear_cache( $post_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the personal data exporter.
|
||||
*
|
||||
* @since 1.0.3
|
||||
*
|
||||
* @param array<int, array<string, mixed>> $exporters List of exporters.
|
||||
* @return array<int, array<string, mixed>> Updated exporters list.
|
||||
*/
|
||||
public function register_privacy_exporter( array $exporters ): array {
|
||||
$exporters[] = array(
|
||||
'exporter_friendly_name' => __( 'OpenGraph Custom Post Data', 'robotstxt-og' ),
|
||||
'callback' => array( $this, 'export_privacy_data' ),
|
||||
);
|
||||
return $exporters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the personal data eraser.
|
||||
*
|
||||
* @since 1.0.3
|
||||
*
|
||||
* @param array<int, array<string, mixed>> $erasers List of erasers.
|
||||
* @return array<int, array<string, mixed>> Updated erasers list.
|
||||
*/
|
||||
public function register_privacy_eraser( array $erasers ): array {
|
||||
$erasers[] = array(
|
||||
'eraser_friendly_name' => __( 'OpenGraph Custom Post Data', 'robotstxt-og' ),
|
||||
'callback' => array( $this, 'erase_privacy_data' ),
|
||||
);
|
||||
return $erasers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export personal data stored by this plugin for a given email address.
|
||||
*
|
||||
* Exports the custom og:title and og:description stored in post meta for
|
||||
* all posts authored by the user with the given email address.
|
||||
*
|
||||
* @since 1.0.3
|
||||
*
|
||||
* @param string $email_address User email address.
|
||||
* @param int $page Pagination page (1-based).
|
||||
* @return array{data: array<int, array<string, mixed>>, done: bool} Export result.
|
||||
*/
|
||||
public function export_privacy_data( string $email_address, int $page = 1 ): array {
|
||||
$user = get_user_by( 'email', $email_address );
|
||||
|
||||
if ( ! $user ) {
|
||||
return array(
|
||||
'data' => array(),
|
||||
'done' => true,
|
||||
);
|
||||
}
|
||||
|
||||
$posts = get_posts(
|
||||
array(
|
||||
'author' => $user->ID,
|
||||
'post_type' => 'any',
|
||||
'post_status' => 'any',
|
||||
'posts_per_page' => 100,
|
||||
'paged' => $page,
|
||||
'fields' => 'ids',
|
||||
)
|
||||
);
|
||||
|
||||
$data = array();
|
||||
|
||||
foreach ( $posts as $post_id ) {
|
||||
$og_title = get_post_meta( $post_id, '_og_title', true );
|
||||
$og_desc = get_post_meta( $post_id, '_og_description', true );
|
||||
|
||||
if ( empty( $og_title ) && empty( $og_desc ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$item_data = array();
|
||||
|
||||
if ( ! empty( $og_title ) && is_string( $og_title ) ) {
|
||||
$item_data[] = array(
|
||||
'name' => __( 'Custom OG Title', 'robotstxt-og' ),
|
||||
'value' => $og_title,
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $og_desc ) && is_string( $og_desc ) ) {
|
||||
$item_data[] = array(
|
||||
'name' => __( 'Custom OG Description', 'robotstxt-og' ),
|
||||
'value' => $og_desc,
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! empty( $item_data ) ) {
|
||||
$data[] = array(
|
||||
'group_id' => 'robotstxt-og-post-meta',
|
||||
'group_label' => __( 'OpenGraph Post Meta', 'robotstxt-og' ),
|
||||
'item_id' => 'post-' . $post_id,
|
||||
'data' => $item_data,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$done = count( $posts ) < 100;
|
||||
|
||||
return array(
|
||||
'data' => $data,
|
||||
'done' => $done,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erase personal data stored by this plugin for a given email address.
|
||||
*
|
||||
* Removes custom og:title and og:description from all posts authored by
|
||||
* the user with the given email address.
|
||||
*
|
||||
* @since 1.0.3
|
||||
*
|
||||
* @param string $email_address User email address.
|
||||
* @param int $page Pagination page (1-based).
|
||||
* @return array{items_removed: int, items_retained: int, messages: string[], done: bool} Erase result.
|
||||
*/
|
||||
public function erase_privacy_data( string $email_address, int $page = 1 ): array {
|
||||
$user = get_user_by( 'email', $email_address );
|
||||
|
||||
if ( ! $user ) {
|
||||
return array(
|
||||
'items_removed' => 0,
|
||||
'items_retained' => 0,
|
||||
'messages' => array(),
|
||||
'done' => true,
|
||||
);
|
||||
}
|
||||
|
||||
$posts = get_posts(
|
||||
array(
|
||||
'author' => $user->ID,
|
||||
'post_type' => 'any',
|
||||
'post_status' => 'any',
|
||||
'posts_per_page' => 100,
|
||||
'paged' => $page,
|
||||
'fields' => 'ids',
|
||||
)
|
||||
);
|
||||
|
||||
$items_removed = 0;
|
||||
|
||||
foreach ( $posts as $post_id ) {
|
||||
$deleted_title = delete_post_meta( $post_id, '_og_title' );
|
||||
$deleted_desc = delete_post_meta( $post_id, '_og_description' );
|
||||
|
||||
if ( $deleted_title || $deleted_desc ) {
|
||||
++$items_removed;
|
||||
}
|
||||
}
|
||||
|
||||
$done = count( $posts ) < 100;
|
||||
|
||||
return array(
|
||||
'items_removed' => $items_removed,
|
||||
'items_retained' => 0,
|
||||
'messages' => array(),
|
||||
'done' => $done,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get image resolver instance.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in a new issue