Skip to content

Commit

Permalink
fix: Compatibility tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
seebeen committed Sep 22, 2024
1 parent 6c6043c commit 5e8315c
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 52 deletions.
38 changes: 26 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
name: Release
name: CI
on:
workflow_dispatch:
push:
branches:
- master
- 1.x

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.OBLAK_BOT_TOKEN }}
- name: Publish a composer package
uses: better-php-actions/publish-composer-package@v1
token: ${{ secrets.OBLAKBOT_PAT }}
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
id: gpg
with:
package_slug: "woocommerce-utils"
package_name: "WooCommerce Utils"
with_gpg: true
gpg_key: ${{ secrets.GPG_PRIVATE_KEY }}
gpg_passphrase: ${{ secrets.GPG_PASSPHRASE }}
release_token: ${{ secrets.OBLAK_BOT_TOKEN }}
gpg_private_key: ${{ secrets.OBLAKBOT_GPG_KEY }}
passphrase: ${{ secrets.OBLAKBOT_GPG_PASS }}
git_config_global: true
git_user_signingkey: true
git_commit_gpgsign: true
git_push_gpgsign: false
- name: Semantic Release
uses: cycjimmy/semantic-release-action@v4
with:
extra_plugins: |
@semantic-release/github
@semantic-release/exec
env:
GIT_AUTHOR_NAME: ${{ steps.gpg.outputs.name}}
GIT_AUTHOR_EMAIL: ${{ steps.gpg.outputs.email}}
GIT_COMMITTER_NAME: ${{ steps.gpg.outputs.name}}
GIT_COMMITTER_EMAIL: ${{ steps.gpg.outputs.email}}
GITHUB_TOKEN: ${{ secrets.OBLAKBOT_PAT }}
28 changes: 28 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"branches": [
"master",
"1.x"
],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
[
"@semantic-release/exec",
{
"prepareCmd": "zip -qr '/tmp/release.zip' ./src README.md composer.json"
}
],
[
"@semantic-release/github",
{
"assets": [
{
"path": "/tmp/release.zip",
"name": "woocommerce-utils.${nextRelease.version}.zip",
"label": "WooCommerce Utils v${nextRelease.version}"
}
]
}
]
]
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
],
"require": {
"php": ">= 8.0",
"oblak/wp-polyfills": "^1.1"
"x-wp/helper-functions": "^1.9",
"x-wp/helper-traits": "^1.9"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.31",
Expand Down
103 changes: 74 additions & 29 deletions composer.lock

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

16 changes: 6 additions & 10 deletions src/Product/Base_Product_Type_Extender.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ public function add_custom_product_options( $options ) {
$options = \array_merge(
$options,
\wp_array_flatmap(
\array_values( $this->get_product_options() ),
static fn( $opt ) => array(
$opt['key'] => array(
'default' => \wc_bool_to_string( $opt['default'] ?? false ),
Expand All @@ -167,10 +166,11 @@ public function add_custom_product_options( $options ) {
),
),
),
\array_values( $this->get_product_options() ),
),
);

return \wp_array_diff_assoc( $options, $this->options_to_remove );
return \xwp_array_diff_assoc( $options, ...$this->options_to_remove );
}

/**
Expand All @@ -183,7 +183,6 @@ public function add_product_type_data_tabs( $tabs ) {
return \array_merge(
$tabs,
\wp_array_flatmap(
$this->get_product_tabs(),
static fn( $tab ) => array(
( $tab['key'] ?? $tab['id'] ) => array(
'class' => \array_map( static fn( $t ) => "show_if_{$t}", $tab['for'] ),
Expand All @@ -192,6 +191,7 @@ public function add_product_type_data_tabs( $tabs ) {
'target' => "{$tab['id']}_product_data",
),
),
$this->get_product_tabs(),
),
);
}
Expand Down Expand Up @@ -221,16 +221,12 @@ public function add_product_type_data_panels() {
public function set_custom_options_status( $product ) {
foreach ( $this->get_product_options() as $slug => $option ) {

//phpcs:disable WordPress.Security.NonceVerification.Missing
$option_status = \wc_bool_to_string(
'on' === \wc_clean( \wp_unslash( $_POST[ "_{$slug}" ] ?? 'no' ) ),
);
//phpcs:enable
$status = \wc_bool_to_string( 'on' === \xwp_fetch_post_var( "_{$slug}", 'no' ) );

if ( ( $option['is_prop'] ?? false ) || \is_callable( array( $product, "set_{$slug}" ) ) ) {
$product->{"set_{$slug}"}( $option_status );
$product->{"set_{$slug}"}( $status );
} else {
$product->update_meta_data( "_{$slug}", $option_status );
$product->update_meta_data( "_{$slug}", $status );
}
}

Expand Down

0 comments on commit 5e8315c

Please sign in to comment.