Unyson icon indicating copy to clipboard operation
Unyson copied to clipboard

Do not load shortcodes views on backend

Open dk-wordpress opened this issue 10 years ago • 33 comments

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!

dk-wordpress avatar Oct 18 '16 15:10 dk-wordpress

I have found that views are loaded only on post save here.

Do you know any cases when the views are loaded in backend?

ghost avatar Oct 19 '16 14:10 ghost

@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!

dk-wordpress avatar Oct 19 '16 15:10 dk-wordpress

That behavior was made to fix this problem. I will add a filter to disable that.

ghost avatar Oct 19 '16 17:10 ghost

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

danyj avatar Nov 30 '16 17:11 danyj

I got to do

if ( is_admin()){
	return;
}

within the view.php for now

danyj avatar Nov 30 '16 17:11 danyj

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

danyj avatar Nov 30 '16 20:11 danyj

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.

danyj avatar Dec 01 '16 17:12 danyj

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);
}

danyj avatar Dec 01 '16 20:12 danyj

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) ?

ghost avatar Dec 21 '16 14:12 ghost

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

danyj avatar Dec 21 '16 14:12 danyj

As a possible solution, why do not add a separate option to Page Builder Settings to enable or disable this feature

dk-wordpress avatar Dec 22 '16 11:12 dk-wordpress

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)

ghost avatar Dec 22 '16 11:12 ghost

@moldcraft Could you make a use of page/post previews for Yoast? that one has no restrictions

danyj avatar Dec 22 '16 11:12 danyj

The user changes something in builder and clicks on Update button. How to use preview in this case?

ghost avatar Dec 22 '16 12:12 ghost

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

danyj avatar Dec 22 '16 12:12 danyj

@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

danyj avatar Dec 22 '16 12:12 danyj

@moldcraft , https://github.com/Yoast/wordpress-seo/issues/6312#issuecomment-268802792

danyj avatar Dec 22 '16 13:12 danyj

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();

danyj avatar Dec 22 '16 13:12 danyj

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

screenshot from 2016-12-26 17-01-03

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.

ghost avatar Dec 26 '16 15:12 ghost

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 ?

danyj avatar Dec 27 '16 15:12 danyj