Hi there,
I’ve tried the sorting snippet here: https://siteorigin.com/docs/page-builder/bundling-prebuilt/
To alphabetically sort the theme saved prebuilt layout for a website of mine. The snippet works, as the layouts are displayed according to their name, but unfortunately sometimes I cannot import them first shown (aka the one flagged with
data-layout-id="0")
The UI just freezes and I get the following error in console: https://postimg.cc/KkyBvpJj
Changing the function priority doesn’t change behaviour, unless you go below 10, in which case the layout won’t be sorted.
It is not layout-related, because if I rename the layout not to appear in 1st position, then I can import it anyway.
I guess the issue is “0” being wrongly evaluated in js: this does not happen without the sorting filter function because in that case the data-layout-id is not a number.
In fact, I have created a dummy layout so that the true layouts will start with 1 as data-layout-id, but it’s a raw workaround.
I would like to add that after more testings, sometimes the selected layout is not the imported one.
For example, If I select the layout with data-id=11, then it imports the layout with data-id=4
Hi Frafor,
I’ve identified an oversight that will prevent a layout from being imported if its id is 0. This will be fixed in an upcoming SiteOrigin Page Builder update. This issue is on the PHP side of things rather than JavaScript.
Regarding the other raised issue with the incorrect layouts being imported, I’m having trouble replicating that result. Is this happening consistently, or infrequently? Can it happen directly after loading the editor, or is it only after a specific action?
Kind regards,
Alex
Hi Alex
I’ve checked the second issue and it was template-related.
Happy to know that you’ll fix the first one :) Anyway, as a temporary workaround, I applied the following fix yesterday:
/*
* Sort SOPB Prebuilt Layouts by Alphabetical ID
*/
add_filter( 'siteorigin_panels_prebuilt_layouts', 'reorder_sopb_layouts', 20, 1);
function reorder_sopb_layouts($layouts) {
// Sort layouts alphabetically.
usort( $layouts, function( $a, $b ) {
return strcmp( $a['id'], $b['id'] );
} );
// It seems SiteOrigin messes with numbers
$reordered = array();
foreach($layouts as $data) {
$reordered[$data['id']] = $data;
}
return $reordered;
};