PluginProbe
Depicter — Popup & Slider Builder / 1.2.0
Depicter — Popup & Slider Builder v1.2.0
4.8.1 trunk 1.0.0 1.1.0 1.1.2 1.1.4 1.1.6 1.1.7 1.1.8 1.1.9 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.5 1.3.8 1.5.0 1.5.1 1.5.2 1.5.5 1.6.0 1.6.1 1.6.2 1.7.0 All 76 releases
depicter / app / hooks.php

hooks.php in Depicter — Popup & Slider Builder 1.2.0, at app/hooks.php

93 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Declare any actions and filters here.
4 * In most cases you should use a service provider, but in cases where you
5 * just need to add an action/filter and forget about it you can add it here.
6 *
7 * @package Depicter
8 */
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit;
12 }
13
14 // phpcs:ignore
15 // add_action( 'some_action', 'some_function' );
16 function depicter_add_thumbnail_size() {
17 add_image_size( 'depicter-thumbnail', 200, 9999, false );
18 }
19 add_action( 'after_setup_theme', 'depicter_add_thumbnail_size' );
20
21
22 function depicter_purge_document_cache( $documentID, $properties ) {
23 if ( $properties['status'] === 'publish' ) {
24 \Depicter::cache('document')->delete( $documentID );
25 }
26 }
27 add_action( 'depicter/editor/after/store', 'depicter_purge_document_cache', 10, 2 );
28
29
30 /**
31 * Depicter sanitize html tags for depicter slider output
32 *
33 * @param array $allowed_tags
34 * @return void
35 */
36 function depicter_sanitize_html_tags_for_output( $allowed_tags ) {
37 return array_merge( $allowed_tags, wp_kses_allowed_html( 'post' ) );
38 }
39 add_filter( 'averta/wordpress/sanitize/html/tags/depicter/output', 'depicter_sanitize_html_tags_for_output' );
40
41
42 function depicter_disable_nocache_headers( $headers ) {
43 unset( $headers['Expires'] );
44 unset( $headers['Cache-Control'] );
45 return $headers;
46 }
47
48
49 /**
50 * Set Svg Meta Data
51 *
52 * Adds dimensions metadata to uploaded SVG files, since WordPress doesn't do it.
53 *
54 * @param array $data
55 * @param int $id
56 * @return array $data
57 */
58 function depicter_set_svg_meta_data( $data, $id ) {
59 // If the attachment is an svg
60 if ( 'image/svg+xml' === get_post_mime_type( $id ) ) {
61 // If the svg metadata are empty or the width is empty or the height is empty.
62 // then get the attributes from xml.
63 if ( empty( $data ) || empty( $data['width'] ) || empty( $data['height'] ) ) {
64 $attachment = get_the_guid( $id );
65 $xml = simplexml_load_file( $attachment );
66
67 if ( ! empty( $xml ) ) {
68 $attr = $xml->attributes();
69 $view_box = explode( ' ', $attr->viewBox );// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
70 $data['width'] = isset( $attr->width ) && preg_match( '/\d+/', $attr->width, $value ) ? (int) $value[0] : ( 4 === count( $view_box ) ? (int) $view_box[2] : null );
71 $data['height'] = isset( $attr->height ) && preg_match( '/\d+/', $attr->height, $value ) ? (int) $value[0] : ( 4 === count( $view_box ) ? (int) $view_box[3] : null );
72 }
73 }
74 }
75
76 return $data;
77 }
78 add_filter( 'wp_update_attachment_metadata', 'depicter_set_svg_meta_data', 10, 2 );
79
80 function depicter_clear_cache_by_cache_enabler() {
81 $cacheEnabled = !empty( $_GET['_cache'] ) && $_GET['_cache'] == 'cache-enabler' ? true : false;
82 $isClearAction = !empty( $_GET['_action'] ) && ( $_GET['_action'] == 'clear' || $_GET['_action'] == 'clearurl' );
83 if ( $cacheEnabled && $isClearAction && !empty( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'cache_enabler_clear_cache_nonce' ) ) {
84 $documents = \Depicter::documentRepository()->getList();
85 if ( !empty( $documents ) ) {
86 foreach( $documents as $document ) {
87 \Depicter::cache('document')->delete( $document['id'] );
88 }
89 }
90 }
91 }
92 add_action( 'init', 'depicter_clear_cache_by_cache_enabler' );
93