WordPress in subdirectory has wrong upload_dir - wordpress

I have a WP installation in the root-folder, and some other WP installations in sub-directories
example.com => has WP-installation in root folder
example.com/project1 => folder named "project1" resides in root and has own WP-installation
everything works fine, except uploads.
Let's say, I'm in example.com/project1/wp-admin and want to upload a file:
Expected behaviour:
file is uploaded to /project1/wp-content/uploads
DB-entry is created in project1-database
Actual behaviour:
file is uploaded to /wp-content/uploads (root-folder)
DB-entry is created in project1-database
I've tried changing upload_dir, resulting into the same behaviour:
define('UPLOADS', 'project1/wp-content/uploads');
I also tried changing the wp_content_dir:
define( 'WP_CONTENT_DIR', dirname(__FILE__).'/project1/wp-content' );
But this gives me an error, like "Can't upload to /project1/wp-content/uploads/2018/09'.
What am I doing wrong here?

Ok, got it fixed now:
I was on the right path with:
define( 'WP_CONTENT_DIR', dirname(__FILE__).'/project1/wp-content' );
The error that I got, was because I created the folder for the mounth by hand as root, and therefore the permissions were wrong.

Related

Get WordPress plugin directory URI

I want to include a WooCommerce file while running a plugin. Here is the code I am using,
include_once(include( content_url() .'/plugins/woocommerce/includes/wc-core-functions.php'));
This gives me below error,
include(): http:// wrapper is disabled in the server configuration by allow_url_include=0 in /nas/content/staging/squatwolf/wp-content/plugins/wpfront-notification-bar/classes/class-wpfront-notification-bar.php on line 58
I understand its being caused because the content_url function is giving complete url instead of relative url. I also tried,
plugin_dir_url(__FILE__)
but it gives the url of the plugin I am in, not the wordpress plugin directory url.
you want like this : /home/user/var/www/wordpress/wp-content/plugins/?
try $dir = plugin_dir_path( __DIR__ );

Create Drupal 8 Multisite on localhost

I want to create a multisite Drupal 8 site. I would like to keep the default site, and then add another site. This is all being done on a WAMP stack and is on a locahost. These are the steps I have taken, but have not worked:
Downloaded most recent Drupal 8 and unzipped (and moved files) to www/my_primary_site
I created two databases in MySQL: site1, site2
in the www/my_primary_site/sites folder, I did the following:
a. Created a folder called "my_second_site"
b. Created a file called sites.php.
c. In sites.php, I have this code:
$sites = array(
'8080.localhost.my_primary_site' => 'default',
'8080.localhost.my_primary_site/my_second_site' => 'my_second_site',
);
I then go to localhost/my_primary_site. This brings me to the Drupal install (localhost/my_primary_site/core/install.php). But, if I go to localhost/my_primary_site/my_second_site, it just redirects me back to localhost/my_primary_site/core/install.php.
I would expect that the second link would take me to a different install path. Is this correct? If not, how would I fix this?
thanks
jason
Make sure to copy the default settings.php and services.yml to the new folder.
Try using the format of using . instead of /' like this:
$sites = array(
'8080.localhost.my_primary_site' => 'default',
'8080.localhost.my_primary_site.my_second_site' => 'my_second_site',
);
Make a symbolic link in your root directory that points to the main Drupal folder.
ln -s /drupal /my_primary_site/my_second_site
Try using this:
$sites['site1.localhost'] = 'site1';
$sites['site2.localhost'] = 'site2';
Also, make sure you add this domain to your etc/hosts file:
127.0.0.1 site1.localhost
127.0.0.1 site2.localhost
There are two approaches :
Try using sysmlinks functions in file myfile.php
2.Using sites.php in /drupal/sites folder
$sites['site1'] = 'site1';
$sites['site2'] = 'site2';

Unable to access analytics.txt once uploaded, returns 404

