Skip to content

Commit

Permalink
Merge pull request #1295 from publishpress/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
htmgarcia authored Jul 25, 2023
2 parents efe8f44 + 4755630 commit d775751
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 168 deletions.
21 changes: 15 additions & 6 deletions src/advanced-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
* Plugin Name: PublishPress Blocks
* Plugin URI: https://publishpress.com/blocks/
* Description: PublishPress Blocks has everything you need to build professional websites with the Gutenberg editor.
* Version: 3.1.4.3
* Tested up to: 6.2.2
* Version: 3.1.5
* Author: PublishPress
* Author URI: https://publishpress.com/
* License: GPL2
* Text Domain: advanced-gutenberg
* Domain Path: /languages
* Requires at least: 5.5
* Requires PHP: 7.2.5
* License: GPL2
*/

/**
Expand Down Expand Up @@ -38,8 +39,16 @@

defined('ABSPATH') || die;

// If the PHP version is not compatible, terminate the plugin execution.
if ( ! include_once __DIR__ . '/incl/check-php-version.php' ) {
global $wp_version;

$min_php_version = '7.2.5';
$min_wp_version = '5.5';

// If the PHP or WP version is not compatible, terminate the plugin execution.
$invalid_php_version = version_compare(phpversion(), $min_php_version, '<');
$invalid_wp_version = version_compare($wp_version, $min_wp_version, '<');

if ($invalid_php_version || $invalid_wp_version) {
return;
}

Expand All @@ -61,7 +70,7 @@
if (! defined('ADVANCED_GUTENBERG_LOADED')) {

if (! defined('ADVANCED_GUTENBERG_VERSION')) {
define('ADVANCED_GUTENBERG_VERSION', '3.1.4.3');
define('ADVANCED_GUTENBERG_VERSION', '3.1.5');
}

if (! defined('ADVANCED_GUTENBERG_PLUGIN')) {
Expand Down
68 changes: 32 additions & 36 deletions src/assets/js/gallery.colorbox.init.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,40 @@ jQuery(document).ready(function ($) {
}

$('.wp-block-gallery').each(function () {
// Add lightbox for images
$(this).find('.blocks-gallery-item, .wp-block-image').colorbox({
title: function () {
if (parseInt(advgb.imageCaption)) {
var imgCap = $(this).find('figcaption').text() || $(this).find('img').attr('alt');
return imgCap;
}

return null;
},
maxWidth: '90%',
maxHeight: '85%',
fixed: true,
className: galClassName,
rel: 'gallery' + galGroup,
photo: true,
href: function () {
if($(this).find('a').length) {
// Link to: Media File or Attachment
galImage = $(this).find('a');
if(galImage.attr('href').indexOf('.jpg') > 0 || galImage.attr('href').indexOf('.png') > 0 || galImage.attr('href').indexOf('.gif') > 0 || galImage.attr('href').indexOf('.jpeg') > 0 || galImage.attr('href').indexOf('.webp') > 0) {
var item = $(this).find('.blocks-gallery-item, .wp-block-image');
// Add lightbox for images with Link to: Media file
if(item.find('a[href$=".jpg"], a[href$=".png"], a[href$=".gif"]').length) {
item.colorbox({
title: function () {
if (parseInt(advgb.imageCaption)) {
var imgCap = $(this).find('figcaption').text() || $(this).find('img').attr('alt');
return imgCap;
}

return null;
},
maxWidth: '90%',
maxHeight: '85%',
fixed: true,
className: galClassName,
rel: 'gallery' + galGroup,
photo: true,
href: function () {
if($(this).find('a').length) {
// Link to: Media File
return $(this).find('a').attr('href');
} else {
// Link to: Attachment
return $(this).find('img').attr('src');
galImage = $(this).find('a');
if(galImage.attr('href').indexOf('.jpg') > 0 || galImage.attr('href').indexOf('.png') > 0 || galImage.attr('href').indexOf('.gif') > 0 || galImage.attr('href').indexOf('.jpeg') > 0 || galImage.attr('href').indexOf('.webp') > 0) {
return $(this).find('a').attr('href');
}
}
} else {
// Link to: None
return $(this).find('img').attr('src');
},
onComplete: function () {
$('.cboxPhoto')
.attr('alt', $(this).find('img').attr('alt'))
.attr('title', $(this).find('img').attr('title'));
}
},
onComplete: function () {
$('.cboxPhoto')
.attr('alt', $(this).find('img').attr('alt'))
.attr('title', $(this).find('img').attr('title'));
}
});
galGroup++;
});
galGroup++;
}
});
});
49 changes: 39 additions & 10 deletions src/assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,28 +187,40 @@ function advgbGetBlocksFeature( inactive_blocks, nonce_field_id, page, exclude_b
// Array of block names already available through wp.blocks.getBlockTypes()
var force_deactivate_blocks = []; // 'advgb/container'

// Array of objects not available through wp.blocks.getBlockTypes()
// As example: the ones that loads only in Appearance > Widget
/* Blocks not available through wp.blocks.getBlockTypes()
* As example: the ones that loads only in Appearance > Widget
* and we don't allow to disable
*
* Removed 'core/legacy-widget' as forced active block - Since 3.1.5
*/
var force_activate_blocks = [
{
'name': 'core/legacy-widget',
'icon': 'block-default',
'title': 'Legacy Widget',
'category': 'widgets'
},
{
'name': 'core/widget-group',
'icon': 'block-default',
'title': 'Widget Group',
'category': 'widgets'
},
];

// Include force_activate_blocks in the blocks list
force_activate_blocks.forEach(function (block) {
allBlocks.push(block);
});

/* Blocks not available through wp.blocks.getBlockTypes() - Since 3.1.5
* As example: the ones that loads only in Appearance > Widget
* and we allow to enable/disable (different to force_activate_blocks var)
*/
var include_blocks = [
{
'name': 'core/legacy-widget',
'icon': 'block-default',
'title': 'Legacy Widget',
'category': 'widgets'
}
];
include_blocks.forEach(function (block) {
allBlocks.push(block);
});

allBlocks.forEach(function (block) {
var blockItemIcon = '';
var blockItem = {
Expand Down Expand Up @@ -278,6 +290,21 @@ function advgbGetBlocksFeature( inactive_blocks, nonce_field_id, page, exclude_b

var list_blocks_names = [];

/* Remove duplicated blocks by block name, just in case - Since 3.1.5
* e.g. when Extended supported block is enabled, 'core/legacy-widget'
* and 'core/widget-group' are duplicated.
*/
var uniqueNames = [];
var i = listBlocks.length;
while ( i-- ) {
var name = listBlocks[i].name;
if( uniqueNames.includes( name ) ) {
listBlocks.splice( i, 1 );
} else {
uniqueNames.push( name );
}
}

// Update blocks
listBlocks.forEach(function (block) {

Expand Down Expand Up @@ -526,6 +553,8 @@ function advgbGetBlockControls( inactive_blocks, nonce_field_id, page, exclude_b

var list_blocks_names = [];

// @TODO - Maybe remove duplicated blocks by block name? - Same as in advgbGetBlocksFeature()

// Update blocks
listBlocks.forEach(function (block) {

Expand Down
Loading

0 comments on commit d775751

Please sign in to comment.