Wordpress Auto Draft disabling - wordpress

I am using Wordpress v.3.3.1 With Multisite management on.
I am trying to disable the auto draft function, but it seems that I have tried everythig.
What I have tried:
define('WP_POST_REVISIONS', false);
define('WP_POST_REVISIONS', false);
Didn't work.
I have tried to remove the auto_save lines in post-new.php, post-php. Both in wp-includes and in wp-admin. Didn't work.
I have also tried several plugins, but they won't do it! Any idea why?

I notice that you are asking about disabling Auto-Drafts and NOT Auto-Save.
You cannot disable Auto-save, but you can achieve a similar affect by setting a long interval, for example:
define( 'AUTOSAVE_INTERVAL', 3600 ); // Default is 60
(You'd add it in your WordPress site's wp-config.php file.)
As for Auto-Drafts, you don't want to disable them. They are there for an important reason. Let me grab a quote or two for ya...
Samuel 'Otto' Wood, Tech Ninja at Audrey Capital (Matt Mullenweg's angel investment company), says:
Auto-drafts exist because of the fact that multiple users can create new posts at the same time. If two people enter post-new at roughly the same moment, then have their first autosaves occur nearly simultaneously, then there is a race condition that can cause one of them to get back the wrong post ID, which will cause a post to be overwritten/lost when they then continue editing the post.
The auto-draft creates the post and gets the ID of the new post before the editing screen is displayed, thus preventing two simultaneous authors from accidentally having the same post ID in the data in their browser.
Andrew Ozz, who worked on WordPress' TinyMCE integration, says:
This also makes it possible to upload images before the first draft is saved and they will be properly attached to the new post.
And lastly:
Auto-drafts are automatically deleted after 7 days of going unused. They're self-cleaning, basically. No need to worry about them.

A) Set it in your wp-config.php file. Else it won't work.
define( 'AUTOSAVE_INTERVAL', 3600 ); // autosave 1x per hour
define( 'WP_POST_REVISIONS', false ); // no revisions
define( 'DISABLE_WP_CRON', true );
define( 'EMPTY_TRASH_DAYS', 7 ); // one week

Open wp-config.php located in your WordPress root directory and add following code:
define('WP_POST_REVISIONS', false );
before of require_once ABSPATH . 'wp-settings.php'; or and top of the file.

For guys who use WordPress 5.0+ version with Gutenberg Editor, the below code snippet works to disable auto drafting/saving
/**
* Disables auto saving feature for Gutenberg Editor (set interval by 3600s)
*/
add_filter( 'block_editor_settings', 'rsm0128_block_editor_settings', 10, 2 );
function rsm0128_block_editor_settings( $editor_settings, $post ) {
$editor_settings['autosaveInterval'] = 3600;
return $editor_settings;
}

I think disabling it is not good (for example, when you parallely try to publish 2 posts, then there may be problems). So, instead, of disabling:
Method 1)
disable them slightly (without CORE-modifications), see this answer.
Method 2)
just clean them using this code or good plugin WP Clean Up

Related

WooCommerce not saving post meta value

In my WooCommerce site i have create a product and in this product i have attached a lot of pdf files so that after user buy it he can download all these pdf files but the problem is that in this product i have more than 375 files so after added 320 files its working fine and when i add 319 product and hit update button page updated successfully but the 321th products is removed i thought it was some mistake so i added it back and same thing happen i don't know why i just enable the debug log
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_DISPLAY', true );
define( 'WP_DEBUG_LOG', true );
but noting log no error just removed the 321th record can anyone please tell me is there any limit of woocommerce or anything else o this problem can be resolved
Thanks
this is probably happening because you must be passing input limits on the form submit. To solve this you will need to open php.ini from your server and increase the max_input_vars variable which will probably be 1000 to 2000.
This happens because for each field you generate woocommerce must be generating one or two more. what goes over the edge. so just increase it and restart that will solve.
Some hosts will not let you modify or increase php.ini in which case you should contact the host and request the increase.

How to attach files to an email sent by a WordPress booking plugin?

