PluginProbe
Depicter — Popup & Slider Builder / 1.5.2
Depicter — Popup & Slider Builder v1.5.2
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.5.2, at app/hooks.php

151 lines 5.0 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 /**
23 * Make assets and cache for slider after publishing the changes
24 *
25 * @param $documentID
26 * @param $properties
27 *
28 * @return void
29 */
30 function depicter_make_document_cache( $documentID, $properties ) {
31 if ( $properties['status'] === 'publish' ) {
32 \Depicter::front()->render()->flushDocumentCache( $documentID );
33 \Depicter::front()->render()->document( $documentID, [ 'echo' => false ] );
34 }
35 }
36 add_action( 'depicter/editor/after/store', 'depicter_make_document_cache', 10, 2 );
37
38
39 /**
40 * Remove document cache after document was deleted
41 *
42 * @param $documentID
43 *
44 * @return void
45 */
46 function depicter_purge_document_cache( $documentID ) {
47 \Depicter::front()->render()->flushDocumentCache( $documentID );
48 }
49 add_action( 'depicter/editor/after/delete', 'depicter_purge_document_cache', 10 );
50
51
52 /**
53 * Depicter sanitize html tags for depicter slider output
54 *
55 * @param array $allowed_tags
56 * @return void
57 */
58 function depicter_sanitize_html_tags_for_output( $allowed_tags ) {
59 return array_merge_recursive( $allowed_tags, wp_kses_allowed_html( 'post' ) );
60 }
61 add_filter( 'averta/wordpress/sanitize/html/tags/depicter/output', 'depicter_sanitize_html_tags_for_output' );
62
63
64 function depicter_disable_nocache_headers( $headers ) {
65 unset( $headers['Expires'] );
66 unset( $headers['Cache-Control'] );
67 return $headers;
68 }
69
70
71 /**
72 * Set Svg Meta Data
73 *
74 * Adds dimensions metadata to uploaded SVG files, since WordPress doesn't do it.
75 *
76 * @param array $data
77 * @param int $id
78 * @return array $data
79 */
80 function depicter_set_svg_meta_data( $data, $id ) {
81 // If the attachment is an svg
82 if ( 'image/svg+xml' === get_post_mime_type( $id ) ) {
83 // If the svg metadata are empty or the width is empty or the height is empty.
84 // then get the attributes from xml.
85 if ( empty( $data ) || empty( $data['width'] ) || empty( $data['height'] ) ) {
86 $attachment = get_the_guid( $id );
87 $xml = simplexml_load_file( $attachment );
88
89 if ( ! empty( $xml ) ) {
90 $attr = $xml->attributes();
91 $view_box = explode( ' ', $attr->viewBox );// phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
92 $data['width'] = isset( $attr->width ) && preg_match( '/\d+/', $attr->width, $value ) ? (int) $value[0] : ( 4 === count( $view_box ) ? (int) $view_box[2] : null );
93 $data['height'] = isset( $attr->height ) && preg_match( '/\d+/', $attr->height, $value ) ? (int) $value[0] : ( 4 === count( $view_box ) ? (int) $view_box[3] : null );
94 }
95 }
96 }
97
98 return $data;
99 }
100 add_filter( 'wp_update_attachment_metadata', 'depicter_set_svg_meta_data', 10, 2 );
101
102 function depicter_clear_cache_by_cache_enabler() {
103 $cacheEnabled = !empty( $_GET['_cache'] ) && $_GET['_cache'] == 'cache-enabler' ? true : false;
104 $isClearAction = !empty( $_GET['_action'] ) && ( $_GET['_action'] == 'clear' || $_GET['_action'] == 'clearurl' );
105 if ( $cacheEnabled && $isClearAction && !empty( $_GET['_wpnonce'] ) && wp_verify_nonce( $_GET['_wpnonce'], 'cache_enabler_clear_cache_nonce' ) ) {
106 $documents = \Depicter::documentRepository()->getList();
107 if ( !empty( $documents ) ) {
108 foreach( $documents as $document ) {
109 \Depicter::cache('document')->delete( $document['id'] );
110 }
111 }
112 }
113 }
114 add_action( 'init', 'depicter_clear_cache_by_cache_enabler' );
115
116
117 add_filter( 'style_loader_tag', 'depicter_add_preload_to_styles', 10, 2 );
118 function depicter_add_preload_to_styles( $html, $handle ){
119 if (strpos( $handle, 'depicter--') === 0) {
120 $html = str_replace("rel='stylesheet'", 'rel="preload" as="style" onload="this.rel=\'stylesheet\';this.onload=null"', $html);
121 }
122 return $html;
123 }
124
125 function depicter_add_defer_to_scripts( $tag, $handle ) {
126 if ( strpos( $handle, 'depicter--') === 0 ) {
127 $tag = str_replace(' src=', ' defer src=', $tag );
128 }
129 return $tag;
130 }
131 add_filter( 'script_loader_tag', 'depicter_add_defer_to_scripts', 15, 2 );
132
133 /**
134 * Check if imported media deleted then remove its ID from imported assets dictionary
135 *
136 * @param int $attachment_id
137 * @return void
138 */
139 function depicter_check_deleted_imported_media( $attachment_id ) {
140 \Depicter::media()->maybeRemoveAttachmentFromDictionary( $attachment_id );
141 }
142 add_action( 'delete_attachment', 'depicter_check_deleted_imported_media');
143
144 function depicter_check_activation() {
145 if ( isset( $_GET['depicter_upgraded'] ) || ( isset( $_GET['page'] ) && $_GET['page'] == 'depicter-dashboard' ) || ( isset( $_GET['action'] ) && $_GET['action'] == 'depicter' ) ) {
146 \Depicter::client()->validateActivation();
147 }
148 }
149 add_action( 'admin_init', 'depicter_check_activation' );
150
151