-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautoLightbox.php
65 lines (55 loc) · 1.66 KB
/
autoLightbox.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/*
Plugin Name: Hello World
Description: Starter plugin
Version: 1.0
Author: GetSimple CE
Author URI: https://www.getsimple-ce.ovh
*/
# get correct id for plugin
$thisfile = basename(__FILE__, ".php");
# register plugin
register_plugin(
$thisfile, //Plugin id
'autoLightbox', //Plugin name
'1.0', //Plugin version
'GetSimple CE', //Plugin author
'https://www.getsimple-ce.ovh/', //author website
'Automatically adds Lightbox to all images in content areas, gallery plugins not needed.', //Plugin description
'plugins', //page type - on which admin tab to display
'' //main function (administration)
);
# activate filter
add_action('theme-header', 'headerLightbox');
add_action('theme-footer', 'footerLightbox');
# functions
function headerLightbox()
{
global $SITEURL;
echo '<link rel="stylesheet" href="' . $SITEURL . 'plugins/autoLightbox/glightbox/glightbox.min.css">';
global $content;
$string = html_entity_decode($content);
function wrap_images_in_link($matches)
{
$img_tag = $matches[0]; // Cały tag <img>
preg_match('/src="([^"]+)"/', $img_tag, $src_match); // Wyszukaj src
$src_url = $src_match[1]; // Pobierz url z src
return '<a href="' . $src_url . '" class="glightbox">' . $img_tag . '</a>'; // Zwróć nowy kod z <a> wokół <img>
}
$content = preg_replace_callback('/<img[^>]*src="[^"]+"[^>]*>/', 'wrap_images_in_link', $string);
}
function footerLightbox()
{
global $GSPLUGINPATH;
echo '<script src="' . $SITEURL . 'plugins/autoLightbox/glightbox/glightbox.min.js"></script>';
echo "
<script type='text/javascript'>
const lightbox = GLightbox({
touchNavigation: true,
loop: true,
autoplayVideos: true
});
</script>
";
}
?>