Plugin Directory

Changeset 2918522


Ignore:
Timestamp:
05/29/2023 10:31:14 AM (3 years ago)
Author:
mailbluster
Message:

fail silently if API is down

Location:
mailbluster4wp
Files:
48 added
6 edited

Legend:

Unmodified
Added
Removed
  • mailbluster4wp/trunk/README.txt

    r2836555 r2918522  
    66Tested up to: 6.1.1
    77Requires PHP: 5.6
    8 Stable tag: 1.2.0.1
     8Stable tag: 1.2.1
    99License: GPLv2 or later
    1010License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    7373
    7474== Changelog ==
     75
     76=1.2.1=
     77* fix: Fail silently if can not communicate with api server.
     78* WP version 6.2.2 compatible.
    7579
    7680= 1.2.0.1 =
  • mailbluster4wp/trunk/admin/partials/form-options/builder.php

    r2835808 r2918522  
    77$form_input_field = get_post_meta($post_id, 'mb4wp_form_builder_options', true);
    88$form_input_field = isset($form_input_field) && !empty($form_input_field) ? $form_input_field : 'email';
    9 $custom_field = MailBluster4WP_Helper::get_custom_field();
     9$custom_field;
     10
     11$response = MailBluster4WP_Helper::get_custom_field_response();
     12$custom_field = json_decode($response['body']);
    1013$newArr = [];
    1114if(isset($custom_field->fields)){
     
    159162                $url_data         = parse_url( $url );
    160163                $url_data['host'] = explode( '.', $url_data['host'] );
    161                 // unset( $url_data['host'][0] );
    162164               
    163165                $urlWithoutSsl = join( '.', $url_data['host'] );
    164                 // echo $urlWithoutSsl;
    165166                ?>
    166167                <div id="mb4wp_builder_form_branding" class="mb4wp-form-branding" style="display: <?php echo (isset($show_branding) && ($show_branding == 'yes')) ? "block" : "none"; ?>">
  • mailbluster4wp/trunk/admin/partials/mailbluster4wp-form-option.php

    r2776930 r2918522  
    1111 */
    1212
     13 $response = MailBluster4WP_Helper::get_custom_field_response();
     14 if(is_wp_error($response)){
     15    $content = '<h3 style="font-weight:normal;">Loading form option...</h3>';
     16    echo $content;
     17    return;
     18 }
    1319?>
    1420<div id="mailbluster-form-options">
  • mailbluster4wp/trunk/includes/class-mailbluster4wp-helper.php

    r2835808 r2918522  
    242242        // Prepare form input detail
    243243        $form_input_detail          = self::mb4wp_process_form_input_fields($post_id);
     244
     245        if(empty($form_input_detail)){
     246            return false;
     247        }
    244248
    245249        // Get form wrapper class
     
    331335                    $url_data         = parse_url( $url );
    332336                    $url_data['host'] = explode( '.', $url_data['host'] );
    333                     // unset( $url_data['host'][0] );
    334337                   
    335338                    $urlWithoutSsl = join( '.', $url_data['host'] );
    336                     // echo $urlWithoutSsl;
    337339            ?>
    338340                <div class="mb4wp-form-branding">
     
    367369        $prefix_s = 'mb4wp_sform_';
    368370        $prefix_n_ar = $prefix_s . intval($post_id);
    369 
    370         $custom_fields = self::get_custom_field()->fields;
     371        $custom_fields = [];
     372
     373        $response = self::get_custom_field_response();
     374        if(is_wp_error($response)){
     375            return [];
     376        } else {
     377            $custom_fields = json_decode($response['body'])->fields;
     378        }
     379       
    371380        $custom_field_label = [];
    372381        foreach ( $custom_fields as $custom_field ) {
     
    387396                $single_field_str = $single_field;
    388397            }
    389             //      if('*' == substr($single_field, -1)){
    390             //          $single_field = substr($single_field, 0, -1);
    391             //      };
    392             //      $single_field = str_replace('_', ' ', trim($single_field));
    393             //      $form_detailed[$single_field_key] = array(
    394             //          'id' => $prefix_s . $single_field_key,
    395             //          'name' => $prefix_n_ar . '[meta][' . $single_field_key . ']',
    396             //          'placeholder' => $single_field,
    397             //          'required' => $required
    398             //      );
     398
    399399            if('email' == $single_field_str){
    400400                $form_detailed['email'] = array(
     
    441441
    442442    /**
    443      * Get the data of custom field from app.mailbluster.com dashboard
    444      *
    445      * @return array|string|WP_Error
    446      */
    447     public static function get_custom_field(){
     443     * Get the response data of custom field from app.mailbluster.com dashboard
     444     *
     445     * @return array|WP_Error
     446     */
     447    public static function get_custom_field_response(){
    448448
    449449        // Set custom field API
    450         $lead_url = 'https://api.mailbluster.com/api/fields';
     450        $url = 'https://api.mailbluster.com/api/fields';
    451451
    452452        // Get response by hitting API
    453         $response = wp_safe_remote_get(esc_url_raw($lead_url), array(
     453        $response = wp_safe_remote_get(esc_url_raw($url), array(
    454454            'headers'     => array(
    455455                'Content-Type' => 'application/json',
     
    458458        ));
    459459
    460         return json_decode($response['body']);
     460        return $response;
    461461    }
    462462
     
    534534                }
    535535            }
    536             // foreach ($meta_form_data as $single_data => $value) {
    537             //  $key = self::mb4wp_make_camel_case($single_data);
    538             //  $request_meta[$key] = self::mb4wp_sanitize_value_of_key($single_data, $value);
    539             //  $request_body['meta'] = $request_meta;
    540             // }
     536
    541537            foreach ($custom_form_data as $single_data => $value) {
    542538                $key = self::mb4wp_make_camel_case($single_data);
     
    587583        $builder_options = explode(',', sanitize_text_field(get_post_meta($post_id, 'mb4wp_form_builder_options', true)));
    588584
    589         // foreach($request_body['meta'] as $k => $v){
    590 
    591         //  if('*' == substr($k, -1)){
    592         //      $newKey = substr($k, 0, -1);
    593         //      $request_body['meta'][$newKey] = $v;
    594         //      // var_dump($request_body['meta'][$k]);
    595         //      // die;
    596         //      if(empty($request_body['meta'][$newKey])){
    597         //          return;
    598         //      }
    599         //      unset($request_body['meta'][$k]);
    600         //  }
    601         // }
    602 
    603585        foreach($request_body['fields'] as $k => $v){
    604586
     
    620602                    foreach($request_body as $key => $value){
    621603
    622                         // if($key == 'meta' && !empty(is_array($request_body[$key]))){
    623                         //  foreach($request_body[$key] as $metaKey => $metaValue){
    624 
    625                         //      if($requireItem == $metaKey && empty($metaValue) ){
    626                         //          return;
    627                         //      }
    628                         //  }
    629                         // }
    630 
    631604                        if($key == 'fields' && !empty(is_array($request_body[$key]))){
    632605                            foreach($request_body[$key] as $metaKey => $metaValue){
     
    658631            $tags = explode(', ', $terms_string);
    659632        }
    660 
    661         // Filter request body's meta array property
    662         // $request_body['meta'] = array_filter((array) $request_body['meta']);
    663633
    664634        // Filter request body's custom fields array property
     
    704674                </script>';
    705675            }
    706 
    707             // var_dump($request_body);
    708             // die();
    709676
    710677            // Return response
  • mailbluster4wp/trunk/mailbluster4wp.php

    r2836555 r2918522  
    1717 * Plugin URI:        https://mailbluster.com
    1818 * Description:       A free and simple WordPress plugin for MailBluster which provides different methods to create and include subscription forms into WordPress pages or posts by utilizing AmazonSES service.
    19  * Version:           1.2.0.1
    20  * Tested up to:      6.1.1
     19 * Version:           1.2.1
     20 * Tested up to:        6.2.2
    2121 * Author:            MailBluster
    2222 * Author URI:        https://mailbluster.com
     
    3737 * Rename this for your plugin and update it as you release new versions.
    3838 */
    39 define('MAILBLUSTER4WP_VERSION', '1.2.0.1');
     39define('MAILBLUSTER4WP_VERSION', '1.2.1');
    4040
    4141/**
  • mailbluster4wp/trunk/public/class-mailbluster4wp-public.php

    r2793017 r2918522  
    115115            'id' => ''
    116116        ), $atts ));
    117         $form_title                     =  get_the_title(intval($id));
    118         $form_description               =  get_post_meta(intval($id), 'mb4wp_form_description', true);
    119         $appearance_theme               =  MailBluster4WP_Helper::mb4wp_get_appearance_by_key('theme', intval($id));
     117        $form_title                                     =  get_the_title(intval($id));
     118        $form_description                       =  get_post_meta(intval($id), 'mb4wp_form_description', true);
     119        $appearance_theme                       =  MailBluster4WP_Helper::mb4wp_get_appearance_by_key('theme', intval($id));
    120120        $appearance_background_color    =  MailBluster4WP_Helper::mb4wp_get_appearance_by_key('background_color', intval($id));
    121         $appearance_color               =  MailBluster4WP_Helper::mb4wp_get_appearance_by_key('text_color', intval($id));
     121        $appearance_color                       =  MailBluster4WP_Helper::mb4wp_get_appearance_by_key('text_color', intval($id));
    122122        $appearance_titleTextSize       =  MailBluster4WP_Helper::mb4wp_get_appearance_by_key('titleTextSize', intval($id));
    123123        $appearance_titleMarginTop      =  MailBluster4WP_Helper::mb4wp_get_appearance_by_key('titleMarginTop', intval($id));
    124124        $appearance_titleMarginRight    =  MailBluster4WP_Helper::mb4wp_get_appearance_by_key('titleMarginRight', intval($id));
    125         $appearance_titleMarginBottom   =  MailBluster4WP_Helper::mb4wp_get_appearance_by_key('titleMarginBottom', intval($id));
     125        $appearance_titleMarginBottom =  MailBluster4WP_Helper::mb4wp_get_appearance_by_key('titleMarginBottom', intval($id));
    126126        $appearance_titleMarginLeft     =  MailBluster4WP_Helper::mb4wp_get_appearance_by_key('titleMarginLeft', intval($id));
    127         $appearance_formPaddingY        =  MailBluster4WP_Helper::mb4wp_get_appearance_by_key('formPaddingY', intval($id));
    128         $appearance_formPaddingX        =  MailBluster4WP_Helper::mb4wp_get_appearance_by_key('formPaddingX', intval($id));
     127        $appearance_formPaddingY            =  MailBluster4WP_Helper::mb4wp_get_appearance_by_key('formPaddingY', intval($id));
     128        $appearance_formPaddingX            =  MailBluster4WP_Helper::mb4wp_get_appearance_by_key('formPaddingX', intval($id));
     129
     130        $render_form = MailBluster4WP_Helper::mb4wp_render_form(intval($id));
     131
     132        if(!$render_form){
     133            return false;
     134        }
     135
    129136        ob_start();
    130137        ?>
     
    142149                <?php
    143150                }
    144                 if(!empty($form_description)) {
    145                     echo '<p>'.esc_html($form_description).'</p>';
     151                if(!empty($form_description)) {
     152                        echo '<p>'.esc_html($form_description).'</p>';
    146153                }
    147                 echo MailBluster4WP_Helper::mb4wp_render_form(intval($id));
    148                 ?>
     154                echo $render_form;
     155        ?>
    149156            </div>
    150157        </div>
Note: See TracChangeset for help on using the changeset viewer.