FLIPSET_URL . 'assets/vendor/pdfjs/pdf.worker.min.js',
)
);
wp_register_style(
'flipset-library',
FLIPSET_URL . 'assets/css/flipset-library.css',
array(),
FLIPSET_VERSION
);
wp_register_script(
'flipset-library-block-editor',
FLIPSET_URL . 'assets/js/flipset-library-block.js',
array( 'wp-blocks', 'wp-element', 'wp-block-editor', 'wp-components', 'wp-i18n', 'wp-server-side-render' ),
FLIPSET_VERSION,
true
);
wp_set_script_translations( 'flipset-library-block-editor', 'flipset' );
register_block_type(
FLIPSET_DIR . 'blocks/viewer',
array(
'render_callback' => array( $this, 'render_block' ),
)
);
register_block_type(
FLIPSET_DIR . 'blocks/library',
array(
'render_callback' => array( $this, 'render_library_block' ),
)
);
$this->register_block_patterns();
}
/**
* Register curated block patterns for document layouts.
*/
public function register_block_patterns() {
if ( ! function_exists( 'register_block_pattern_category' ) || ! function_exists( 'register_block_pattern' ) ) {
return;
}
register_block_pattern_category(
'flipset',
array(
'label' => __( 'Flipset Documents', 'flipset' ),
)
);
register_block_pattern(
'flipset/lead-magnet',
array(
'title' => __( 'Whitepaper / Lead Magnet', 'flipset' ),
'description' => __( 'Two-column document showcase with title, summary, and PDF viewer.', 'flipset' ),
'categories' => array( 'flipset', 'featured' ),
'content' => '
' . esc_html__( 'Free Research Report', 'flipset' ) . '
' . esc_html__( 'Explore key insights, comprehensive findings, and actionable recommendations in our latest publication.', 'flipset' ) . '
',
)
);
register_block_pattern(
'flipset/research-paper',
array(
'title' => __( 'Academic / Research Document', 'flipset' ),
'description' => __( 'Formal document layout with metadata, abstract callout, and full-width PDF viewer.', 'flipset' ),
'categories' => array( 'flipset' ),
'content' => '
' . esc_html__( 'Document Title & Research Paper', 'flipset' ) . '
' . esc_html__( 'Published by Author / Institution — Last Updated: 2026', 'flipset' ) . '
' . esc_html__( 'Abstract:', 'flipset' ) . ' ' . esc_html__( 'This publication examines core methodologies, experimental data, and concluding outcomes.', 'flipset' ) . '
',
)
);
register_block_pattern(
'flipset/annual-report',
array(
'title' => __( 'Annual Report / Catalog Hero', 'flipset' ),
'description' => __( 'Wide annual report showcase with key metrics and wide-format PDF reader.', 'flipset' ),
'categories' => array( 'flipset' ),
'content' => '
' . esc_html__( 'Annual Report & Highlights', 'flipset' ) . '
' . esc_html__( 'Browse through our full annual review, financial statistics, and milestones.', 'flipset' ) . '
',
)
);
}
/**
* Delegates to the same shortcode renderer used by [flipset].
*
* @param array $attributes Block attributes.
* @param string $content Block inner content (unused).
* @param WP_Block $block Block instance when available.
* @return string
*/
public function render_block( $attributes, $content = '', $block = null ) {
unset( $content ); // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
// block.json gives every attribute a default, so $attributes always holds
// file="", width="100%", etc. For a saved embed those defaults would
// overwrite the stored config. Pass only what the author actually set.
if ( ! empty( $attributes['id'] ) && $block instanceof WP_Block
&& isset( $block->parsed_block['attrs'] ) && is_array( $block->parsed_block['attrs'] ) ) {
$attributes = $block->parsed_block['attrs'];
}
$html = Flipset::instance()->viewer->render_shortcode( $attributes );
if ( function_exists( 'get_block_wrapper_attributes' ) ) {
$html = ' 'flipset-block' ) ) . '>' . $html . '
';
}
return wp_kses( $html, Flipset_Viewer::allowed_html() );
}
/**
* Delegates to the same shortcode renderer used by [flipset_library].
*
* @param array $attributes Block attributes.
* @param string $content Block inner content (unused).
* @param WP_Block $block Block instance when available.
* @return string
*/
public function render_library_block( $attributes, $content = '', $block = null ) {
unset( $content, $block ); // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed
$html = Flipset::instance()->library->render_shortcode( $attributes );
if ( function_exists( 'get_block_wrapper_attributes' ) ) {
$html = ' 'flipset-library-block' ) ) . '>' . $html . '
';
}
return wp_kses( $html, Flipset_Viewer::allowed_html() );
}
}