Skip to content

Added a migration routine for WV rules.#6615

Merged
dereksmart merged 6 commits intomasterfrom
add/widget-visibility-migration
Mar 9, 2017
Merged

Added a migration routine for WV rules.#6615
dereksmart merged 6 commits intomasterfrom
add/widget-visibility-migration

Conversation

@zinigor
Copy link
Copy Markdown
Contributor

@zinigor zinigor commented Mar 9, 2017

This routine will run only on Jetpack upgrade and will only affect rules that have been set for Post Type major category. Both custom post types and custom post type archive pages will now be set to Page -> Custom Post Type.

Fixes #6596
Fixes #6595

Testing instructions:

  • Dowgrade to Jetpack 4.6 at least.
  • Set up widget visibility rules to Post Type -> anything or Post Type Archive -> anything.
  • Update to Jetpack 4.7
  • Observe that all set rules have been successfully migrated to Page -> Selected Post Type.

Proposed changelog entry for your changes:

  • Restored the option to make widgets appear on archive pages of different content types.
  • Added a rule to migrate widget visibility settings to the new major Page rule.

This routine will run only on Jetpack upgrade and will only affect rules that have been set for Post Type major category. Both custom post types and custom post type archive pages will now be set to Page
-> Custom Post Type.
@zinigor zinigor added [Feature] Widget Visibility [Status] Needs Review This PR is ready for review. Bug When a feature is broken and / or not performing as intended labels Mar 9, 2017
@zinigor zinigor added this to the 4.7.1 milestone Mar 9, 2017
@zinigor zinigor self-assigned this Mar 9, 2017
@davecpage
Copy link
Copy Markdown

Note that the old rule/condition for targeting a custom Post Type Archive is not the same as the new rule/condition of "Page" => Selected Post Type. The latter only works when the Post Type is_singular https://github.com/Automattic/jetpack/blob/master/modules/widget-visibility/widget-conditions.php#L492 so fails for Post Type Archives.

@stoyan0v
Copy link
Copy Markdown
Contributor

stoyan0v commented Mar 9, 2017

Works fine! 👍

* @since 4.7.1
*
*/
static function migrate_widget_visibility() {
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.

@zinigor should we move this method over to somewhere in the Jetpack_Widget_Conditions class so that we can use it when we merge these changes to wpcom?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, totally, great idea!

@zinigor
Copy link
Copy Markdown
Contributor Author

zinigor commented Mar 9, 2017

Props for @davidpagepsycle for adding a commit to this PR. Can you please test it once more to make sure that your widgets work as expected after the migration?


foreach ( $sidebar as $w => $widget ) {
// $widget is the id of the widget
if ( empty( $wp_registered_widgets[$widget] ) ) {
Copy link
Copy Markdown
Contributor

@dereksmart dereksmart Mar 9, 2017

Choose a reason for hiding this comment

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

should be a space in brackets with a variable [ $space_plz ]

continue;
}

$opts = $wp_registered_widgets[$widget];
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.

should be a space in brackets with a variable [ $space_plz ]

}
}

$sidebars_widgets = get_option( 'sidebars_widgets' );
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.

@zinigor I don't think there's any use to this?

@davecpage
Copy link
Copy Markdown

@zinigor I've tested this patch locally and it works great, all rules in the admin migrated and the frontend visibility conditions continue to work.

Copy link
Copy Markdown
Contributor

@dereksmart dereksmart left a comment

Choose a reason for hiding this comment

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

This tests very well, and I've fixed the minor things I commented about. :shipit:

Copy link
Copy Markdown
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

This seems to work well in my tests! 🚢

@jeherve jeherve 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 Mar 9, 2017
jeherve added a commit that referenced this pull request Mar 9, 2017
@dereksmart dereksmart merged commit b89da8e into master Mar 9, 2017
@dereksmart dereksmart removed the [Status] Ready to Merge Go ahead, you can push that green button! label Mar 9, 2017
dereksmart pushed a commit that referenced this pull request Mar 9, 2017
* Added a migration routine for WV rules.

This routine will run only on Jetpack upgrade and will only affect rules that have been set for Post Type major category. Both custom post types and custom post type archive pages will now be set to Page
-> Custom Post Type.

* Removed unrelated changes that appeared due to whitespace cleanup.

* Widget Visibility: Restore the Post Type Archive minor rules (#6595)

* Moved the migration method to the Widget Visibility class.

Also modified the migration procedure to keep the old archive page rules.

* Made the upgrade routine to run on module load event.

* Whitespace and removed unused var declaration
@dereksmart
Copy link
Copy Markdown
Contributor

merged to 4.7 1c81bea

@dereksmart dereksmart deleted the add/widget-visibility-migration branch March 9, 2017 18:12
dereksmart pushed a commit that referenced this pull request Mar 9, 2017
* Update stable tag.

* Move 4.7 changelog to changelog.txt

* Changelog: add #6571

* Changelog: add #6600

* Changelog: add #6604

* Changelog: add #6608

* Changelog: remove PR numbers and add release date and link.

* Changelog: add #6615
dereksmart pushed a commit that referenced this pull request Mar 9, 2017
* Update stable tag.

* Move 4.7 changelog to changelog.txt

* Changelog: add #6571

* Changelog: add #6600

* Changelog: add #6604

* Changelog: add #6608

* Changelog: remove PR numbers and add release date and link.

* Changelog: add #6615
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] Widget Visibility Touches WP.com Files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants