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

Mark publisher logo as such in WordPress media library #11836

Merged
merged 11 commits into from
Jun 29, 2022
23 changes: 22 additions & 1 deletion includes/Admin/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@
use Google\Web_Stories\Model\Story;
use Google\Web_Stories\Renderer\Story\Image;
use Google\Web_Stories\Service_Base;
use Google\Web_Stories\Settings;
use Google\Web_Stories\Story_Post_Type;
use WP_Post;

/**
* Admin class.
*/
class Admin extends Service_Base {

/**
* Context instance.
*
Expand All @@ -64,6 +66,8 @@ public function register(): void {
add_filter( 'admin_body_class', [ $this, 'admin_body_class' ], 99 );
add_filter( 'default_content', [ $this, 'prefill_post_content' ], 10, 2 );
add_filter( 'default_title', [ $this, 'prefill_post_title' ] );
add_filter( 'default_title', [ $this, 'prefill_post_title' ] );
timarney marked this conversation as resolved.
Show resolved Hide resolved
add_filter( 'display_media_states', [ $this, 'media_states' ], 10, 2 );
}

/**
Expand Down Expand Up @@ -155,7 +159,6 @@ public function prefill_post_content( $content, WP_Post $post ) {
];

if ( ! use_block_editor_for_post( $post ) ) {

$content = '[web_stories_embed url="%1$s" title="%2$s" poster="%3$s" width="%4$s" height="%5$s" align="%6$s"]';

return sprintf(
Expand Down Expand Up @@ -229,4 +232,22 @@ public function prefill_post_title( $title ) {
// Otherwise it runs through wptexturize() and the like, which we want to avoid.
return $post->post_title;
}


/**
* Adds active publisher logo to media state output.
*
* @since 1.2.2
timarney marked this conversation as resolved.
Show resolved Hide resolved
*
* @param string[] $media_states Array of media states.
* @param WP_Post $post Post object.
* @return string[] updated media states.
*/
public function media_states( $media_states, $post ): array {
timarney marked this conversation as resolved.
Show resolved Hide resolved
$active_publisher_logo = absint( get_option( Settings::SETTING_NAME_ACTIVE_PUBLISHER_LOGO ) );
timarney marked this conversation as resolved.
Show resolved Hide resolved
if ( $post->ID === $active_publisher_logo ) {
$media_states[] = __( 'Web Stories Publisher Logo', 'web-stories' );
}
return $media_states;
}
}