I'm using a WordPress plugin for accepting online bookings (Appointment Hour Booking) and I need to attach a file to the emails sent after submitting the booking request (a PDF file with the general booking terms). I already applied a solution by editing the calls to the wp_mail() function in this way:
wp_mail(trim($payer_email), $subject, $message,
"From: ".$from."\r\n".
$content_type. "X-Mailer: PHP/" . phpversion(),
array(WP_CONTENT_DIR . '/uploads/agreement.pdf'));
The above works but everytime the plugin updates the file is overwritten and I've to reapply the code modification again. There is a better way to do that without being affected by the plugin updates or there is a way to prevent partially or completely a plugin update in WordPress?
Thank you in advance for any help.
Disabling the plugin update isn't a good idea, you may lost important compatibility or security updates. The way the call to the wp_mail() was modified also causes other attachment-related features stop working. The plugin you mention has a filter that can be used to modify the list of attached files, you can put the following code for example into your theme’s functions.php file:
add_filter( 'cpappb_email_attachments', 'my_attach_function', 10, 3 );
function my_attach_function( $attachments, $params, $form_id )
{
$attachments[] = WP_CONTENT_DIR . '/uploads/agreement.pdf';
return $attachments;
}
With the above code located out of the plugin files your file is added to the list of attachments without removing other attachments and locating the code out of the plugin files will prevent being overwritten by the plugin updates.
Your options are:
Fork the plugin and customize it to your needs.
Ask the team behind the plugin to implement a filter hook to allow customizing the headers passed to the wp_mail() function (so you can then attach files to e-mails).
Keep doing what you have been doing until now.
I like option two the best because:
It allows you to customize the behavior of the plugin from the outside, and,
Your changes will survive plugin updates.

How to stop W3 Total Cache from globally replacing URLs in Wordpress

I'm trying to create a custom wp_head implementation in a Wordpress theme to work alongside the original method.
I've setup my code like this in functions.php:
function wp_head_r()
{
echo '<script src="http://sample-url.com/js/file.js"></script>';
}
Then in header.php, I have this:
wp_head(); //original
wp_head_r();
The problem I have is that the Wordpress install I'm working with has W3 Total Cache installed. So what is happening is that any file that has sample-url.com that references a JavaScript or CSS file is being replaced to sample-url-cdn.com before it is output to the page.
This was happening with enqueued scripts and stylesheets, and I was thinking that setting up a custom wp_head method would prevent this, but that doesn't seem to be the case.
Is it possible to create some kind of filter to prevent W3 Total Cache from globally replacing all the urls?
I managed to figure this out. The trick is to use a filter with a high priority, effectively overriding [I think] the one that W3 Total Cache is leveraging.
Here's the code [for functions.php]:
function my_filter_w3tc_cdn_url( $new_url, $url, $is_engine_mirror )
{
if(preg_match('/\/(my_special_dir_pattern)/i', $new_url))
{
$new_url = $url;
}
return $new_url;
};
add_filter( 'w3tc_cdn_url', 'my_filter_w3tc_cdn_url', 100, 3 );
I used preg_match to target all urls that fit a specific pattern, and then exclude them from being updated to the CDN url. Also, notice that I used a priority of 100, which seems high enough and worked in my specific use case.
Hope it helps.

Customizing Text in WordPress's wp-signup.php

I need to change the following default text on the WordPress multisite signup page (wp-signup.php):
"There is no limit to the number of sites you can have, so create to
your heart’s content, but write responsibly!"
...since this WordPress install will be limiting the number of sites a user can create.
Is it possible to override the content of this page without hacking the wp-signup.php file or dealing with .htaccess?
This WordPress install is being hosted by a third party service and it would be best if I could avoid dealing with modifying these files.
I've managed to hit on another solution. It turns out, that since the text on the wp-signup.php page is run through __(), you can alter it using the 'gettext' filter like so:
/**
* Modify default wp-signup.php text
*/
function themename_wp_signup_text( $translated_text, $untranslated_text, $domain ) {
global $pagenow;
if ( is_multisite() && $pagenow === 'wp-signup.php' ) {
switch ( $untranslated_text ) {
case 'Welcome back, %s. By filling out the form below, you can <strong>add another site to your account</strong>. There is no limit to the number of sites you can have, so create to your heart’s content, but write responsibly!' :
$translated_text = __( 'Welcome back, %s. By filling out the form below, you can <strong>add another site to your account</strong>. You can create a maximum of 5 sites. Remember to write responsibly or some junk! Ciao!', 'theme_text_domain' );
break;
}
}
return $translated_text;
}
add_filter( 'gettext', 'themename_wp_signup_text', 20, 3 );
...which is just for a theme, but you could do this in a plugin too.
So the text is technically filterable, but I'd say this is a huge hack though, but it'll do, and shouldn't have any consequences until that particular text changes in WordPress core...
As Dave Kiss said in his comment above, this string isn't filterable so you can't filter the text. The string isn't marked either so you can't use a translation file.
I suggest you open a WordPress Trac ticket requesting the text be marked or made filterable.
You can open a new ticket here: http://core.trac.wordpress.org/

