Kadence Themes Toolkit - Version 3.3

Version Description

  • Add: Img src set for gallery.
Download this release

Release Info

Developer britner
Plugin Icon wp plugin Kadence Themes Toolkit
Version 3.3
Comparing to
See all releases

Code changes from version 3.2 to 3.3

Files changed (5) hide show
  1. gallery.php +104 -15
  2. page-contact.php +1 -1
  3. readme.txt +6 -3
  4. template-contact.php +1 -1
  5. virtue_toolkit.php +1 -2
gallery.php CHANGED
@@ -1,4 +1,68 @@
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  /**
3
  *
4
  * Re-create the [gallery] shortcode and use thumbnails styling from kadencethemes
@@ -37,8 +101,12 @@ function kadence_shortcode_gallery($attr) {
37
  'icontag' => '',
38
  'captiontag' => '',
39
  'columns' => 3,
 
40
  'size' => 'full',
41
  'include' => '',
 
 
 
42
  'lightboxsize' => 'full',
43
  'exclude' => ''
44
  ), $attr));
@@ -75,29 +143,50 @@ function kadence_shortcode_gallery($attr) {
75
  }
76
  return $output;
77
  }
78
- // NORMAL
79
- $output .= '<div id="kad-wp-gallery'.esc_attr($gallery_rn).'" class="kad-wp-gallery kad-light-wp-gallery clearfix rowtight">';
80
- if ($columns == '2') {$itemsize = 'tcol-lg-6 tcol-md-6 tcol-sm-6 tcol-xs-12 tcol-ss-12'; $imgsize = 600;}
81
- else if ($columns == '1') {$itemsize = 'tcol-lg-12 tcol-md-12 tcol-sm-12 tcol-xs-12 tcol-ss-12'; $imgsize = 1200;}
82
- else if ($columns == '3'){ $itemsize = 'tcol-lg-4 tcol-md-4 tcol-sm-4 tcol-xs-6 tcol-ss-12'; $imgsize = 400;}
83
- else if ($columns == '6'){ $itemsize = 'tcol-lg-2 tcol-md-2 tcol-sm-3 tcol-xs-4 tcol-ss-6'; $imgsize = 300;}
84
- else if ($columns == '8' || $columns == '9' || $columns == '7'){ $itemsize = 'tcol-lg-2 tcol-md-2 tcol-sm-3 tcol-xs-4 tcol-ss-4'; $imgsize = 260;}
85
- else if ($columns == '12' || $columns == '11'){ $itemsize = 'tcol-lg-1 tcol-md-1 tcol-sm-2 tcol-xs-2 tcol-ss-3'; $imgsize = 240;}
86
- else if ($columns == '5'){ $itemsize = 'tcol-lg-25 tcol-md-25 tcol-sm-3 tcol-xs-4 tcol-ss-6'; $imgsize = 300;}
87
- else {$itemsize = 'tcol-lg-3 tcol-md-3 tcol-sm-4 tcol-xs-6 tcol-ss-12'; $imgsize = 300;}
 
 
 
 
 
 
 
 
 
 
 
88
  $i = 0;
89
  foreach ($attachments as $id => $attachment) {
90
  $attachment_url = wp_get_attachment_url($id);
91
- $image = aq_resize($attachment_url, $imgsize, $imgsize, true);
92
- if(empty($image)) {$image = $attachment_url;}
 
93
  if($lightboxsize != 'full') {
94
  $attachment_url = wp_get_attachment_image_src( $id, $lightboxsize);
95
  $attachment_url = $attachment_url[0];
96
  }
97
- $link = isset($attr['link']) && 'post' == $attr['link'] ? wp_get_attachment_link($id, $size, true, false) : wp_get_attachment_link($id, $size, false, false);
 
 
 
 
 
 
 
 
 
98
 
99
- $output .= '<div class="'.esc_attr($itemsize).' g_item"><div class="grid_item kad_gallery_fade_in gallery_item"><a href="'.esc_url($attachment_url).'" rel="lightbox[pp_gal]" class="lightboxhover">
100
- <img src="'.esc_url($image).'" alt="'.esc_attr($attachment->post_excerpt).'" class="light-dropshaddow"/>';
101
  $output .= '</a>';
102
  $output .= '</div></div>';
103
  }
1
  <?php
2
+
3
+ function kt_toolkit_get_srcset($width,$height,$url,$id) {
4
+ if(empty($id) || empty($url)) {
5
+ return;
6
+ }
7
+
8
+ $image_meta = get_post_meta( $id, '_wp_attachment_metadata', true );
9
+ if(empty($image_meta['file'])){
10
+ return;
11
+ }
12
+ // If possible add in our images on the fly sizes
13
+ $ext = substr($image_meta['file'], strrpos($image_meta['file'], "."));
14
+ $pathflyfilename = str_replace($ext,'-'.$width.'x'.$height.'' . $ext, $image_meta['file']);
15
+ $pathretinaflyfilename = str_replace($ext, '-'.$width.'x'.$height.'@2x' . $ext, $image_meta['file']);
16
+ $flyfilename = basename($image_meta['file'], $ext) . '-'.$width.'x'.$height.'' . $ext;
17
+ $retinaflyfilename = basename($image_meta['file'], $ext) . '-'.$width.'x'.$height.'@2x' . $ext;
18
+
19
+ $upload_info = wp_upload_dir();
20
+ $upload_dir = $upload_info['basedir'];
21
+
22
+ $flyfile = trailingslashit($upload_dir).$pathflyfilename;
23
+ $retinafile = trailingslashit($upload_dir).$pathretinaflyfilename;
24
+ if(empty($image_meta['sizes']) ){ $image_meta['sizes'] = array();}
25
+ if (file_exists($flyfile)) {
26
+ $kt_add_imagesize = array(
27
+ 'kt_on_fly' => array(
28
+ 'file'=> $flyfilename,
29
+ 'width' => $width,
30
+ 'height' => $height,
31
+ 'mime-type' => $image_meta['sizes']['thumbnail']['mime-type']
32
+ )
33
+ );
34
+ $image_meta['sizes'] = array_merge($image_meta['sizes'], $kt_add_imagesize);
35
+ }
36
+ if (file_exists($retinafile)) {
37
+ $size = getimagesize( $retinafile );
38
+ if(($size[0] == 2 * $width) && ($size[1] == 2 * $height) ) {
39
+ $kt_add_imagesize_retina = array(
40
+ 'kt_on_fly_retina' => array(
41
+ 'file'=> $retinaflyfilename,
42
+ 'width' => 2 * $width,
43
+ 'height' => 2 * $height,
44
+ 'mime-type' => $image_meta['sizes']['thumbnail']['mime-type']
45
+ )
46
+ );
47
+ $image_meta['sizes'] = array_merge($image_meta['sizes'], $kt_add_imagesize_retina);
48
+ }
49
+ }
50
+ if(function_exists ( 'wp_calculate_image_srcset') ){
51
+ $output = wp_calculate_image_srcset(array( $width, $height), $url, $image_meta, $id);
52
+ } else {
53
+ $output = '';
54
+ }
55
+ return $output;
56
+ }
57
+ function kt_toolkit_get_srcset_output($width,$height,$url,$id) {
58
+ $img_srcset = kt_toolkit_get_srcset( $width, $height, $url, $id);
59
+ if(!empty($img_srcset) ) {
60
+ $output = 'srcset="'.esc_attr($img_srcset).'" sizes="(max-width: '.esc_attr($width).'px) 100vw, '.esc_attr($width).'px"';
61
+ } else {
62
+ $output = '';
63
+ }
64
+ return $output;
65
+ }
66
  /**
67
  *
68
  * Re-create the [gallery] shortcode and use thumbnails styling from kadencethemes
101
  'icontag' => '',
102
  'captiontag' => '',
103
  'columns' => 3,
104
+ 'link' => 'file',
105
  'size' => 'full',
106
  'include' => '',
107
+ 'attachment_page' => 'false',
108
+ 'use_image_alt' => 'false',
109
+ 'gallery_id' => (rand(10,100)),
110
  'lightboxsize' => 'full',
111
  'exclude' => ''
112
  ), $attr));
143
  }
144
  return $output;
145
  }
146
+
147
+ if ($columns == '2') {
148
+ $itemsize = 'tcol-lg-6 tcol-md-6 tcol-sm-6 tcol-xs-12 tcol-ss-12'; $imgsize = 600;
149
+ } else if ($columns == '1') {
150
+ $itemsize = 'tcol-lg-12 tcol-md-12 tcol-sm-12 tcol-xs-12 tcol-ss-12'; $imgsize = 1200;
151
+ } else if ($columns == '3'){
152
+ $itemsize = 'tcol-lg-4 tcol-md-4 tcol-sm-4 tcol-xs-6 tcol-ss-12'; $imgsize = 400;
153
+ } else if ($columns == '6'){
154
+ $itemsize = 'tcol-lg-2 tcol-md-2 tcol-sm-3 tcol-xs-4 tcol-ss-6'; $imgsize = 300;
155
+ } else if ($columns == '8' || $columns == '9' || $columns == '7'){
156
+ $itemsize = 'tcol-lg-2 tcol-md-2 tcol-sm-3 tcol-xs-4 tcol-ss-4'; $imgsize = 260;
157
+ } else if ($columns == '12' || $columns == '11'){
158
+ $itemsize = 'tcol-lg-1 tcol-md-1 tcol-sm-2 tcol-xs-2 tcol-ss-3'; $imgsize = 240;
159
+ } else if ($columns == '5'){
160
+ $itemsize = 'tcol-lg-25 tcol-md-25 tcol-sm-3 tcol-xs-4 tcol-ss-6'; $imgsize = 300;
161
+ } else {
162
+ $itemsize = 'tcol-lg-3 tcol-md-3 tcol-sm-4 tcol-xs-6 tcol-ss-12'; $imgsize = 300;
163
+ }
164
+
165
+ $output .= '<div id="kad-wp-gallery'.esc_attr($gallery_rn).'" class="kad-wp-gallery kad-light-wp-gallery clearfix kt-gallery-column-'.esc_attr($columns).' rowtight">';
166
+
167
  $i = 0;
168
  foreach ($attachments as $id => $attachment) {
169
  $attachment_url = wp_get_attachment_url($id);
170
+ $image = aq_resize($attachment_url, $imgsize, $imgsize, true, false);
171
+ if(empty($image[0])) {$image = array($attachment_url,$imgsize,$imgsize);}
172
+ $img_srcset_output = kt_get_srcset_output( $image[1], $image[2], $attachment_url, $id);
173
  if($lightboxsize != 'full') {
174
  $attachment_url = wp_get_attachment_image_src( $id, $lightboxsize);
175
  $attachment_url = $attachment_url[0];
176
  }
177
+ $lightbox_data = 'data-rel="lightbox"';
178
+ if($link == 'attachment_page' || $attachment_page == 'true') {
179
+ $attachment_url = get_permalink($id);
180
+ $lightbox_data = '';
181
+ }
182
+ if($use_image_alt == 'true') {
183
+ $alt = get_post_meta($id, '_wp_attachment_image_alt', true);
184
+ } else {
185
+ $alt = $attachment->post_excerpt;
186
+ }
187
 
188
+ $output .= '<div class="'.esc_attr($itemsize).' g_item"><div class="grid_item kad_gallery_fade_in gallery_item"><a href="'.esc_url($attachment_url).'" '.$lightbox_data.' class="lightboxhover">';
189
+ $output .= '<img src="'.esc_url($image[0]).'" width="'.esc_attr($image[1]).'" height="'.esc_attr($image[2]).'" alt="'.esc_attr($alt).'" '.$img_srcset_output.' class="light-dropshaddow"/>';
190
  $output .= '</a>';
191
  $output .= '</div></div>';
192
  }
page-contact.php CHANGED
@@ -108,7 +108,7 @@ Template Name: Contact
108
  if(trim($_POST['email']) === '') {
109
  $emailError = __('Please enter your email address.', 'virtue-toolkit');
110
  $hasError = true;
111
- } else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) {
112
  $emailError = __('You entered an invalid email address.', 'virtue-toolkit');
113
  $hasError = true;
114
  } else {
108
  if(trim($_POST['email']) === '') {
109
  $emailError = __('Please enter your email address.', 'virtue-toolkit');
110
  $hasError = true;
111
+ } else if (!is_email($_POST['email'])) {
112
  $emailError = __('You entered an invalid email address.', 'virtue-toolkit');
113
  $hasError = true;
114
  } else {
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
  === Virtue / Pinnacle ToolKit ===
2
  Contributors: britner
3
  Tags:
4
- Requires at least: 3.5
5
- Tested up to: 4.2
6
- Stable tag: 3.2
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -43,6 +43,9 @@ Install the plugin into the `/wp-content/plugins/` folder, and activate it.
43
 
44
  == Changelog ==
45
 
 
 
 
46
  = 3.2 =
47
  * Add: filter for portfolio-type slug.
48
  * Update: Page Template filter.
1
  === Virtue / Pinnacle ToolKit ===
2
  Contributors: britner
3
  Tags:
4
+ Requires at least: 4.0
5
+ Tested up to: 4.5
6
+ Stable tag: 3.3
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
43
 
44
  == Changelog ==
45
 
46
+ = 3.3 =
47
+ * Add: Img src set for gallery.
48
+
49
  = 3.2 =
50
  * Add: filter for portfolio-type slug.
51
  * Update: Page Template filter.
template-contact.php CHANGED
@@ -109,7 +109,7 @@ global $post;
109
  if(trim($_POST['email']) === '') {
110
  $emailError = __('Please enter your email address.', 'virtue-toolkit');
111
  $hasError = true;
112
- } else if (!preg_match("/^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$/i", trim($_POST['email']))) {
113
  $emailError = __('You entered an invalid email address.', 'virtue-toolkit');
114
  $hasError = true;
115
  } else {
109
  if(trim($_POST['email']) === '') {
110
  $emailError = __('Please enter your email address.', 'virtue-toolkit');
111
  $hasError = true;
112
+ } else if (!is_email($_POST['email'])) {
113
  $emailError = __('You entered an invalid email address.', 'virtue-toolkit');
114
  $hasError = true;
115
  } else {
virtue_toolkit.php CHANGED
@@ -3,14 +3,13 @@
3
  /*
4
  Plugin Name: Virtue / Pinnacle ToolKit
5
  Description: Custom Portfolio and Shortcode functionality for Virtue and Pinnacle Wordpress Theme
6
- Version: 3.2
7
  Author: Kadence Themes
8
  Author URI: http://kadencethemes.com/
9
  License: GPLv2 or later
10
  */
11
 
12
  function virtue_toolkit_activation() {
13
- kad_portfolio_post_init();
14
  flush_rewrite_rules();
15
  get_option('kadence_toolkit_flushpermalinks', '1');
16
  }
3
  /*
4
  Plugin Name: Virtue / Pinnacle ToolKit
5
  Description: Custom Portfolio and Shortcode functionality for Virtue and Pinnacle Wordpress Theme
6
+ Version: 3.3
7
  Author: Kadence Themes
8
  Author URI: http://kadencethemes.com/
9
  License: GPLv2 or later
10
  */
11
 
12
  function virtue_toolkit_activation() {
 
13
  flush_rewrite_rules();
14
  get_option('kadence_toolkit_flushpermalinks', '1');
15
  }