# depicter/1.3.3/app/hooks.php

Depicter — Popup &amp; Slider Builder, version 1.3.3. 132 lines.

- Page: https://pluginprobe.com/plugins/depicter/1.3.3/code/app/hooks.php
- Raw: https://pluginprobe.com/plugins/depicter/1.3.3/raw/app/hooks.php
- Modified: 2022-09-24T14:46:54+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/depicter/1.3.3/code/app/hooks.php#L10-L20`.

```php
<?php
/**
 * Declare any actions and filters here.
 * In most cases you should use a service provider, but in cases where you
 * just need to add an action/filter and forget about it you can add it here.
 *
 * @package Depicter
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

// phpcs:ignore
// add_action( 'some_action', 'some_function' );
function depicter_add_thumbnail_size() {
	add_image_size( 'depicter-thumbnail', 200, 9999, false );
}
add_action( 'after_setup_theme', 'depicter_add_thumbnail_size' );


/**
 * Make assets and cache for slider after publishing the changes
 *
 * @param $documentID
 * @param $properties
 *
 * @return void
 */
function depicter_make_document_cache( $documentID, $properties ) {
	if ( $properties['status'] === 'publish' ) {
		\Depicter::front()->render()->flushDocumentCache( $documentID );
		\Depicter::front()->render()->document( $documentID, [ 'echo' => false ] );
	}
}
add_action( 'depicter/editor/after/store', 'depicter_make_document_cache', 10, 2 );


/**
 * Remove document cache after document was deleted
 *
 * @param $documentID
 *
 * @return void
 */
function depicter_purge_document_cache( $documentID ) {
	\Depicter::front()->render()->flushDocumentCache( $documentID );
}
add_action( 'depicter/editor/after/delete', 'depicter_purge_document_cache', 10 );


/**
 * Depicter sanitize html tags for depicter slider output
 *
 * @param array $allowed_tags
 * @return void
 */
function depicter_sanitize_html_tags_for_output( $allowed_tags ) {
	return array_merge( $allowed_tags, wp_kses_allowed_html( 'post' ) );
}
add_filter( 'averta/wordpress/sanitize/html/tags/depicter/output', 'depicter_sanitize_html_tags_for_output' );


function depicter_disable_nocache_headers( $headers ) {
	unset( $headers['Expires'] );
	unset( $headers['Cache-Control'] );
	return $headers;
}


/**
 * Set Svg Meta Data
 *
 * Adds dimensions metadata to uploaded SVG files, since WordPress doesn't do it.
 *
 * @param array $data
 * @param int $id
 * @return array $data
 */
function depicter_set_svg_meta_data( $data, $id ) {
	// If the attachment is an svg
	if ( 'image/svg+xml' === get_post_mime_type( $id ) ) {
		// If the svg metadata are empty or the width is empty or the height is empty.
		// then get the attributes from xml.
		if ( empty( $data ) || empty( $data['width'] ) || empty( $data['height'] ) ) {
			$attachment = get_the_guid( $id );
			$xml = simplexml_load_file( $attachment );

			if ( ! empty( $xml ) ) {
				$attr = $xml->attributes();
				$view_box = explode( ' ', $attr->viewBox );// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
				$data['width'] = isset( $attr->width ) && preg_match( '/\d+/', $attr->width, $value ) ? (int) $value[0] : ( 4 === count( $view_box ) ? (int) $view_box[2] : null );
				$data['height'] = isset( $attr->height ) && preg_match( '/\d+/', $attr->height, $value ) ? (int) $value[0] : ( 4 === count( $view_box ) ? (int) $view_box[3] : null );
			}
		}
	}

	return $data;
}
add_filter( 'wp_update_attachment_metadata', 'depicter_set_svg_meta_data', 10, 2 );

function depicter_clear_cache_by_cache_enabler() {
	$cacheEnabled =  !empty( $_GET['_cache'] ) && $_GET['_cache'] == 'cache-enabler' ? true : false;
	$isClearAction = !empty( $_GET['_action'] ) && ( $_GET['_action'] == 'clear' || $_GET['_action'] == 'clearurl' );
	if ( $cacheEnabled && $isClearAction && !empty( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'cache_enabler_clear_cache_nonce' ) ) {
		$documents = \Depicter::documentRepository()->getList();
		if ( !empty( $documents ) ) {
			foreach( $documents as $document ) {
				\Depicter::cache('document')->delete( $document['id'] );
			}
		}
	}
}
add_action( 'init', 'depicter_clear_cache_by_cache_enabler' );


add_filter( 'style_loader_tag',  'depicter_add_preload_to_styles', 10, 2 );
function depicter_add_preload_to_styles( $html, $handle ){
    if (strpos( $handle, 'depicter--') === 0) {
        $html = str_replace("rel='stylesheet'", 'rel="preload" as="style" onload="this.rel=\'stylesheet\';this.onload=null"', $html);
    }
    return $html;
}

function depicter_add_defer_to_scripts( $tag, $handle ) {
	if ( strpos( $handle, 'depicter--') === 0 ) {
        $tag = str_replace(' src=', ' defer src=', $tag );
    }
    return $tag;
}
add_filter( 'script_loader_tag', 'depicter_add_defer_to_scripts', 15, 2 );

```
