Modify uploads directory for gutenberg block - wordpress

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.

Related

How to change the WordPress Upload directory, if file is uploaded from specific front end page

I am using the Profile Builder Pro Plugin to let users upload files to Wordpress. So the files get uploaded to the standard Wordpress upload folder.
However I need to change the upload directory to a subfolder of the uploads folder, but only if the files are uploaded from a certain front end page.
Is there a way I can do this?
Here is the example I use when uploading my custom avatars. Basically you need to add a filter when wp_handle_upload is executed and remove it afterwards, you will also need to add your conditions and generally complete the code to handle posted files, attach them to user or post etc.
//UPLOAD FOLDER FILTER FOR AVATAR
function avatar_upload_dir( $dirs ) {
$dirs['subdir'] = '/avatars';
$dirs['path'] = $dirs['basedir'] . '/avatars';
$dirs['url'] = $dirs['baseurl'] . '/avatars';
return $dirs;
}
//SOME CUSTOM UPLOAD FUNCTION
function somefunction() {
//some code here
add_filter( 'upload_dir', 'avatar_upload_dir' );
$uploaded_file = wp_handle_upload( $data['file'], array( 'test_form' => false ) );
remove_filter( 'upload_dir', 'avatar_upload_dir' );
//some code here
}
You can create new folder media in wordpress directory, then edit the wp-config.php file and this line before
define('UPLOADS', 'media');
/*Thats all, stop editing!, Happy blogging*/
For more detail check this link

Reset company logo for all job listings in wp job manager

I did import all of my job listings from one site to another, and I have problem with company logo image url, what I'm trying to do is to reset company logo for all job listings, so set it using a filter, or find a way to import the images correctly.
/* This code will set the default company logo, but if there is already existing logo it will not work*/
add_filter( 'job_manager_default_company_logo', 'smyles_custom_job_manager_logo' );
function smyles_custom_job_manager_logo( $logo_url ){
// Change the value below to match the filename of the custom logo you want to use
// Place the file in a /images/ directory in your child theme's root directory.
// The example provided assumes "/images/custom_logo.png" exists in your child theme
$filename = 'logo_clear.png';
$logo_url = get_stylesheet_directory_uri() . '/img/' . $filename;
return $logo_url;
}

Get setting form wordpress customizer and display in a url

How can I create a custom url like this :
www.my-wordpress-blog.com/?layout=fullwidth
www.my-wordpress-blog.com/?layout=grid
www.my-wordpress-blog.com/?layout=list
See Example what excepted as output,
http://themes.themegoods2.com/letsblog/?layout=fullwidth
http://gleedthemes.com/themes/elora/?layout=2
I tried looking on Google, but no "how to" tutorials show up for anything like this.
How create custom URL
Step:1 Login to admin panel and go to "Appreance->Menu"
Step:2 Use the Custom Links panel to add a custom link to your menu, such as a link to an external website.
Step:3 Simply type in the website URL in the URL field and the menu name in the Link Text field.
Step:4 Click the Add to Menu button when done. Use the same steps outlined previously to adjust the order of the menu item and click the Save Menu button at the top or bottom of the screen to save your changes.
Please refer following for more information,
http://www.templatemonster.com/help/wordpress-add-custom-link-menu.html#gref
How To set Layout page
Add page from page menu
Select a Right side Page attribute select a template from there.
publish page and visit a menu from front side.
Final Solution Suggested By [Sociopath]
Path : wp-content/themes/yourtheme/functions.php
add this code at the end of file.
if( ! function_exists( 'themename_demo_set_the_header_layout' ) ){
/**
* Set the demo header layout from child theme.
* #param unknown_type $header
* #return Ambigous <NULL, string>
*/
function themename_demo_set_the_header_layout( $header = 'layout1' ) {
$header = isset( $_GET['header'] ) ? trim( $_GET['header'] ) : null;
// Add more checking conditions here.
return $header;
}
add_filter( 'themename_set_my_header_layout', 'themename_demo_set_the_header_layout', 10, 1 );
}

Set default image for woocommerce products

In my project I have many products whose image is not available till now. So I want to show custom image for those products who don't have image.
Is there a way to set default image for products (in case if product don't have image).
I solved it by adding following code in functions.php file
add_action( 'init', 'custom_fix_thumbnail' );
function custom_fix_thumbnail() {
add_filter('woocommerce_placeholder_img_src', 'custom_woocommerce_placeholder_img_src');
function custom_woocommerce_placeholder_img_src( $src ) {
$upload_dir = wp_upload_dir();
$uploads = untrailingslashit( $upload_dir['baseurl'] );
$src = $uploads . '/2012/07/thumb1.jpg';
return $src;
}
}
NOTE : Do not type complete url of image. Instead of complete url, use only short url as shown in code.
Original Post
TLDR;
You need to upload an image via default Wordpress Media uploader, then copy its URL (or just ID) and paste it to "WooCommerce->Settings->Products->Placeholder image"
Found an answer here: https://www.iqcomputing.com/support/articles/changing-the-woocommerce-default-image/

Fetch image from specific directory in drupal

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;
}
}

Resources