Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media connector test implemented. #1154

Merged
merged 3 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 50 additions & 43 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 14 additions & 24 deletions connectors/class-connector-media.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function callback_add_attachment( $post_id ) {
$url = $post->guid;
$parent_id = $post->post_parent;
$parent = get_post( $parent_id );
$parent_title = $parent_id ? $parent->post_title : null;
$parent_title = $parent instanceof \WP_Post ? $parent->post_title : 'Unidentifiable post';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kasparsd Please take a look at this ☝️. It resolves #907. I also updated the corresponding test to test this logic as well.

$attachment_type = $this->get_attachment_type( $post->guid );

$this->log(
Expand All @@ -171,18 +171,14 @@ public function callback_add_attachment( $post_id ) {
* @param int $post_id Post ID.
*/
public function callback_edit_attachment( $post_id ) {
$post = get_post( $post_id );
$name = $post->post_title;
$attachment_type = $this->get_attachment_type( $post->guid );

/* translators: %s: an attachment title (e.g. "PIC001") */
$message = esc_html__( 'Updated "%s"', 'stream' );
$post = get_post( $post_id );

$this->log(
$message,
compact( 'name' ),
/* translators: %s: an attachment title (e.g. "PIC001") */
esc_html__( 'Updated "%s"', 'stream' ),
array( 'name' => $post->post_title ),
$post_id,
$attachment_type,
$this->get_attachment_type( $post->guid ),
'updated'
);
}
Expand All @@ -195,21 +191,17 @@ public function callback_edit_attachment( $post_id ) {
* @param int $post_id Post ID.
*/
public function callback_delete_attachment( $post_id ) {
$post = get_post( $post_id );
$parent = $post->post_parent ? get_post( $post->post_parent ) : null;
$parent_id = $parent ? $parent->ID : null;
$name = $post->post_title;
$url = $post->guid;
$attachment_type = $this->get_attachment_type( $post->guid );

/* translators: %s: an attachment title (e.g. "PIC001") */
$message = esc_html__( 'Deleted "%s"', 'stream' );
$post = get_post( $post_id );
$parent_id = $post->post_parent ? $post->post_parent : null;
$name = $post->post_title;
$url = $post->guid;

$this->log(
$message,
/* translators: %s: an attachment title (e.g. "PIC001") */
esc_html__( 'Deleted "%s"', 'stream' ),
compact( 'name', 'parent_id', 'url' ),
$post_id,
$attachment_type,
$this->get_attachment_type( $post->guid ),
'deleted'
);
}
Expand All @@ -233,14 +225,12 @@ public function callback_wp_save_image_editor_file( $dummy, $filename, $image, $
$name = basename( $filename );
$post = get_post( $post_id );

$attachment_type = $this->get_attachment_type( $post->guid );

$this->log(
/* translators: Placeholder refers to an attachment title (e.g. "PIC001") */
__( 'Edited image "%s"', 'stream' ),
compact( 'name', 'filename', 'post_id' ),
$post_id,
$attachment_type,
$this->get_attachment_type( $post->guid ),
'edited'
);
}
Expand Down
Loading