is_block_editor() ) { return true; } return false; } /** * Add video post format. */ public static function add_extra_post_format() { global $_wp_theme_features; $formats = array( 'image', 'video' ); // Add existing formats. if ( isset( $_wp_theme_features['post-formats'] ) && isset( $_wp_theme_features['post-formats'][0] ) ) { $formats = array_merge( (array) $_wp_theme_features['post-formats'][0], $formats ); } $formats = array_unique( $formats ); add_theme_support( 'post-formats', $formats ); } /** * Register post meta. */ public static function register_post_meta() { $post_type_names = array_keys( get_post_types() ); foreach ( $post_type_names as $post_type ) { if ( ! is_post_type_viewable( $post_type ) ) { continue; } // Register meta for all post types. register_meta( 'post', '_vp_format_video_url', array( 'object_subtype' => $post_type, 'type' => 'string', 'single' => true, 'show_in_rest' => true, 'auth_callback' => array( __CLASS__, 'rest_auth' ), ) ); register_meta( 'post', '_vp_image_focal_point', array( 'object_subtype' => $post_type, 'type' => 'object', 'single' => true, 'show_in_rest' => array( 'schema' => array( 'type' => 'object', 'properties' => array( 'x' => array( 'type' => 'number', ), 'y' => array( 'type' => 'number', ), ), ), ), 'auth_callback' => array( __CLASS__, 'rest_auth' ), ) ); // Add support for 'custom-fields' to work in Gutenberg. add_post_type_support( $post_type, 'custom-fields' ); } } /** * Determines REST API authentication. * * @param bool $allowed Whether it is allowed. * @param string $meta_key The meta key being checked. * @param int $post_id The post ID being checked. * @param int $user_id The user ID being checked. * @param string $cap The current capability. * @param array $caps All capabilities. * @return bool Whether the user can do it. */ // phpcs:ignore public static function rest_auth( $allowed, $meta_key, $post_id, $user_id, $cap, $caps ) { return user_can( $user_id, 'edit_post', $post_id ); } /** * Add post format metaboxes. * * @param string $post_type post type. */ public static function add_post_format_metaboxes( $post_type ) { // Prevent if Gutenberg enabled. if ( self::is_gutenberg() ) { return; } // Prevent if no Video post format supported. if ( ! post_type_supports( $post_type, 'post-formats' ) ) { return; } add_meta_box( 'vp_format_video', esc_html__( 'Video', 'visual-portfolio' ), array( __CLASS__, 'add_video_format_metabox' ), null, 'side', 'default' ); } /** * Add Video Format metabox * * @param object $post The post object. */ public static function add_video_format_metabox( $post ) { wp_nonce_field( basename( __FILE__ ), 'vp_format_video_nonce' ); $video_url = self::get_video_format_url( $post->ID ); $oembed_html = false; $wpkses_iframe = array( 'iframe' => array( 'src' => array(), 'height' => array(), 'width' => array(), 'frameborder' => array(), 'allowfullscreen' => array(), ), ); if ( $video_url ) { $oembed = visual_portfolio()->get_oembed_data( $video_url ); if ( $oembed && isset( $oembed['html'] ) ) { $oembed_html = $oembed['html']; } } ?>
$reading_time ) { $reading_time = esc_html__( '< 1', 'visual-portfolio' ); } else { $reading_time = ceil( $reading_time ); } return $reading_time; } /** * Calculate words count. * * @param int $post_id The post ID. */ public static function calculate_words_count( $post_id ) { if ( ! $post_id ) { $post_id = get_the_ID(); } $content = get_the_content( null, false, $post_id ); $content = wp_strip_all_tags( $content ); $words_count = count( preg_split( '/\s+/', $content ) ); return $words_count; } } Visual_Portfolio_Custom_Post_Meta::init();