Skip to content
Merged
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
2 changes: 1 addition & 1 deletion autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
function ( $class ) {
$namspaces = [
'Eighteen73\\Orbit\\' => __DIR__ . '/includes/classes/',
'Eighteen73\\Orbit\\Dependencies\\' => __DIR__ . '/includes/dependencies/',
'Eighteen73\\Orbit\\Dependencies\\' => __DIR__ . '/includes/lib/',
];
foreach ( $namspaces as $prefix => $base_dir ) {
$len = strlen( $prefix );
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"extra": {
"mozart": {
"dep_namespace": "Eighteen73\\Orbit\\Dependencies\\",
"dep_directory": "/includes/Dependencies/",
"classmap_directory": "/includes/classes/dependencies/",
"dep_directory": "/includes/lib/",
"classmap_directory": "/includes/classes/lib/",
"classmap_prefix": "Eighteen73_Orbit_",
"packages": [
"pelago/emogrifier"
Expand Down
123 changes: 123 additions & 0 deletions includes/classes/BlockEditor/Patterns.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php
/**
* Modification to patterns.
*
* @package Orbit
*/

namespace Eighteen73\Orbit\BlockEditor;

use Eighteen73\Orbit\Singleton;

/**
* Patterns class.
*/
class Patterns {

use Singleton;

/**
* Primary constructor
*
* @return void
*/
public function setup() {
if ( ! apply_filters( 'orbit_enable_disable_external_patterns', true ) ) {
return;
}

add_action( 'init', [ $this, 'remove_woocommerce_patterns' ], 15 );
add_filter( 'rest_dispatch_request', [ $this, 'filter_woocommerce_patterns_rest' ], 10, 4 );
}

/**
* Remove WooCommerce patterns early in the init process.
*
* @return void
*/
public function remove_woocommerce_patterns(): void {
$patterns = \WP_Block_Patterns_Registry::get_instance()->get_all_registered();

if ( ! empty( $patterns ) ) {
foreach ( $patterns as $pattern ) {
if ( $this->is_woocommerce_pattern( $pattern ) ) {
unregister_block_pattern( $pattern['name'] );
}
}
}
}

/**
* Filter WooCommerce patterns from REST API responses.
*
* @param mixed $dispatch_result Dispatch result, will be used if not empty.
* @param \WP_REST_Request $request Request used to generate the response.
* @param string $route Route matched for the request.
* @param array $handler Route handler used for the request.
* @return mixed
*/
public function filter_woocommerce_patterns_rest( $dispatch_result, $request, $route, $handler ) {
// Check if this is a block patterns request
if ( strpos( $route, '/wp/v2/block-patterns/patterns' ) !== 0 ) {
return $dispatch_result;
}

// If we already have a result, filter it
if ( ! empty( $dispatch_result ) && is_array( $dispatch_result ) ) {
return $this->filter_patterns_from_response( $dispatch_result );
}

return $dispatch_result;
}

/**
* Check if a pattern is a WooCommerce pattern.
*
* @param array $pattern The pattern data.
* @return bool
*/
private function is_woocommerce_pattern( array $pattern ): bool {
// Check by category
if ( ! empty( $pattern['categories'] ) && in_array( 'woo-commerce', $pattern['categories'], true ) ) {
return true;
}

// Check by pattern name/slug
$woo_prefixes = [
'woocommerce-blocks/',
'woocommerce/',
'woo/',
'wc-',
];

foreach ( $woo_prefixes as $prefix ) {
if ( strpos( $pattern['name'], $prefix ) === 0 ) {
return true;
}
}

return false;
}

/**
* Filter WooCommerce patterns from a REST response.
*
* @param array $response The response data.
* @return array
*/
private function filter_patterns_from_response( array $response ): array {
if ( isset( $response['data'] ) && is_array( $response['data'] ) ) {
$response['data'] = array_filter(
$response['data'],
function ( $pattern ) {
return ! $this->is_woocommerce_pattern( $pattern );
}
);

// Re-index the array to maintain proper JSON structure
$response['data'] = array_values( $response['data'] );
}

return $response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
* @package Orbit
*/

namespace Eighteen73\Orbit;
namespace Eighteen73\Orbit\Branding;

use Exception;
use Eighteen73\Orbit\Singleton;
use Eighteen73\Orbit\Environment;
use Eighteen73\Orbit\Utilities\Templates;
use Eighteen73\Orbit\Dependencies\Pelago\Emogrifier\CssInliner;

/**
Expand Down Expand Up @@ -262,7 +265,7 @@ public static function orbit_branded_emails_resolve_color( $color_value, $fallba
}
}

if ( $value ) {
if ( is_string( $value ) && $value !== '' ) {
return self::orbit_branded_emails_resolve_color( $value, $fallback );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
* @package Orbit
*/

namespace Eighteen73\Orbit;
namespace Eighteen73\Orbit\Media;

use Eighteen73\Orbit\Environment;
use Eighteen73\Orbit\Singleton;
use Roots\WPConfig\Config;
use Roots\WPConfig\Exceptions\UndefinedConfigKeyException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
* @package Orbit
*/

namespace Eighteen73\Orbit;
namespace Eighteen73\Orbit\Monitoring;

use Eighteen73\Orbit\Singleton;
use WP_REST_Request;

/**
Expand Down
26 changes: 0 additions & 26 deletions includes/classes/OtherFilters.php

This file was deleted.

29 changes: 29 additions & 0 deletions includes/classes/ThirdParty/WooCommerce.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* Modifications to WooCommerce.
*
* @package Orbit
*/

namespace Eighteen73\Orbit\ThirdParty;

use Eighteen73\Orbit\Singleton;

/**
* Modifications to WooCommerce.
*/
class WooCommerce {
use Singleton;

/**
* Run on init
*
* @return void
*/
public function setup() {

// Force WooCommerce tracking to always be disabled.
// This setting loads additional patterns from PTK.
add_filter( 'option_woocommerce_allow_tracking', '__return_false' );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
* @package Orbit
*/

namespace Eighteen73\Orbit;
namespace Eighteen73\Orbit\Utilities;

use Eighteen73\Orbit\Environment;
use Eighteen73\Orbit\Singleton;

/**
* This class is built upon BE Media from Production so all due credit to those authors.
Expand Down
12 changes: 6 additions & 6 deletions orbit.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Author URI: https://eighteen73.co.uk
* Text Domain: orbit
* Domain Path: /languages
* Version: 2.2.0
* Version: 2.2.1
* Update URI: https://github.com/eighteen73/orbit
*
* @package Orbit
Expand All @@ -29,7 +29,7 @@

DisallowIndexing\DisallowIndexing::instance()->setup();
Performance\Fast404::instance()->setup();

ThirdParty\WooCommerce::instance()->setup();

add_action(
'init',
Expand All @@ -45,9 +45,9 @@ function () {
Security\HideAuthor::instance()->setup();
Security\HideVersion::instance()->setup();
Security\RemoveHeadLinks::instance()->setup();
BrandedEmails::instance()->setup();
OtherFilters::instance()->setup();
HealthCheck::instance()->setup();
RemoteFiles::instance()->setup();
Branding\BrandedEmails::instance()->setup();
Monitoring\HealthCheck::instance()->setup();
Media\RemoteFiles::instance()->setup();
BlockEditor\Patterns::instance()->setup();
}
);
2 changes: 1 addition & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<!-- Scan all files in directory -->
<file>.</file>
<exclude-pattern type="relative">lib/packages/*</exclude-pattern>
<exclude-pattern type="relative">includes/Dependencies/*</exclude-pattern>
<exclude-pattern type="relative">includes/lib/*</exclude-pattern>

<!-- Scan only PHP files -->
<arg name="extensions" value="php"/>
Expand Down
2 changes: 2 additions & 0 deletions templates/branded-emails/email-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace Eighteen73\Orbit;

use Eighteen73\Orbit\Branding\BrandedEmails;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
Expand Down
2 changes: 2 additions & 0 deletions templates/branded-emails/email-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace Eighteen73\Orbit;

use Eighteen73\Orbit\Utilities\Templates;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
Expand Down