plugin updates

This commit is contained in:
Tony Volpe
2024-12-02 15:56:58 -05:00
parent 8cdfd97703
commit d3696168c9
102 changed files with 557 additions and 214 deletions

View File

@@ -63,7 +63,7 @@ if (class_exists('WPBakeryShortCode')) {
'front_enqueue_css' => array(
WPMF_PLUGIN_URL . 'assets/js/slick/slick.css',
WPMF_PLUGIN_URL . 'assets/js/slick/slick-theme.css',
WPMF_PLUGIN_URL . '/assets/css/display-gallery/style-display-gallery.css',
WPMF_PLUGIN_URL . 'assets/css/display-gallery/style-display-gallery.css',
),
'params' => array(
array(

View File

@@ -29,10 +29,11 @@ class WpmfWatermark
*
* @param array $metadata An array of attachment meta data.
* @param integer $attachment_id Current attachment ID.
* @param boolean $isWoo Check images of woocommerce product
*
* @return mixed $metadata
*/
public function createWatermarkImage($metadata, $attachment_id)
public function createWatermarkImage($metadata, $attachment_id, $isWoo = false)
{
$option_image_watermark = get_option('wpmf_option_image_watermark');
if (empty($option_image_watermark)) {
@@ -52,22 +53,52 @@ class WpmfWatermark
$watermark_exclude_photograph_gallery = wpmfGetOption('watermark_exclude_photograph_gallery');
$check = false;
if (!empty($watermark_exclude_public_gallery)) {
if (!empty($galleryid)) {
$gallery_type = get_term_meta((int)$galleryid, 'gallery_type', true);
if (!empty($gallery_type) && $gallery_type === 'photographer') {
if ($isWoo) {
$gallery_terms = get_the_terms($attachment_id, WPMF_GALLERY_ADDON_TAXO);
if (!empty($gallery_terms)) {
$check = true;
if (empty($watermark_exclude_photograph_gallery)) {
foreach ($gallery_terms as $gallery_term) {
$gallery_type = get_term_meta((int)$gallery_term->term_id, 'gallery_type', true);
if (!empty($gallery_type) && $gallery_type === 'photographer') {
$check = false;
}
}
}
}
} else {
if (!empty($galleryid)) {
$check = true;
if (empty($watermark_exclude_photograph_gallery)) {
$gallery_type = get_term_meta((int)$galleryid, 'gallery_type', true);
if (!empty($gallery_type) && $gallery_type === 'photographer') {
$check = false;
}
}
}
}
if (!$check) {
if ($check) {
return $metadata;
}
}
if (!empty($watermark_exclude_photograph_gallery)) {
if (!empty($galleryid)) {
$gallery_type = get_term_meta((int)$galleryid, 'gallery_type', true);
if (!empty($gallery_type) && $gallery_type === 'photographer') {
$check = true;
if ($isWoo) {
$gallery_terms = get_the_terms($attachment_id, WPMF_GALLERY_ADDON_TAXO);
if (!empty($gallery_terms)) {
foreach ($gallery_terms as $gallery_term) {
$gallery_type = get_term_meta((int)$gallery_term->term_id, 'gallery_type', true);
if (!empty($gallery_type) && $gallery_type === 'photographer') {
$check = true;
}
}
}
} else {
if (!empty($galleryid)) {
$gallery_type = get_term_meta((int)$galleryid, 'gallery_type', true);
if (!empty($gallery_type) && $gallery_type === 'photographer') {
$check = true;
}
}
}
@@ -128,18 +159,24 @@ class WpmfWatermark
}
// Using the wp_upload_dir replace the baseurl with the basedir
$path = str_replace($uploads['baseurl'], $uploads['basedir'], $image_url);
if (!empty($path)) {
if (!empty($path) && file_exists($path)) {
$pathinfo = pathinfo($path);
$imageInfo = getimagesize($path);
}
try {
if (!empty($pathinfo)) {
$this->generatePicture($pathinfo['basename'], $imageInfo, $pathinfo['dirname'], $imageSize);
$this->generatePicture($pathinfo['basename'], $imageInfo, $pathinfo['dirname'], $imageSize, '', $isWoo);
} else {
if ($isWoo) {
return;
}
wp_send_json(array('status' => false));
}
} catch (Exception $e) {
if ($isWoo) {
return;
}
wp_send_json(array('status' => false));
}
}
@@ -169,11 +206,17 @@ class WpmfWatermark
try {
if (!empty($pathinfo)) {
$this->generatePicture($pathinfo['basename'], $imageInfo, $pathinfo['dirname'], $imageSize);
$this->generatePicture($pathinfo['basename'], $imageInfo, $pathinfo['dirname'], $imageSize, '', $isWoo);
} else {
if ($isWoo) {
return;
}
wp_send_json(array('status' => false));
}
} catch (Exception $e) {
if ($isWoo) {
return;
}
wp_send_json(array('status' => false));
}
}
@@ -249,6 +292,7 @@ class WpmfWatermark
$excludes = array();
$exclude_folders = wpmfGetOption('watermark_exclude_folders');
$watermark_apply = get_option('wpmf_image_watermark_apply');
$option_watermark_only_woo = get_option('wpmf_watermark_only_woo');
foreach (array_unique($exclude_folders) as $folder) {
if ($folder === 'root') {
$excludes[] = 0;
@@ -287,6 +331,16 @@ class WpmfWatermark
}
if (!empty($attachments)) {
foreach ($attachments as $attachment) {
$isWoo = false;
if (!empty($option_watermark_only_woo) && (int) $option_watermark_only_woo === 1 && class_exists('WooCommerce')) {
$product_id = $this->getProductIdByImageId($attachment->ID);
if (!empty($product_id)) {
$isWoo = true;
} else {
$k ++;
continue;
}
}
// exclude watermark on gallery
if (is_plugin_active('wp-media-folder-gallery-addon/wp-media-folder-gallery-addon.php')) {
$watermark_exclude_public_gallery = wpmfGetOption('watermark_exclude_public_gallery');
@@ -295,14 +349,17 @@ class WpmfWatermark
if (!empty($watermark_exclude_public_gallery)) {
$gallery_terms = get_the_terms($attachment->ID, WPMF_GALLERY_ADDON_TAXO);
if (!empty($gallery_terms)) {
foreach ($gallery_terms as $gallery_term) {
$gallery_type = get_term_meta((int)$gallery_term->term_id, 'gallery_type', true);
if (!empty($gallery_type) && $gallery_type === 'photographer') {
$check = true;
$check = true;
if (empty($watermark_exclude_photograph_gallery)) {
foreach ($gallery_terms as $gallery_term) {
$gallery_type = get_term_meta((int)$gallery_term->term_id, 'gallery_type', true);
if (!empty($gallery_type) && $gallery_type === 'photographer') {
$check = false;
}
}
}
}
if (!$check) {
if ($check) {
$k ++;
continue;
}
@@ -363,7 +420,7 @@ class WpmfWatermark
$pathinfo = pathinfo($path);
$imageInfo = getimagesize($path);
try {
$this->generatePicture($pathinfo['basename'], $imageInfo, $pathinfo['dirname'], $imageSize);
$this->generatePicture($pathinfo['basename'], $imageInfo, $pathinfo['dirname'], $imageSize, '', $isWoo);
} catch (Exception $e) {
wp_send_json(array('status' => 'limit', 'percent' => $present));
}
@@ -396,7 +453,7 @@ class WpmfWatermark
$imageInfo = getimagesize($path);
if ((int) $value === 1) {
try {
$this->generatePicture($pathinfo['basename'], $imageInfo, $pathinfo['dirname'], $imageSize);
$this->generatePicture($pathinfo['basename'], $imageInfo, $pathinfo['dirname'], $imageSize, '', $isWoo);
} catch (Exception $e) {
wp_send_json(array('status' => 'limit', 'percent' => $present));
}
@@ -414,8 +471,8 @@ class WpmfWatermark
}
}
}
$k ++;
}
$k ++;
}
if ($k >= $limit) {
wp_send_json(array('status' => 'limit', 'percent' => $present));
@@ -428,15 +485,16 @@ class WpmfWatermark
/**
* Generate Picture
*
* @param string $newname New name of image
* @param array $imageInfo Image infomartion
* @param string $full_dir Path of image
* @param string $wtm_apply_on Image size
* @param string $type Type
* @param string $newname New name of image
* @param array $imageInfo Image infomartion
* @param string $full_dir Path of image
* @param string $wtm_apply_on Image size
* @param string $type Type
* @param boolean $isWoo Check images of woocommerce product
*
* @return void
*/
public function generatePicture($newname, $imageInfo, $full_dir, $wtm_apply_on, $type = '')
public function generatePicture($newname, $imageInfo, $full_dir, $wtm_apply_on, $type = '', $isWoo = false)
{
$wtm_images = get_option('wpmf_option_image_watermark');
//$wtm_apply_on = get_option('wpmf_image_watermark_apply');
@@ -455,49 +513,40 @@ class WpmfWatermark
$check_image_logo_exit = false;
}
}
$this->copyFileWithNewName($full_dir, $newname, 'initimage');
if ($imageInfo['mime'] === 'image/jpeg') {
if (!empty($wtm_images) && $check_image_logo_exit) {
$this->checkCopyFileWithNewName($full_dir, $newname, $wtm_apply_on, $type);
}
} elseif ($imageInfo['mime'] === 'image/png') {
if (!empty($wtm_images) && $check_image_logo_exit) {
$this->checkCopyFileWithNewName($full_dir, $newname, $wtm_apply_on, $type);
}
} elseif ($imageInfo['mime'] === 'image/gif') {
if (!empty($wtm_images) && $check_image_logo_exit) {
$this->checkCopyFileWithNewName($full_dir, $newname, $wtm_apply_on, $type);
}
$this->copyFileWithNewName($full_dir, $newname, 'initimage', $isWoo);
if (in_array($imageInfo['mime'], ['image/jpeg', 'image/png', 'image/gif']) && !empty($wtm_images) && $check_image_logo_exit) {
$this->checkCopyFileWithNewName($full_dir, $newname, $wtm_apply_on, $type, $isWoo);
}
}
/**
* Generate Picture
*
* @param string $full_dir Path of image
* @param string $newname New name of image
* @param string $wtm_apply_on The sizes to apply watermark
* @param string $type Type
* @param string $full_dir Path of image
* @param string $newname New name of image
* @param string $wtm_apply_on The sizes to apply watermark
* @param string $type Type
* @param boolean $isWoo Check images of woocommerce product
*
* @return void
*/
public function checkCopyFileWithNewName($full_dir, $newname, $wtm_apply_on, $type = '')
public function checkCopyFileWithNewName($full_dir, $newname, $wtm_apply_on, $type = '', $isWoo = false)
{
$this->copyFileWithNewName($full_dir, $newname, $wtm_apply_on, $type);
$this->copyFileWithNewName($full_dir, $newname, $wtm_apply_on, $type, $isWoo);
}
/**
* Generate Picture
*
* @param string $pathdir Path to file
* @param string $fname New file name
* @param string $wtmApplyOn The size to apply watermark
* @param string $type Type
* @param string $pathdir Path to file
* @param string $fname New file name
* @param string $wtmApplyOn The size to apply watermark
* @param string $type Type
* @param boolean $isWoo Check images of woocommerce product
*
* @return void
*/
public function copyFileWithNewName($pathdir, $fname, $wtmApplyOn, $type = '')
public function copyFileWithNewName($pathdir, $fname, $wtmApplyOn, $type = '', $isWoo = false)
{
$option_image_watermark = get_option('wpmf_option_image_watermark');
if ((int) $option_image_watermark === 0) {
@@ -551,6 +600,11 @@ class WpmfWatermark
}
}
$option_watermark_only_woo = get_option('wpmf_watermark_only_woo');
if (!empty($option_watermark_only_woo) && (int) $option_watermark_only_woo === 1 && !$isWoo && class_exists('WooCommerce')) {
return;
}
if ($add_water) {
if ((int) $wtm_apply_on['all_size'] === 1) {
if (file_exists($newfile)) {
@@ -610,7 +664,7 @@ class WpmfWatermark
$watermark_opacity,
$watermark_margin_unit
);
}//
}
}
}
}
@@ -637,6 +691,14 @@ class WpmfWatermark
return imagecreatefrompng($image);
case 'image/gif':
return imagecreatefromgif($image);
case 'image/webp':
if (function_exists('imagecreatefromwebp')) {
return imagecreatefromwebp($image);
} else {
return imagecreatefromstring(readfile($image));
}
default:
return imagecreatefromstring(readfile($image));
}
}
@@ -720,35 +782,35 @@ class WpmfWatermark
// set image scaling
$r = $logo_x / $logo_y;
$new_width = $image_x * (int) $percent / 100;
$new_width = round($image_x * (int) $percent / 100);
if ($new_width > $logo_x) {
$new_width = $logo_x;
}
$new_height = $new_width / $r;
$new_height = round($new_width / $r);
if ($new_height > $logo_y) {
$new_height = $logo_y;
}
if ($position === 'center' || (int) $position === 0) {
$watermark_pos_x = ($image_x - $new_width) / 2; //watermark left
$watermark_pos_y = ($image_y - $new_height) / 2; //watermark bottom
$watermark_pos_x = round(($image_x - $new_width) / 2); //watermark left
$watermark_pos_y = round(($image_y - $new_height) / 2); //watermark bottom
}
if ($position === 'top_left') {
$watermark_pos_x = (int) $watermark_margin['left'];
$watermark_pos_y = (int) $watermark_margin['top'];
}
if ($position === 'top_right') {
$watermark_pos_x = $image_x - $new_width - (int) $watermark_margin['right'];
$watermark_pos_x = round($image_x - $new_width - (int) $watermark_margin['right']);
$watermark_pos_y = (int) $watermark_margin['top'];
}
if ($position === 'bottom_right') {
$watermark_pos_x = $image_x - $new_width - (int) $watermark_margin['right'];
$watermark_pos_y = $image_y - $new_height - (int) $watermark_margin['bottom'];
$watermark_pos_x = round($image_x - $new_width - (int) $watermark_margin['right']);
$watermark_pos_y = round($image_y - $new_height - (int) $watermark_margin['bottom']);
}
if ($position === 'bottom_left') {
$watermark_pos_x = (int) $watermark_margin['left'];
$watermark_pos_y = $image_y - $new_height - (int) $watermark_margin['bottom'];
$watermark_pos_y = round($image_y - $new_height - (int) $watermark_margin['bottom']);
}
imagecopyresampled(
@@ -805,4 +867,45 @@ class WpmfWatermark
return;
}
}
/**
* Optimized function to get WooCommerce product ID by image attachment ID.
*
* @param integer $attachment_id The ID of the image attachment.
*
* @return integer|boolean Product ID if found, otherwise false.
*/
public function getProductIdByImageId($attachment_id)
{
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => 1,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => '_thumbnail_id',
'value' => $attachment_id,
'compare' => '='
),
array(
'key' => '_product_image_gallery',
'value' => $attachment_id,
'compare' => 'LIKE'
),
),
);
$query = new WP_Query($args);
if ($query->have_posts()) {
$query->the_post();
$product_id = get_the_ID();
wp_reset_postdata();
return $product_id;
}
wp_reset_postdata();
return false;
}
}

View File

@@ -1629,6 +1629,10 @@ class WpmfMediaFolderOption
add_option('wpmf_watermark_image_id', 0, '', 'yes');
}
if (!get_option('wpmf_watermark_only_woo', false)) {
add_option('wpmf_watermark_only_woo', 0, '', 'yes');
}
$gallery_settings = array(
'theme' => array(
'default_theme' => array(
@@ -2754,7 +2758,8 @@ class WpmfMediaFolderOption
'wpmf_image_watermark_apply',
'wpmf_options_format_title',
'wpmf_watermark_image',
'wpmf_watermark_image_id'
'wpmf_watermark_image_id',
'wpmf_watermark_only_woo'
);
foreach ($options_name as $option) {
@@ -2862,6 +2867,7 @@ class WpmfMediaFolderOption
$options_format_title = wpmfGetOption('wpmf_options_format_title');
$watermark_image = get_option('wpmf_watermark_image');
$watermark_image_id = get_option('wpmf_watermark_image_id');
$watermark_only_woo = get_option('wpmf_watermark_only_woo');
$padding_masonry = get_option('wpmf_padding_masonry');
$padding_portfolio = get_option('wpmf_padding_portfolio');

View File

@@ -1,6 +1,12 @@
<?php
/* Prohibit direct script loading */
defined('ABSPATH') || die('No direct script access allowed!');
if (is_plugin_active('wp-media-folder-gallery-addon/wp-media-folder-gallery-addon.php')) {
$col_class = 'wpmf_width_50 m-r-0';
} else {
$col_class = '';
}
?>
<div id="rename_on_upload" class="tab-content">
<div class="content-box content-wpmf-files-folders">
@@ -274,9 +280,8 @@ defined('ABSPATH') || die('No direct script access allowed!');
<div class="ju-settings-option wpmf_width_40 wpmf-no-shadow wpmf-no-padding wpmf-no-margin">
<div class="wpmf_row_full">
<input type="hidden" name="wpmf_option_image_watermark" value="0">
<b data-wpmftippy="<?php esc_html_e('Watermark will be applied only after saving the
settings and regenerate the thumnails (hit the regenerate thumnails button)', 'wpmf'); ?>"
class="ju-setting-label text wpmf-no-padding"><?php esc_html_e('Images watermark', 'wpmf') ?></b>
<label data-wpmftippy="<?php esc_html_e('Watermark will be applied only after saving the settings and regenerate the thumnails (hit the regenerate thumnails button)', 'wpmf'); ?>"
class="ju-setting-label text wpmf-no-padding"><?php esc_html_e('Images watermark', 'wpmf') ?></label>
<div class="ju-switch-button">
<label class="switch">
<input type="checkbox" id="cb_option_image_watermark"
@@ -292,7 +297,6 @@ defined('ABSPATH') || die('No direct script access allowed!');
</div>
</div>
</div>
<div class="ju-settings-option wpmf_width_100 wpmf-no-shadow">
<div class="wpmf_row_full">
<label data-wpmftippy="<?php esc_html_e('Select a picture that will be applied over your images', 'wpmf') ?>"
@@ -449,10 +453,10 @@ defined('ABSPATH') || die('No direct script access allowed!');
</div>
<div class="ju-settings-option wpmf_width_100 p-lr-20">
<div class="ju-settings-option wpmf-no-shadow">
<div class="ju-settings-option wpmf-no-shadow <?php echo esc_attr($col_class); ?>">
<div class="wpmf_row_full">
<h4 data-wpmftippy="<?php esc_html_e('Select the size where you want to apply the watermark', 'wpmf'); ?>"
class="text title_h4 font-size-16 color-7f8a98"><?php esc_html_e('Apply watermark on', 'wpmf') ?></h4>
class="text title_h4 font-size-16 color-404852"><?php esc_html_e('Apply watermark on', 'wpmf') ?></h4>
<div class="ju-settings-option wpmf-no-shadow wpmf_width_100">
<div class="pure-checkbox ju-setting-label line-height-30">
<input type="hidden" name="wpmf_image_watermark_apply[all_size]" value="0">
@@ -494,10 +498,10 @@ defined('ABSPATH') || die('No direct script access allowed!');
</div>
<?php if (is_plugin_active('wp-media-folder-gallery-addon/wp-media-folder-gallery-addon.php')) : ?>
<div class="ju-settings-option wpmf-no-shadow wpmf_right m-r-0">
<div class="ju-settings-option wpmf-no-shadow <?php echo esc_attr($col_class); ?>">
<div class="wpmf_row_full">
<h4 data-wpmftippy="<?php esc_html_e('Select the size where you want to apply the watermark', 'wpmf'); ?>"
class="text title_h4 font-size-16 color-7f8a98"><?php esc_html_e('Watermark on photograph image', 'wpmf') ?></h4>
class="text title_h4 font-size-16 color-404852"><?php esc_html_e('Watermark on photograph image', 'wpmf') ?></h4>
<?php
$sizes = array(
'all_size' => array(
@@ -542,11 +546,12 @@ defined('ABSPATH') || die('No direct script access allowed!');
</div>
</div>
<?php endif; ?>
</div>
<div class="ju-settings-option wpmf_width_100 p-lr-20">
<div class="ju-settings-option wpmf-no-shadow">
<div class="wpmf_row_full">
<h4 data-wpmftippy="<?php esc_html_e('Exclude Folders', 'wpmf'); ?>"
class="text title_h4 font-size-16 color-7f8a98"><?php esc_html_e('Exclude Folders', 'wpmf') ?></h4>
class="text title_h4 font-size-16 color-404852"><?php esc_html_e('Exclude Folders', 'wpmf') ?></h4>
<input type="hidden" name="wpmf_watermark_exclude_folders">
<div class="wrap_apply">
<div class="watermark_exclude_folders tree_option_folders">
@@ -555,11 +560,35 @@ defined('ABSPATH') || die('No direct script access allowed!');
</div>
</div>
</div>
<?php if (class_exists('WooCommerce')) : ?>
<div class="ju-settings-option wpmf-transparent">
<div class="wpmf_row_full">
<input type="hidden" name="wpmf_watermark_only_woo" value="0">
<label data-wpmftippy="<?php esc_attr_e('Possibility to add watermark to only images of WooCommerce Products', 'wpmf') ?>" class="ju-setting-label text wpmf-no-padding">
<?php esc_html_e('Apply watermark only on WooC. products', 'wpmf') ?>
</label>
<div class="ju-switch-button">
<label class="switch">
<input type="checkbox" name="wpmf_watermark_only_woo" value="1"
<?php
if (isset($watermark_only_woo) && (int)$watermark_only_woo === 1) {
echo 'checked';
}
?>
>
<span class="slider round"></span>
</label>
</div>
</div>
</div>
<?php endif; ?>
<?php if (is_plugin_active('wp-media-folder-gallery-addon/wp-media-folder-gallery-addon.php')) : ?>
<div class="ju-settings-option wpmf-transparent">
<div class="wpmf_row_full">
<input type="hidden" name="watermark_exclude_public_gallery" value="0">
<label class="ju-setting-label text"><?php esc_html_e('Exclude public galleries', 'wpmf') ?>
<label class="ju-setting-label text wpmf-no-padding"><?php esc_html_e('Exclude public galleries', 'wpmf') ?>
</label>
<div class="ju-switch-button">
<label class="switch">
@@ -579,7 +608,7 @@ defined('ABSPATH') || die('No direct script access allowed!');
<div class="ju-settings-option wpmf-transparent">
<div class="wpmf_row_full">
<input type="hidden" name="watermark_exclude_photograph_gallery" value="0">
<label class="ju-setting-label text"><?php esc_html_e('Exclude photographer galleries', 'wpmf') ?>
<label class="ju-setting-label text wpmf-no-padding"><?php esc_html_e('Exclude photographer galleries', 'wpmf') ?>
</label>
<div class="ju-switch-button">
<label class="switch">

View File

@@ -184,10 +184,12 @@ class JUQueueActions
if ($dirname) {
$dirname = trailingslashit($dirname);
}
if ($dirname === '') {
$data['file'] = $destination . '/' . $data['file'];
} else {
$data['file'] = str_replace($dirname, $destination . '/', $data['file']);
if (isset($destination)) {
if ($dirname === '') {
$data['file'] = $destination . '/' . $data['file'];
} else {
$data['file'] = str_replace($dirname, $destination . '/', $data['file']);
}
}
}