Can somebody tell me the difference between these two parts of codes - wordpress

I'm trying to read wordpress codes to have a deep insight about how things work, and also because I need to put my hand into it for special reasons, but I got stuck in this, hope some of you guys can explain the difference between these for me:
if ( file_exists( ABSPATH . 'wp-config.php') )
and
if ( file_exists( dirname(ABSPATH) . '/wp-config.php' )
Many thanks

Assuming you're looking at wp-load.php, these pieces of code do what their associated comments say:
if ( file_exists( ABSPATH . 'wp-config.php') ) {
/** The config file resides in ABSPATH */
require_once( ABSPATH . 'wp-config.php' );
} elseif ( file_exists( dirname(ABSPATH) . '/wp-config.php' ) && ! file_exists( dirname(ABSPATH) . '/wp-settings.php' ) ) {
/** The config file resides one level above ABSPATH but is not part of another install */
require_once( dirname(ABSPATH) . '/wp-config.php' );
That is, they're trying to find the wp-config.php file.
As described in Hardening WordPress, one option you have for increasing the security of your WordPress installation is to move your wp-config.php file one level above the root of your WordPress installation. This is because you can then configure your web sever not to serve any files above the standard WordPress root (where index.php lives, so has to be accessible from the web.) That makes it a little less likely that someone can see the content of your wp-config.php, which has important things like your database password in it.
So, given that:
Note that wp-config.php can be stored ONE directory level above the WordPress (where wp-includes resides) installation. Also, make sure that only you (and the web server) can read this file (it generally means a 400 or 440 permission).
...WordPress uses the code you're seeing to first check if there's a wp-config.php file at the absolute path of your WordPress installation, i.e. your root WordPress directory, ABSPATH, but if there isn't, it uses the dirname method to go one step up, by checking for a wp-config.php file in the directory that contains the root WordPress directory.

Related

Wordpress error PCLZIP_ERR_MISSING_FILE (-4) when I'm trying to install, update a plugin, but the error is solved temporarily if I restart the server [duplicate]

Our web server hard disk went full overnight and all our sites crashed. We increased hard disk size and then sites were working okay.
Now we found out that we are unable to update plugins automatically from the plugins.php page. We are getting the following error:
Update Failed: The package could not be installed. PCLZIP_ERR_MISSING_FILE (-4) : Missing archive file '/tmp/woocommerce-customer-order-xml-export-suite-Wa6DIQ.tmp'
See also screenshot: http://imgur.com/a/9969E
What do we need to do to rectify this?
On your server, navigate to the /wp-content folder. Create a new folder inside it called TEMP.
Download /wp-config.php from your server to your computer. Open it up in a text editor, and beneath:
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
add the line
define('WP_TEMP_DIR', ABSPATH . 'wp-content/TEMP');
Taken from: http://birchenough.co.uk/pclzip_err_missing_file-4-missing-archive-file-cwindowstempwhatever-tmp/
Once this happened to me but with a Windows Server. And I solved doing the following.
I created a folder in wp-content named temp
Then I edit the wp-config and below the following line
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
I paste this line:
define('WP_TEMP_DIR', ABSPATH . 'wp-content/tmp');
And since that moment I stop using Windows as Servers LOL.. And moved to Linux

Wordpress plugin ABSPATH or die

wordpress plugin .php file has the first line as
defined('ABSPATH') or die("Cannot access pages directly.");
i understand that this line protects php file and prevents direct access.
what to do if i want to access the file or activate it in a wordpress website. Thanks
Try:
include_once plugin_dir_path( __FILE__ ) . 'my-plugin-dir/my-filename.php';
Where my-plugin-dir is the server directory of your plugin, and my-filename.php is the file you want to load.
(I've used include_once in my example, but obviously if you need to load this file more than once use include instead)

How do I fix WordPress PCLZIP_ERR_MISSING_FILE (-4) : plugins error?

So I am trying to install recommended plugins from a WordPress theme after installing the theme but the plugins installing return errors. Below is the response for contact form 7:
Downloading installation package from
https://downloads.wordpress.org/plugin/contact-form-7.5.2.1.zip…
Unpacking the package… The package could not be installed.
PCLZIP_ERR_MISSING_FILE (-4) : Missing archive file
'/tmp/contact-form-7.5.2.1-ribBpT.tmp'
I read some inputs about adding some lines of codes into the wp-config file and adding the below and created a folder called "temp" under the contents folder:
/*Set WordPress temporary directory */
define('WP_TEMP_DIR', ABSPATH . 'wp-content/temp');
I then went back to refresh before I tried installing the plugin but the issue remained the same.
Here is what I have in the wp-config file:
/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', __DIR__ . '/' );
/*Set WordPress temporary directory */
define('WP_TEMP_DIR', ABSPATH . 'wp-content/temp');
}
/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';
Am I missing anything here? If yes, how do I fix this?
Thanks!
This might happen when you do not have space left on your disk drive. Check this with df -h.
Go to Your wp-content folder. You can access the wp-content folder by using a file manager on your hosting or using FTP. The location will be domain/wp-content (where domain is the website domain name)
When you are in wp-content create new folder under wp-content and call it temp.
Download your wp-config file from your server to your computer. This is just in case you make a mistake and have a backup which you can quickly restore. Open the wp-config file and search for the following line of code.
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(FILE) . '/');
Add following line of code after that line.
**/Set WordPress temporary directory /
define('WP_TEMP_DIR', ABSPATH . 'wp-content/temp');
Save the wp-config.php file. If you edited it on your PC upload it to the website
just add define('WP_TEMP_DIR', ABSPATH . 'wp-content/temp'); right after }!
and create temp folder in wp-content/temp.
if put cod inside {} won't work
somthing like this will work:
if ( ! defined( 'ABSPATH' ) ) {
define( 'ABSPATH', __DIR__ . '/' );
}
define('WP_TEMP_DIR', ABSPATH . 'wp-content/temp');

Custom php file in root folder

So, I have a custom php file in my wordpress root folder.
I have a link in frontend "example.com/custom.php" that I would like to access.
How would I include this custom php in root folder in function.php so that it can be recognized by other wordpress function?
Thanks
Add this line in your themes functions.php:
include(ABSPATH . 'custom.php');
Explanation:
Your wp-config.php should contain the following code (near the bottom of the page):
/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
They are saving the path to the wordpress installation to ABSPATH.
It will be something like "/var/www/foo/" or similar. So you can concat the ABSPATH with path to your file. If for example, your php file is located inside some folder like this "example.com/somefolder/custom.php" you would use
include(ABSPATH . 'somefolder/custom.php');
Hope this helps!

Move wordpress to root

A friend of mine asked me to help him to move his website from website.com/wp to the root website.com/
Its Wordpress installation is automatized by some script on register.it
I followed this guide, I log on, I changed both WordPress and Site Address from website.com/wp to website.com and saved.
Then from the ftp, I copied and pasted all my public/www/wp one step higher to public/www/ but the site was down and I couldn't even reach website.com/wp-admin or website.com/wp-login.php
Then I restored one of the backups I had and I tried this other guide, I moved the index.php one step higher by changing
/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
to
/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp/wp-blog-header.php' );
And of course this didn't work neither..
Now I start also wondering if that one was the real Wordpress root, this is the structure
How can I make the website be reachable on the root?
I solved it.
I tried the whole time playing with the /public/www folder, while instead the real Wordpress root was under /web/

Resources