Skip to content

Commit

Permalink
Allow guest authors have personal data exported (#528)
Browse files Browse the repository at this point in the history
* [Style] Identation changed to tab

* [Feat] Added personal data exporter to guest authors

* [Feat] Added a filter to allow third part plugins add guest author data

* [Style] WPCS fixes

* [Fix] Filter name changed

* [Style] WPCS fixes

* [Fix] Filter name changed
  • Loading branch information
mariovalney authored and mjangda committed Jun 13, 2018
1 parent c3a4e65 commit 2026d4c
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 10 deletions.
20 changes: 10 additions & 10 deletions co-authors-plus.php
Original file line number Diff line number Diff line change
Expand Up @@ -1595,16 +1595,16 @@ public function clear_cache_on_terms_set( $object_id, $terms, $tt_ids, $taxonomy

}

/**
* Filter of the header of author archive pages to correctly display author.
*/
public function filter_author_archive_title() {
if ( is_author() ) {
$author_slug = sanitize_user( get_query_var( 'author_name' ) );
$author = $this->get_coauthor_by( 'user_nicename', $author_slug );
return sprintf( __( 'Author: %s' ), $author->display_name );
}
}
/**
* Filter of the header of author archive pages to correctly display author.
*/
public function filter_author_archive_title() {
if ( is_author() ) {
$author_slug = sanitize_user( get_query_var( 'author_name' ) );
$author = $this->get_coauthor_by( 'user_nicename', $author_slug );
return sprintf( __( 'Author: %s' ), $author->display_name );
}
}
}

global $coauthors_plus;
Expand Down
94 changes: 94 additions & 0 deletions php/class-coauthors-guest-authors.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ function __construct() {
// Add support for featured thumbnails that we can use for guest author avatars
add_filter( 'get_avatar', array( $this, 'filter_get_avatar' ),10 ,5 );

// Add a Personal Data Exporter to guest authors
add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'filter_personal_data_exporter' ), 1 );

// Allow users to change where this is placed in the WordPress admin
$this->parent_page = apply_filters( 'coauthors_guest_author_parent_page', $this->parent_page );

Expand Down Expand Up @@ -1503,4 +1506,95 @@ public function filter_author_feed_link( $feed_link, $feed ) {

return $link;
}

/**
* Filter Personal Data Exporters to add Guest Author exporter
*
* @since 3.3.1
*/
public function filter_personal_data_exporter( $exporters ) {
$exporters['cap-guest-author'] = array(
'exporter_friendly_name' => __( 'Guest Author', 'co-authors-plus' ),
'callback' => array( $this, 'personal_data_exporter' ),
);

return $exporters;
}

/**
* Finds and exports personal data associated with an email address for guest authors
*
* @since 3.3.1
*
* @param string $email_address The guest author email address.
* @return array An array of personal data.
*/
public function personal_data_exporter( $email_address ) {
$email_address = trim( $email_address );

$data_to_export = array();

$author = $this->get_guest_author_by( 'user_email', $email_address );

if ( ! $author ) {
return array(
'data' => array(),
'done' => true,
);
}

$author_data = array(
'ID' => __( 'ID', 'co-authors-plus' ),
'user_login' => __( 'Login Name', 'co-authors-plus' ),
'display_name' => __( 'Display Name', 'co-authors-plus' ),
'user_email' => __( 'Email', 'co-authors-plus' ),
'first_name' => __( 'First Name', 'co-authors-plus' ),
'last_name' => __( 'Last Name', 'co-authors-plus' ),
'website' => __( 'Website', 'co-authors-plus' ),
'aim' => __( 'AIM', 'co-authors-plus' ),
'yahooim' => __( 'Yahoo IM', 'co-authors-plus' ),
'jabber' => __( 'Jabber / Google Talk', 'co-authors-plus' ),
'description' => __( 'Biographical Info', 'co-authors-plus' ),
);

$author_data_to_export = array();

foreach ( $author_data as $key => $name ) {
if ( empty( $author->$key ) ) {
continue;
}

$author_data_to_export[] = array(
'name' => $name,
'value' => $author->$key,
);
}

/**
* Filters extra data to allow plugins add data related to guest author
*
* @since 3.3.1
*
* @param array $extra_data A empty array to be populated with extra data
* @param int $author->ID The guest author ID
* @param string $email_address The guest author email address
*/
$extra_data = apply_filters( 'coauthors_guest_author_personal_export_extra_data', [], $author->ID, $email_address );

if ( is_array( $extra_data ) && ! empty( $extra_data ) ) {
$author_data_to_export = array_merge( $author_data_to_export, $extra_data );
}

$data_to_export[] = array(
'group_id' => 'cap-guest-author',
'group_label' => __( 'Guest Author', 'co-authors-plus' ),
'item_id' => "cap-guest-author-{$author->ID}",
'data' => $author_data_to_export,
);

return array(
'data' => $data_to_export,
'done' => true,
);
}
}

0 comments on commit 2026d4c

Please sign in to comment.