Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add migration guide for canonical URL replacement #996

Merged
merged 4 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
faisal-alvi marked this conversation as resolved.
Show resolved Hide resolved

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