Wordpress: how to get plugin's folders permission - wordpress

SOLVED: plugin_dir_path(--FILE--).'MyFolder';
I have built a wordpress plugin (wp-content/plugins/MyPlugin) and I would to check some folders permission inside the MyPlugin directory.
My problem is that I don't what Wordpress constant or what PHP function I should use to target on of these directories.
if( !is_writable(WP_PLUGIN_URL.'MyFolder') )
{
echo 'NOK'.'<hr>';
}
This piece of code always returns 'NOK' whereas I am 100% sure 'MyFolder' is actually writable
.
Can you give me some piece of advice here to get the right file in order to target any folder that would be in my plugin directory?
thanks

Related

Wordpress in subdirectory using wrong path for enqueing scripts

I have been searching for a while but I haven't really seen anyone talk about this or found solutions.
At least nothing other then some hacks to help out from the functions.php
For a WordPress install at work I had to move the install into its own folder.
I used the guide here: https://wordpress.org/support/article/giving-wordpress-its-own-directory/#method-ii-with-url-change
Everything is working great and the folder structure is as expected:
- /
|-- Wordpress
|-- wp-content
|-- themes
|-- WebsiteTheme
So no worries there.
The functions.php has, for the moment, the following 2 lines in the wp-config.php
define( 'WP_HOME', 'https://dev.website.nl/' );
define( 'WP_SITEURL', 'https://dev.website.nl/wordpress' );
All in accordance with the guide from the official WordPress website.
But here is where things go weird.
When I try to Enqueue a script like this
$path = '/wp-content/themes/website/js/app.js';
wp_register_script('someName-'.$entry, $path, [], false, true);
wp_enqueue_script('someName-'.$entry);
the path eventually is set as
/wordpress/wp-content/themes/website/js/app.js
which of course won't work.
It looks like the path is pre-fixed with the SITEURL instead of the HOME url.
Currently I am using a filter that hooks into the script_loader_tag and str_replace the "/wordpress" part out of the path if a conditional statement is true based on the name I gave the script.
But as I just followed the WordPress guide set this up, I thought this would not be an issue.
Any idea if I am missing something here?
Thanks
The second parameter of wp_register_script() accepts $src as the full URL of the script OR the path of the script relative to the WordPress root directory.
To prevent this issue caused by the latter default, you'd probably be better off passing the full URL.
I think you can do so by prepending get_template_directory_uri() or get_stylesheet_directory_uri().
E.g.:
$path = '/js/app.js';
wp_register_script('someName-'.$entry, get_template_directory_uri() . $path, [], false, true);

Finding the path of a specific WordPress install

I have recently taken over a WordPress website.
Once I got access to the server I found that there were more than 70 installations of WordPress spread across it (files and DBs).
What is the quickest/easiest way for me to determine which installation is the one that is running the actual live website?
I thought of putting a PHP file into each installation (a file that echoed something along the lines of $_SERVER['PHP_SELF'];) - then try and access that file from the site itself, from there I know which installation is the correct one (I can then work out which DB is the correct one from the wp-config).
But surely there is an easier way? I have access to wp-admin, is there anything I can do in there to show me the base install path of this particular WordPress?
Save the follwoing code into a php file and put it into the root foler. This will list all the folders which have the WordPress installation.
<?php
$dirs = array_filter(glob('*'), 'is_dir');
foreach($dirs as $dir)
{
$path=$dir.'/wp-config.php';
if(file_exists($path))
{
echo $dir.'<br>';
}
}

Locating local directory for localhost

I've been spending hours trying to locate where localhost's files are stored.
I've tried looking at the page source but all it tells me is http:/localhost/....
which is not what I need.
My Xampp directory (where I load Xampp control) is located in my desktop but there is no change when I alter stuff inside its htdocs.
The default root for XAMPP, assuming you installed in the default location, is c:\xampp\htdocs. You can change this by modifying the Apache configuration in c:\xampp\apache\conf\httpd.conf.
You can always check it through PHP:
echo $_SERVER["DOCUMENT_ROOT"];
Or if you want to use WordPress functions:
echo get_stylesheet_directory();
Include these codes in your page.php or header.php for example.

