WordPress will only prompt you for your FTP connection information while trying to install plugins or a WordPress update if it cannot write to /wp-content
directly. Otherwise, if your web server has write access to the necessary files, it will take care of the updates and installation automatically. This method does not require you to have FTP/SFTP or SSH access, but it does require your to have specific file permissions set up on your webserver.
It will try various methods in order, and fall back on FTP if Direct and SSH methods are unavailable.
https://github.com/WordPress/WordPress/blob/4.2.2/wp-admin/includes/file.php#L912
WordPress will try to write a temporary file to your /wp-content
directory. If this succeeds, it compares the ownership of the file with its own uid, and if there is a match it will allow you to use the 'direct' method of installing plugins, themes, or updates.
Now, if for some reason you do not want to rely on the automatic check for which filesystem method to use, you can define a constant, 'FS_METHOD'
in your wp-config.php
file, that is either 'direct', 'ssh', 'ftpext' or 'ftpsockets'
and it will use that method. Keep in mind that if you set this to 'direct', but your web user (the username under which your web server runs) does not have proper write permissions, you will receive an error.
In summary, if you do not want to (or you cannot) change permissions on wp-content so your web server has write permissions, then add this to your wp-config.php file:
define('FS_METHOD', 'direct');
Permissions explained here:
The WordPress global variable $pagename
should be available for you. I have just tried with the same setup you specified.
$pagename
is defined in the file wp-includes/theme.php, inside the function get_page_template()
, which is of course is called before your page theme files are parsed, so it is available at any point inside your templates for pages.
Although it doesn't appear to be documented, the $pagename
var is only set if you use permalinks. I guess this is because if you don't use them, WordPress doesn't need the page slug, so it doesn't set it up.
$pagename
is not set if you use the page as a static front page.
- This is the code inside /wp-includes/theme.php, which uses the solution you pointed out when
$pagename
can't be set:
--
if ( !$pagename && $id > 0 ) {
// If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object
$post = $wp_query->get_queried_object();
$pagename = $post->post_name;
}
Best Solution
The
$post->post_parent
is allowed to be0
. If the value is0
, it simply means that the page is a top level page.A page that has a
$post->post_parent
other than0
, is a child of another page.For example, take this page structure as an example:
The resulting page/menu structure would be:
The code in question:
I'm not sure why your theme might have the code, but a possible reason might be to get a menu related to the current page. If you're viewing the top level page (i.e.
$post->post_parent == 0
), then it would show all child pages, or if you're viewing a sub page, the menu might show all sibling pages.A sample menu generated using this method
Add this to your
functions.php
file so it's accessible throughout the theme.Add this code to your theme where you want to display a menu. You will need to customise it to suit your particular needs, but it gives you an example of why someone might use the code you asked about.