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

Introduce filter to allow limiting filter_status_text to certain post types. #47

Open
peterwilsoncc opened this issue Dec 27, 2023 · 0 comments · May be fixed by #49
Open

Introduce filter to allow limiting filter_status_text to certain post types. #47

peterwilsoncc opened this issue Dec 27, 2023 · 0 comments · May be fixed by #49

Comments

@peterwilsoncc
Copy link

This filter_status_text method filters the default text when sharing to mastondon to use the content of the post.

/**
* Filter a toot so that the note content is used rather than the title.
*
* @param string $status The status text.
* @param \WP_Post $post The post object.
* @return string The modified status text.
*/
function filter_status_text( string $status, \WP_Post $post ): string {
$status = Note\transform_content( $post->post_content );
return $status;
}

Unfortunately it's a little blunt and filters the text for all post types, be that posts, pages, or shortnotes.

A filter to allow other plugins to remove bypass the modification with ease would be most helpful. It can be done with a little work but it's a little unwieldy and probably flakey:

add_filter( 'share_on_mastodon_status', __NAMESPACE__ . '\\share_on_mastodon_status_text', 9, 2 );function share_on_mastodon_status_text( $status, $post ) {
	if ( ! in_array( $post->post_type, array( 'shortnote', 'pwcc_notes' ), true ) ) {
		// Remove Jeremy's filter.
		remove_filter( 'share_on_mastodon_status', 'ShortNotes\\ShareOnMastodon\\filter_status_text', 10 );
	}

	return $status;
}

I suggest a simple preflight filter of some description:

/**
 * Filter to bypass modification of default sharing text.
 * 
 * @param bool $bypass Whether to bypass the modifying text. Default false.
 * @param string $status The default status. 
 * @param \WP_Post $post The post being shared.
 */
$bypass = apply_filter( 'shortnotes_pre_modify_status_text', false, $status, $post );

if ( $bypass === true ) {
    return $status;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant