Skip to content

Fixes default global options array merging.#7538

Merged
dereksmart merged 2 commits intomasterfrom
fix/sharing-global-defaults
Jul 31, 2017
Merged

Fixes default global options array merging.#7538
dereksmart merged 2 commits intomasterfrom
fix/sharing-global-defaults

Conversation

@zinigor
Copy link
Copy Markdown
Contributor

@zinigor zinigor commented Jul 26, 2017

A change introduced in #6355 started merging the regular options array with the global options. This has been largely unnoticed, but sometimes resulted in weird errors like this:

 PHP Catchable fatal error:  Argument 2 passed to Share_Twitter::__construct() must be of the type array, null given, called in /home/asotestjetpack/main/wp-content/plugins/jetpack-dev/modules/sharedaddy/sharing-service.php on line 227 and defined in /home/asotestjetpack/main/wp-content/plugins/jetpack-dev/modules/sharedaddy/sharing-sources.php on line 562
 PHP Warning:  array_merge(): Argument #1 is not an array in /home/asotestjetpack/main/wp-content/plugins/jetpack-dev/modules/sharedaddy/sharing-service.php on line 227
 PHP Notice:  Undefined index: global in /home/asotestjetpack/main/wp-content/plugins/jetpack-dev/modules/sharedaddy/sharing-service.php on line 196

Testing instructions:

  • I have been able to reproduce the problem when testing Jetpack 5.2 beta1 with doing an options reset. It may have been related to the fact that I was testing PHP 5.2.

A change introduced in #6355 started merging the regular options array with the global options. This has been largely unnoticed, but sometimes resulted in weird errors like this:

```
 PHP Catchable fatal error:  Argument 2 passed to Share_Twitter::__construct() must be of the type array, null given, called in /home/asotestjetpack/main/wp-content/plugins/jetpack-dev/modules/sharedaddy/sharing-service.php on line 227 and defined in /home/asotestjetpack/main/wp-content/plugins/jetpack-dev/modules/sharedaddy/sharing-sources.php on line 562
 PHP Warning:  array_merge(): Argument #1 is not an array in /home/asotestjetpack/main/wp-content/plugins/jetpack-dev/modules/sharedaddy/sharing-service.php on line 227
 PHP Notice:  Undefined index: global in /home/asotestjetpack/main/wp-content/plugins/jetpack-dev/modules/sharedaddy/sharing-service.php on line 196
```
@zinigor zinigor added [Feature] Sharing Post sharing, sharing buttons [Status] Needs Review This PR is ready for review. Bug When a feature is broken and / or not performing as intended labels Jul 26, 2017
@zinigor zinigor requested a review from thingalon July 26, 2017 14:29
@zinigor zinigor requested a review from a team as a code owner July 26, 2017 14:29
Copy link
Copy Markdown
Member

@thingalon thingalon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! Fix looks good to me.

@zinigor zinigor added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review This PR is ready for review. labels Jul 27, 2017
$options = array_merge(
is_array( $options ) ? $options : array(),
array( 'global' => $this->get_global_options() )
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't do an array_merge unnecessarily (with an empty array) since it's expensive. Can we do this?

$options = is_array( $options )
    ? array_merge( $options, array( 'global' => $this->get_global_options() ) )
    : array( 'global' => $this->get_global_options() );

@eliorivero eliorivero added the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jul 27, 2017
@zinigor
Copy link
Copy Markdown
Contributor Author

zinigor commented Jul 27, 2017

Thanks Elio! Fixed!

@eliorivero eliorivero removed the [Status] Needs Author Reply We need more details from you. This label will be auto-added until the PR meets all requirements. label Jul 31, 2017
@dereksmart dereksmart merged commit 6fc40ed into master Jul 31, 2017
@dereksmart dereksmart removed the [Status] Ready to Merge Go ahead, you can push that green button! label Jul 31, 2017
@dereksmart dereksmart deleted the fix/sharing-global-defaults branch July 31, 2017 18:11
eliorivero pushed a commit that referenced this pull request Jul 31, 2017
* Fixes default global options array merging.

A change introduced in #6355 started merging the regular options array with the global options. This has been largely unnoticed, but sometimes resulted in weird errors like this:

```
 PHP Catchable fatal error:  Argument 2 passed to Share_Twitter::__construct() must be of the type array, null given, called in /home/asotestjetpack/main/wp-content/plugins/jetpack-dev/modules/sharedaddy/sharing-service.php on line 227 and defined in /home/asotestjetpack/main/wp-content/plugins/jetpack-dev/modules/sharedaddy/sharing-sources.php on line 562
 PHP Warning:  array_merge(): Argument #1 is not an array in /home/asotestjetpack/main/wp-content/plugins/jetpack-dev/modules/sharedaddy/sharing-service.php on line 227
 PHP Notice:  Undefined index: global in /home/asotestjetpack/main/wp-content/plugins/jetpack-dev/modules/sharedaddy/sharing-service.php on line 196
```

* Improved array merge logic.

Props @eliorivero for the tip.
@eliorivero
Copy link
Copy Markdown
Contributor

cherry picked to 5.2 in ccf4950

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug When a feature is broken and / or not performing as intended [Feature] Sharing Post sharing, sharing buttons Touches WP.com Files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants