Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[WordPress][Press This] Sets a custom default post format and category for post drafts saved via PressThis.
<?php
/**
* Plugin Name: Press This | Default Terms
* Description: Sets a custom default post format and category for post drafts saved via Press This.
* Version: 0.0.2
* Author: Caspar Hübinger
* Author URI: http://glueckpress.com/
* License: GNU General Public License v2 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
*/
defined( 'ABSPATH' ) or exit;
/**
* Add category and post format to Press This post before saving
*
* See: https://github.com/WordPress/press-this/blob/master/class-wp-press-this-plugin.php#L159
*/
add_filter( 'press_this_save_post', function ( $post_data ) {
// Post format must be supported by theme
// Note: Idk why, but the post format in Press This itself when you save a
// draft still says Standard. However, when you open the draft in the
// regular editor, it shows the value from here; so this works, even if
// it looks like it doesn’t as long as you’re in Press This.
$post_data['post_format'] = 'link';
// Get category ID from slug
$category = get_category_by_slug( 'example-category' );
$category_id = absint( $category->term_id );
if ( 0 < $category_id ) {
$post_data['post_category'] = [ $category_id ];
}
return $post_data;
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.