Wordpress - disable cache for admin panel while creating plugin - wordpress

I am creating plugin for first time and facing major issue regarding cache.
I register my js files as
wp_register_script("custom-js-backend", PLUGIN_URL . 'assets/js/custom.js', array(
'jquery',
'jquery-blockui'
));
wp_enqueue_script("custom-js-backend");
But unable to reflect changes on admin panel.
Tried
function cache_cleanup()
{
remove_action('wp_head', 'wp_generator');
remove_action('wp_footer', 'wp_generator');
}
add_action('init', 'cache_cleanup');
Also defined in wp-config.php
define('WP_CACHE',false);
But no luck.
Since by default my js file comes with 5.1.0 version so tried to remove the version from it using
https://wordpress.org/plugins/disable-version-caching/
Now the version is being removed but still file is not updating.
One solution is adding version number to my js file and changing version after every small change but this is quite not right.
Any help how to disable cache for admin panel while creating plugin.

you can use filemtime(PLUGIN_URL . 'assets/js/custom.js') as a version number - that will make the version number, the unix time of the last time the file was saved -
Meaning that everytime you same the file, you automatically get a new version number higher than the last one, that way it is still cacheable, but will get cleared when there are changes
So it would look like
wp_register_script("custom-js-backend", PLUGIN_URL . 'assets/js/custom.js', array(
'jquery',
'jquery-blockui'
), filemtime(PLUGIN_URL . 'assets/js/custom.js'), true);

Add this to .htaccess to disable browser caching during development:
# Disable browser caching.
# Ensure mod_headers is installed.
# To install on Debian, run `a2enmod headers`, then restart the server.
FileETag None
Header unset ETag
Header set Cache-Control "no-cache, no-store, must-revalidate, max-age=0"
Header set Pragma "no-cache"
Header set Expires "Thu, 1 Jan 1970 00:00:00 GMT"
Note: your browser may still cache external content from CDNs, but anything on your server won't be cached.

Related

WordPress image URLs have a blank space before /wp-content

I have run into a WP site which is not loading almost all images. The developer tools console shows 100s of these errors.
Failed parsing 'srcset' attribute value since it has an unknown descriptor.
Dropped srcset candidate "https://domain.tld"
After looking at the source code of the page, I found that the image URLs have a space before /wp-content/
This is happening for all src and srcset URLs.
I have tried troubleshooting by deactivating all plugins, but it did not fix the problem.
How do I go about fixing this issue?
The issue is that siteurl and home setting have a space at the end. The setting can either be found in wp-config.php file or in the database. I had to run the following command to fix it (replace https://example.com with the name your domain)
UPDATE `wp_options` SET `option_value` = 'http://example.com' WHERE `wp_options`.`option_name` = 'siteurl';
UPDATE `wp_options` SET `option_value` = 'http://example.com' WHERE `wp_options`.`option_name` = 'home';
You might find the following lines in wp-config.php:
define('WP_HOME','https://example.com');
define('WP_SITEURL','https://example.com');
Make sure they don't have a space at the end

wordpress upload media http error when size over 20~30KB

my wordpress will have http error when uploading media. After some testing that I found out all files above 30KB will have this error while size below 30KB will be more likely to be successfully uploaded (but still some small files like 6KB size will also have http error as well)
I have done a few search and below fixed has already been done:
configure php.ini
post_max_size=300M
upload_max_filesize=300M
memory_limit=1024M
You can find the phpinfo here.
in wp-config.php
define('WP_MEMORY_LIMIT', '1024M')
in theme functions.php
add_filter( 'wp_image_editors', 'change_graphic_lib' );
function change_graphic_lib($array) {
return array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
}
add in .htaccess
<IfModule mod_security.c>
SecFilterEngine Off
SecFilterScanPOST Off
</IfModule>
add in httpd.conf
<IfModule mod_fcgid.c>
MaxRequestLen 20000000
</IfModule>
still the problem is the same, and I still could not upload media normally.
Also I noticed that I could not submit new post which have large text content, I guess it is due to the same issue that the size of the post request is limited.
However I have already changed the post_max_size=300M, so I don't know what causes this issue now.

Is there a way to modify ioncube files to make it more secure

Basically I want to set a script that unless user insert "?hithisisme" the ioncube won't run. However, I run afoul of their anti corruption file mechanism.
I think that anti corruption file mechanism uses also date of creation / date of modification so if you even add something to file and remove and date of file modification will change, there will be corrupted info (tested myself just right now) .
To achieve what you want you have to create .htaccess file with:
php_value auto_prepend_file prepend.php
and in prepend.php you have to put:
<?php
if (strpos($_SERVER['REQUEST_URI'], '?hithisisme') === false) {
exit;
}
On my localhost it works without any problems

Wordpress: Cannot login in after upgrade - redirects to blank page

I updated a clients Wordpress to 3.5.2 and now cannot login via wp-admin.
The login form appears but once I hit the Log In button I am just redirect to a blank page with a single . on it. Same happens if I enter the wrong password.
I have checked out the Login Trouble Codex and tried replacing the wp-login.php file and disabling all plugins to no affect. I get the same issue occuring.
Front of the site seems fine.
What appreas in debug:
Warning: Cannot modify header information - headers already sent by (output started at /home/stretton/public_html/fo/wp-content/themes/freya/lib/widgets/banners-125.php:13) in /home/stretton/public_html/fo/wp-login.php on line 369
Warning: Cannot modify header information - headers already sent by (output started at /home/stretton/public_html/fo/wp-content/themes/freya/lib/widgets/banners-125.php:13) in /home/stretton/public_html/fo/wp-login.php on line 381
EDIT: I have also tried:
Renaming my theme to defualt it to the twentytwelve theme
Renaming the plugins directory
Removing the widgets directory
Replacing WP-Admin with from a fresh download
No luck with these either
Rename the active theme and force a revert to twentytwelve. Theme issues can still sometimes cause admin errors. But once the theme reverts, you should be able to get into admin, even if the front end is white-screened.
To figure out what's causing the white screen on the front end (or, if needed, the backend, too) use Debug. See https://codex.wordpress.org/WP_DEBUG
Add to wp-config.php:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
and the debug.log file will be in wp-content. And/or, add this line
define( 'WP_DEBUG_DISPLAY', true);
to dump them to the browser, too.

I want to download csv in wordpress admin page...it works fine at local server but live it give header already sent error

The code for download that works at localhost is but live at hostgather server it throughs error
ob_get_clean();
header("Content-type: text/x-csv"); # DECLARING FILE TYPE
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: attachment; filename=".$csv_file_name); # EXPORT GENERATED CSV FILE
header("Pragma: no-cache");
header("Expires: 0");
echo $fields;
exit;
The error is
Warning: Cannot modify header information - headers already sent by (output started at /home/londoner/public_html/pkfones.com/pinquest/wp-admin/includes/template.php:1679) in /home/londoner/public_html/pkfones.com/pinquest/wp-content/plugins/wp-gamesize/setgamesize_admin.php on line 131
Make sure you're calling ob_start() at the beginning (or very close) of your code execution. This will buffer all your output and allow you send headers any time. You can probably just place this at the very top of your functions.php.
The reason this works on your local and not live is probably a difference in the server config, where locally you are buffering by default but not on live. This is a good reason to make sure that your development and production environments are as similar as possible.

Resources