formulaire limiter photo upload dokan (Créer un compte)

  • WordPress :6.2
  • Statut : hors support
2 sujets de 1 à 2 (sur un total de 2)
  • Auteur
    Messages
  • #2460676
    kate66
    Participant
    Padawan WordPress
    90 contributions

    Bonjour,

    J’utilise dokan mon serveur se rempli trop vite dut au photo des multi boutiques vendeurs.

    J’ai 3 mois activité est 37500 fichiers déjà crées avec 70 multi boutique et je pense que cela va encore vite monté dans les prochains moins.

    Je suis passé donc a un serveur dédié à la place mutualisé.

    Mais je préfére optimiser aussi mon site.

    Je pense que deja restreindre l’upload de photo par annonce de produit dans les tableaux vendeurs seraient une solution mais je ne vois pas trop comment faire ?

     

    Voici le code trouvé sur la page pour l »upload comment le remplacer pour avoir exemple que max 14 images possible pour chaque produit.

    <?php

    use WeDevs\Dokan\ProductCategory\Helper;

    $created_product = null;
    $feat_image_id = null;
    $regular_price = '';
    $sale_price = '';
    $sale_price_date_from = '';
    $sale_price_date_to = '';
    $post_content = '';
    $post_excerpt = '';
    $product_images = '';
    $post_title = '';
    $terms = [];
    $currency_symbol = get_woocommerce_currency_symbol();

    if ( isset( $_REQUEST['_dokan_add_product_nonce'] ) && wp_verify_nonce( sanitize_key( $_REQUEST['_dokan_add_product_nonce'] ), 'dokan_add_product_nonce' ) ) {
    if ( ! empty( $_REQUEST['created_product'] ) ) {
    $created_product = intval( $_REQUEST['created_product'] );
    }

    if ( ! empty( $_REQUEST['feat_image_id'] ) ) {
    $feat_image_id = intval( $_REQUEST['feat_image_id'] );
    }

    if ( ! empty( $_REQUEST['_regular_price'] ) ) {
    $regular_price = floatval( $_REQUEST['_regular_price'] );
    }

    if ( ! empty( $_REQUEST['_sale_price'] ) ) {
    $sale_price = floatval( $_REQUEST['_sale_price'] );
    }

    if ( ! empty( $_REQUEST['_sale_price_dates_from'] ) ) {
    $sale_price_date_from = sanitize_text_field( wp_unslash( $_REQUEST['_sale_price_dates_from'] ) );
    }

    if ( ! empty( $_REQUEST['_sale_price_dates_to'] ) ) {
    $sale_price_date_to = sanitize_text_field( wp_unslash( $_REQUEST['_sale_price_dates_to'] ) );
    }

    if ( ! empty( $_REQUEST['post_content'] ) ) {
    $post_content = wp_kses_post( wp_unslash( $_REQUEST['post_content'] ) );
    }

    if ( ! empty( $_REQUEST['post_excerpt'] ) ) {
    $post_excerpt = sanitize_textarea_field( wp_unslash( $_REQUEST['post_excerpt'] ) );
    }

    if ( ! empty( $_REQUEST['post_title'] ) ) {
    $post_title = sanitize_text_field( wp_unslash( $_REQUEST['post_title'] ) );
    }

    if ( ! empty( $_REQUEST['product_image_gallery'] ) ) {
    $product_images = sanitize_text_field( wp_unslash( $_REQUEST['product_image_gallery'] ) );
    }

    if ( ! empty( $_REQUEST['product_tag'] ) ) {
    $terms = array_map( 'intval', (array) wp_unslash( $_REQUEST['product_tag'] ) );
    }
    }

    /**
    * Action hook to fire before new product wrap.
    *
    * @since 2.4
    */
    do_action( 'dokan_new_product_wrap_before' );
    ?>

    <?php do_action( 'dokan_dashboard_wrap_start' ); ?>

    <div class="dokan-dashboard-wrap">
    <?php
    /**
    * Action hook to fire before rendering dashboard content.
    *
    * @hooked get_dashboard_side_navigation
    *
    * @since 2.4
    */
    do_action( 'dokan_dashboard_content_before' );

    /**
    * Action hook to fire before rendering product content
    *
    * @since 2.4
    */
    do_action( 'dokan_before_new_product_content_area' );
    ?>


    <div class="dokan-dashboard-content">

    <?php
    /**
    * Action hook to fire inside new product content before
    *
    * @since 2.4
    */
    do_action( 'dokan_before_new_product_inside_content_area' );
    ?>

    <header class="dokan-dashboard-header dokan-clearfix">
    <h1 class="entry-title">
    <?php esc_html_e( 'Add New Product', 'dokan-lite' ); ?>
    </h1>
    </header><!-- .entry-header -->

    <?php do_action( 'dokan_new_product_before_product_area' ); ?>

    <div class="dokan-new-product-area">
    <?php if ( dokan()->dashboard->templates->products->has_errors() ) : ?>
    <div class="dokan-alert dokan-alert-danger">
    <a class="dokan-close" data-dismiss="alert">×</a>

    <?php foreach ( dokan()->dashboard->templates->products->get_errors() as $error_msg ) : ?>
    <strong><?php esc_html_e( 'Error!', 'dokan-lite' ); ?></strong> <?php echo wp_kses_post( $error_msg ); ?>.<br>
    <?php endforeach; ?>
    </div>
    <?php endif; ?>

    <?php if ( ! empty( $created_product ) ) : ?>
    <div class="dokan-alert dokan-alert-success">
    <a class="dokan-close" data-dismiss="alert">×</a>
    <strong><?php esc_html_e( 'Success!', 'dokan-lite' ); ?></strong>
    <?php
    printf(
    /* translators: %s: product title with edit link */
    __( 'You have successfully created %s product', 'dokan-lite' ),
    sprintf(
    '<a href="%s"><strong>%s</strong></a>',
    esc_url( dokan_edit_product_url( $created_product ) ),
    get_the_title( $created_product )
    )
    );
    ?>
    </div>
    <?php endif ?>

    <?php
    if ( apply_filters( 'dokan_can_post', true ) ) :
    $feat_image_url = '';
    $hide_instruction = '';
    $hide_img_wrap = 'dokan-hide';

    if ( ! empty( $feat_image_id ) ) {
    $feat_image_url = wp_get_attachment_url( $image_id );
    $hide_instruction = 'dokan-hide';
    $hide_img_wrap = '';
    }

    if ( dokan_is_seller_enabled( get_current_user_id() ) ) :
    ?>
    <form class="dokan-form-container" method="post">
    <div class="product-edit-container dokan-clearfix">
    <div class="content-half-part featured-image">
    <div class="featured-image">
    <div class="dokan-feat-image-upload">
    <div class="instruction-inside <?php echo esc_attr( $hide_instruction ); ?>">
    <input type="hidden" name="feat_image_id" class="dokan-feat-image-id" value="<?php echo esc_attr( $feat_image_id ); ?>">
    <i class="fas fa-cloud-upload-alt"></i>
    <a href="#" class="dokan-feat-image-btn dokan-btn"><?php esc_html_e( 'Upload Product Image', 'dokan-lite' ); ?></a>
    </div>

    <div class="image-wrap <?php echo esc_attr( $hide_img_wrap ); ?>">
    <a class="close dokan-remove-feat-image">×</a>
    <img src="<?php echo esc_url( $feat_image_url ); ?>" alt="">
    </div>
    </div>
    </div>

    <div class="dokan-product-gallery">
    <div class="dokan-side-body" id="dokan-product-images">
    <div id="product_images_container">
    <ul class="product_images dokan-clearfix">
    <?php
    if ( ! empty( $product_images ) ) :
    $gallery = explode( ',', $product_images );
    if ( $gallery ) :
    foreach ( $gallery as $image_id ) :
    if ( empty( $image_id ) ) :
    continue;
    endif;

    $attachment_image = wp_get_attachment_image_src( $image_id );

    if ( ! $attachment_image ) :
    continue;
    endif;
    ?>
    <li class="image" data-attachment_id="<?php echo esc_attr( $image_id ); ?>">
    <img src="<?php echo esc_url( $attachment_image[0] ); ?>" alt="">
    <a href="#" class="action-delete" title="<?php esc_attr_e( 'Delete image', 'dokan-lite' ); ?>">×</a>
    </li>
    <?php
    endforeach;
    endif;
    endif;
    ?>
    <li class="add-image add-product-images tips" data-title="<?php esc_attr_e( 'Add gallery image', 'dokan-lite' ); ?>">
    <a href="#" class="add-product-images"><i class="fas fa-plus" aria-hidden="true"></i></a>
    </li>
    </ul>
    <input type="hidden" id="product_image_gallery" name="product_image_gallery" value="">
    </div>
    </div>
    </div> <!-- .product-gallery -->
    <?php do_action( 'dokan_product_gallery_image_count' ); ?>
    </div>

     

    merci pour vos conseils.

    Je pensai aussi reduire le nombre de fichier en ne gardant que les photos nécessaires au format d’affichage car si j’ai compris woocommerce duplique les photos en plusieurs format ?

    Si vous avez d’autres conseils.

    #2461511
    kate66
    Participant
    Padawan WordPress
    90 contributions

    j’ai trouvé DES fonction qui restreint les membres qui sont abonnée avec un pack subscription je voudrait que tous les membres ont cette limitation ceux qui on un role vendeur comment l’adapter ? MERCI

     

     


    /**
    * Restrict gallery image count for new product & edit product
    *
    * @return void
    */
    public function restrict_gallery_image_count() {
    $image_count = $this->get_restricted_image_count();
    if ( $image_count == - 1 ) {
    return;
    }
    if ( $image_count >= 0 ) { ?>
    <script type="text/javascript">
    ;(function () {
    var image_count = <?php echo json_encode( $image_count, JSON_HEX_TAG ); ?>;
    var observer = new MutationObserver(function () {
    if (document.querySelector('.attachments-browser ul')) {
    var selected_image = document.querySelectorAll("[aria-checked='true']").length;
    var added_image = document.querySelectorAll("#product_images_container .image").length;
    if(document.querySelector('.media-toolbar button').innerText !== 'Set featured image' ){
    var submit_button=document.querySelector('.media-toolbar button');
    if ((selected_image + added_image) > image_count || selected_image < 1) {
    submit_button.disabled = true;
    } else {
    submit_button.disabled = false;
    }
    }

    if (added_image >= image_count) {
    document.querySelector("#product_images_container .add-image").style.display = 'none';
    } else {
    document.querySelector("#product_images_container .add-image").style.display = '';
    }
    }
    });

    observer.observe(document.body,
    {
    childList: true,
    subtree: true,
    }
    )
    })();
    </script>

    <?php }
    }

    /**
    * Restrict already added gallery image using woocommerce_before_single_product
    *
    * @return void
    */
    public function restrict_added_image_display() {
    global $product, $post;

    $image_count = $this->get_restricted_image_count( $post->post_author );
    if ( $image_count == - 1 ) {
    return;
    }

    $product_gallery_image = $this->count_filter( $product->get_gallery_image_ids(), $image_count );
    $product->set_gallery_image_ids( $product_gallery_image );
    }

    /**
    * Restricted gallery image count for vendor subscription
    *
    * @return int
    */
    public function get_restricted_image_count( $vendor_id = null ) {
    $vendor_id = ! empty( $vendor_id ) ? $vendor_id : dokan_get_current_user_id();
    $vendor = dokan()->vendor->get( $vendor_id )->subscription;

    if ( $vendor && $vendor->is_gallery_image_upload_restricted() ) {
    return $vendor->gallery_image_upload_count();
    }

    return -1;
    }

    /**
    * Restrict gallery image when creating product
    *
    * @param '' $errors
    * @param array $data
    *
    * @return string
    */
    public function restrict_gallery_image_on_product_create( $errors, $data ) {
    $gallery_image = ! empty( $data['product_image_gallery'] ) ? array_filter( explode( ',', wc_clean( $data['product_image_gallery'] ) ) ) : [];
    $image_count = $this->get_restricted_image_count();
    if ( $image_count == - 1 ) {
    return;
    }
    if ( count( $gallery_image ) > $image_count ) {
    $errors = new \WP_Error( 'not-allowed', __( sprintf( 'You are not allowed to add more than %s gallery images', $image_count ), 'dokan' ) );

    return $errors;
    }

    }


    /**
    * Restrict gallery image when editing product
    *
    * @param $postdata
    *
    * @return array
    */
    public function restrict_gallery_image_on_product_edit( $postdata ) {
    $gallery_image = ! empty( $postdata['product_image_gallery'] ) ? array_filter( explode( ',', wc_clean( $postdata['product_image_gallery'] ) ) ) : [];
    $image_count = $this->get_restricted_image_count();
    if ( $image_count == - 1 ) {
    return;
    }
    $postdata['product_image_gallery'] = implode( ',', $this->count_filter( $gallery_image, $image_count ) );

    return $postdata;
    }

     

    j’ai commencé ceci :

    add_action( 'init', 'restrict_gallery_image_count_vendor_all' );
    function restrict_gallery_image_count_vendor_all() {

    // Getting user data for logged users
    if( is_user_logged_in() ){
    $current_user = wp_get_current_user();
    $current_user_id = $current_user->ID;
    $current_user_roles = $current_user->roles;
    // $bilal_id = 0;
    }

    // Exempting of VAT non logged users, customers and the main admin ID (you)
    if( ! is_user_logged_in() || in_array( 'vendor','customer', $current_user_roles ) ){
    //WC()->customer->set_is_vat_exempt(true);

    }
    }

    • Cette réponse a été modifiée le il y a 8 mois et 1 semaine par kate66.
2 sujets de 1 à 2 (sur un total de 2)
  • Vous devez être connecté pour répondre à ce sujet.