mathieu
Forum Replies Created
-
I have the same issue… it’s happening way too often.
Thanks a lot 🙂 Have a nice weekend!
If the php would noticably slow down the experience for the people I pay to write content, absolutely.
But I don’t feel that is the case with your plugin anymore since you stop enqueuing the media player everywhere.
If every plugin would always load everything on every call with no regards to performance it would get bloated quick.
I run a tight ship 🙂Yes it works well but you are still loading a tons of templates for nothing.
public function templates()
{
if (did_action('wp_enqueue_media') || (isset($_GET['page']) && $_GET['page'] === 'stockpack')) {
include_once(__DIR__ . '/../templates/attachment.php');
include_once(__DIR__ . '/../templates/empty.php');
include_once(__DIR__ . '/../templates/details.php');
include_once(__DIR__ . '/../templates/downloader.php');
include_once(__DIR__ . '/../templates/dialog.php');
include_once(__DIR__ . '/../templates/attribution.php');
include_once(__DIR__ . '/../templates/no-search.php');
}
}Otherwise it works very well.
Hopes I am not getting too annoying.
I am just in a phase where I am optimizing everything and your plugin is good enough that I am willing to go deep in the code to help you make it better.
Cheers.
Thanks 🙂 please let me know.
Have a nice weekend.
Hi,
Great, however, I discovered that it creates other issue on pages that doesn’t have the media player loaded. You seem to load pretty much everything on everypage even if there is no upload happening on a page.
stockpack-load-admin.js?ver=3.2.4:1 Uncaught TypeError: Cannot read properties of undefined (reading 'search')
at Object.<anonymous> (stockpack-load-admin.js?ver=3.2.4:1:20702)
at i (stockpack-load-admin.js?ver=3.2.4:1:110)
at Module.<anonymous> (stockpack-load-admin.js?ver=3.2.4:1:51573)
at i (stockpack-load-admin.js?ver=3.2.4:1:110)
at Object.<anonymous> (stockpack-load-admin.js?ver=3.2.4:1:51525)
at i (stockpack-load-admin.js?ver=3.2.4:1:110)
at stockpack-load-admin.js?ver=3.2.4:1:903
at stockpack-load-admin.js?ver=3.2.4:1:912I do however have a fix AND a tricks that solves the issue.
The idea is to check if did_action(“wp_enqueue_media”) is true
In class-stockpackmedia.php, you can do this, it works
public function enqueue($admin = true, $no_dialog = false)
{
if (did_action('wp_enqueue_media')) {
$this->enqueue_script($admin);
$this->enqueue_style($no_dialog);
$this->enqueue_settings($admin);
}
}But I think there’s a better way that keeps your exact same logic and doesn’t messed up anything.
The idea is to use stockpack_frontend_load later when enqueue scripts are called. That makes the “frontend_load_stockpack” filter much more useful.
Here’s what I tested successfuly.
public function enqueue($admin = true, $no_dialog = false)
{
if (stockpack_frontend_load()) {
$this->enqueue_script($admin);
$this->enqueue_style($no_dialog);
$this->enqueue_settings($admin);
}
}
public function templates()
{
if (stockpack_frontend_load()) {
include_once(__DIR__ . '/../templates/attachment.php');
include_once(__DIR__ . '/../templates/empty.php');
include_once(__DIR__ . '/../templates/details.php');
include_once(__DIR__ . '/../templates/downloader.php');
include_once(__DIR__ . '/../templates/dialog.php');
include_once(__DIR__ . '/../templates/attribution.php');
include_once(__DIR__ . '/../templates/no-search.php');
}
}
public function enqueue_frontend()
{
if (stockpack_frontend_load()) {
$this->enqueue(false);
}
}
public function load_frontend_style()
{
if (stockpack_frontend_load()) {
wp_enqueue_style('stockpack-frontend', plugins_url('/dist/css/stockpack-frontend.css', STOCKPACK_DIR), false, $this->version);
}
}And then somebody can filter it out with :
add_filter("frontend_load_stockpack", function ($load) {
if (!did_action("wp_enqueue_media")) {
return false;
} else {
return $load;
}
});Let me know what you think
Thanks 🙂
No problem. Thanks.
Hi Pedro,
Yes, It works !
thanks a lot. Do you have an idea on when you push the new release?
So far so good. But I don’t know what triggered it so I can’t really test it besides monitoring log. I’ll check it closely and keep you updated.
Have a great weekend.
I am sorry, I don’t have a testing platform but I will test it out when your release come out and I’ll keep you updated.
Do you know when it is released?Thanks Pedro
Yes it is still happening and I am up to date.
- This reply was modified 2 years, 5 months ago by mathieu.
Yes, you nailed it ! So glad, that I can finally remove the hack from my codebase.
Thanks a lot Pedro
Like I told you earlier, I don’t have the proper test environment to try the dev version.
But if you can notice me when 5.4.2 goes out, I will update it and test it thoroughly.Best regards
Let me know when you have a new fix. I’ll try it again and keep you updated.
Best regards