%2$s', esc_url( 'https://wordpress.org/support/plugin/acs-pdf-slide-viewer/reviews/#new-post' ), esc_html__( 'Write a review', 'acs-pdf-slide-viewer' ) ); return $links; } /** * Load the bundled translations from /languages. * * @return void */ public static function load_textdomain() { load_plugin_textdomain( 'acs-pdf-slide-viewer', false, dirname( plugin_basename( ACSPSV_PLUGIN_FILE ) ) . '/languages' ); } /** * Register the PDF slide block from block metadata. * * @return void */ public static function register_block() { $registered = register_block_type( ACSPSV_PLUGIN_DIR . 'blocks/pdf-slide', array( 'render_callback' => 'acspsv_render_pdf_slide_block', ) ); self::setup_editor_script_translations( $registered ); } /** * Hand the bundled JSON translations to the editor script. * * The handle is decided by WordPress when block.json is registered, * so it is read back from the registration result instead of guessed. * * @param WP_Block_Type|false $block_type Registration result. * @return void */ private static function setup_editor_script_translations( $block_type ) { if ( ! $block_type || ! is_object( $block_type ) || ! function_exists( 'wp_set_script_translations' ) ) { return; } $handles = isset( $block_type->editor_script_handles ) ? (array) $block_type->editor_script_handles : array(); foreach ( $handles as $handle ) { if ( '' === (string) $handle ) { continue; } wp_set_script_translations( $handle, 'acs-pdf-slide-viewer', ACSPSV_PLUGIN_DIR . 'languages' ); } } /** * Render the shortcode for Classic Editor or template usage. * * Example: * [acs_pdf_slide_viewer url="https://example.com/file.pdf" pages="8" title="Slides"] * * @param array $atts Shortcode attributes. * @return string */ public static function render_shortcode( $atts ) { $atts = shortcode_atts( array( 'url' => '', 'title' => '', 'pages' => 1, 'start' => 1, 'height' => 560, 'aspect_ratio' => 'auto', 'mode' => 'inline', 'download' => 'false', 'carousel' => 'false', 'interval' => 5000, 'loop' => 'true', 'show_controls' => 'true', ), $atts, 'acs_pdf_slide_viewer' ); $attributes = array( 'pdfUrl' => esc_url_raw( $atts['url'] ), 'title' => sanitize_text_field( $atts['title'] ), 'pageCount' => absint( $atts['pages'] ), 'startPage' => absint( $atts['start'] ), 'height' => absint( $atts['height'] ), 'aspectRatio' => sanitize_text_field( $atts['aspect_ratio'] ), 'displayMode' => sanitize_key( $atts['mode'] ), 'showDownload' => filter_var( $atts['download'], FILTER_VALIDATE_BOOLEAN ), 'carousel' => filter_var( $atts['carousel'], FILTER_VALIDATE_BOOLEAN ), 'interval' => absint( $atts['interval'] ), 'loop' => filter_var( $atts['loop'], FILTER_VALIDATE_BOOLEAN ), 'showControls' => filter_var( $atts['show_controls'], FILTER_VALIDATE_BOOLEAN ), ); $html = acspsv_render_pdf_slide_block( $attributes ); if ( '' !== $html ) { self::enqueue_block_frontend_assets(); } return $html; } /** * Enqueue the block's front-end script and style for shortcode output. * * WordPress enqueues block.json "viewScript" and "style" only when the * block itself renders, so the shortcode path enqueues the same handles * read back from the registered block type. * * @return void */ private static function enqueue_block_frontend_assets() { $block_type = WP_Block_Type_Registry::get_instance()->get_registered( 'acs-pdf-slide-viewer/pdf-slide' ); if ( ! $block_type ) { return; } $script_handles = isset( $block_type->view_script_handles ) ? (array) $block_type->view_script_handles : array(); $style_handles = isset( $block_type->style_handles ) ? (array) $block_type->style_handles : array(); foreach ( $script_handles as $handle ) { if ( '' !== (string) $handle ) { wp_enqueue_script( $handle ); } } foreach ( $style_handles as $handle ) { if ( '' !== (string) $handle ) { wp_enqueue_style( $handle ); } } } } ACSPSV_Plugin::init();