* @since 3.0.0 */ namespace Beyondwords\Wordpress\Component\Post\GenerateAudio; use Beyondwords\Wordpress\Component\Post\PostMetaUtils; use Beyondwords\Wordpress\Component\Settings\SettingsUtils; /** * GenerateAudio * * @since 3.0.0 */ class GenerateAudio { /** * Init. * * @since 4.0.0 * @since 6.0.0 Make static. */ public static function init() { add_action('wp_loaded', function (): void { $postTypes = SettingsUtils::getCompatiblePostTypes(); if (is_array($postTypes)) { foreach ($postTypes as $postType) { add_action("save_post_{$postType}", [self::class, 'save'], 10); } } }); } /** * Check whether the post type should preselect the "Generate audio" checkbox. * * @param \WP_Post|int $post The post object or ID. * * @todo move this function to somewhere reusable for the Block editor. * * @since 6.0.0 Make static. */ public static function shouldPreselectGenerateAudio($post) { $postType = get_post_type($post); if (! $postType) { return false; } $preselect = get_option('beyondwords_preselect'); if (! is_array($preselect)) { return false; } // Preselect if the post type in the settings has been checked (not the taxonomies) if (array_key_exists($postType, $preselect) && $preselect[$postType] === '1') { return true; } return false; } /** * Render the element. * * @since 6.0.0 Make static and refactor generate audio check. */ public static function element($post) { wp_nonce_field('beyondwords_generate_audio', 'beyondwords_generate_audio_nonce'); $generateAudio = PostMetaUtils::hasGenerateAudio($post->ID); ?>

/>