Disable template caching for development in OpenCart 3 - php

I am making changes in my theme templates in OpenCart 3. Due to template caching I have to clear cache every time under "storage/cache" directory. It is very annoying when working and previewing changes frequently during development. Please provide some solution how we can configure caching according to production and development environment.
Note: I have already searched for solutions online but there is no solution related to template caching. Solutions are available to disable image caching but "Image Caching" and "Template Caching" are different features provided in Opencart.

You might need to upgrade to a more recent version of OpenCart3 - the first one (3.0.0.0) didn't have a way of doing this in the GUI.
More recent versions, such as 3.0.2.0, have a gear on the admin dashboard. Click the gear and you get options to disable caching.

Another way to do this:
Open to system\library\template\Twig\Cache\Filesystem.php, find following lines of code
public function load($key)
{
if (file_exists($key)) {
#include_once $key;
}
}
Comment out as in the following code:
public function load($key)
{
// if (file_exists($key)) {
// #include_once $key;
// }
}
This will remove the template cache of the twig and recreate every time, once development is over you have to remove the comment.

You can also do this from CODE directly if you have the access. Go to this file path below via ftp or cPanel:
system\library\template\Twig\Environment.php
Find
$this->debug = (bool) $options['debug'];
Replace:
$this->debug = (bool) true;

Opencart Version 3.0.2.0
I was having same problem, try working in theme editor or the actual raw twig file, after an hour or two i tried this it worked.
Delete the changes in theme editor and got back editing actual twig file
my screen shot

I think you edit the template as the path: Design->Theme Editor before.
Clear all of the date in the oc_theme data table of your database.

Scott's answer is best but in case it's not available due to version or you want to disable it programmatically you can do this anywhere before the twig is rendered:
$this->config->set('template_cache', false);

in OC 3.0.3.6, if you have some twig extension, like twig managers, after changes maded you should select that extention in modifications and refresh push button on top right corner.
P.S. loose whole day to find this, hope it helps someone

This is similar to Scott's answer but just on the database/backend. In case you can't rely on the UI and can only access the DB (like me, I'm messing up with the UI) it's on settings table search for 'developer_theme' key and set it to false or 0.
UPDATE `oc_setting` SET `value` = '0' WHERE `oc_setting`.`key` = 'developer_theme';

Related

My php code is keep getting disable in wordpress editor after upgraded into latest version

My website had a older version of wordpress. Recently I upgraded it to the latest version. After that my php code what I write in the editor is keep getting disabled.
The old page which has php code in ti still works. Although in the editor the php codes are disabled. But if I try to save that it stops working. So i cannot update those page. And also I cannot create new page with php code in it
Exec-PHP plugin is installed.
If I write
<?php echo $c; ?>
It converts into
<!--?php echo $c; ?-->
How to fix that
attached image for better understanding.
Another way, which I don't quite recommend, is to follow this direction:
https://wordpress.org/support/topic/exec-php-to-work-in-php-7-needs-this/
This is basically updating the actual plugin, which will surely be overwritten by their next update.
This plugin requires a number of changes to work with php 7.
In exec-php.php
$GLOBALS[‘g_execphp_manager’] =& new ExecPhp_Manager();
must be changed to
$GLOBALS[‘g_execphp_manager’] = new ExecPhp_Manager();
In includes/manager.php from line 36
change each =& to =
In includes/admin.php lines 53,56,57,63,64,79 change =& to =
In includes/cache.php line 22,39 change =& to =
In includes/ajax.php line 64 change =& to =
I don't know about the plugin you use for this. However, I use xyzscripts for the same cause. It creates short-codes for me to use.
Here is an example:
Create your PHP code and get a Tracking Name.
You will then get your short-code as below, note the Tracking Name.
I personally think this is the best way as it allows re-usability and centralized location to update all your scripts.
XYZ WP PHP Code Download and Documentation
Thank you all for responding.
Apparently I find the solution by installing the Classic Editor plugin
https://en-gb.wordpress.org/plugins/classic-editor/
It prevents disabling the php code.
If you are facing similar problem you can try this one

how to remove font awesome from my page load

baytalebaa.com
wordpress,
first
1- search for "fontawesome" using inspect
the following link casing my website to slow down by 2 sec
and i want to remove it .
2- http://baytalebaa.com/?ngg_serve_fontawesome_css=1&ver=4.6.1
it seems that nextgen plugin is calling it , how to stop it ? please help
i have tried the following
wp_dequeue_style( 'fontawesome' );
didnt work...
You can try to edit the plugin directly and serve the CDN version of the plugin, or remove the reference all together.
An alternative option is to serve the plugin files directly from CDN and distribute them via Cloudfront or an alternative service if you are not doing so already.
W3 Cache is a great plugin for managing issues like this.
You can try following code on page load. this might be helpful for you.
function remove_unwanted_css(){
wp_dequeue_style(‘font-awesome’, ‘https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css’);
}
add_filter(‘wp_print_styles’, ‘remove_unwanted_css’);

CKFinder 3 upgrade difficulty

I'm following the CKFinder 2 to 3 upgrade guide and it's not making much sense. In CKFinder 2, the PHP code provided could be used to generate the JS snippet with appropriate config and params, like this:
require_once 'ckfinder/core/ckfinder_php5.php';
$finder = new CKFinder() ;
$finder->SelectFunction = 'ShowFileInfo' ;
$finder->DisableThumbnailSelection = true;
$finder->RememberLastFolder = true;
$finder->Id = $name;
$finder->StartupFolderExpanded = true;
$finder->Width = $width;
$finder->Height = $height;
echo $finder->CreateHtml();
This code picks up the config and incorporates it into the generated JS.
In 3 this seems to have disappeared entirely - the upgrade guide describes the changes needed in config.php, but there is no indication of how this is ever used since there is no other PHP involved, and it says
It is no longer possible to enable CKFinder on a page from the PHP level
All that is shown is how to create the JS snippet, which does not contain any config, and so will use incorrect settings. There is no indication of how the config properties set in config.php ever get to the JS code - as far as I can see there is no connection at all and no mention of any other PHP files, even though some are provided but not documented.
This makes no sense - PHP can quite happily generate HTML and JS that is run on the page, which is all the old CreateHTML function did. I don't understand why there is no mention of this mechanism since it was how we were supposed to use CKFinder previously - it's as if the migration guide is for some unrelated package!
If I update the config file and use the default JS widget code as suggested, it breaks the page completely, altering the MIME output type so it does not get rendered as HTML and appends this error:
{"error":{"number":10,"message":"Invalid command."}}
The docs cover various fine details of what PHP config settings mean, but nowhere that I've found says how it's ever loaded, triggered or associated with the JS. How is this supposed to work?
Indeed the CKFinder 3 documentation was lacking some important information. We're gradually adding new articles there. Based on topics you mentioned I just added:
Explanation how PHP code that worked for CKFinder 2 can be refactored to plain JavaScript in CKFinder 3. Should look familiar ;)
A table with Configuration Options Migration - JavaScript Settings which should help you with discovering again options like rememberLastFolder

