PHP code example of humanmade / propose-draft-date
1. Go to this page and download the library: Download humanmade/propose-draft-date library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
humanmade / propose-draft-date example snippets
/**
* Customize the post types which support the proposed date feature.
*
* @param array $post_types Array of supported post types.
* Defaults to "post" and "page".
*
* @return array Filtered post types array.
*/
function filter_types_with_proposed_dates( array $post_types ) : array {
$post_types = array_diff( $post_types, [ 'page' ] );
$post_types[] = 'my_custom_post_type';
return $post_types;
}
add_filter( 'proposed_date.supported_post_types', 'filter_types_with_proposed_dates', 10, 1 );
/**
* Always accept any available proposed date when transitioning to the
* `my-scheduled` custom post status.
*
* @param bool $accept_proposal Whether a proposal should be accepted.
* @param string $new_status New post status.
* @param string $old_status Previous post status.
* @param WP_Post $post The post being updated, before changes are applied.
*
* @return bool Whether a proposed date should be applied at this time.
*/
function accept_date_proposals_in_custom_status(
bool $accept_proposal,
string $new_status,
string $old_status,
WP_Post $post
) : bool {
if ( $new_status === 'my_custom_status' ) {
return true;
}
return $accept_proposal;
}
add_filter( 'proposed_date.should_accept_proposal', 'accept_date_proposals_in_custom_status', 10, 4 );