' . PHP_EOL; } } // cleanup cached data when thumbed attachment deleted include_once DG_PATH . 'inc/class-thumber.php'; add_action( 'delete_attachment', array( 'DG_Thumb', 'cleanupAttachmentMeta' ) ); if ( is_admin() ) { // admin house keeping include_once DG_PATH . 'admin/class-admin.php'; // AJAX handling include_once DG_PATH . 'admin/class-ajax-handler.php'; // add links to plugin index add_filter( 'plugin_action_links_' . DG_BASENAME, array( 'DG_Admin', 'addSettingsLink' ) ); add_filter( 'plugin_row_meta', array( 'DG_Admin', 'addDonateLink' ), 10, 2 ); // build options page add_action( 'admin_menu', array( 'DG_Admin', 'addAdminPage' ) ); // add meta box for managing thumbnail generation to attachment Edit Media page add_action( 'add_meta_boxes', array( 'DG_Admin', 'addMetaBox' ) ); add_action( 'wp_ajax_dg_upload_thumb', array( 'DG_Admin', 'saveMetaBox' ) ); if ( DG_Admin::doRegisterSettings() ) { add_action( 'admin_init', array( 'DG_Admin', 'registerSettings' ) ); } } else { // styling for gallery if ( apply_filters( 'dg_use_default_gallery_style', true ) ) { add_action( 'wp_enqueue_scripts', array( 'DocumentGallery', 'enqueueGalleryStyle' ) ); } add_action( 'wp_print_scripts', array( 'DocumentGallery', 'printCustomStyle' ) ); add_action( 'wp_enqueue_scripts', array( 'DocumentGallery', 'enqueueGalleryScript' ) ); } /** * Registers the block using the metadata loaded from the `block.json` file. * Behind the scenes, it registers also all assets so they can be enqueued * through the block editor in the corresponding context. * * @see https://developer.wordpress.org/reference/functions/register_block_type/ */ function document_gallery_block_init() { register_block_type( __DIR__ . '/build/block', array( 'render_callback' => 'document_gallery_block_render_callback' ) ); } add_action( 'init', 'document_gallery_block_init' ); /** * Pass default options to block editor script. */ function document_gallery_block_localize() { global $dg_options; // Script handle is auto-generated: {namespace}-{block-name}-editor-script wp_localize_script( 'document-gallery-document-gallery-block-editor-script', 'dgBlockConfig', array( 'dgDefaults' => $dg_options['gallery'] ) ); } add_action( 'enqueue_block_editor_assets', 'document_gallery_block_localize' ); /** * This function is called when the block is being rendered on the front end of the site * * @param array $attributes The array of attributes for this block. * @param string $content Rendered block output. ie. . * @param WP_Block $block_instance The instance of the WP_Block class that represents the block being rendered. */ function document_gallery_block_render_callback( $attributes, $content, $block_instance ) { return DocumentGallery::doShortcode( $attributes ); } // adds 'dg' shortcode add_shortcode( 'dg', array( 'DocumentGallery', 'doShortcode' ) ); // public API for developers include_once DG_PATH . 'inc/class-api.php';