Skip to content

Commit 0b68b84

Browse files
committed
Merge branch 'release/2.33.1'
2 parents 6111507 + 6929926 commit 0b68b84

File tree

5 files changed

+86
-51
lines changed

5 files changed

+86
-51
lines changed

changelog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
== Changelog ==
22

3+
= 2.33.1 – 31 July 2025 =
4+
* Layout Directory: Fixed pagination and search functionality.
5+
* Layouts: Fixed an issue with cloning layouts.
6+
* Layouts: Improved security by checking nonce earlier when fetching prebuilt layouts.
7+
38
= 2.33.0 – 29 July 2025 =
49
* Layout Directory: Added category and niche filtering, search functionality, and pagination support.
510
* Mode Switcher: Hidden when parent dialog exists for cleaner interface.

inc/admin-layouts.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,13 @@ public function decode_panels_data( $data, $file = null ) {
485485
* Ajax handler to get an individual prebuilt layout
486486
*/
487487
public function action_get_prebuilt_layout() {
488+
if (
489+
empty( $_REQUEST['_panelsnonce'] ) ||
490+
! wp_verify_nonce( $_REQUEST['_panelsnonce'], 'panels_action' )
491+
) {
492+
wp_die();
493+
}
494+
488495
$type = isset( $_REQUEST['type'] ) ? sanitize_key( $_REQUEST['type'] ) : '';
489496
$layout_id = isset( $_REQUEST['lid'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['lid'] ) ) : '';
490497

@@ -496,10 +503,6 @@ public function action_get_prebuilt_layout() {
496503
wp_die();
497504
}
498505

499-
if ( empty( $_REQUEST['_panelsnonce'] ) || ! wp_verify_nonce( $_REQUEST['_panelsnonce'], 'panels_action' ) ) {
500-
wp_die();
501-
}
502-
503506
header( 'content-type: application/json' );
504507
$panels_data = array();
505508
$raw_panels_data = false;

js/siteorigin-panels/dialog/prebuilt.js

Lines changed: 66 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = panels.view.dialog.extend( {
1010

1111
currentTab: false,
1212
directoryPage: 1,
13+
maxPages: 1,
1314
itemsPer: 16,
1415
activeFilter: [],
1516

@@ -234,7 +235,7 @@ module.exports = panels.view.dialog.extend( {
234235
type = 'directory-siteorigin';
235236
}
236237

237-
if ( type.match( '^directory-' ) && ! panelsOptions.directory_enabled ) {
238+
if ( this.isLayoutDirectory() && ! panelsOptions.directory_enabled ) {
238239
// Display the button to enable the prebuilt layout
239240
c.removeClass( 'so-panels-loading' ).html( $( '#siteorigin-panels-directory-enable' ).html() );
240241
c.find( '.so-panels-enable-directory' ).on( 'click', function( e ) {
@@ -278,6 +279,7 @@ module.exports = panels.view.dialog.extend( {
278279
// Depending on the active type, we need to handle things slightly differently.
279280
if ( type.match( '^directory-' ) ) {
280281
thisView.directoryPage = page;
282+
thisView.maxPages = data.max_num_pages;
281283
thisView.updatePagination();
282284
} else {
283285
// Lets setup the next and previous buttons
@@ -369,32 +371,86 @@ module.exports = panels.view.dialog.extend( {
369371
}
370372
},
371373

374+
/**
375+
* Get the maximum number of pages for the current context.
376+
*
377+
* @param {*} $items An optional jQuery collection of items to calculate the maximum pages for.
378+
* @returns int The maximum number of pages based on the items and items per page.
379+
*/
380+
contextualMaxPages: function( $items = null ) {
381+
if ( $items === null ) {
382+
$items = this.getItems();
383+
}
384+
385+
const contextualMaxPages = Math.ceil( $items.length / this.itemsPer );
386+
return contextualMaxPages > this.maxPages ? contextualMaxPages : this.maxPages;
387+
},
388+
372389
updatePagination: function() {
373390
var $items = this.getItems();
374391

375-
// Hide any items not on the current page.
376-
var startIndex = ( this.directoryPage - 1 ) * this.itemsPer;
377-
var endIndex = startIndex + this.itemsPer;
392+
const startIndex = this.isLayoutDirectory() ?
393+
this.directoryPage - 1 :
394+
( this.directoryPage - 1 ) * this.itemsPer;
395+
396+
const endIndex = startIndex + this.itemsPer;
378397

398+
// Hide any items not on the current page.
379399
this.$( '.so-directory-items-wrapper .so-directory-item' ).addClass( 'so-hidden' );
380400
$items.slice( startIndex, endIndex ).removeClass( 'so-hidden' );
381401

382402
this.$( '.so-previous' ).toggleClass( 'button-disabled', this.directoryPage === 1 );
383-
this.$( '.so-next' ).toggleClass( 'button-disabled', this.directoryPage === Math.ceil( $items.length / this.itemsPer ) );
403+
this.$( '.so-next' ).toggleClass(
404+
'button-disabled',
405+
this.directoryPage === this.contextualMaxPages( $items )
406+
);
407+
},
408+
409+
isLayoutDirectory: function() {
410+
return this.currentTab.match( '^directory-' );
411+
},
412+
413+
/**
414+
* Update the layout directory interface with the new search value and page.
415+
*
416+
* @param {string} directoryPath - The path to the layout directory.
417+
* @param {Object} config - Configuration options for the update.
418+
* @returns {boolean} - Returns true if the update was successful, otherwise false.
419+
*/
420+
updateLayoutDirectory: function() {
421+
if ( ! this.isLayoutDirectory() ) {
422+
return false;
423+
}
424+
425+
const searchVal = this.$( '.so-sidebar-search' ).val().toLowerCase();
426+
this.displayLayoutDirectory(
427+
searchVal,
428+
this.directoryPage,
429+
this.currentTab
430+
);
431+
432+
return true;
384433
},
385434

386435
previousPage: function() {
387436
if (this.directoryPage > 1) {
388437
this.directoryPage--;
389-
this.updatePagination();
438+
439+
if ( ! this.updateLayoutDirectory() ) {
440+
this.updatePagination();
441+
}
390442
}
391443
},
392444

393445
nextPage: function() {
394-
var numPages = Math.ceil( this.getItems().length / this.itemsPer );
395-
if ( this.directoryPage < numPages ) {
446+
const maxPages = this.contextualMaxPages();
447+
448+
if ( this.directoryPage < maxPages ) {
396449
this.directoryPage++;
397-
this.updatePagination();
450+
451+
if ( ! this.updateLayoutDirectory() ) {
452+
this.updatePagination();
453+
}
398454
}
399455
},
400456

@@ -503,47 +559,13 @@ module.exports = panels.view.dialog.extend( {
503559
return deferredLayout.promise();
504560
},
505561

506-
filterByTitle: function( title ) {
507-
508-
if ( title === '' ) {
509-
this.$( '.so-directory-items-wrapper .so-directory-item' ).removeClass( 'so-hidden so-search-hidden' );
510-
} else {
511-
this.$( '.so-directory-items' ).removeClass( 'so-search-hidden' );
512-
var $items = this.getItems();
513-
514-
$items.each( function() {
515-
let $$ = $( this );
516-
let found = $$.find( '.so-title' ).text().toLowerCase().includes( title );
517-
518-
if ( found && $$.hasClass( 'so-hidden' ) ) {
519-
$$.removeClass( 'so-hidden so-search-hidden' )
520-
} else if ( ! found ) {
521-
$$.addClass( 'so-hidden so-search-hidden' );
522-
}
523-
} );
524-
525-
}
526-
527-
// Show or hide the no results message.
528-
this.$( '.so-directory-items' ).toggleClass(
529-
'so-empty',
530-
! this.$('.so-directory-items-wrapper .so-directory-item:not(.so-hidden)').length
531-
);
532-
533-
this.updatePagination();
534-
},
535-
536562
/**
537563
* Handle an update to the search
538564
*/
539565
searchHandler: function ( e ) {
540566
if ( e.keyCode === 13 ) {
541567
var search = $( e.currentTarget ).val().toLowerCase();
542-
if ( this.currentTab.match( '^directory-' ) ) {
543-
this.filterByTitle( search );
544-
} else {
545-
this.displayLayoutDirectory( search, 1, this.currentTab );
546-
}
568+
this.displayLayoutDirectory( search, 1, this.currentTab );
547569
}
548570
},
549571

readme.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ SiteOrigin offers a single premium plugin that enhances and extends Page Builder
121121

122122
== Changelog ==
123123

124+
= 2.33.1 – 31 July 2025 =
125+
* Layout Directory: Fixed pagination and search functionality.
126+
* Layouts: Fixed an issue with cloning layouts.
127+
* Layouts: Improved security by checking nonce earlier when fetching prebuilt layouts.
128+
124129
= 2.33.0 – 29 July 2025 =
125130
* Layout Directory: Added category and niche filtering, search functionality, and pagination support.
126131
* Mode Switcher: Hidden when parent dialog exists for cleaner interface.

tpl/js-templates.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,9 @@ class="button-primary so-button-mode dashicons so-mode"
548548
{{% _.each( items, function( item ) { %}}
549549
<div
550550
class="so-directory-item
551-
{{% if ( typeof item.class != 'undefined' ) { %}}
552-
{{%- item.class %}}"
553-
{{% } %}}
551+
{{% if ( typeof item.class != 'undefined' ) {
552+
%}}{{%- item.class %}}{{%
553+
} %}}"
554554

555555
data-layout-id="{{%- item.id %}}"
556556
data-layout-type="{{%- item.type %}}"

0 commit comments

Comments
 (0)