stop wordpress revision and autosave to page - wordpress

Wordpress revision and autosave is keeping reverting my changes to a wordpress page. No matter how many changes I make always reverting to that point.
Is there some solution to stop doing that but not to disable revision to all site.

To Disable Autosave put the code below in your functions.php.
function disableAutoSave(){
wp_deregister_script('autosave');
}
add_action( 'wp_print_scripts', 'disableAutoSave' );
To Disable Post Revisions put the code below in your wp-config.php file.
define( 'WP_POST_REVISIONS', false ); // no revisions
Note: Using the above code will disable the Autosave and/or Post Revisions
throughout the site.

I believe the correct code should be as above code throws notification messages.
add_action( 'admin_init', 'disable_autosave' );
function disable_autosave() {
wp_deregister_script( 'autosave' );
}

Related

Problem with the media library in wordpress

I am building my own wordpress theme and I have such a problem. Media library doesn't work, I can't add any image to the page. I am using the latest version of wordpress.
Files available on github https://github.com/krysba/themes-wordpress
When I turn on the standard wordpress theme, the library works :(
I am asking for help in solving this problem.
If you have not tried, the first thing that i'll tring it's enable debug mode on Wordpress from wp-config.php and check if some alerts or errors can help.
define('WP_DEBUG', true);
I think that you must try to comment all function.php and debugging it row by row.
At the first check i've found a wrong use of the function add_theme_support and in the enqeueing files.
For example the right way to user add_theme_support is on the after_setup_theme action:
function my_setup_theme(){
add_theme_support('post-formats',array('gallery','link','image','quote','status','video','audio'));
}
add_action( 'after_setup_theme', 'my_setup_theme' );
Also the right way to enqueing scripts or styles is that:
function add_theme_scripts() {
wp_enqueue_style( 'style', get_stylesheet_uri() );
}
add_action( 'wp_enqueue_scripts', 'add_theme_scripts' );
See it on this page: https://developer.wordpress.org/themes/basics/including-css-javascript/

Disable WP Gutenberg prepublish checks globaly

Im creating custom user edit post interface and i need to completely remove gutenberg pos prepublish checks and publish. How can i do this?
You can disable the publish sidebar completly with
wp.data.dispatch('core/editor').disablePublishSidebar();
Simply enqueue this JS with a dependance to .
add_action( 'enqueue_block_editor_assets', function () {
wp_enqueue_script( 'so69031961', 'gutenberg-editor.js', [ 'wp-edit-post', 'wp-dom-ready' ] );
} );
This will have the same effect than unchecking this box :
So yes, your users might still be able to reactivate the checks, but it's better than nothing ;)

How to set WooCommerce notices from functions,php?

I'm processing some requests in my Wordpress theme's functions.php, and need to set notices there.
But none of the WooCommerce methods are available. How can I access wc_add_notice() from there?
Code from my functions.php file:
function my_function() {
// some code
wc_add_notice('Yay!', 'success');
wp_redirect( '/' );
die();
}
add_action( 'admin_post_nopriv_action', 'my_function' );
add_action( 'admin_post_action', 'my_function' );
NOTE: There is a similar question Display Woocommerce notices on a page, but this question is not a duplicate of that one. The notices will be displayed on standard WooCommerce template files. I'm attempting to set notices from within the functions.php file.
WC Notices will only show on WooCommerce template pages it won't show on your main home page unless it's a WooCommerce page. They are shown when the function wc_print_notices() is called.

Disable prettyPhoto WordPress (Visual Composer)

Hi I'm trying to get WP Featherlight setup as the default lightbox, right now Visual Composer is using prettyPhoto. So I need to disable it, so that WP Featherlight will overwrite it.
I asked wpbakery and I got this response.
Hello, you can actually overwrite prettyphoto by adding prettyPhoto() in your functions.php and call another lightbox.
And from the plug-in author I got this:
Once prettyPhoto has been disabled, you shouldn't need to do anything
else to lightbox images on the site.
So it's pretty clear what I need to do. Disable prettyPhoto. But I don't know how to do that. Can I add a simple line to my child theme's functions.php? Or?
Any help would really be appreciated.
Thanks.
Place the following code in your theme's function file.
function remove_vc_prettyphoto(){
wp_dequeue_script( 'prettyphoto' );
wp_deregister_script( 'prettyphoto' );
wp_dequeue_style( 'prettyphoto' );
wp_deregister_style( 'prettyphoto' );
}
add_action( 'wp_enqueue_scripts', 'remove_vc_prettyphoto', 9999 );
I have tested this on my installation and it works flawlessly.
What it does is dequeues and deregisters the javascript and stylesheets that Visual Composer enqueues and registers throughout the plugin's PHP files for the various template elements and shortcodes that use the prettyPhoto lightbox.
The '9999' parameter enforces that the dequeuing/deregistering happens well after any enqueuing or registering took place earlier on in the loading of the plugin. Any number will do, but the higher the number the better.
You have to enqueue a custom javascript in your child theme where you override the following function:
function vc_prettyPhoto() {
}
in this way you disable prettyPhoto script initialization made by Visual Composer.
You can use code bellow to disable that javascript lib. Put that into your functions.php of theme
wp_dequeue_script( 'prettyphoto' );
wp_dequeue_style( 'prettyphoto' );
Also other page buider you can use is King Composer, which is faster VC
https://wordpress.org/plugins/kingcomposer/
Not sure if you solved the problem, but I have a solution (not very elegant, but it works).
I did buy ePix theme for a photographer and noticed that Masonry Media Grid from Visual Composer isn't fully responsive. So my soulution was to edit 3 files from wp-content/assets/js/dist. Those files are:
vc_grid.min.js
page_editable.min.js
js_composer_front.min.js
Just remove window.vc_prettyPhoto() or vc_prettyPhoto() from wherever they appear.
After that I installed Lightbox by dFactor, choose swipebox and used as selector prettyPhoto. Also I did force lightbox on link images. Now the lightbox is fully-responsive.
Hopefully this will help somebody :)
You can disable Pretty Photo. Use the below code in theme's function file, thats it.
function remove_scripts(){
wp_dequeue_script('prettyphoto' );
wp_deregister_script('prettyphoto' );
}
add_action( 'wp_enqueue_scripts', 'remove_scripts', 100 );
It will work.
I have tested on my own issue to deactivate some sliders from the Visual Composer and it works. An example how to deactivate the whole Flexslider, Nivoslider and Owl Carousel sliders in the Visual Composer plugin. Add this code into theme functions.php file:
add_action( 'wp_enqueue_scripts', 'deregister_vc_modules', 99 );
function deregister_vc_modules() {
wp_deregister_style( 'flexslider' );
wp_deregister_script( 'flexslider' );
wp_deregister_style( 'nivo-slider-css' );
wp_deregister_style( 'nivo-slider-theme' );
wp_deregister_script( 'nivo-slider' );
wp_deregister_style( 'owl-carousel' );
wp_deregister_script( 'owl-carousel' );
}

