Wordpress plugin ABSPATH or die - wordpress

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)

Related

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/

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

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.

wordpress change themes location

Usually all the wordpress themes are uploaded and saved over the server say http://example.com/wp-content/themes/ . I am developing a plug-in to change this path to something like http://xyz.com/themeFolder/ . So i have to develop such a functionality where my wordpress installation will be on one server and the themes and plug-ins folders will be on another server.
Any help, will be highly appreciated.
Thanks in advance to all the genius people out there :)
Since Version 2.6, you can move the wp-content directory, which holds your themes, plugins, and uploads, outside of the WordPress application directory.
Set WP_CONTENT_DIR to the full local path of this directory (no trailing slash), e.g.
define( 'WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/blog/wp-content' );
Set WP_CONTENT_URL to the full URI of this directory (no trailing slash), e.g.
define( 'WP_CONTENT_URL', 'http://example/blog/wp-content');
SOURCE
Do not forget to check THIS page as well.

Can I call wordpress functions only in theme files with supported names?

I have created a file called, nl.php inside my wordpress theme folder and when I try to call a function like wp_header or any function, i get an error message, that the function does not exist.
How can I solve this problem.
you need to load the wp-load.php file, which will then allow you to call wordpress functions.
For example:
require( '../wordpress/wp-load.php' );
with 'wordpress' being your install root.
You need to load the core Wordpress files.
<?php require 'wordpresspath/wp-blog-header.php'; ?>

Resources