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 );