Blank Page Encountered When Moved Wp-content Directory Outside

I'm trying to install Wordpress with clean subversion repositories, as in http://codex.wordpress.org/Installing_WordPress_With_Clean_Subversion_Repositories. I have followed every step accordingly until the second last step, where it says 'You should now be able to view the site via the root URL (http://example.com)', and indeed I can see my website on, say, http://example.com.
Once I go to the final step of changing the wp-config.php though, http://example.com draws a blank page. I am quite sure the wp-config.php is the problem, i.e. Wordpress doesn't know that it should retrieve my wp-content contents from outside the core Wordpress directory. My directory structure is as such:
.htaccess
core/
custom/
wp-config.php
, where core/ holds the files checked out with Subversion, custom/ holds my themes/ and plugins/ directory, and wp-config.php contains the below lines:
define('WP_CONTENT_DIR', dirname(__FILE__) . '/custom');
define('WP_CONTENT_URL', 'http://example.com/custom');
I have tried other variations, like:
define('WP_CONTENT_DIR', $_SERVER['DOCUMENT_ROOT'] . '/custom');
define('WP_CONTENT_URL', 'http://example.com/custom');
I have also tried hardcoding the local path, like:
define('WP_CONTENT_DIR', '/home/MYUSERNAME/example.com/custom');
define('WP_CONTENT_URL', 'http://example.com/custom');
, but none of the above works. Then I renamed the custom/ folder to wp-content/, but again nothing. I even went into Dreamhost to prevent redirecting http://example.com to http://www.example.com and vice versa, but again to no avail. I don't believe core/ is the problem, because I can access the Dashboard via http://example.com/core/wp-login.php, and the Dashboard says it can't detect my themes, which confirms my suspicion that WP doesn't know to retrieve the files from the custom/ folder.
By now, I have run out of ideas as to where could the problem be. Can anyone experienced in this area please give me some advice? Thanks a million.
Ensure that your statements come BEFORE the call for wp-settings.php, which is usually around line 90. Wp-settings (or more accurately default-constants.php) checks if the paths and URLs have already been defined, so you want to make sure you define them beforehand.
If that isn't the issue then check if $_SERVER['DOCUMENT_ROOT'] is returning the values you expect; you might have issues if working in a sub-directory.

WordPress Renaming Themes Folder

I'm wondering how I would rename the 'themes' folder in the wp-content. I've renamed my wp-content folder and the actual active theme folder name, but I'm after renaming the folder the themes are stored in.
/wp-content/themes/themename
the middle one lol.
Does anyone know how this would be achieved?
The following will enable the directory "t", in the root of the site, to be used as an extra Themes directory
register_theme_directory( '/www/htdocs/username/public_html/t' );
I think you'd like this thread: Steps to Take to Hide the Fact a Site is Using WordPress?
This is usefull if you want to keep plugins and uploads in ex. separate server for CDN purpose (NFS) and remove public/www permission. In this case you only deploying themes instead of plugins, uploads etc.
define('WP_CONTENT_DIR', __DIR__ . '/data/wp-content');
define('WP_CONTENT_URL', 'http://{your-url/to-blog}/wp-content');
define('WP_PLUGIN_DIR', __DIR__ . '/data/wp-content/plugins');
define('WP_PLUGIN_URL', 'http://{your-url/to-blog}/wp-content/plugins');
$wp_theme_directories = array(__DIR__ . '{/directory-to-themes}');
define('WP_DEFAULT_THEME', '{your-default-theme}');
Remember:
1. Order of lines in wp-config is important
2. Keep themes folder in wp-content (even if it will be empty)

Resources