Skip to content

Commit

Permalink
Merge pull request #996 from 10up/fix/989-migration-guide
Browse files Browse the repository at this point in the history
Add migration guide for canonical URL replacement
  • Loading branch information
peterwilsoncc authored Jan 10, 2023
2 parents 9242d18 + a990330 commit 1059ce4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
4 changes: 4 additions & 0 deletions .github/hookdoc-tmpl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ This resource is generated documentation on actions and filters found in the Dis

For more information about using Distributor with WordPress, please see the [Distributor website](https://distributorplugin.com/).

## Migrating to version 2.0

Version 2.0 of Distributor contains breaking changes. Please review the <a href="./tutorial-migration-guide-version-1-to-version-2.html">migration guide</a> tutorial and follow any steps required.

To report an issue with Distributor or contribute back to the project, please visit the [GitHub repository](https://github.com/10up/distributor/).

<a href="http://10up.com/contact/" class="banner"><img src="https://10updotcom-wpengine.s3.amazonaws.com/uploads/2016/10/10up-Github-Banner.png" width="850"></a>
25 changes: 25 additions & 0 deletions docs/migration-guide-version-1-to-version-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## Migration Guide Version 1 to Version 2.

Version 2 of Distributor includes a number of breaking changes that will require updates to custom code you may have written for distributor.

### Remove canonical links for both Internal and External Connections

The code snippet required to prevent sites from displaying the source post as canonical URLs for distributed posts has changed.

If you have implemented this using the code snippet from our tutorial file, please update your code to the following:

```php
/**
* Stop Distributor from changing the canonical links.
*
* This removes Distributor's canonical functionality from both Internal and
* External Connections.
*
* This accounts for sites using either WordPress or Yoast SEO to generate the
* canonical URL.
*/
add_action( 'plugins_loaded', function() {
add_action( 'get_canonical_url', '\\Distributor\\Hooks\\get_canonical_url', 10, 2 );
add_action( 'wpseo_canonical', '\\Distributor\\Hooks\\wpseo_canonical', 10, 2 );
} );
```
18 changes: 9 additions & 9 deletions docs/snippets.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ function client_prefix_filter_authorized_sites( array $authorized_sites, string
/**
* Stop Distributor from changing the canonical links.
*
* This removes Distributor's canonical functionality from
* both Internal and External Connections and for those sites
* that use Yoast SEO.
* This removes Distributor's canonical functionality from both Internal and
* External Connections.
*
* This accounts for sites using either WordPress or Yoast SEO to generate the
* canonical URL.
*/
add_action( 'template_redirect', function () {
remove_filter( 'get_canonical_url', array( '\Distributor\InternalConnections\NetworkSiteConnection', 'canonical_url' ), 10, 2 );
remove_filter( 'wpseo_canonical', array( '\Distributor\InternalConnections\NetworkSiteConnection', 'wpseo_canonical_url' ) );
remove_filter( 'get_canonical_url', array( '\Distributor\ExternalConnections\WordPressExternalConnection', 'canonical_url' ), 10, 2 );
remove_filter( 'wpseo_canonical', array( '\Distributor\ExternalConnections\WordPressExternalConnection', 'wpseo_canonical_url' ) );
}, 20 );
add_action( 'plugins_loaded', function() {
add_action( 'get_canonical_url', '\\Distributor\\Hooks\\get_canonical_url', 10, 2 );
add_action( 'wpseo_canonical', '\\Distributor\\Hooks\\wpseo_canonical', 10, 2 );
} );
```

### Push original publication date
Expand Down

0 comments on commit 1059ce4

Please sign in to comment.