Last active
February 11, 2022 09:01
-
-
Save janboddez/8f990373e1fdfd7e212075fff44539ba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Post "Reads" to F-Stop, a feed reader not unlike Aperture. | |
*/ | |
add_filter( 'wp_insert_post_data', function( $data, $postarr ) { | |
if ( ! empty( $postarr['ID'] ) ) { | |
// Not a new post. Bail. | |
return $data; | |
} | |
if ( empty( $postarr['meta_input']['mf2_read-of'][0] ) ) { | |
// Not a "Read" post. | |
return $data; | |
} | |
// These are optional, really. | |
$data['post_type'] = 'iwcpt_read'; // My CPT. | |
$data['post_status'] = 'draft'; // I save Reads as draft. | |
// This is where the magic happens. | |
if ( defined( 'FSTOP_READ_IT_LATER_TOKEN' ) ) { | |
wp_remote_post( | |
esc_url_raw( 'https://fstop.cloud/micropub' ), | |
array( | |
'headers' => array( | |
'Authorization' => 'Bearer ' . FSTOP_READ_IT_LATER_TOKEN, | |
'Content-type' => 'application/x-www-form-urlencoded', | |
), | |
'body' => array( | |
'h' => 'entry', | |
'read-of' => strtok( $postarr['meta_input']['mf2_read-of'][0], '?' ), // Strip query string. | |
), | |
'timeout' => 15, | |
) | |
); | |
strtok( '', '' ); // Clear up some memory? | |
} | |
return $data; // Always return `$data`! | |
}, 20, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment