Skip to content

Commit

Permalink
Plugins: Deprecate 'withPluginContext' HOC (WordPress#66363)
Browse files Browse the repository at this point in the history
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: gziolo <gziolo@git.wordpress.org>
  • Loading branch information
4 people authored Oct 23, 2024
1 parent 78b65c5 commit 71bb8b8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions packages/plugins/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ _Returns_

#### withPluginContext

> **Deprecated** 6.8.0 Use `usePluginContext` hook instead.
A Higher Order Component used to inject Plugin context to the wrapped component.

_Parameters_
Expand Down
1 change: 1 addition & 0 deletions packages/plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"@babel/runtime": "7.25.7",
"@wordpress/components": "*",
"@wordpress/compose": "*",
"@wordpress/deprecated": "*",
"@wordpress/element": "*",
"@wordpress/hooks": "*",
"@wordpress/icons": "*",
Expand Down
7 changes: 7 additions & 0 deletions packages/plugins/src/components/plugin-context/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { createContext, useContext } from '@wordpress/element';
import { createHigherOrderComponent } from '@wordpress/compose';
import deprecated from '@wordpress/deprecated';

/**
* Internal dependencies
Expand Down Expand Up @@ -34,6 +35,8 @@ export function usePluginContext() {
* A Higher Order Component used to inject Plugin context to the
* wrapped component.
*
* @deprecated 6.8.0 Use `usePluginContext` hook instead.
*
* @param mapContextToProps Function called on every context change,
* expected to return object of props to
* merge with the component's own props.
Expand All @@ -47,6 +50,10 @@ export const withPluginContext = (
) => T & PluginContext
) =>
createHigherOrderComponent( ( OriginalComponent ) => {
deprecated( 'wp.plugins.withPluginContext', {
since: '6.8.0',
alternative: 'wp.plugins.usePluginContext',
} );
return ( props ) => (
<Context.Consumer>
{ ( context ) => (
Expand Down
1 change: 1 addition & 0 deletions packages/plugins/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"references": [
{ "path": "../components" },
{ "path": "../compose" },
{ "path": "../deprecated" },
{ "path": "../element" },
{ "path": "../hooks" },
{ "path": "../icons" },
Expand Down

0 comments on commit 71bb8b8

Please sign in to comment.