How to wp_dequeue_script or wp_deregister_script jquery (not effected) file from wp theme

NOTE: I already use wp_dequeue_script or wp_deregister_script but not successfull
Here is the scenario, i make a image slider plugin that use jquery-cycle2 and it work successfully.
There is a user who used a wp theme and in theme there is a jquery-cycle1, now when he install my plugin the jquery-cycle1 and jquery-cycle2 conflicts, when user delete the jquery-cycle1 file all things work fine and perfectly but i don't want to delete file by user.
Now i am trying that when user install my plugin the jquery-cycle1 in theme close or deregister or stop its effect.
I get file from theme successfully
if((file_exists($theme_file_path."/jquery.cycle.all.js"))){
echo "yes";
}
but i have no idea to close jquery-cycle1 file or stop its effect.
Last Option: I have last solution that delete the file from theme but its my last option.
Please any suggestions, help me.
You will have to place an incompatibility notice on your theme.
It is not possible to attempt to detect the existence of script from server side. You are able to detect queued scripts via the word press methods, however, this assumes that the user has not simply linked the file with a <script></script> tag. The file_exists method assume the file is stored on the server itself - it could be linked from a CDN or another server.
Also, whatever methods you use to detect and remove jQuery-Cycle; You are going to break any feature on the site that uses the existing plugin.
Thus, any solution you able to devise would either be extremely complicated, or would not be generalised enough to account for all these possibilities.
You may be able to use the following to prevent loading your script
if (jQuery().cycle) {
// Script already loaded
console.log("Error: Another version of jQuery-Cycle is already loaded!");
} else {
// Load your script
}
but this cannot unload what is already loaded.
There is a simple hack you can do on you end. In the Cycle2 source replace all $.fn.cycle with $.fn.cycle2 and ).cycle( to ).cycle2(.
I am using the source from here http://malsup.github.io/jquery.cycle2.js
After that You can access it like
$("#id").cycle2({option})
Here is a demo http://jsfiddle.net/33g6z79h/
Here i assume that you are not using cycle events http://jquery.malsup.com/cycle2/api/#events
and cycle extra transitions.
If you are using it you can make a fiddle for your cycle2 implementation and i would be glad to help :)

How to configure Vimeo-Service-module in Silverstripe

Forgive me for my English
I am new in PHP. And I'm building a site using Silverstripe and trying to configure Vimeo-Service-module. I'd follow the steps from this link
https://github.com/r0nn1ef/Silverstripe-Vimeo-Service-module
I did everything that mentions in the article. And created a page in admin panel of VimeoGallery page type and set the parameters on Videos tab to grab the videos for display.
After created page, I visited my and clicked on video menu but then all I see is no videos returned. It is showing blank page and no any error messages.
Is that I've done anything wrong. Please guide me...
Thanks in advance.
OK, I think I see the issue here. You are calling VimeoService::setAPIKey() however accessing the method like that is deprecated in the new version (the 2.0 branch - I was incorrect in my comment when I mentioned master) of the module.
The module instead uses the Site Config in the CMS to set the API key and a few other settings.
Now just remove VimeoService::setAPIKey() from your _config.php file, run /dev/build and set the API key through the CMS.
EDIT
On line 142 of VimeoGalleryPage.php, there is a function called flushCache. Replace the code in that function with the following:
public function flushCache($persistent = true) {
parent::flushCache($persistent);
unset($this->_cachedVideos);
}
Basically, the code in the 2.0 branch for this function does not correctly extend the same named function in SiteTree.

Categories