Only apply function on certain page

WCMp Advanced Frontend Manager

Resolved
Viewing 14 reply threads
  • Author
    Posts
    • #138148
      Tim Kerremans
      Participant

      Hi there, so I’m storing my media files in a S3 bucket and have a function that stores certain media files under a different subfolder in my bucket as you can see below:

      add_filter( ‘as3cf_object_meta’, array( $this, ‘object_meta’ ), 10, 4 );

      function object_meta( $args, $post_id, $image_size, $copy ) {
      $extension = pathinfo( $args[‘Key’], PATHINFO_EXTENSION );

      // Example places (potentially large) movie files in a different bucket than configured.
      // Also changes path prefix to match that used in CDN behavior’s “Path Prefix” for this second origin.

      if ( in_array( $extension, array( ‘pdf’, ‘csv’ ) ) ) {
      // Change bucket.
      $args[‘Bucket’] = ‘media.holymowly.com’;

      // Change key (don’t do this for images, thumbnails will not get new prefix and will not be usable).
      $filename = pathinfo( $args[‘Key’], PATHINFO_FILENAME ) . ‘.’ . $extension;
      $args[‘Key’] = ‘other/’ . $filename;
      }

      // Example sets “Content-Disposition” header to “attachment” so that browsers download rather than play audio files.
      /*
      if ( in_array( $extension, array( ‘mp3’, ‘wav’ ) ) ) {
      // Note, S3 format trims “-” from header names.
      $args[‘ContentDisposition’] = ‘attachment’;
      }*/

      return $args;
      }

      Apart from checking if the media is from a certain type I also need to check for the current page as I only want the product images that are uploaded by the vendors to be placed in a different subfolder. Unfortunately I haven’t been able to do so, this is what I currently have:

      add_filter( ‘as3cf_object_meta’, array( $this, ‘object_meta’ ), 10, 4 );

      function object_meta( $args, $post_id, $image_size, $copy ) {
      if ( is_page_template( ‘dc-woocommerce-multi-vendor/templates/vendor-dashboard/product-manager/edit-product.php’ ) ) {

      $extension = pathinfo( $args[‘Key’], PATHINFO_EXTENSION );

      // Example places (potentially large) movie files in a different bucket than configured.
      // Also changes path prefix to match that used in CDN behavior’s “Path Prefix” for this second origin.

      if ( in_array( $extension, array( ‘pdf’, ‘csv’ ) ) ) {
      // Change bucket.
      $args[‘Bucket’] = ‘media.holymowly.com’;

      // Change key (don’t do this for images, thumbnails will not get new prefix and will not be usable).
      $filename = pathinfo( $args[‘Key’], PATHINFO_FILENAME ) . ‘.’ . $extension;
      $args[‘Key’] = ‘other/’ . $filename;
      }

      // Example sets “Content-Disposition” header to “attachment” so that browsers download rather than play audio files.
      /*
      if ( in_array( $extension, array( ‘mp3’, ‘wav’ ) ) ) {
      // Note, S3 format trims “-” from header names.
      $args[‘ContentDisposition’] = ‘attachment’;
      }*/

      return $args;
      }
      }

      Can you provide me with the correct code to also check if current page is: http://www.mydomain.com/dashboard/edit-product/**PRODUCT-ID**

    • #138207

      Hi,
      You can use below code to check current page edit product page.

      global $WCMp;
      $current_endpoint_key = $WCMp->endpoints->get_current_endpoint();
      // retrive the actual endpoint name in case admn changes that from settings
      $current_endpoint = get_wcmp_vendor_settings( 'wcmp_' . str_replace( '-', '_', $current_endpoint_key ) . '_endpoint', 'vendor', 'general', $current_endpoint_key );
      // retrive edit-product endpoint name in case admn changes that from settings
      $edit_product_endpoint = get_wcmp_vendor_settings( 'wcmp_edit_product_endpoint', 'vendor', 'general', 'edit-product' );
      //Return if not edit product endpoint
      if ( $current_endpoint == $edit_product_endpoint ) {
      
          // your custom code
      
      }
      Copy

      regards,

    • #138210
      Tim Kerremans
      Participant

      Hi,

      Thanks for this, how would this merge with the code I provided? Just tried combining them but now function seems to be ignored, all content is now uploading to the same bucket

    • #138232

      HI,
      Kindly share your code.

      Regards,

    • #138233
      Tim Kerremans
      Participant

      add_filter( ‘as3cf_object_meta’, array( $this, ‘object_meta’ ), 10, 4 );

      function object_meta( $args, $post_id, $image_size, $copy ) {
      $extension = pathinfo( $args[‘Key’], PATHINFO_EXTENSION );

      // Example places (potentially large) movie files in a different bucket than configured.
      // Also changes path prefix to match that used in CDN behavior’s “Path Prefix” for this second origin.

      if ( in_array( $extension, array( ‘pdf’, ‘csv’ ) ) ) {
      // Change bucket.
      $args[‘Bucket’] = ‘media.holymowly.com’;

      // Change key (don’t do this for images, thumbnails will not get new prefix and will not be usable).
      $filename = pathinfo( $args[‘Key’], PATHINFO_FILENAME ) . ‘.’ . $extension;
      $args[‘Key’] = ‘files/’ . $filename;
      }

      // Example sets “Content-Disposition” header to “attachment” so that browsers download rather than play audio files.
      /*
      if ( in_array( $extension, array( ‘mp3’, ‘wav’ ) ) ) {
      // Note, S3 format trims “-” from header names.
      $args[‘ContentDisposition’] = ‘attachment’;
      }*/

    • #138263

      HI,
      kindly add below code and check.

      add_filter( 'as3cf_object_meta', array( $this, 'object_meta' ), 10, 4 );
      
      	function object_meta( $args, $post_id, $image_size, $copy ) {
      		global $WCMp;
      		$current_endpoint_key = $WCMp->endpoints->get_current_endpoint();
      		// retrive the actual endpoint name in case admn changes that from settings
      		$current_endpoint = get_wcmp_vendor_settings( 'wcmp_' . str_replace( '-', '_', $current_endpoint_key ) . '_endpoint', 'vendor', 'general', $current_endpoint_key );
      		// retrive edit-product endpoint name in case admn changes that from settings
      		$edit_product_endpoint = get_wcmp_vendor_settings( 'wcmp_edit_product_endpoint', 'vendor', 'general', 'edit-product' );
      		//Return if not edit product endpoint
      		if ( $current_endpoint == $edit_product_endpoint ) {
      
      		   $extension = pathinfo( $args['Key'], PATHINFO_EXTENSION );
      
      			// Example places (potentially large) movie files in a different bucket than configured.
      			// Also changes path prefix to match that used in CDN behavior's "Path Prefix" for this second origin.
      			
      			if ( in_array( $extension, array( 'pdf', 'csv' ) ) ) {
      				// Change bucket.
      				$args['Bucket'] = 'media.holymowly.com';
      
      				// Change key (don't do this for images, thumbnails will not get new prefix and will not be usable).
      				$filename    = pathinfo( $args['Key'], PATHINFO_FILENAME ) . '.' . $extension;
      				$args['Key'] = 'files/' . $filename;
      			}
      			
      
      			// Example sets "Content-Disposition" header to "attachment" so that browsers download rather than play audio files.
      			/*
      			if ( in_array( $extension, array( 'mp3', 'wav' ) ) ) {
      				// Note, S3 format trims "-" from header names.
      				$args['ContentDisposition'] = 'attachment';
      			}*/
      
      		}
      	}
      Copy
    • #138268
      Tim Kerremans
      Participant

      Hi,

      I forgot to return $args in the function I shared so I have added it to below code but it still is not working.. The files are not placed in a seperate subfolder, all files go to the same location while CSV and PDF files should go to different folder.

      add_filter( ‘as3cf_object_meta’, array( $this, ‘object_meta’ ), 10, 4 );

      function object_meta( $args, $post_id, $image_size, $copy ) {
      global $WCMp;
      $current_endpoint_key = $WCMp->endpoints->get_current_endpoint();
      // retrive the actual endpoint name in case admn changes that from settings
      $current_endpoint = get_wcmp_vendor_settings( ‘wcmp_’ . str_replace( ‘-‘, ‘_’, $current_endpoint_key ) . ‘_endpoint’, ‘vendor’, ‘general’, $current_endpoint_key );
      // retrive edit-product endpoint name in case admn changes that from settings
      $edit_product_endpoint = get_wcmp_vendor_settings( ‘wcmp_edit_product_endpoint’, ‘vendor’, ‘general’, ‘edit-product’ );
      //Return if not edit product endpoint
      if ( $current_endpoint == $edit_product_endpoint ) {

      $extension = pathinfo( $args[‘Key’], PATHINFO_EXTENSION );

      // Example places (potentially large) movie files in a different bucket than configured.
      // Also changes path prefix to match that used in CDN behavior’s “Path Prefix” for this second origin.

      if ( in_array( $extension, array( ‘pdf’, ‘csv’ ) ) ) {
      // Change bucket.
      $args[‘Bucket’] = ‘media.holymowly.com’;

      // Change key (don’t do this for images, thumbnails will not get new prefix and will not be usable).
      $filename = pathinfo( $args[‘Key’], PATHINFO_FILENAME ) . ‘.’ . $extension;
      $args[‘Key’] = ‘files/’ . $filename;
      }

      // Example sets “Content-Disposition” header to “attachment” so that browsers download rather than play audio files.
      /*
      if ( in_array( $extension, array( ‘mp3’, ‘wav’ ) ) ) {
      // Note, S3 format trims “-” from header names.
      $args[‘ContentDisposition’] = ‘attachment’;
      }*/

      return $args;

      }
      }

    • #138285

      Hi,
      seems like you added your custom code by using other plugins hook, so, it’s batter to ask the plugin author. They will help you.

      Let me know if you need any WCMp related question.

      Regards,

    • #138286
      Tim Kerremans
      Participant

      They are not helping me.
      They are telling me I need to reach out to you as this is a page that is created by your plugin and therefore I need the correct filter to check for this page

    • #138312

      Kindly ask the plugin author to give a working code snippet that lets the admin place the files in a separate folder.

      We will try to modify that code for the vendor dashboard.

    • #138313
      Tim Kerremans
      Participant

      I already gave you a working code snippet in my first message.

      add_filter( ‘as3cf_object_meta’, array( $this, ‘object_meta’ ), 10, 4 );

      function object_meta( $args, $post_id, $image_size, $copy ) {
      $extension = pathinfo( $args[‘Key’], PATHINFO_EXTENSION );

      // Example places (potentially large) movie files in a different bucket than configured.
      // Also changes path prefix to match that used in CDN behavior’s “Path Prefix” for this second origin.

      if ( in_array( $extension, array( ‘pdf’, ‘csv’ ) ) ) {
      // Change bucket.
      $args[‘Bucket’] = ‘media.holymowly.com’;

      // Change key (don’t do this for images, thumbnails will not get new prefix and will not be usable).
      $filename = pathinfo( $args[‘Key’], PATHINFO_FILENAME ) . ‘.’ . $extension;
      $args[‘Key’] = ‘other/’ . $filename;
      }

      // Example sets “Content-Disposition” header to “attachment” so that browsers download rather than play audio files.
      /*
      if ( in_array( $extension, array( ‘mp3’, ‘wav’ ) ) ) {
      // Note, S3 format trims “-” from header names.
      $args[‘ContentDisposition’] = ‘attachment’;
      }*/

      return $args;
      }

    • #138330

      Hi,
      WCMp check current page is edit product page using above code, I shared in https://multivendorx.com/support-forum/topic/only-apply-function-on-certain-page/#post-138207

      regards,

    • #138332
      Tim Kerremans
      Participant

      Are you even reading my questions? It is not working, like I already said

    • #140030

      @Tim Kerremans, as this is third party compatibility, hence we can assist you as far as our hook filter and coding procedure.

      Why your code is not working requires further debugging and checking third-party code. I would recommend you to contact your developer or you may hire our service team. They can develop this compatibility for your site. You can contact them via this link : https://multivendorx.com/custom-development/

    • #144912

      Hi @Tim, we haven’t heard back from you for a while.
      So we presume this issue has been fixed. We are closing this for now.

Viewing 14 reply threads

The topic ‘Only apply function on certain page’ is closed to new replies.