How to customize Wordpress Theme before going live

Yesterday I installed a new theme on Wordpress on my self-hosted website. I am aware of the feature that allows you to preview a theme and have used it to select a new Theme that I want to install.
Problem
I do not want to interrupt normal operations of my website, but this new theme requires a lot of customization before it is ready to go. How do I do this?
My Crappy Solution
Is the only way to go about it to run a virtual server on my desktop? This seems tedious, not to mention all the errors I usually get when switching to the "real" server when doing this.
A better way?
I've been searching on SO as well as the WordPress Forum for an answer as to how to do this, but have come up short. I would have thought this is a common question. Maybe I'm using the wrong search terms [themes, customization, before installing]???
Any help is greatly appreciated! Thanks!
Ok, since your question is a pretty good one and probably not a few people are going through the same process when they decide to update their site, I decided to give a try to the get_stylesheet and get_template filter hooks. It turns out that with a very small plugin, you can easily enforce a specific theme(well in this case any logged-in visitor, but you can change this to use any logic you want) according to a specific rule/s.
Here's the code that you need to put in a file in your plugins directory:
<?php
/*
Plugin Name: Switch Theme
Description: Switches the theme for logged-in visitors, while keeping the current theme for everyone else. !!!NOTE!!! Please back-up your database prior using this plugin - I can't guarantee that it will work with any theme, nor that it won't break your site's set-up - USE AT YOUR OWN RISK(I did a quick test and it seemed to be fine, but haven't done extensive testing).
You don't need to switch to the desired theme before that - you want to keep active the theme that you will display to your visitors - the one that you will see will be used programatically.
Before activating the plugin, change the line that says `private $admin_theme = '';` to `private $admin_theme = 'theme-directory-name';` where "theme-directory-name" is obviously the name of the directory in which the desired theme resides in.
*/
class MyThemeSwitcher {
private $admin_theme = '';
function MyThemeSwitcher() {
add_filter( 'stylesheet', array( &$this, 'get_stylesheet' ) );
add_filter( 'template', array( &$this, 'get_template' ) );
}
function get_stylesheet($stylesheet = '') {
if ( is_user_logged_in() && $this->admin_theme ) {
return $this->admin_theme;
}
return $stylesheet;
}
function get_template( $template ) {
if ( is_user_logged_in() && $this->admin_theme ) {
return $this->admin_theme;
}
return $template;
}
}
$theme_switcher = new MyThemeSwitcher();
So - first of all BACKUP YOUR DATABASE! I tested locally with Twenty Eleven being the default theme and a basic framework theme as my custom theme - the theme options and navigation menus were saved properly.
Then all you need to do is to update the file(change the line that says private $admin_theme = ''; to private $admin_theme = 'theme-slug'; where theme-slug is the name of the directory in which the theme you want to use is).
Also - you won't be able to change the Front page and Posts page options, without this affecting the live site, nor will you be able to change the any shared components that both themes use(Site name, Front Page, Posts page, Posts Per Page, etc options, content and so on).
So if you have no clue whether this solution is for you - well, it depends.
If both themes are not relatively complex, then most-likely you should be able to use this hack. If they are though maybe you should do a second installation of your website as others suggested - I think that a second installation in either a sub-domain or a sub-directory would be the best option for you(simply because moving a multisite database is more complex than moving a normal WP database).
I'd setup local apache server with a wordpress installed to customize and test a new theme. When you finished customizing it then you can upload the theme to your live site and activate it. If there are settings that you need to set in the dashboard then you probably will have to adjust them again. That's one way to test/customize a theme before putting it live.
You could create a network (make WordPress multisite with define('WP_ALLOW_MULTISITE', true);, see : http://codex.wordpress.org/Create_A_Network) and then create one sub-site, then turn it "off" with a Maintenance plugin so it is not accessible to users not logged in as admin, export your posts & data from main blog, import them in sub-blog with WordPress default importer, then apply your new theme to this sub-blog and work on it. When everything satisfies you, apply the theme to the main site and deactivate subsite.

Resources