Skip to content
Draft
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
50 changes: 50 additions & 0 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Generate Documentation (main)

on:
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'

- name: Clear Composer Cache
run: composer clear-cache

- name: Install or Update Composer Dependencies
run: |
composer update bc-andreadao/wp-documentor --no-dev
composer update bc-andreadao/phpdocumentor-markdown --no-dev --with-all-dependencies

- name: Run shell script to generate documentation
run: ./generate-docs.sh

- name: Generate and push documentation
run: |
git clone https://$GITHUB_ACTOR:${{ secrets.ACCESS_TOKEN }}@github.com/bc-andreadao/bc-wordpress-reference.git
cd bc-wordpress-reference
git fetch origin
BRANCH_NAME="docs-$(date +'%Y-%m-%d_%H-%M-%S')"
git checkout main
git checkout -b $BRANCH_NAME
rsync -av --ignore-times $GITHUB_WORKSPACE/docs/ pages/
git config user.name "GitHub Actions"
git config user.email "actions@github.com"s
git add .
git commit -m "Update documentation from $(date +'%Y-%m-%d')" || echo "No changes to commit"
echo "Current branch: $(git branch --show-current)"
git push -v --set-upstream origin $BRANCH_NAME || {
echo "Push failed. Current git status:"
git status
echo "Remote branches:"
git branch -r
exit 1
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ pimple.json
.scssc
/node_modules/
phpdoc.json
vendor/*
.phpdoc/*
docs/*
composer.phar

# Packages #
############
Expand Down
22 changes: 22 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ By contributing to the Wordpress for BigCommerce plugin, you agree that your con
[How Can I Contribute?](#how-can-i-contribute)
* [Your First Code Contribution](#your-first-code-contribution)
* [Pull Requests](#pull-requests)
* [Documentation](#documentation)

[Styleguides](#styleguides)
* [Git Commit Messages](#git-commit-messages)
Expand All @@ -25,6 +26,27 @@ Unsure where to begin contributing? Check our [Community group](https://forum.bi
* Include screenshots and animated GIFs in your pull request whenever possible.
* End files with a newline.

### Documentation

The v1 release of the BC for Wordpress reference docs are hosted on https://bc-wordpress-reference.vercel.app/.

To add descriptions for classes and their methods, functions, or hooks, add a docblock to the appropriate file in the [src](https://github.com/bc-andreadao/bigcommerce-for-wordpress/tree/master/src/BigCommerce) folder.

The BC for Wordpress team will manually trigger the [Generation Documentation Github Action ](https://github.com/bc-andreadao/bigcommerce-for-wordpress/actions/workflows/doc.yml)workflow to regenerate the docs. The docs will be synced to a timestamped branch in the [bc-andreadao/bc-wordpress-reference](https://github.com/bc-andreadao/bc-wordpress-reference) repository, where your changes will be merged by a BC for Wordpress team member.

#### Testing

The Generate Documentation workflow parses docblocks using the following parsers:

* [bc-andreadao/wp-documentor](https://github.com/bc-andreadao/wp-documentor)
* [bc-andreadao/phpdocumentor-markdown](https://github.com/bc-andreadao/phpdocumentor-markdown)

To test the parsers, install docker and run the following command in your terminal:

`./generate-docs.sh`

This will generate a local `docs` folder with markdown files generated from the parsers. You can change the folders that the parses parse in the [generate-docs.sh](https://github.com/bc-andreadao/bigcommerce-for-wordpress/blob/master/generate-docs.sh) file.

## Styleguides

### Git Commit Messages
Expand Down
168 changes: 86 additions & 82 deletions bigcommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,92 +19,96 @@
define( 'BIGCOMMERCE_WP_OPTIMAL_VERSION', '5.8' );

if ( version_compare( PHP_VERSION, BIGCOMMERCE_PHP_MINIMUM_VERSION, '<' ) || version_compare( get_bloginfo( 'version' ), BIGCOMMERCE_WP_MINIMUM_VERSION, '<' ) ) {
add_action( 'admin_notices', function() {
$message = sprintf( esc_html__( 'BigCommerce requires PHP version %s+ and WP version %s+, plugin is currently NOT RUNNING.', 'bigcommerce' ), BIGCOMMERCE_PHP_OPTIMAL_VERSION, BIGCOMMERCE_WP_OPTIMAL_VERSION );
echo wp_kses_post( sprintf( '<div class="error">%s</div>', wpautop( $message ) ) );
} );
add_action( 'admin_notices', function() {
$message = sprintf( esc_html__( 'BigCommerce requires PHP version %s+ and WP version %s+, plugin is currently NOT RUNNING.', 'bigcommerce' ), BIGCOMMERCE_PHP_OPTIMAL_VERSION, BIGCOMMERCE_WP_OPTIMAL_VERSION );
echo wp_kses_post( sprintf( '<div class="error">%s</div>', wpautop( $message ) ) );
});

return;
return;
} elseif ( version_compare( PHP_VERSION, BIGCOMMERCE_PHP_OPTIMAL_VERSION, '<' ) || version_compare( get_bloginfo( 'version' ), BIGCOMMERCE_WP_OPTIMAL_VERSION, '<' ) ) {
add_action( 'admin_notices', function() {
$message = sprintf( esc_html__( 'BigCommerce requires PHP version %s+ and WP version %s+', 'bigcommerce' ), BIGCOMMERCE_PHP_OPTIMAL_VERSION, BIGCOMMERCE_WP_OPTIMAL_VERSION );
echo wp_kses_post( sprintf( '<div class="notice">%s</div>', wpautop( $message ) ) );
} );
add_action( 'admin_notices', function() {
$message = sprintf( esc_html__( 'BigCommerce requires PHP version %s+ and WP version %s+', 'bigcommerce' ), BIGCOMMERCE_PHP_OPTIMAL_VERSION, BIGCOMMERCE_WP_OPTIMAL_VERSION );
echo wp_kses_post( sprintf( '<div class="notice">%s</div>', wpautop( $message ) ) );
});
}

if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/vendor/autoload.php';
}

register_activation_hook( __FILE__, [ \BigCommerce\Plugin::class, 'activate' ] );

// Start the plugin
add_action( 'plugins_loaded', 'bigcommerce_init', 2, 0 );

/**
* Fires after the plugin has initialized.
*
* @param \BigCommerce\Plugin $plugin The global instance of the plugin controller.
* @param \Pimple\Container $container The plugin's dependency injection container.
* @return \BigCommerce\Plugin
*/
function bigcommerce_init() {
// Don't load on frontend for non-active channel status
$channel_status = bigcommerce_get_primary_channel_status();
$is_front_page = ! defined( 'WP_CLI' ) && ! is_admin() && $channel_status !== null;
$channel_status = bigcommerce_get_primary_channel_status();
$is_front_page = ! defined( 'WP_CLI' ) && ! is_admin() && $channel_status !== null;
// Don't load on frontend for non-active channel status
if ( $is_front_page && ! in_array( $channel_status, [ BC_Status::STATUS_ACTIVE, BC_Status::STATUS_PRE_LAUNCH ] ) ) {
return;
}

if ( ! defined( 'DOING_CRON' ) && $is_front_page && $channel_status === BC_Status::STATUS_PRE_LAUNCH && ! current_user_can( 'publish_posts' ) ) {
handle_404_redirect_in_prelaunch();
return;
}
$container = new \Pimple\Container( [ 'plugin_file' => __FILE__ ] );
$plugin = \BigCommerce\Plugin::instance( $container );
$plugin->init();
if ( $is_front_page && ! in_array( $channel_status, [ BC_Status::STATUS_ACTIVE, BC_Status::STATUS_PRE_LAUNCH ] ) ) {
return;
}

if ( ! defined( 'DOING_CRON' ) && $is_front_page && $channel_status === BC_Status::STATUS_PRE_LAUNCH && ! current_user_can( 'publish_posts' ) ) {
handle_404_redirect_in_prelaunch();
return;
}
$container = new \Pimple\Container( [ 'plugin_file' => __FILE__ ] );
$plugin = \BigCommerce\Plugin::instance( $container );
$plugin->init();

/**
* Fires after the plugin has initialized
*
* @param \BigCommerce\Plugin $plugin The global instance of the plugin controller
* @param \Pimple\Container $container The plugin's dependency injection container
*/
do_action( 'bigcommerce/init', $plugin, $container );
do_action( 'bigcommerce/init', $plugin, $container );

return $plugin;
return $plugin;
}

function handle_404_redirect_in_prelaunch() {
// We have to do that here because we don't initialize the plugin in case of prelaunch status
add_filter( 'pre_handle_404', function ( $preempt ) {
if ( is_admin() || ! ( is_page() && is_main_query() ) ) {
return $preempt;
}

$plugin_pages = [
\BigCommerce\Pages\Account_Page::SLUG,
\BigCommerce\Pages\Address_Page::SLUG,
\BigCommerce\Pages\Cart_Page::SLUG,
\BigCommerce\Pages\Check_Balance_Page::SLUG,
\BigCommerce\Pages\Checkout_Complete_Page::SLUG,
\BigCommerce\Pages\Checkout_Page::SLUG,
\BigCommerce\Pages\Login_Page::SLUG,
\BigCommerce\Pages\Gift_Certificate_Page::SLUG,
\BigCommerce\Pages\Orders_Page::SLUG,
\BigCommerce\Pages\Registration_Page::SLUG,
\BigCommerce\Pages\Shipping_Returns_Page::SLUG,
\BigCommerce\Pages\Wishlist_Page::SLUG
];

if ( ! in_array( get_queried_object()->post_name, $plugin_pages ) ) {
return $preempt;
}

global $wp_query;
$wp_query->set_404();
status_header( 404 );
nocache_headers();

return '';
}, 10, 1 );

add_filter( 'pre_handle_404', function ( $preempt ) {
if ( is_admin() || ! ( is_page() && is_main_query() ) ) {
return $preempt;
}

$plugin_pages = [
\BigCommerce\Pages\Account_Page::SLUG,
\BigCommerce\Pages\Address_Page::SLUG,
\BigCommerce\Pages\Cart_Page::SLUG,
\BigCommerce\Pages\Check_Balance_Page::SLUG,
\BigCommerce\Pages\Checkout_Complete_Page::SLUG,
\BigCommerce\Pages\Checkout_Page::SLUG,
\BigCommerce\Pages\Login_Page::SLUG,
\BigCommerce\Pages\Gift_Certificate_Page::SLUG,
\BigCommerce\Pages\Orders_Page::SLUG,
\BigCommerce\Pages\Registration_Page::SLUG,
\BigCommerce\Pages\Shipping_Returns_Page::SLUG,
\BigCommerce\Pages\Wishlist_Page::SLUG
];

if ( ! in_array( get_queried_object()->post_name, $plugin_pages ) ) {
return $preempt;
}

global $wp_query;
$wp_query->set_404();
status_header( 404 );
nocache_headers();

return '';
}, 10, 1 );
}

function bigcommerce() {
Expand All @@ -125,39 +129,39 @@ function bigcommerce() {
* @return mixed The found value. false if not found.
*/
function bigcommerce_get_env( $key ) {
$value = getenv( $key, true ) ?: getenv( $key );
if ( $value === false && defined( $key ) ) {
$value = constant( $key );
}
$value = getenv( $key, true ) ?: getenv( $key );
if ( $value === false && defined( $key ) ) {
$value = constant( $key );
}

return $value;
return $value;
}

/**
* Get the status of the primary channel
* Get the status of the primary channel.
*
* @return mixed The found value. null if not found.
*/
function bigcommerce_get_primary_channel_status() {
$cache_key = 'bigcommerce_primary_channel_status';
$status = wp_cache_get( $cache_key );
if ( empty( $status ) ) {
global $wpdb;

$sql = "SELECT tm.meta_value
FROM {$wpdb->termmeta} tm
INNER JOIN {$wpdb->termmeta} tm2 ON tm2.term_id=tm.term_id
WHERE tm.meta_key=%s AND tm2.meta_key=%s AND tm2.meta_value=%s";

$status = $wpdb->get_var( $wpdb->prepare(
$sql,
BC_Status::STATUS,
\BigCommerce\Taxonomies\Channel\Channel::STATUS,
\BigCommerce\Taxonomies\Channel\Channel::STATUS_PRIMARY
) );

wp_cache_set( $cache_key, $status );
}
$cache_key = 'bigcommerce_primary_channel_status';
$status = wp_cache_get( $cache_key );
if ( empty( $status ) ) {
global $wpdb;

$sql = "SELECT tm.meta_value
FROM {$wpdb->termmeta} tm
INNER JOIN {$wpdb->termmeta} tm2 ON tm2.term_id=tm.term_id
WHERE tm.meta_key=%s AND tm2.meta_key=%s AND tm2.meta_value=%s";

$status = $wpdb->get_var( $wpdb->prepare(
$sql,
BC_Status::STATUS,
\BigCommerce\Taxonomies\Channel\Channel::STATUS,
\BigCommerce\Taxonomies\Channel\Channel::STATUS_PRIMARY
) );

wp_cache_set( $cache_key, $status );
}

return $status;
}
15 changes: 10 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "GPLv2",
"config": {
"platform": {
"php": "8.1"
"php": "8.2"
},
"vendor-dir": "vendor",
"sort-packages": true,
Expand All @@ -21,17 +21,22 @@
"moderntribe/bigcommerce-api-php-v3": "2.3.4",
"monolog/monolog": "1.24.0",
"pimple/pimple": "3.2.3",
"vlucas/phpdotenv": "2.4.0"
"vlucas/phpdotenv": "2.4.0",
"bc-andreadao/wp-documentor": "dev-main",
"bc-andreadao/phpdocumentor-markdown": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "git@github.com:moderntribe/bigcommerce-api-php-v3.git",
"no-api": true
"url": "https://github.com/bordoni/phpass.git"
},
{
"type": "vcs",
"url": "git@github.com:bordoni/phpass.git"
"url": "https://github.com/bc-andreadao/wp-documentor.git"
},
{
"type": "vcs",
"url": "https://github.com/bc-andreadao/phpDocumentor-markdown.git"
}
],
"autoload": {
Expand Down
Loading