I've been asked to add an analytics.txt file to a wordpress website so I've created the file and uploaded it to the server document root but when I go to it via the url www.examples.com/analytics.txt all I get is a 404 error.
I've checked the file permissions and I've cleared the wordpress cache but neither have helped.
Any ideas?
The folder structure is as follows:
wp-admin
wp-content
wp-includes
analytics.txt <-- added this file, but cannot seem to access it via a web browser
index.php
etc...
This is NOT the solution but it is a work-around while I carry on trying to figure out why wordpress won't allow me to access my file.
So if you're desperate and HAVE to get it sorted right now, here is what you could do, but I warn you, it's ugly! Open your index.php file and you should see something like this:
<?php
define('WP_USE_THEMES', true);
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
?>
Make a backup copy first and then add the wrapping if statement:
<?php
if ($_SERVER[REQUEST_URI] == '/analytics.txt') {
die('Put the text that you were instructed to put into your analytics.txt file in here');
} else {
define('WP_USE_THEMES', true);
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
}
?>
Like I said, this is a dirty solution but when needs must and the client is getting impatient, this could help in the mean time.
Hoping that someone will have a better solution though!
I was able to get this to work with the following for the Sage theme:
Upload the analytics.txt through the theme administration panel
Copy the url of the upload and remove the hostname. For me it looked like this: app/uploads/2018/09/analytics.txt
Open the functions.php file and add the following:
function analytics_txt_rewrite(){
add_rewrite_rule('^analytics\.txt$','<route to your analytics.txt file>','top');
}
add_action('init','analytics_txt_rewrite');
Flush and regenerate the rewrite rules database: From WordPress Administration Screens, Select Settings -> Permalinks and just click Save Changes without any changes.

How do i locate wordpress plugin directory?

I am trying to add a function from plugin 1(wp job manager) to plugin 2(woocommerce).
I have decided to do this by including the php file from plugin 1, however I am unable to locate the file directory. I have used:
include( plugin_dir_path( __FILE__ ) . 'wp-job-manager/includes/class-wp-job-manager-applications.php');
but it returns the following error:
Warning:
include(/home/content/p3pnexwpnas05_data02/78/2394078/html/wp-content/themes/listify-child/wp-job-manager/includes/class-wp-job-manager-applications.php): failed to open stream: No such file or directory in
/home/content/p3pnexwpnas05_data02/78/2394078/html/wp-content/themes/listify-child/functions.php
on line 77
Please advise me as I've been stuck on this issue for really long... Thanks!!!
Wordpress setups have a constant ABSPATH defined (look at the bottom lines of wp_config.php) which points to the full and absolute path of the Wordpress setup, so in your case echo ABSPATH; would return /home/content/p3pnexwpnas05_data02/78/2394078/html/.
For most installations, appending wp-content/plugins/ to that string would point you to your plugins directory.
However, in a Wordpress configuration one can also customize the wp-content and or plugins directory to their own preference, so building plugins on ABSPATH.'wp-content/plugins/ is not recommended. Unfortunately Wordpress simply doesn't have a get_absolute_pluginspath() function or something available. A trick would be to fetch the plugins-URL, and remove the site-URL from it, so the remaining data is wp-content/plugins/ (or whatever the user has made of it). In code:
$plugins_directory = ABSPATH.str_replace(site_url()."/","",plugins_url())."/";
Which in your case would return:
/home/content/p3pnexwpnas05_data02/78/2394078/html/wp-content/plugins/
You probably mean:
plugin_dir_path(__FILE__)
That gives you the directory path to the file that statement is in. So what that returns depends on where you run it. If you use this statement
include( plugin_dir_path(__FILE__) . 'wp-job-manager/includes/class-wp-job-manager-applications.php');
in the main plugin file for wp_job_manager (probably wp_job_manager.php), then plugin_dir_path(__FILE__) give the path of the directory that file is in (the plugin directory).
If you use it in some other file, you will need to adjust the rest of the path string accordingly.

Drupal: The selected file intersection.png could not be uploaded

I don't understand why I get this error when I upload images...
The selected file intersection.png could not be uploaded. The file is not a known image format.
It is just a png file, and the problem came when I moved the website on the server. On localhost everything was perfect.
1) I've deleted the "files" folder and created it again with a php script (to make the server the owner)
2) drupal automatically creates 2 folders into it (imagecache and temp) so I assume it has the privilegies to write into it.
3) I've changed the temporary folder in Settings > Filesystem from "/tmp" to "temp", since I got an error before (probably the /tmp folder on the server is not writable by drupal
thanks
http://drupal.org/project/transliteration I think this module help me in my problem related this issue.
There's a known problem with Drupal 6.15 and IIS (see http://drupal.org/node/419734). If you're on 6.15, try backing down to 6.14 until a fix is completed.
I solved it. The rewrite module is not enabled on my IIS server, so I had to change a line of code inside the imagecache.module to add "index.php?q=
return url($GLOBALS['base_url'] . '/index.php?q=' . file_directory_path() .'/imagecache/'. $presetname .'/'. $path, $args);

Resources