Skip to content

Commit

Permalink
Merge pull request #1058 from publishpress/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
htmgarcia authored Aug 25, 2022
2 parents 8198249 + 6ef04c2 commit 73f1c85
Show file tree
Hide file tree
Showing 22 changed files with 4,744 additions and 4,636 deletions.
4 changes: 2 additions & 2 deletions src/advanced-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 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: 2.14.1
* Version: 2.14.2
* Tested up to: 6.0.1
* Author: PublishPress
* Author URI: https://publishpress.com/
Expand Down Expand Up @@ -56,7 +56,7 @@
if (! defined('ADVANCED_GUTENBERG_LOADED')) {

if (! defined('ADVANCED_GUTENBERG_VERSION')) {
define('ADVANCED_GUTENBERG_VERSION', '2.14.1');
define('ADVANCED_GUTENBERG_VERSION', '2.14.2');
}

if (! defined('ADVANCED_GUTENBERG_PLUGIN')) {
Expand Down
5 changes: 2 additions & 3 deletions src/assets/blocks/recent-posts/block.php
Original file line number Diff line number Diff line change
Expand Up @@ -1337,15 +1337,14 @@ function advgbMultipleAuthorSortREST( $args, $request ) {
function advgbMultipleAuthorSort() {
if ( function_exists('get_multiple_authors') ){
add_action('pre_get_posts', function( $query ) {
if ( is_admin() ) {
if ( is_admin() || $query->query_vars['orderby'] !== 'author' ) {
return $query;
}

$query->set('orderby', 'meta_value');
$query->set('meta_key', 'ppma_authors_name');

return $query;

} );
}
}
Expand All @@ -1357,7 +1356,7 @@ function advgbMultipleAuthorSort() {
function advgbSeriesOrderSort() {
if ( class_exists('orgSeries') ){
add_action('pre_get_posts', function( $query ) {
if ( is_admin() ) {
if ( is_admin() || $query->query_vars['orderby'] !== 'series_order' ) {
return $query;
}
$query->set('orderby', 'meta_value');
Expand Down
2 changes: 1 addition & 1 deletion src/assets/css/recent-posts.css

Large diffs are not rendered by default.

30 changes: 27 additions & 3 deletions src/assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,26 @@ function advgbGetBlocks( inactive_blocks, nonce_field_id, blocks_list_id ) {
var listBlocks = [];
var nonce = '';

// Get blocks saved in advgb_blocks_list option to include the ones that are missing in allBlocks.
// e.g. blocks registered only via PHP
if(
typeof advgbBlocks.block_extend !== 'undefined'
&& parseInt(advgbBlocks.block_extend)
&& typeof advgb_blocks_list !== 'undefined'
&& advgb_blocks_list.length > 0
) {
let diff_blocks = advgb_blocks_list.filter(
blocksA => !allBlocks.some( blocksB => blocksA.name === blocksB.name )
);
if( diff_blocks.length > 0 ) {
diff_blocks.forEach(function (block) {
allBlocks.push(block);
});
}
}

// Array of block names already available through wp.blocks.getBlockTypes()
var force_deactivate_blocks = ['advgb/container'];
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
Expand All @@ -265,7 +283,7 @@ function advgbGetBlocks( inactive_blocks, nonce_field_id, blocks_list_id ) {
var blockItemIcon = '';
var blockItem = {
name: block.name,
icon: block.icon.src,
icon: block.icon.src || block.icon,
title: block.title,
category: block.category,
parent: block.parent
Expand All @@ -288,9 +306,15 @@ function advgbGetBlocks( inactive_blocks, nonce_field_id, blocks_list_id ) {
blockItem.icon = wp.element.renderToString(savedIcon);
blockItem.icon = blockItem.icon.replace(/stopcolor/g, 'stop-color');
blockItem.icon = blockItem.icon.replace(/stopopacity/g, 'stop-opacity');
} else if (typeof savedIcon === 'string') {
} else if (
typeof savedIcon === 'string'
&& !savedIcon.includes('<span') // Merged blocks icons from 'advgb_blocks_list' are stored as html
&& !savedIcon.includes('<svg') // Merged blocks icons from 'advgb_blocks_list' are stored as html
) {
blockItemIcon = wp.element.createElement(wp.components.Dashicon, {icon: savedIcon});
blockItem.icon = wp.element.renderToString(blockItemIcon);
} else {
blockItem.icon = savedIcon; // Pure html for merged blocks icons from 'advgb_blocks_list'
}

listBlocks.push(blockItem);
Expand Down
4 changes: 4 additions & 0 deletions src/assets/scss/recent-posts.scss
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@

.advgb-post-readmore {
margin-top: 10px;

a {
display: inline-block;
}
}

.advgb-recent-posts-loading,
Expand Down
36 changes: 28 additions & 8 deletions src/incl/advanced-gutenberg-main.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function __construct()
add_action('wp_ajax_nopriv_advgb_lores_validate', array($this, 'validateLoresForm'));

if (is_admin()) {
add_action('admin_footer', array($this, 'initBlocksList')); // @TODO - Non essentially required since 2.14.1; remove this in future
add_action('admin_footer', array($this, 'initBlocksList'));
add_action('admin_menu', array($this, 'registerMainMenu'));
add_action('admin_menu', array($this, 'registerBlockConfigPage'));
add_action('load-toplevel_page_advgb_main', array($this, 'saveAdvgbData'));
Expand Down Expand Up @@ -193,7 +193,7 @@ public function __construct()
}

// Ajax
add_action('wp_ajax_advgb_update_blocks_list', array($this, 'updateBlocksList')); // @TODO - Non essentially required since 2.14.1; remove this in future
add_action('wp_ajax_advgb_update_blocks_list', array($this, 'updateBlocksList'));
add_action('wp_ajax_advgb_custom_styles_ajax', array($this, 'customStylesAjax'));
add_action('wp_ajax_advgb_block_config_save', array($this, 'saveBlockConfig'));
} else {
Expand Down Expand Up @@ -599,6 +599,7 @@ public function advgbBlocksVariables($post = true)
$pp_series_slug = isset($pp_series_options['series_taxonomy_slug']) && !empty($pp_series_options['series_taxonomy_slug']) ? $pp_series_options['series_taxonomy_slug'] : 'series';
$pp_series_post_types = isset($pp_series_options['post_types_for_series']) && !empty($pp_series_options['post_types_for_series']) ? $pp_series_options['post_types_for_series'] : ['post'];
$block_controls = $this->settingIsEnabled( 'block_controls' ) ? 1 : 0;
$block_extend = $this->settingIsEnabled( 'block_extend' ) ? 1 : 0;
$timezone = function_exists( 'wp_timezone_string' ) ? wp_timezone_string() : '';
global $wp_version;
$blocks_widget_support = ( $wp_version >= 5.8 ) ? 1 : 0;
Expand All @@ -625,6 +626,7 @@ public function advgbBlocksVariables($post = true)
'pp_series_slug' => $pp_series_slug,
'pp_series_post_types' => $pp_series_post_types,
'block_controls' => $block_controls,
'block_extend' => $block_extend,
'timezone' => $timezone
));

Expand Down Expand Up @@ -726,8 +728,6 @@ function advgbAddScriptAttributes($tag, $handle)
}

/**
* @TODO - Non essentially required since 2.14.1; remove this in future
*
* Update the blocks list for first time install
*
* @return void
Expand Down Expand Up @@ -915,8 +915,6 @@ public function getFeaturedImg($object)
}

/**
* @TODO - Non essentially required since 2.14.1; remove this in future
*
* Ajax to update blocks list
*
* @return mixed
Expand Down Expand Up @@ -1512,7 +1510,6 @@ public function registerStylesScripts()
array(),
ADVANCED_GUTENBERG_VERSION
);
// @TODO - Non essentially required since 2.14.1; remove this in future
wp_register_script(
'advgb_update_list',
plugins_url('assets/js/update-block-list.js', dirname(__FILE__)),
Expand Down Expand Up @@ -1989,6 +1986,12 @@ public function saveSettings()
$save_config['enable_block_access'] = 0;
}

if (isset($_POST['block_extend'])) {
$save_config['block_extend'] = 1;
} else {
$save_config['block_extend'] = 0;
}

if (isset($_POST['enable_custom_styles'])) {
$save_config['enable_custom_styles'] = 1;
} else {
Expand Down Expand Up @@ -2230,6 +2233,24 @@ public function advgbBlocksFeatureData( $feature, $script, $option )
}
}

/* Get blocks saved in advgb_blocks_list option to include the ones that are missing
* as result of javascript method wp.blocks.getBlockTypes()
* e.g. blocks registered only via PHP
*/
if( $this->settingIsEnabled( 'block_extend' ) ) {
$advgb_blocks_list = get_option( 'advgb_blocks_list' );
if( $advgb_blocks_list && is_array( $advgb_blocks_list ) ) {
$saved_blocks = $advgb_blocks_list;
} else {
$saved_blocks = [];
}
wp_localize_script(
'advgb_main_js',
'advgb_blocks_list',
$saved_blocks
);
}

// Current role
$current_user_role = $this->advgbBlocksFeatureCUserRole();

Expand Down Expand Up @@ -2578,7 +2599,6 @@ public function getUserBlocksForGutenberg()
}

// All saved blocks (even the ones not detected by Block Access)
// @TODO - Non essentially required since 2.14.1; remove involved code with 'advgb_blocks_list' option in future
$all_blocks = get_option( 'advgb_blocks_list' );

// Get the array from advgb_blocks_user_roles option that match current user role
Expand Down
24 changes: 24 additions & 0 deletions src/incl/view/advanced-gutenberg-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
$editor_width = isset($saved_settings['editor_width']) ? $saved_settings['editor_width'] : '0';
$default_thumb = plugins_url('assets/blocks/recent-posts/recent-post-default.png', ADVANCED_GUTENBERG_PLUGIN);
$rp_default_thumb = isset($saved_settings['rp_default_thumb']) ? $saved_settings['rp_default_thumb'] : array('url' => $default_thumb, 'id' => 0);
$block_extend = isset($saved_settings['block_extend']) && $saved_settings['block_extend'] ? 'checked' : '';

$gallery_lightbox_checked = isset($saved_settings['gallery_lightbox']) && $saved_settings['gallery_lightbox'] ? 'checked' : '';
if (!isset($saved_settings['gallery_lightbox'])) {
Expand Down Expand Up @@ -431,6 +432,29 @@ class="advgb_qtip ju-setting-label"
</div>
</div>
</li>
<li class="ju-settings-option clearfix">
<div class="settings-option-wrapper clearfix">
<label for="block_extend"
class="advgb_qtip ju-setting-label"
data-qtip="<?php esc_attr_e(
'If some blocks are not listed in Block access, try enabling Extend supported blocks',
'advanced-gutenberg'
) ?>"
>
<?php esc_html_e('Extend supported blocks (beta)', 'advanced-gutenberg') ?>
</label>
<div class="ju-switch-button">
<label class="switch">
<input type="checkbox" name="block_extend"
id="block_extend"
value="1"
<?php echo esc_attr($block_extend) ?>
/>
<span class="slider"></span>
</label>
</div>
</div>
</li>
</ul>

<div class="save-settings-block">
Expand Down
1 change: 1 addition & 0 deletions src/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
'enable_pp_branding' => 1,
'enable_core_blocks_features' => 1,
'block_controls' => 1,
'block_extend' => 0
));
}

Expand Down
2 changes: 1 addition & 1 deletion src/languages/advanced-gutenberg-es_ES-editor.json

Large diffs are not rendered by default.

Binary file modified src/languages/advanced-gutenberg-es_ES.mo
Binary file not shown.
Loading

0 comments on commit 73f1c85

Please sign in to comment.