I have a wordpress multisite + domain mapping with one main and two child website. I have setup threewp broadcast to share products to childsites.
Everything works so far but when displaying products on the childsite the image path is the mainsite with a 403 (Forbidden) I have used the below code in my themes function.php to make the main and the child sites share uploads paths. Is that the best way to do it? I'm trying to get all the child site product image paths to be the same as childsite domain. Does anyone know how to fix this?
// Define a single common image directory for your Multisite
add_filter('upload_dir', 'mu_media_upload_dir');
function mu_media_upload_dir($upload) {
global $user_ID;
if ((int)$user_ID > 0) {
$upload['path'] = ABSPATH . 'uploads/images';
switch_to_blog(1);
$upload['url'] = site_url() . '/' . 'uploads/images';
restore_current_blog();
$upload['subdir'] = "";
$upload['basedir'] = $upload['path'];
$upload['baseurl'] = $upload['url'];
}
return $upload;
}
https://wordpress.org/plugins/threewp-broadcast/
Related
I actually create an extranet space on my website, with pages where you must to be logged-in to see the content.
My problem is about media uploads.
I want to make them private for a specific custom post type, and upload them in a sub directory (uploads/private).
I use the upload_dir filter (add_filter('upload_dir', 'extranet_upload_directory');) with success for thumbnail for exemple, but when I upload an image in the content with a gutenberg block, this one is upload in the initial foldier (uploads), not in uploads/private.
Does anyone have an idea where to look at ?
My code below :
add_filter('upload_dir', 'extranet_upload_directory');
function extranet_upload_directory( $param ){
$id = $_REQUEST['post_id'];
if ( ( get_post_type( $id ) == 'test-extranet' ) ) {
$param['subdir'] = '/private' . $param['subdir'];
$param['path'] = $param['basedir'] . $param['subdir'];
$param['url'] = $param['baseurl'] . $param['subdir'];
}
return $param;
}
This may be a bug... I have a plugin that offers the same functionality as yours and noticed the following:
While creating a post of that new custom post type (e.g. PATHTOsite.fr/wp-admin/post-new.php?post_type=post_type_name):
When I immediately press upload after opening an new image block the uploaded image goes to default directory, uploads.
but, if I first press 'media library' after opening an new image block and then go to the upload button there and upload the image there, the image will be uploaded in the modified uploads directory.
I'm working on a WordPress site in which the services page is one long page with anchors for each section.
www.mysite.com/services/#human-resources jumps to the Human Resources section as expected.
Is there any way in the .htaccess file to make a url such as www.mysite.com/services/human-resources/ jump directly to the anchor?
I've tried several different rewrite rules, the closest I've gotten is:
RewriteRule services/human-resources services/#human-resources [NE,L,R=301]
But this shows the # in the url which defeats the purpose. Removing the R=301 just causes it to do nothing.
Thanks.
I have been working on a similar site and this is how I solved that issue.
First add this action to functions.php, witch redirects the user to the proper anchor on the page.
function url_handler(){
$path = substr($_SERVER['REQUEST_URI'], 1); //get the path minus the '/'
if( is_page() || is_404() ){ // do you own conditional tags
wp_redirect( home_url("#" . $path) ); //redirect to the #anchor
exit();
}
}
add_action( 'template_redirect', 'url_handler' );
Next you need to make a javascirpt handler witch gets the url of the page (the url with the anchor) and make the proper event to scroll to that section. Something like this:
var hash = window.location.hash;
hash = hash.replace('#','');
hash = hash.replace('/','');
/* do stuff here */
Hope this helps
I'm working with WordPress.
I have two different menu.
If the user log in, the menu change.
So the first one is just for users that aren't connected.
Do you know a solution to do that ?
Have I to change some PHP files ?
EDIT
QUESTION
On my website I have a Back-Office. On the BO there is menu-2.
How could I put menu-2 only on the Back-Office ? And have the other menu (menu-1) on the original website ?
You need function is_user_logged_in() .
Shortest path to solve your problem is creating two different menus, one for logged in users and another for "guests".
Go to Appearance » Menus, create two menus logged-in and logged-out.
After creating the menus, add this code in your theme’s functions.php file or a site-specific plugin:
function my_wp_nav_menu_args( $args = '' ) {
if( is_user_logged_in() ) {
$args['menu'] = 'logged-in';
} else {
$args['menu'] = 'logged-out';
}
return $args;
}
add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );
Reference:
1.https://developer.wordpress.org/reference/functions/is_user_logged_in/
I'm beginner in drupal. I would like to fetch images from specific folder in drupal. Is there any way to fetch drupal images directly from any specific in custom theme.
You should use only images from your theme. And you can get path to your theme like this:
$theme = drupal_get_path('theme',$GLOBALS['theme']);
Put that i.e. at top of template file that uses theme images. And then inside your theme templates you can have something like:
<img src="/<?php echo $theme; ?>/images/my_image.png">
If you stored you theme images inside images dir...
If an array of image paths on your local filesystem is what you want - use this code, it should do what you need. gets all the png jpg gif paths within the sites/default/files/vegas directory.
//We will use the stream wrapper to access your files directory
if ($wrapper = file_stream_wrapper_get_instance_by_uri('public://')) {
//Now we can easily get an actual path to that folder
$directory = $wrapper->realpath();
//Don't forget to append your "vegas" subfolder here
$directory .= DIRECTORY_SEPARATOR . 'vegas' . DIRECTORY_SEPARATOR;
$images = glob($directory . "*.{jpg,png,gif}", GLOB_BRACE);
foreach($images as $imagePath)
{
//Do your thing!
echo $imagePath;
}
}
I am using Wp Store Locator plugin.And I have Modified it according my need.But I am stuck in redirection.
Basically this plugin works with short code.So at the time of listing my URL is like that : localhost/wordpress/?page_id=391
Now there is one link which is redirects me to http://localhost/wordpress/?wpsl_id=3
Here is code for that :
add_action("template_redirect", 'my_theme_redirect');
function my_theme_redirect() {
$dpath = $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] ;
$templatefilename = 'single-store.php';
if (strpos($dpath,'wpsl_id') !== false){
$return_template = get_template_directory() .'/' .$templatefilename ;
//$nurl = get_permalink($return_template);
//echo $return_template; exit;
wp_redirect($return_template);
exit;
}
}
This code is not redirecting me to any-where.It stays on the same page localhost/wordpress/?page_id=391 What might be the issue?
Anyone can suggest me how can I direct to URL when it detects wpsl_id in the URL ? I want to redirect them to plugin's template folder where I have added a file for that.
EDITED :
I have added above code in the plugin file just above the short code. Hope I has nothing to do with this issue :)
The template name looks fine. You just need to register the template before you call it.
Add this filter so this will execute before your action:
add_filter( 'template_include', 'single-store' );