Wordpress

ترفندهای کاربردی wp-config.php در وردپرس

A concise collection of wp-config.php tricks from my WordPress sites to yours.

Debugging

All of my sites include the following constant definitions:

define('WP_DEBUG',         false);
define('WP_DEBUG_LOG',     false);
define('WP_DEBUG_DISPLAY', false);
define('SAVEQUERIES',      false);

This set of constants makes it easy to toggle “debug mode” off and on. Specifically, when it’s time to debug stuff, I change the first two constants to true, and then change them back to false when finished debugging.

For reference purposes, here are some additional wp-config snippets that I’ve used in the past:

@ini_set('log_errors', 1);
@ini_set('display_errors', 0);
@ini_set('error_log', ABSPATH . '/debug.log');

If I recall, these were useful in setting up error logging in an otherwise limited shared hosting environment. Just FYI mostly, best to use the WP definitions instead of these workarounds.

Updates, Revisions, and Trash

I also include the following constants, which disable auto-updates, post-revisions, and automatic trash deletion.

define('WP_AUTO_UPDATE_CORE', false);
define('WP_POST_REVISIONS',   false);
define('EMPTY_TRASH_DAYS',    999999);

Site URL and Home URL

Although not really necessary, I also like to define the Site URL and Home URL constants:

define('WP_SITEURL', 'https://example.com/wp');
define('WP_HOME',    'https://example.com');

These constants are used for the General Settings, “WordPress Address (URL)” and “Site Address (URL)”, respectively. Including these definitions helps to prevent “accidents” on multi-author blogs.

WP Memory Limit

If you are experiencing “out of memory” or similar errors, try adding the following definition to your site’s wp-config.php file:

define('WP_MEMORY_LIMIT', '64M');

As-is, this sets the WP Memory Limit to 64 MB, and you certainly can change that to whatever value works.

FTP Credentials

When using WordPress’ one-click update feature, it’s a bit tedious having to reenter your FTP credentials every single time. Fortunately, WordPress lets you define your creds as constants in the wp-config.php file:

define('FTP_USER', 'username');
define('FTP_PASS', 'password');
define('FTP_HOST', 'localhost');

Of course here you should replace the constant values with your actual credentials. In most cases, “localhost” is the correct value and does not need changed.

Multisite Stuff

I try to avoid WP Multisite, but when a client or something needs to set it up, I’ll add the following constant definitions to wp-config.php:

define('WP_ALLOW_MULTISITE', true);
$base = '/wp/';
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', false);
define('DOMAIN_CURRENT_SITE', 'example.com');
define('PATH_CURRENT_SITE', '/wp/');
define('SITE_ID_CURRENT_SITE', 1);
define('BLOG_ID_CURRENT_SITE', 1);

Make sure to check the WP Codex to verify current definitions and correct values for these constants. Stuff changes all the time.

Uploads Directory Path

On certain sites, one-click updates and media uploads do not work as advertised, but in some cases adding the following definitions to wp-config.php does the trick:

define('WP_TEMP_DIR', ABSPATH .'wp-content/uploads/');
define('WP_TEMP_DIR', '/abs/path/to/example.com/httpdocs/wp-content/uploads');

You don’t need to include both of these; only one is necessary. I’ve included both to show usage of the ABSPATH constant.

Disable File Editing

By default, WordPress enables admin-level users to edit plugin and theme files from within the WP Admin Area (under Appearance > Editor). I like to disable this functionality to help contain any security breach, and also because I never use it. To disable file editing from within the Admin Area, add this line to wp-config.php:

define('DISALLOW_FILE_EDIT', true);

Placing this line in wp-config.php is equivalent to removing the edit_themes, edit_plugins and edit_files capabilities of all users.

Maximum Execution Time

set_time_limit(300);

Maximum input of PHP variables:

مقدار توصیه شده: 3000. حداکثر محدودیت ورودی ممکن است انتشار داده هایی مانند منوها را کوتاه کند. مشاهده کنید

روش اول: فایل PHP.ini را ویرایش کنید

NOTE: many shared hosts prohibit you from having direct access to the PHP.ini file. Only do this method if you have direct access to your PHP.ini file or if you’re on your localhost.

  1. Locate your PHP.ini file. If you can’t find it, then you can create your own PHP.ini file in the root folder of your WordPress installation.
  2. If you find your existing PHP.ini, open the file and locate the following line of code (xx represents a number):max_input_vars = xx; And set it to your desired limit. For example, 5000.
  3. If you created your own PHP.ini file, then add the same code inside it:max_input_vars = 5000 Simply change the value to the recommended value. For example, 5000.
  4. Save your changes, and reboot your localhost or your server.

روش دوم: فایل .HTACCESS را ویرایش کنید

NOTE: make sure to backup your .htaccess file before editing.

  1. Locate your .htaccess file which is usually in the root folder of your WordPress installation. If you can’t find it, it may be because it’s hidden. Here’s a tutorial for Windows and a tutorial for Mac on how to reveal hidden files on your computer.
  2. Open the .htaccess file with a text editor program (Notepad or TextEdit) and add the following line of code:php_value max_input_vars 5000. Simply change the value to the recommended value. For example, 300.
  3. Save the file and refresh your website.

اترك تعليقاً

لن يتم نشر عنوان بريدك الإلكتروني.

زر الذهاب إلى الأعلى
x

Legimus intellegam ea est, tamquam appellantur nec ei. Dicant perfecto deserunt quo id, ea etiam impetus pri. Mel ne vidit laboramus definiebas, quo esse aeterno

arالعربية