Skip to content

Commit 00b1321

Browse files
authored
Merge pull request #26 from mailchimp/feat/php-compat
PHP Compat to 8.3
2 parents ddcdcf7 + 7e675a0 commit 00b1321

File tree

9 files changed

+28
-21
lines changed

9 files changed

+28
-21
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
],
1313
"prefer-stable": true,
1414
"require": {
15-
"php": ">=5.6"
15+
"php": ">=7.0"
1616
},
1717
"require-dev": {
1818
"10up/phpcs-composer": "^3.0",

composer.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/mailchimp/mailchimp.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ public function post( $endpoint, $body, $method = 'POST' ) {
141141
return new WP_Error( 'mc-subscribe-error', $request->get_error_message() );
142142
}
143143

144-
$body = json_decode( $request['body'], true );
145-
$merges = get_option( 'mc_merge_vars' );
144+
$body = json_decode( $request['body'], true );
145+
$merges = get_option( 'mc_merge_vars' );
146+
$field_name = '';
146147
foreach ( $merges as $merge ) {
147148
if ( empty( $body['errors'] ) ) {
148149
// Email address doesn't come back from the API, so if something's wrong, it's that.

mailchimp.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
* Description: Add a Mailchimp signup form widget to your WordPress site.
66
* Version: 1.5.8
77
* Requires at least: 2.8
8-
* Requires PHP: 5.6
8+
* Requires PHP: 7.0
9+
* PHP tested up to: 8.3
910
* Author: Mailchimp
1011
* Author URI: https://mailchimp.com/
1112
* License: GPL-2.0-or-later
@@ -69,7 +70,7 @@ function mailchimp_sf_plugin_init() {
6970

7071
// Remove Sopresto check. If user does not have API key, make them authenticate.
7172

72-
if ( get_option( 'mc_list_id' ) && get_option( 'mc_merge_field_migrate' ) !== true && mailchimp_sf_get_api() !== false ) {
73+
if ( get_option( 'mc_list_id' ) && get_option( 'mc_merge_field_migrate' ) !== '1' && mailchimp_sf_get_api() !== false ) {
7374
mailchimp_sf_update_merge_fields();
7475
}
7576

@@ -126,7 +127,7 @@ function mailchimp_sf_load_resources() {
126127
wp_enqueue_script( 'jquery-ui-datepicker' );
127128
}
128129

129-
if ( get_option( 'mc_nuke_all_styles' ) !== true ) {
130+
if ( get_option( 'mc_nuke_all_styles' ) !== '1' ) {
130131
wp_enqueue_style( 'mailchimp_sf_main_css', home_url( '?mcsf_action=main_css&ver=' . MCSF_VER, 'relative' ), array(), MCSF_VER );
131132
wp_enqueue_style( 'mailchimp_sf_ie_css', MCSF_URL . 'css/ie.css', array(), MCSF_VER );
132133
global $wp_styles;
@@ -644,6 +645,10 @@ function mailchimp_sf_change_list_if_necessary() {
644645
// we *could* support paging, but few users have that many lists (and shouldn't)
645646
$lists = $api->get( 'lists', 100, array( 'fields' => 'lists.id,lists.name,lists.email_type_option' ) );
646647

648+
if ( ! isset( $lists['lists'] ) || is_wp_error( $lists['lists'] ) ) {
649+
return;
650+
}
651+
647652
$lists = $lists['lists'];
648653

649654
if ( is_array( $lists ) && ! empty( $lists ) && isset( $_POST['mc_list_id'] ) ) {
@@ -703,7 +708,7 @@ function mailchimp_sf_change_list_if_necessary() {
703708
*
704709
* @param string $list_id List ID
705710
* @param bool $new_list Whether this is a new list
706-
* @return void
711+
* @return array
707712
*/
708713
function mailchimp_sf_get_merge_vars( $list_id, $new_list ) {
709714
$api = mailchimp_sf_get_api();
@@ -984,7 +989,7 @@ function mailchimp_sf_merge_submit( $mv ) {
984989
$opt_val = isset( $_POST[ $opt ] ) ? map_deep( stripslashes_deep( $_POST[ $opt ] ), 'sanitize_text_field' ) : '';
985990

986991
// Handle phone number logic
987-
if ( 'phone' === $mv_var['type'] && 'US' === $mv_var['options']['phone_format'] ) {
992+
if ( isset( $mv_var['options']['phone_format'] ) && 'phone' === $mv_var['type'] && 'US' === $mv_var['options']['phone_format'] ) {
988993
$opt_val = mailchimp_sf_merge_validate_phone( $opt_val, $mv_var );
989994
if ( is_wp_error( $opt_val ) ) {
990995
return $opt_val;
@@ -1265,7 +1270,7 @@ function mailchimp_sf_where_am_i() {
12651270
// Set defaults
12661271
$mscf_dirbase = trailingslashit( basename( __DIR__ ) ); // Typically wp-mailchimp/ or mailchimp/
12671272
$mscf_dir = trailingslashit( plugin_dir_path( __FILE__ ) );
1268-
$mscf_url = trailingslashit( plugins_url( null, __FILE__ ) );
1273+
$mscf_url = trailingslashit( plugins_url( '', __FILE__ ) );
12691274

12701275
// Try our hands at finding the real location
12711276
foreach ( $locations as $key => $loc ) {

mailchimp_widget.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function mailchimp_sf_signup_form( $args = array() ) {
6363

6464
$sub_heading = trim( get_option( 'mc_subheader_content' ) );
6565

66-
if ( get_option( 'mc_nuke_all_styles' ) !== true ) {
66+
if ( get_option( 'mc_nuke_all_styles' ) !== '1' ) {
6767
?>
6868
<style>
6969
.widget_mailchimpsf_widget .widget-title {
@@ -235,7 +235,7 @@ function mailchimp_sf_signup_form( $args = array() ) {
235235
<div class="field-group groups mc_email_options">
236236
<ul class="mc_list">
237237
<li><input type="radio" name="email_type" id="email_type_html" value="html" checked="checked"><label for="email_type_html" class="mc_email_type"><?php esc_html_e( 'HTML', 'mailchimp_i18n' ); ?></label></li>
238-
<li><input type="radio" name="email_type" id="email_type_text" value="text"><label for="email_type_text" class="mc_email_type"><?php esc_html_( 'Text', 'mailchimp_i18n' ); ?></label></li>
238+
<li><input type="radio" name="email_type" id="email_type_text" value="text"><label for="email_type_text" class="mc_email_type"><?php esc_html_e( 'Text', 'mailchimp_i18n' ); ?></label></li>
239239
</ul>
240240
</div>
241241
</div>
@@ -465,7 +465,7 @@ function mailchimp_form_field( $data, $num_fields ) {
465465
<input type="text" size="18" maxlength="5" value="" name="' . esc_attr( $opt ) . '" id="' . esc_attr( $opt ) . '" class="mc_input" />';
466466
break;
467467
case 'phone':
468-
if ( 'US' === $data['options']['phone_format'] ) {
468+
if ( isset( $data['options']['phone_format'] ) && 'US' === $data['options']['phone_format'] ) {
469469
$html .= '
470470
<input type="text" size="2" maxlength="3" value="" name="' . esc_attr( $opt . '[area]' ) . '" id="' . esc_attr( $opt . '-area' ) . '" class="mc_input mc_phone" />
471471
<input type="text" size="2" maxlength="3" value="" name="' . esc_attr( $opt . '[detail1]' ) . '" id="' . esc_attr( $opt . '-detail1' ) . '" class="mc_input mc_phone" />

phpcs-compat.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
<exclude-pattern>*/po/*</exclude-pattern>
1515

1616
<config name="minimum_supported_wp_version" value="6.0"/>
17-
<config name="testVersion" value="5.6-"/>
17+
<config name="testVersion" value="7.0-"/>
1818
</ruleset>

phpcs.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<exclude-pattern>*/tests/*</exclude-pattern>
88

99
<config name="minimum_supported_wp_version" value="6.0"/>
10-
<config name="testVersion" value="5.6-"/>
10+
<config name="testVersion" value="7.0-"/>
1111

1212
<!-- Exclude the PHPCompatibilityWP ruleset -->
1313
<rule ref="PHPCompatibilityWP">

readme.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Add a Mailchimp signup form widget to your WordPress site.
1010

1111
== Description ==
1212

13-
Use the Mailchimp List Subscribe plugin to quickly add a Mailchimp signup form widget to your WordPress 2.8 or higher site.
13+
Use the Mailchimp List Subscribe plugin to quickly add a Mailchimp signup form widget to your WordPress 2.8 or higher site.
1414

1515
After installation, you’ll log in with your API key, select your Mailchimp list, choose merge fields and groups, and add the widget to your site. Typically, installation and setup will take about 5-10 minutes, and absolutely everything can be done via the WordPress Setting GUI, with no file editing at all.
1616

@@ -34,7 +34,7 @@ This section describes how to install the plugin and get started using it.
3434

3535
If you have a custom coded sidebar or bells and whistles that prevent enabling widgets through the WordPress GUI, complete these steps instead.
3636

37-
WordPress v2.8 or higher:
37+
WordPress v2.8 or higher:
3838
` [mailchimpsf_form] `
3939

4040
If you are adding it inside a php code block, pop this in:
@@ -100,6 +100,7 @@ If your language is not listed above, feel free to create a translation. Here ar
100100

101101
= 1.6.0 =
102102
* Deprecated function `mailchimpSF_signup_form`. Function `mailchimp_sf_signup_form` should be used instead.
103+
* Bumps minimum PHP version to 7.0
103104

104105
= 1.5.8 =
105106
* Fix PHP warning for merge tags.

views/setup_page.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676

7777
<br/>
7878
<?php
79-
if ( '' !== $user && $user['username'] ) {
79+
if ( '' !== $user && isset( $user['username'] ) && $user['username'] ) {
8080
?>
8181
<!--<div class="notes_msg">
8282
<strong><?php esc_html_e( 'Notes', 'mailchimp_i18n' ); ?>:</strong>
@@ -233,7 +233,7 @@
233233
<tr><th colspan="2">Remove Mailchimp CSS</th></tr>
234234
<tr class="mc-internal-heading"><th><label for="mc_nuke_all_styles"><?php esc_html_e( 'Remove CSS' ); ?></label></th><td><span class="mc-pre-input"></span><input type="checkbox" name="mc_nuke_all_styles" id="mc_nuke_all_styles" <?php checked( get_option( 'mc_nuke_all_styles' ), true ); ?> onclick="showMe('mc-custom-styling')"/><?php esc_html_e( 'This will disable all Mailchimp CSS, so it\'s recommended for WordPress experts only.' ); ?></td></tr>
235235
</table>
236-
<?php if ( get_option( 'mc_nuke_all_styles' ) === true ) { ?>
236+
<?php if ( get_option( 'mc_nuke_all_styles' ) === '1' ) { ?>
237237
<table class="widefat mc-widefat mc-custom-styling" id="mc-custom-styling" style="display:none">
238238
<?php } else { ?>
239239
<table class="widefat mc-widefat mc-custom-styling" id="mc-custom-styling">
@@ -331,7 +331,7 @@
331331
<?php
332332
$mv = get_option( 'mc_merge_vars' );
333333

334-
if ( count( $mv ) === 0 || ! is_array( $mv ) ) {
334+
if ( ! is_array( $mv ) || count( $mv ) === 0 ) {
335335
?>
336336
<em><?php esc_html_e( 'No Merge Fields found.', 'mailchimp_i18n' ); ?></em>
337337
<?php

0 commit comments

Comments
 (0)