-
Notifications
You must be signed in to change notification settings - Fork 205
Add dynamic social share images for plugin pages (Meta #5926) #706
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
Open
mathetos
wants to merge
2
commits into
WordPress:trunk
Choose a base branch
from
mathetos:add-plugin-share-images-5926
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| #!/usr/bin/env node | ||
| /** | ||
| * Runs after wp-env start. Sets up permalinks, creates pages, and imports plugins. | ||
| * | ||
| * Cross-platform replacement for after-start.sh (Windows lacks /bin/bash in wp-env's shell). | ||
| */ | ||
|
|
||
| const { spawnSync } = require( 'child_process' ); | ||
| const path = require( 'path' ); | ||
|
|
||
| const ROOT = path.resolve( __dirname, '..', '..' ); | ||
| const CONFIG = '--config plugin-directory/.wp-env.json'; | ||
|
|
||
| function run( args, options = {} ) { | ||
| const result = spawnSync( 'npx', [ 'wp-env', ...CONFIG.split( ' ' ), ...args ], { | ||
| cwd: ROOT, | ||
| shell: true, | ||
| encoding: 'utf8', | ||
| ...options, | ||
| } ); | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| function wp( ...wpArgs ) { | ||
| return run( [ 'run', 'cli', '--', 'wp', ...wpArgs ], { | ||
| stdio: [ 'pipe', 'pipe', 'pipe' ], | ||
| } ); | ||
| } | ||
|
|
||
| function wpQuiet( ...wpArgs ) { | ||
| return wp( ...wpArgs ); | ||
| } | ||
|
|
||
| function tryWp( message, ...wpArgs ) { | ||
| const result = wpQuiet( ...wpArgs ); | ||
|
|
||
| if ( result.status === 0 ) { | ||
| console.log( message ); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| function wpOutput( ...wpArgs ) { | ||
| const result = wp( ...wpArgs ); | ||
| return ( result.stdout || '' ).trim(); | ||
| } | ||
|
|
||
| // Install CLI tools needed by the plugin directory (svn, unzip, etc.). | ||
| console.log( 'Installing CLI tools...' ); | ||
| run( [ | ||
| 'run', | ||
| 'wordpress', | ||
| 'sudo', | ||
| 'bash', | ||
| '-c', | ||
| 'command -v svn > /dev/null || (apt-get -qy update && apt-get -qy install subversion unzip zip) > /dev/null 2>&1', | ||
| ], { stdio: 'inherit' } ); | ||
|
|
||
| run( [ | ||
| 'run', | ||
| 'cli', | ||
| 'sudo', | ||
| 'sh', | ||
| '-c', | ||
| 'command -v svn > /dev/null || apk add --no-cache -q subversion unzip zip coreutils > /dev/null 2>&1', | ||
| ], { stdio: 'inherit' } ); | ||
|
|
||
| // Set up permalinks. | ||
| wp( 'rewrite', 'structure', '/%postname%/', '--hard' ); | ||
|
|
||
| // Create pages that exist on wordpress.org/plugins (if they don't already exist). | ||
| console.log( 'Creating pages...' ); | ||
| tryWp( | ||
| ' Created page: /developers/', | ||
| 'post', | ||
| 'create', | ||
| '--post_type=page', | ||
| '--post_status=publish', | ||
| '--post_title=Developer Information', | ||
| '--post_name=developers', | ||
| '--porcelain' | ||
| ); | ||
|
|
||
| const developersId = wpOutput( | ||
| 'post', | ||
| 'list', | ||
| '--post_type=page', | ||
| '--name=developers', | ||
| '--field=ID' | ||
| ); | ||
|
|
||
| if ( developersId ) { | ||
| tryWp( | ||
| ' Created page: /developers/add/', | ||
| 'post', | ||
| 'create', | ||
| '--post_type=page', | ||
| '--post_status=publish', | ||
| '--post_title=Add your Plugin', | ||
| '--post_name=add', | ||
| `--post_parent=${ developersId }`, | ||
| '--porcelain' | ||
| ); | ||
| tryWp( | ||
| ' Created page: /developers/readme-validator/', | ||
| 'post', | ||
| 'create', | ||
| '--post_type=page', | ||
| '--post_status=publish', | ||
| '--post_title=Readme Validator', | ||
| '--post_content=[readme-validator]', | ||
| '--post_name=readme-validator', | ||
| `--post_parent=${ developersId }`, | ||
| '--porcelain' | ||
| ); | ||
| tryWp( | ||
| ' Created page: /developers/block-plugin-validator/', | ||
| 'post', | ||
| 'create', | ||
| '--post_type=page', | ||
| '--post_status=publish', | ||
| '--post_title=Block Plugin Checker', | ||
| '--post_content=[block-validator]', | ||
| '--post_name=block-plugin-validator', | ||
| `--post_parent=${ developersId }`, | ||
| '--porcelain' | ||
| ); | ||
| tryWp( | ||
| ' Created page: /developers/releases/', | ||
| 'post', | ||
| 'create', | ||
| '--post_type=page', | ||
| '--post_status=publish', | ||
| '--post_title=Release Management', | ||
| '--post_content=[release-confirmation]', | ||
| '--post_name=releases', | ||
| `--post_parent=${ developersId }`, | ||
| '--porcelain' | ||
| ); | ||
| } | ||
|
|
||
| // Create stub database tables that exist outside WordPress on production. | ||
| wp( 'db', 'import', 'wp-content/env-bin/database-tables.sql' ); | ||
|
|
||
| // Create browse section terms with proper display names. | ||
| console.log( 'Creating browse sections...' ); | ||
| const sections = { | ||
| featured: 'Featured', | ||
| popular: 'Popular', | ||
| beta: 'Beta', | ||
| blocks: 'Block-Enabled', | ||
| new: 'New', | ||
| updated: 'Recently Updated', | ||
| favorites: 'Favorites', | ||
| 'dashboard-widgets': 'Dashboard Widgets', | ||
| }; | ||
|
|
||
| for ( const [ slug, name ] of Object.entries( sections ) ) { | ||
| tryWp( | ||
| ` Created section: ${ name } (${ slug })`, | ||
| 'term', | ||
| 'create', | ||
| 'plugin_section', | ||
| name, | ||
| `--slug=${ slug }` | ||
| ); | ||
| } | ||
|
|
||
| // Import plugins from wordpress.org. | ||
| wp( 'eval-file', 'wp-content/env-bin/import-plugins.php' ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What makes this change necessary?