Plugin Directory

Changeset 2242119


Ignore:
Timestamp:
02/10/2020 11:06:00 PM (6 years ago)
Author:
avs2738
Message:

v.1.2 - minor bug fix (error handling)

Location:
wc-remove-bg/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • wc-remove-bg/trunk/admin/class-wc-remove-bg-admin.php

    r2234477 r2242119  
    1010 * @subpackage wc-remove-bg/admin
    1111 */
     12
    1213
    1314/**
     
    101102        global $wpdb;
    102103
    103 
    104104        if(  wp_verify_nonce( sanitize_text_field($_POST['_nonce']), 'update-options' ) && user_can(intval($_POST['schk']), 'edit_pages') ) {
     105         
    105106            $process = sanitize_text_field($_POST['process']);
    106107            $sql     = "SELECT * FROM `" . $wpdb->prefix . "wc_remove_bg`";
    107108            $res     = $wpdb->get_results( $sql );
    108109            if ( $process == 'start_queue' || $process == 'save' ) {
    109                 update_option( 'RemoveBG_ApiKey', sanitize_text_field($_POST['RemoveBG_ApiKey']) );
     110                update_option( 'RemoveBG_ApiKey', sanitize_text_field(trim($_POST['RemoveBG_ApiKey'])) );
    110111                update_option( 'RemoveBG_products', sanitize_text_field($_POST['RemoveBG_products']) );
    111112                update_option( 'RemoveBG_products_IDs', sanitize_text_field($_POST['RemoveBG_products_IDs']) );
     
    522523                    if ( $img_thumbnail == 'yes' ) {
    523524                        set_post_thumbnail( $post_id, $new_img_id );
    524                     } elseif ( $img_gallery == 'yes' ) {
     525                    }
     526                    if ( $img_gallery == 'yes' ) {
    525527                        $galleryIds = get_post_meta( $post_id, '_product_image_gallery' );
    526528                        if ( isset( $galleryIds[0] ) && ! empty( $galleryIds[0] ) ) {
     
    639641            unlink( $tmp_img );
    640642           
    641             if ( is_wp_error( $response ) ) {
     643            if ( $this->isJSON($response['body']) ) {
     644                $errorResponseArray = json_decode($response['body']);
     645                $errorResponseSelected = [];
     646                if(!empty($errorResponseArray->errors)){
     647                    foreach ($errorResponseArray->errors as $error){
     648                        $errorResponseSelected[] = ['title' => $error->title];
     649                    }
     650                }
     651               
    642652                return array(
    643653                    'errors'     => true,
    644654                    'code'       => 400,
    645655                    'img_id'     => $old_img,
    646                     'errors_msg' => $response->get_error_message()
     656                    'errors_msg' => $errorResponseSelected
    647657                );
    648658            }
     
    702712        }
    703713    }
     714   
     715    function isJSON($string) {
     716        return ((is_string($string) && (is_object(json_decode($string)) || is_array(json_decode($string))))) ? true : false;
     717    }
    704718   
    705719    public function Remove_BG_Restore_Backup()
     
    844858    {
    845859        if(  wp_verify_nonce( sanitize_text_field($_POST['_nonce']), 'update-options' ) ) {
    846             update_option( 'RemoveBG_ApiKey', sanitize_text_field($_POST['RemoveBG_ApiKey']) );
     860            update_option( 'RemoveBG_ApiKey', sanitize_text_field(trim($_POST['RemoveBG_ApiKey'])) );
    847861            update_option( 'RemoveBG_Background', sanitize_text_field($_POST['RemoveBG_Background']) );
    848862            update_option( 'RemoveBG_Background_Color', sanitize_text_field($_POST['RemoveBG_Background_Color']) );
  • wc-remove-bg/trunk/admin/js/wc-remove-bg-admin.js

    r2164019 r2242119  
    6767                    if(data.hasErrors == true) {
    6868                        $('.wc_remove_bg').hide();
    69                         $('.wc_remove_bg#status_e').show();
    70                         $('.wc_remove_bg#status_e p').html(data.error_msg+' ('+$('.wc_remove_bg-log').html()+')');
     69                        $('.wc_remove_bg#status_restore_e').show();
     70                        $('.wc_remove_bg#status_restore_e p').html(data.error_msg+' ('+$('.wc_remove_bg-log').html()+')');
    7171                        $("html, body").animate({ scrollTop: 0 }, "slow");
    7272
  • wc-remove-bg/trunk/readme.txt

    r2234496 r2242119  
    101101= 1.1 =
    102102* minor bug fix
     103= 1.2 =
     104* minor bug fix
    103105
    104106== Upgrade Notice ==
  • wc-remove-bg/trunk/wc-remove-bg.php

    r2234509 r2242119  
    77 * Description:       Remove/change background of WooCommerce product images.
    88 * Plugin URI:        http://fresh-d.biz/wocommerce-remove-background.html
    9  * Version:           1.1
     9 * Version:           1.2
    1010 * Author:            Fresh-d
    1111 * Author URI:        https://fresh-d.biz/about-us.html
     
    2727
    2828
    29 define( 'Remove_BG_VERSION', '1.1' );
     29define( 'Remove_BG_VERSION', '1.2' );
    3030
    3131/**
Note: See TracChangeset for help on using the changeset viewer.