Do not load shortcodes views on backend
Hello!
I noticed that Unyson loads view files for shortcodes in WordPress admin. Is it possible do not load all view files from all registered shortcodes (to increase backend loading speed)?
Thank you!
I have found that views are loaded only on post save here.
Do you know any cases when the views are loaded in backend?
@moldcraft, this is what i meant, for example, on my home page i have several shortcodes that make different posts queries, when i save the page, unyson executes all of these shortcodes, and this makes WP admin slower, is it possible to disable this behaviour? Thank you for a fast reply!
That behavior was made to fix this problem. I will add a filter to disable that.
Just now same thing , I made posts shortcode and included a file via get_template_part within the view
on save I get bunch of undefined notices , and a class that is called inside the included file runs also
$find_atts = new ThzShortcodeOptions($thz_object_id,$thz_posts_id,'posts');
http://prntscr.com/ddpv1p
I got to do
if ( is_admin()){
return;
}
within the view.php for now
this works
add_filter( 'fw:ext:page-builder:generate-post-content-html', '__return_false' );
but than this does not https://github.com/ThemeFuse/Unyson/issues/845
Please reopen this , loading all views without them being properly processed is not something we should do.
Half of the vars cant be visible because we need an object which is not accessible in admin. I should not be coding the frontend view.php and at the same time paying attention to the admin
we cant use that filter either becuase it kills something else, so please find a suitable solution that does not affect the views and lets us code the frontend without unnecessary triple checks.
becuase of this I have to convert term objects in to an array since in frontend I get the term object but in backend I get the array.
try
$post_tax = get_the_terms($post->ID, 'category');
foreach ( $post_tax as $tax){
fw_print( $tax->term_id);
}
The only solution is see is to make a background request to page frontend url and extract its content html, but this will cause problems:
- It will be slower
- On some servers it will not be able to reach the frontend (remember in Backup extension the "Loopback is not enabled on this server")
- The backuground request will be made as unauthenticated user, and if on your site is enabled "comming soon", then it will return a wrong html
So I don't know how to fix this.
Should I change this filter default value to false (disabled by default) ?
not sure bud but so far I see the only reason for this is Yoast, cant we make something for Yoast only ? like load page html via ajax (background request ) for yoast or something
As a possible solution, why do not add a separate option to Page Builder Settings to enable or disable this feature
We already have that filter.
The problem is when it is enabled it works wrong (views meant to be rendered in frontend are executed in backend and some frontend global variables are not initialized)
@moldcraft Could you make a use of page/post previews for Yoast? that one has no restrictions
The user changes something in builder and clicks on Update button. How to use preview in this case?
I did not explain
The background request will be made as unauthenticated user, and if on your site is enabled "comming soon", then it will return a wrong html
what I mean is on page load pull the ajax content of the preview page
$.ajax({
url: preview_link
}).done(function(data) {
console.log( $(data).html() );
});
beside that why is it that ajax is not allowed? kinda makes no sense
The user changes something in builder and clicks on Update button. How to use preview in this case?
same thing the button is still available , if you update or not
@moldcraft did you see this Yoast filter
https://github.com/Yoast/wordpress-seo/issues/6210#issuecomment-265900473
could we use that instead ?
meantime I will post on their git to see if they can help us here
@moldcraft , https://github.com/Yoast/wordpress-seo/issues/6312#issuecomment-268802792
Basically we could use this
var ExamplePlugin = function() {
YoastSEO.app.registerPlugin( 'examplePlugin', {status: 'ready'} );
/**
* @param modification {string} The name of the filter
* @param callable {function} The callable
* @param pluginName {string} The plugin that is registering the modification.
* @param priority {number} (optional) Used to specify the order in which the callables
* associated with a particular filter are called. Lower numbers
* correspond with earlier execution.
*/
YoastSEO.app.registerModification( 'content', this.myContentModification, 'examplePlugin', 5 );
}
/**
* Adds some text to the data...
*
* @param data The data to modify
*/
ExamplePlugin.prototype.myContentModification = function(data) {
return data + ' some text to add';
};
new ExamplePlugin();
I have tried the above event https://github.com/ThemeFuse/Unyson-PageBuilder-Extension/commit/017d183a2236c6d7c1261591b24b7163a0795f53#diff-4509d66d33039c01d9424e6e67f61a54
On my side it is executed on page load 3 times

It requires me to provide the post html right away. So I must do
{pageBuilderJson} --> [shortcodes] --> <shortcodes-frontend-html>
in that js event. I don't know how to achieve that.
page load 3 times
how about ,
jQuery(window).one(...
instead ? or off/on ?
I would like to help but not sure what to post here https://github.com/Yoast/YoastSEO.js/issues
It requires me to provide the post html right away
frontent via ajax ? or do you you have to process it ?