* @since 6.3.0 */ namespace Beyondwords\Wordpress\Component\Post\ContentId; use Beyondwords\Wordpress\Component\Post\PostMetaUtils; use Beyondwords\Wordpress\Component\Settings\SettingsUtils; use Beyondwords\Wordpress\Core\CoreUtils; /** * ContentId * * @since 6.3.0 */ defined('ABSPATH') || exit; class ContentId { /** * Init. * * @since 6.3.0 */ public static function init() { add_action('admin_enqueue_scripts', [self::class, 'adminEnqueueScripts']); 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); } } }); } /** * HTML output for this component. * * @since 6.3.0 * * @param \WP_Post $post The post object. */ public static function element($post) { $contentId = PostMetaUtils::getContentId($post->ID) ?: ''; $projectId = PostMetaUtils::getProjectId($post->ID) ?: get_option('beyondwords_project_id', ''); $postType = get_post_type($post); $postTypeObj = $postType ? get_post_type_object($postType) : null; $restBase = ($postTypeObj && ! empty($postTypeObj->rest_base)) ? $postTypeObj->rest_base : $postType; wp_nonce_field('beyondwords_content_id', 'beyondwords_content_id_nonce'); ?>