Removing action added by a plugin in Wordpress

I am using Popup Maker plugin for Wordpress and I am trying to prevent it to load on a particular page using the functions.php file of a child theme.
I've located in the plugin's directory the file popup-maker.php which contains the following line at the end:
add_action( 'plugins_loaded', 'popmake_initialize', 0 );
If I remove / comment this line, the popup will not fire, so I guess this is the action I need to remove. I have read the WP codex and numerous posts but still can't get it to work.
Right now I am stuck at this (function I have added in my child theme's functions.php file):
function remove_popmaker() {
remove_action('plugins_loaded', 'popmake_initialize', 0);
}
add_action( 'init', 'remove_popmaker', 1 );
PS: I am using shopkeeper theme and Woocommerce.
All help appreciated, thanks.
you are adding a action to init which is after plugins_loaded so you cannot remove a action after it has run.
you can try the same action but you will have to do this from a plugin
remove_action( 'plugins_loaded', 'remove_popmaker', 0 );
But i suspect actions added before yours will be run after, this may be unpredictable if not you may have to code a MUplugin (google this).
There is a way I managed to do this:
add_action('wp', 'disableEmailPopup');
function disableEmailPopup () {
global $post;
if ($post->ID === 11625249) return remove_action( 'wp_enqueue_scripts', 'popmake_load_site_scripts');
}
#BMM - Without knowing the use case as to why you need to disable the entire plugin on one page its hard to give you the best answer.
For example if you simply wanted a single popup to not show on one page you can use the conditions panel to add a negative condition using the (!) button. Click it to turn it red and you will check for the opposite of a condition, so (!) Page Selected: Page xyz would prevent it from loading on that page.
Alternatively you can create your own custom conditions allowing you to add that condition to any popup.
Lastly if you wanted to unhook it just from the front end you can simply remove the rendering & script handlers
remove_action( 'wp_footer', 'popmake_render_popups', 1 );
remove_action( 'wp_head', 'popmake_script_loading_enabled' );
And if you want to prevent the queries as well
remove_action( 'wp_enqueue_scripts', 'popmake_preload_popups', 11 );
Hope that helps.

Resources