Plugin Page

DICOM — WP Medical Image Viewer

View Plugin

Developer Reference

This section is for developers extending the DICOM Viewer plugin or integrating it with custom code.


Requirements

  • PHP 8.0+ — the plugin requires modern PHP with type hints and features from PHP 8.0
  • WordPress 6.4+
  • Basic WordPress development knowledge (hooks, filters, REST API)

Topics


Common Tasks

Access plugin settings:

if ( class_exists( 'DV_Plugin' ) ) {
    $defaults = DV_Plugin::get_viewer_default_settings();
    $default_height = $defaults['height'] ?? '480px';
}

Check if license is active:

if ( class_exists( 'DV_License' ) && DV_License::is_active() ) {
    // License is active
}

Get attachment details:

$original_name = get_post_meta( $attachment_id, '_dv_original_name', true );

Render a DICOM viewer programmatically:

if ( class_exists( 'DV_Plugin' ) ) {
    echo DV_Plugin::render_viewer( [
        'url'    => 'https://example.com/scan.dcm',
        'height' => '600px',
    ] );
}

File Structure

dicom-viewer/
├── dicom-viewer.php              Main plugin file
├── includes/
│   ├── class-dv-plugin.php       Plugin orchestrator
│   ├── class-dv-settings.php     Settings UI
│   ├── class-dv-shortcode.php    Shortcode handler
│   ├── class-dv-block.php        Gutenberg block
│   ├── class-dv-upload.php       File upload handling
│   ├── class-dv-file-server.php  Protected file serving
│   ├── class-dv-license.php      License validation
│   └── class-dv-classic-editor.php  Classic editor support
├── lib/dicom-viewer-core/        JavaScript viewer library
├── webdevelop-license-client/    Shared license client
└── uninstall.php                 Cleanup on uninstall

Hooks & Filters

The plugin exposes a small set of public WordPress hooks you can use to adjust shared defaults, change render arguments, add toolbar UI, or post-process the final HTML.


dv_viewer_default_settings

Type: Filter

Filters the shared viewer defaults used by front-end rendering and editor tooling.

Arguments:

  • $defaults — associative array of default settings such as height, cine_speed, layout, grid_cols, show_pan_control, show_slider, and related viewer toggles

Example:

add_filter( 'dv_viewer_default_settings', function ( $defaults ) {
    $defaults['layout'] = 'grid';
    $defaults['grid_cols'] = 3;
    $defaults['show_slider'] = false;

    return $defaults;
} );

dv_render_viewer_args

Type: Filter

Filters the final viewer arguments after global defaults have been merged and before the HTML is rendered.

Arguments:

  • $args — final render arguments passed into the viewer markup
  • $context — render context array with a source key of shortcode, block, or direct

Example:

add_filter( 'dv_render_viewer_args', function ( $args, $context ) {
    if ( ( $context['source'] ?? '' ) === 'shortcode' ) {
        $args['show_zoom_control'] = false;
    }

    return $args;
}, 10, 2 );

dv_viewer_toolbar_end

Type: Action

Fires at the end of the viewer toolbar button group, allowing custom buttons or markup to be injected.

Arguments:

  • $args — final viewer render arguments
  • $context — render context array with a source key
  • $id — unique DOM id for the viewer element

Example:

add_action( 'dv_viewer_toolbar_end', function ( $args, $context, $id ) {
    echo '<button type="button" class="dcm-custom-tool" data-viewer-id="' . esc_attr( $id ) . '">Custom</button>';
}, 10, 3 );

dv_rendered_viewer_html

Type: Filter

Filters the final rendered HTML string after the viewer markup has been generated.

Arguments:

  • $html — rendered viewer HTML
  • $args — final viewer render arguments
  • $context — render context array with a source key

Example:

add_filter( 'dv_rendered_viewer_html', function ( $html, $args, $context ) {
    return str_replace( 'dcm-viewer-wrap', 'dcm-viewer-wrap custom-viewer', $html );
}, 10, 3 );