Skip to content

Commit

Permalink
chore: 🔀 merge pull request #16 from vlasscontreras/hotfix/settings-api
Browse files Browse the repository at this point in the history
Fix settings fatal error
  • Loading branch information
vlasscontreras authored May 21, 2021
2 parents 525bf23 + f59697c commit 5508244
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 150 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Gragrid: Gravity Forms + SendGrid

[![GitHub Workflows](https://github.com/vlasscontreras/gragrid/workflows/Build/badge.svg)](https://github.com/vlasscontreras/gragrid)
[![Version](https://img.shields.io/badge/version-2.1.0-brightgreen.svg)](https://github.com/vlasscontreras/gragrid)
[![Version](https://img.shields.io/badge/version-2.2.0-brightgreen.svg)](https://github.com/vlasscontreras/gragrid)
[![Plugin Version](https://img.shields.io/wordpress/plugin/v/gragrid)](https://wordpress.org/plugins/gragrid/)
[![PHP Version](https://img.shields.io/wordpress/plugin/required-php/gragrid)](https://github.com/vlasscontreras/gragrid)
[![WordPress Plugin: Required WP Version](https://img.shields.io/wordpress/plugin/wp-version/gragrid)](https://github.com/vlasscontreras/gragrid)
Expand Down
28 changes: 13 additions & 15 deletions class-gragrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ class Gragrid extends GFFeedAddOn {
* @since 1.0.0
*
* @access protected
* @var Gragrid_API $api Contains an instance of the SendGrid API library.
* @var Gragrid_API|null $api Contains an instance of the SendGrid API library.
*/
public $api = null;
protected $api = null;

/**
* Add-on constructor
Expand Down Expand Up @@ -307,21 +307,15 @@ public function settings_sendgrid_list( $field, $echo = true ) {
return;
}

try {
$this->log_debug( __METHOD__ . '(): Retrieving contact lists.' );

$lists = $this->api->get_lists();
} catch ( Exception $e ) {
$this->log_error( __METHOD__ . ': Could not retrieve the contact lists ' . $e->getMessage() );
$lists = $this->api->get_lists();

printf(
// Translators: 1 line break, 2 error message.
esc_html__( 'Could not load the contact lists. %1$sError: %2$s', 'gragrid' ),
'<br/>',
$e->getMessage()
); // phpcs:ignore: XSS ok.
if ( is_wp_error( $lists ) ) {
$this->log_error( __METHOD__ . ': Could not retrieve the contact lists ' . $lists->get_error_message() );

return;
return sprintf(
'<div class="notice notice-error inline" style="display: block !important;"><p>%s</p></div>',
esc_html__( 'Could not load the contact lists. Make sure you have a valid API key.', 'gragrid' )
);
}

if ( ! count( $lists['result'] ) > 0 ) {
Expand Down Expand Up @@ -469,6 +463,10 @@ public function sengrid_field_map() {
* @return array
*/
public function sengrid_custom_fields_map() {
if ( ! $this->init_api() ) {
return array();
}

$fields = array();
$custom_fields = (array) rgar( $this->api->get_custom_fields(), 'custom_fields' );
$custom_fields = array_filter( $custom_fields );
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"scripts": {
"lint:wpcs": "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs",
"lint:php": "@php ./vendor/bin/parallel-lint --exclude .git --exclude vendor .",
"make-pot": "wp i18n make-pot . languages/gragrid.pot"
"make:pot": "wp i18n make-pot . languages/gragrid.pot"
},
"support": {
"issues": "https://github.com/vlasscontreras/gragrid/issues",
Expand Down
Loading

0 comments on commit 5508244

Please sign in to comment.