0

I wrote a filter hook for wp_handle_upload_prefilter to crop and add watermark simultaneously when upload new image to wordpress media. It works in every page that there is wp media upload, but I want to execute this filter hook just in a certain page. (i.e. in Dokan dashboard)

/dashboard/upload_image URL link.

Thank you for helping me...

codes to create new item and page in Dokan dahsboard:

add_filter( 'dokan_query_var_filter', 
'dokan_load_document_menu_add_product' );
function dokan_load_document_menu_add_product($query_vars){
  $query_vars['upload_image'] = 'upload_image';
  return $query_vars;
}

add_filter( 'dokan_get_dashboard_nav', 'dokan_add_new_product_menu' );
function dokan_add_new_product_menu( $urls ) {
$urls['upload_image'] = array(
    'title' => __( 'Upload Image', 'dokan'),
    'icon'  => '<i class="fa fa-user"></i>',
    'url'   => dokan_get_navigation_url( 'upload_image' ),
    'pos'   => 42
);
 return $urls;
}

add_action( 'dokan_load_custom_template', 'dokan_load_template' );
function dokan_load_template( $query_vars ) {
   if ( isset( $query_vars['upload_image'] ) ) {
       include YDE_INC.'upload_image.php';
   }
}

YDE_INC is plugin_dir_path to folder in which upload_image.php exists.

Filter to modify uploading image:

add_filter('wp_handle_upload_prefilter', 'custom_upload_filter' );
function custom_upload_filter( $file ){ 
    ...Codes to crop and watermark the new image for uploading... 
}
Web Design
  • 77
  • 2
  • 19
  • You need to use conditionals. https://codex.wordpress.org/Conditional_Tags – Howard E Jan 20 '22 at 10:45
  • @WebDesign I can't see the `url`/`page` you're referring to! Is `/dashboard/upload_image` a custom page you've created? Can you confirm that the `url` you're referring to actually exists? I can see that there's `dashboard/orders/`, `dashboard/products/`, `dashboard/settings/store/` and `dashboard/settings/payment/`. – Ruvee Jan 20 '22 at 13:23
  • @Ruvee, Yes this is custom page. using `dokan_query_var_filter` , `dokan_get_dashboard_nav` and `dokan_load_custom_template` – Web Design Jan 21 '22 at 06:40
  • can I use `is_single()` condition, i.e. `if( is_single('upload_image') ){...} `? – Web Design Jan 21 '22 at 07:02

0 Answers0