-
Notifications
You must be signed in to change notification settings - Fork 8
Add initial dynamic shapes plugin #109
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
philcable
wants to merge
1
commit into
trunk
Choose a base branch
from
feature/dynamic-shapes
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # This file is for unifying the coding style for different editors and IDEs | ||
| # editorconfig.org | ||
|
|
||
| # WordPress Coding Standards | ||
| # https://make.wordpress.org/core/handbook/coding-standards/ | ||
|
|
||
| root = true | ||
|
|
||
| [*] | ||
| charset = utf-8 | ||
| end_of_line = lf | ||
| insert_final_newline = true | ||
| trim_trailing_whitespace = true | ||
| indent_style = tab | ||
|
|
||
| [*.{yml,yaml}] | ||
| indent_style = space | ||
| indent_size = 2 |
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,30 @@ | ||
| # Logs | ||
| logs | ||
| *.log | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
|
|
||
| # Coverage directory used by tools like istanbul | ||
| coverage | ||
|
|
||
| # Compiled binary addons (https://nodejs.org/api/addons.html) | ||
| build/Release | ||
|
|
||
| # Dependency directories | ||
| node_modules/ | ||
|
|
||
| # Optional npm cache directory | ||
| .npm | ||
|
|
||
| # Optional eslint cache | ||
| .eslintcache | ||
|
|
||
| # Output of `npm pack` | ||
| *.tgz | ||
|
|
||
| # Output of `wp-scripts plugin-zip` | ||
| *.zip | ||
|
|
||
| # dotenv environment variables file | ||
| .env |
80 changes: 80 additions & 0 deletions
80
dynamic-shapes/classes/class-wpcomsp-blocks-self-update.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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| <?php | ||
| /** | ||
| * Plugin Autoupdate Filter Self Update class. | ||
| * sets up autoupdates for this GitHub-hosted plugin. | ||
| * | ||
| * @package wpcomsp | ||
| */ | ||
|
|
||
| if ( ! defined( 'ABSPATH' ) ) { | ||
| exit; // Exit if accessed directly. | ||
| } | ||
|
|
||
| class WPCOMSP_Blocks_Self_Update { | ||
|
|
||
| public static $instance; | ||
|
|
||
| /** | ||
| * Get instance of this class. | ||
| * | ||
| * @return WPCOMSP_Blocks_Self_Update | ||
| */ | ||
| public static function get_instance() { | ||
| if ( ! self::$instance ) { | ||
| self::$instance = new self(); | ||
| } | ||
|
|
||
| return self::$instance; | ||
| } | ||
|
|
||
| /** | ||
| * Initialize WordPress hooks | ||
| */ | ||
| public function hooks() { | ||
| add_filter( 'update_plugins_opsoasis.wpspecialprojects.com', array( $this, 'self_update' ), 10, 3 ); | ||
| } | ||
|
|
||
| /** | ||
| * Check for updates to this plugin | ||
| * | ||
| * @param array $update Array of update data. | ||
| * @param array $plugin_data Array of plugin data. | ||
| * @param string $plugin_file Path to plugin file. | ||
| * | ||
| * @return array|bool Array of update data or false if no update available. | ||
| */ | ||
| public function self_update( $update, array $plugin_data, string $plugin_file ) { | ||
| // Already completed update check elsewhere. | ||
| if ( ! empty( $update ) ) { | ||
| return $update; | ||
| } | ||
|
|
||
| $plugin_filename_parts = explode( '/', $plugin_file ); | ||
|
|
||
| // Ask opsoasis.mystagingwebsite.com if there's an update. | ||
| $response = wp_remote_get( | ||
| 'https://opsoasis.wpspecialprojects.com/wp-json/opsoasis-blocks-version-manager/v1/update-check', | ||
| array( | ||
| 'body' => array( | ||
| 'plugin' => $plugin_filename_parts[0], | ||
| 'version' => $plugin_data['Version'], | ||
| ), | ||
| ) | ||
| ); | ||
|
|
||
| // Bail if this plugin wasn't found on opsoasis.mystagingwebsite.com. | ||
| if ( 404 === wp_remote_retrieve_response_code( $response ) || 202 === wp_remote_retrieve_response_code( $response ) ) { | ||
| return $update; | ||
| } | ||
|
|
||
| $updated_version = wp_remote_retrieve_body( $response ); | ||
| $updated_array = json_decode( $updated_version, true ); | ||
|
|
||
| return array( | ||
| 'slug' => $updated_array['slug'], | ||
| 'version' => $updated_array['version'], | ||
| 'url' => $updated_array['package_url'], | ||
| 'package' => $updated_array['package_url'], | ||
| ); | ||
| } | ||
| } | ||
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,50 @@ | ||
| <?php | ||
| /** | ||
| * Plugin Name: Dynamic Shapes | ||
| * Description: Extends the core Group, Image, and Featured Image blocks with controls for adjusting corners to create unique shapes. | ||
| * Version: 0.1.0 | ||
| * Requires at least: 6.7 | ||
| * Requires PHP: 7.4 | ||
| * Author: Automattic Special Projects | ||
| * Author URI: https://wpspecialprojects.wordpress.com/ | ||
| * Update URI: https://opsoasis.wpspecialprojects.com/dynamic-shapes/ | ||
| * License: GPL-2.0-or-later | ||
| * License URI: https://www.gnu.org/licenses/gpl-2.0.html | ||
| * Text Domain: wpcomsp-dynamic-shapes | ||
| * | ||
| * @package wpcomsp-dynamic-shapes | ||
| */ | ||
|
|
||
| defined( 'ABSPATH' ) || exit; | ||
|
|
||
| define( 'WPCOMSP_DYNAMIC_SHAPES_DIR', plugin_dir_path( __FILE__ ) ); | ||
| define( 'WPCOMSP_DYNAMIC_SHAPES_URL', plugin_dir_url( __FILE__ ) ); | ||
|
|
||
| // Add the self update class if needed. | ||
| if ( ! class_exists( 'WPCOMSP_Blocks_Self_Update' ) ) { | ||
| require __DIR__ . '/classes/class-wpcomsp-blocks-self-update.php'; | ||
|
|
||
| $wpcomsp_blocks_self_update = WPCOMSP_Blocks_Self_Update::get_instance(); | ||
| $wpcomsp_blocks_self_update->hooks(); | ||
| } | ||
|
|
||
| /** | ||
| * Setup auto-updates from the monorepo. | ||
| * | ||
| * @param array $blocks Array of plugin files. | ||
| * | ||
| * @return array | ||
| */ | ||
| add_filter( | ||
| 'wpcomsp_installed_blocks', | ||
| function ( $blocks ) { | ||
| $blocks[] = 'dynamic-shapes'; | ||
|
|
||
| return $blocks; | ||
| } | ||
| ); | ||
|
|
||
| // Autoload all files in the includes directory. | ||
| foreach ( glob( __DIR__ . '/includes/*.php' ) as $wpcomsp_dynamic_shapes_filename ) { | ||
| include $wpcomsp_dynamic_shapes_filename; | ||
| } |
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.
Harden the self-update response handling.
If
wp_remote_get()returns aWP_Error, a non-JSON body, or a payload missing the expected keys, line 74 tries to read array offsets onnull, which triggers a fatal error during the update check. Guard the remote call and decode before dereferencing.📝 Committable suggestion
🤖 Prompt for AI Agents