shop changes

This commit is contained in:
2025-06-25 16:04:19 -07:00
parent 8d33ce2dc7
commit b0635919b1
30 changed files with 550 additions and 144 deletions

View File

@@ -0,0 +1,20 @@
<?php
namespace Actions;
use ofc\RadAction;
class WooCommerceAfterContent extends RadAction
{
protected string $hookName = "woocommerce_after_main_content";
protected int $priority = 50;
public function callback()
{
if (is_product()) {
return;
}
echo site()->render('woocommerce-after-content');
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace Actions;
use ofc\RadAction;
class WooCommerceAfterProductSummary extends RadAction
{
protected string $hookName = "woocommerce_after_single_product_summary";
protected int $priority = 0;
public function callback()
{
echo site()->render('woocommerce-before-content');
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Actions;
use ofc\RadAction;
class WooCommerceBeforeProductSummary extends RadAction
{
protected string $hookName = "woocommerce_before_single_product_summary";
protected int $priority = 0;
public function callback()
{
echo site()->render('woocommerce-before-content', [
"additionalTopLevelClass" => "single-product-top",
]);
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace Actions;
use ofc\RadAction;
class WooCommerceCategoryLayout extends RadAction
{
protected string $hookName = "woocommerce_before_main_content";
protected int $priority = 5;
public function callback()
{
if (!is_product_category()) {
return;
}
echo site()->render("shop-category-slice", site()->getQueriedObject(null, [
"title",
"description",
"thumbnail",
"url",
"acf.intro_headline",
"acf.intro_content",
]));
$type = site()->getQueriedObject(null, ['display_type']);
if ($type === "") {
$type = "products";
} else {
$type = $type["display_type"];
}
if ($type === "both" || $type === "subcategories") {
$childCats = site()->getQueriedObject(null, ["children.url,thumbnail,title,count"]);
echo site()->render("shop-sub-categories", $childCats);
}
if ($type === "both" || $type === "products") {
// die("why?");
}
echo site()->render('woocommerce-before-content');
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Actions;
use ofc\RadAction;
class WooCommerceCategoryLayoutHideProducts extends RadAction
{
protected string $hookName = "woocommerce_before_main_content";
public function callback()
{
if (!is_product_category()) {
return;
}
$type = site()->getQueriedObject(null, ['display_type']);
if ($type === "") {
$type = "products";
} else {
$type = $type["display_type"];
}
if ($type != "subcategories") {
return;
}
echo site()->render("hideProducts");
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace Actions;
use ofc\RadAction;
class WooCommerceCleanup extends RadAction
{
protected string $hookName = "init";
protected int $priority = 5;
public function callback()
{
remove_all_actions('woocommerce_before_shop_loop_item');
remove_all_actions('woocommerce_before_shop_loop_item_title');
remove_all_actions('woocommerce_shop_loop_item_title');
remove_all_actions('woocommerce_after_shop_loop_item_title');
remove_all_actions('woocommerce_after_shop_loop_item');
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace Actions;
use ofc\RadAction;
class WooCommerceProductSummary extends RadAction
{
protected string $hookName = "woocommerce_single_product_summary";
public function callback()
{
echo site()->render('woocommerce-after-content');
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Actions;
use Helpers\McCansHelpers;
use ofc\RadAction;
class WooCommerceProductTile extends RadAction
{
protected string $hookName = "woocommerce_shop_loop_item_title";
protected bool $wrapInit = true;
public function callback()
{
global $product;
$data = site()->getPost($product->id, [
"url",
"id",
"title",
"thumbnail",
"woocommerce.price",
"woocommerce.attribute.msrp",
"woocommerce.cartUrl",
"woocommerce.sku",
]);
$data["savings"] = McCansHelpers::calcDifference($data["price"], $data["msrp"]);
echo site()->render("product-tile", $data);
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Actions;
use ofc\RadAction;
class WooCommerceShopLayout extends RadAction
{
protected string $hookName = "woocommerce_before_main_content";
protected int $priority = 5;
public function callback()
{
if (!is_shop()) {
return;
}
// shop page
echo site()->render("shop-top", site()->getPost(wc_get_page_id('shop'), [
"headline",
"intro_text",
"thumbnail",
]));
echo site()->render('woocommerce-before-content');
}
}

View File

@@ -80,6 +80,7 @@ return [
"renderCallout" => \Helpers\McCansHelpers::renderCallout(),
"productBox" => \Helpers\McCansHelpers::searchResultBox('product'),
"pageBox" => \Helpers\McCansHelpers::searchResultBox('page'),
"categoryBox" => \Helpers\McCansHelpers::categoryBox(),
"usd" => \Helpers\McCansHelpers::usd(),
"fourColContent" => \Helpers\McCansHelpers::fourColContent(),
],
@@ -121,21 +122,6 @@ return [
],
"actions" => [
"woocommerce_before_single_product_summary" => [function () {
echo site()->render('woocommerce-before-content', [
"additionalTopLevelClass" => "single-product-top",
]);
}, 0],
"woocommerce_single_product_summary" => function () {
echo site()->render('woocommerce-after-content');
},
[
"hook" => "woocommerce_after_single_product_summary",
"priority" => 0,
"callback" => function () {
echo site()->render('woocommerce-before-content');
},
],
"woocommerce_after_single_product" => function () {
echo site()->render('woocommerce-after-content');
},
@@ -159,75 +145,5 @@ return [
]);
}
],
"woocommerce_before_main_content" => [function () {
// skip this for individual products
if (is_product()) {
return;
}
// shop page
if (is_shop()) {
echo site()->render("shop-top", site()->getPost(wc_get_page_id('shop'), [
"headline",
"intro_text",
"thumbnail",
]));
echo site()->render('woocommerce-before-content');
return;
}
if (is_product_category()) {
echo site()->render("shop-category-slice", site()->getQueriedObject(null, [
"title",
"description",
"thumbnail",
"url",
"acf.intro_headline",
"acf.intro_content",
]));
echo site()->render('woocommerce-before-content');
return;
}
echo site()->render('woocommerce-before-content');
}, 5],
[
"hook" => "woocommerce_after_main_content",
"callback" => function () {
// skip this for individual products
if (is_product()) {
return;
}
echo site()->render('woocommerce-after-content');
},
"priority" => 50,
],
"init" => function () {
remove_all_actions('woocommerce_before_shop_loop_item');
remove_all_actions('woocommerce_before_shop_loop_item_title');
remove_all_actions('woocommerce_shop_loop_item_title');
remove_all_actions('woocommerce_after_shop_loop_item_title');
remove_all_actions('woocommerce_after_shop_loop_item');
add_action('woocommerce_shop_loop_item_title', function () {
global $product;
$data = site()->getPost($product->id, [
"url",
"id",
"title",
"thumbnail",
"woocommerce.price",
"woocommerce.attribute.msrp",
"woocommerce.cartUrl",
"woocommerce.sku",
]);
$data["savings"] = McCansHelpers::calcDifference($data["price"], $data["msrp"]);
echo site()->render("product-tile", $data);
});
}
],
];

117
dist/app.css vendored
View File

@@ -12327,7 +12327,7 @@ input, label, textarea {
.top-bar a.account-button {
border: 0;
text-transform: uppercase;
color: #ae1716;
color: #c80000;
font-weight: bold;
background: transparent;
text-decoration: none;
@@ -12342,16 +12342,31 @@ input, label, textarea {
}
.main-nav {
z-index: 3;
padding: 2rem 0;
position: relative;
z-index: 2;
}
.main-nav .logo-wrapper {
.shop-nav {
z-index: 2;
padding: 1rem 0;
}
.shop-nav #menu-shop-navigation {
justify-content: center;
width: 100%;
}
.shop-nav .menu-shop-navigation-container {
width: 100%;
}
.main-nav, .shop-nav {
position: relative;
}
.main-nav .logo-wrapper, .shop-nav .logo-wrapper {
max-width: 400px;
width: 20%;
}
@media (max-width: 991.98px) {
.main-nav .logo-wrapper {
.main-nav .logo-wrapper, .shop-nav .logo-wrapper {
width: 100%;
display: flex;
justify-content: space-between;
@@ -12359,69 +12374,69 @@ input, label, textarea {
gap: 3rem;
align-items: center;
}
.main-nav .logo-wrapper img {
.main-nav .logo-wrapper img, .shop-nav .logo-wrapper img {
max-width: 250px;
}
.main-nav .logo-wrapper a {
.main-nav .logo-wrapper a, .shop-nav .logo-wrapper a {
color: #000;
}
.main-nav .logo-wrapper svg {
.main-nav .logo-wrapper svg, .shop-nav .logo-wrapper svg {
width: 50px;
height: 50px;
}
}
@media (max-width: 575.98px) {
.main-nav .logo-wrapper {
.main-nav .logo-wrapper, .shop-nav .logo-wrapper {
gap: 1rem !important;
}
}
@media (min-width: 992px) {
.main-nav .logo-wrapper #mobile-nav-toggle {
.main-nav .logo-wrapper #mobile-nav-toggle, .shop-nav .logo-wrapper #mobile-nav-toggle {
display: none;
}
}
.main-nav .logo-wrapper #mobile-nav-toggle svg:first-of-type {
.main-nav .logo-wrapper #mobile-nav-toggle svg:first-of-type, .shop-nav .logo-wrapper #mobile-nav-toggle svg:first-of-type {
display: block;
}
.main-nav .logo-wrapper #mobile-nav-toggle svg:last-of-type {
.main-nav .logo-wrapper #mobile-nav-toggle svg:last-of-type, .shop-nav .logo-wrapper #mobile-nav-toggle svg:last-of-type {
display: none;
}
.mobile-nav-open .main-nav .logo-wrapper #mobile-nav-toggle svg:first-of-type {
.mobile-nav-open .main-nav .logo-wrapper #mobile-nav-toggle svg:first-of-type, .mobile-nav-open .shop-nav .logo-wrapper #mobile-nav-toggle svg:first-of-type {
display: none;
}
.mobile-nav-open .main-nav .logo-wrapper #mobile-nav-toggle svg:last-of-type {
.mobile-nav-open .main-nav .logo-wrapper #mobile-nav-toggle svg:last-of-type, .mobile-nav-open .shop-nav .logo-wrapper #mobile-nav-toggle svg:last-of-type {
display: block;
}
.main-nav .logo-wrapper img {
.main-nav .logo-wrapper img, .shop-nav .logo-wrapper img {
width: 100%;
}
.main-nav nav.main-nav {
.main-nav nav.main-nav, .main-nav nav.shop-nav, .shop-nav nav.main-nav, .shop-nav nav.shop-nav {
display: none;
width: 100%;
}
.mobile-nav-open .main-nav nav.main-nav {
.mobile-nav-open .main-nav nav.main-nav, .mobile-nav-open .main-nav nav.shop-nav, .mobile-nav-open .shop-nav nav.main-nav, .mobile-nav-open .shop-nav nav.shop-nav {
display: flex;
flex-direction: column;
}
@media (min-width: 992px) {
.main-nav nav.main-nav {
.main-nav nav.main-nav, .main-nav nav.shop-nav, .shop-nav nav.main-nav, .shop-nav nav.shop-nav {
display: flex;
width: auto;
}
}
.main-nav .menu-main-menu-container {
.main-nav .menu-main-menu-container, .main-nav .menu-shop-navigation-container, .shop-nav .menu-main-menu-container, .shop-nav .menu-shop-navigation-container {
display: flex;
align-items: center;
}
@media (max-width: 991.98px) {
.main-nav .menu-main-menu-container {
.main-nav .menu-main-menu-container, .main-nav .menu-shop-navigation-container, .shop-nav .menu-main-menu-container, .shop-nav .menu-shop-navigation-container {
width: 100%;
}
.main-nav .menu-main-menu-container > ul {
.main-nav .menu-main-menu-container > ul, .main-nav .menu-shop-navigation-container > ul, .shop-nav .menu-main-menu-container > ul, .shop-nav .menu-shop-navigation-container > ul {
width: 100%;
}
}
.main-nav #menu-main-menu {
.main-nav #menu-main-menu, .main-nav #menu-shop-navigation, .shop-nav #menu-main-menu, .shop-nav #menu-shop-navigation {
display: flex;
margin: 0;
padding: 0;
@@ -12429,20 +12444,20 @@ input, label, textarea {
gap: 1rem;
}
@media (max-width: 991.98px) {
.main-nav #menu-main-menu {
.main-nav #menu-main-menu, .main-nav #menu-shop-navigation, .shop-nav #menu-main-menu, .shop-nav #menu-shop-navigation {
flex-direction: column;
}
}
.main-nav #menu-main-menu a {
.main-nav #menu-main-menu a, .main-nav #menu-shop-navigation a, .shop-nav #menu-main-menu a, .shop-nav #menu-shop-navigation a {
text-transform: uppercase;
color: #000;
text-decoration: none;
}
.main-nav #menu-main-menu > li {
.main-nav #menu-main-menu > li, .main-nav #menu-shop-navigation > li, .shop-nav #menu-main-menu > li, .shop-nav #menu-shop-navigation > li {
position: relative;
}
@media (min-width: 1200px) {
.main-nav #menu-main-menu > li:hover > ul {
.main-nav #menu-main-menu > li:hover > ul, .main-nav #menu-shop-navigation > li:hover > ul, .shop-nav #menu-main-menu > li:hover > ul, .shop-nav #menu-shop-navigation > li:hover > ul {
display: block;
position: absolute;
top: 100%;
@@ -12453,7 +12468,7 @@ input, label, textarea {
padding: 10px 15px;
transform: translate(-5px, -5px);
}
.main-nav #menu-main-menu > li:hover > ul li a {
.main-nav #menu-main-menu > li:hover > ul li a, .main-nav #menu-shop-navigation > li:hover > ul li a, .shop-nav #menu-main-menu > li:hover > ul li a, .shop-nav #menu-shop-navigation > li:hover > ul li a {
padding-top: 5px;
padding-bottom: 5px;
display: inline-block;
@@ -12461,25 +12476,25 @@ input, label, textarea {
}
}
@media (max-width: 991.98px) {
.main-nav #menu-main-menu > li.children-showing ul {
.main-nav #menu-main-menu > li.children-showing ul, .main-nav #menu-shop-navigation > li.children-showing ul, .shop-nav #menu-main-menu > li.children-showing ul, .shop-nav #menu-shop-navigation > li.children-showing ul {
display: flex;
flex-direction: column;
list-style-type: none;
}
.main-nav #menu-main-menu > li.children-showing ul li {
.main-nav #menu-main-menu > li.children-showing ul li, .main-nav #menu-shop-navigation > li.children-showing ul li, .shop-nav #menu-main-menu > li.children-showing ul li, .shop-nav #menu-shop-navigation > li.children-showing ul li {
position: relative;
}
.main-nav #menu-main-menu > li.children-showing ul a {
.main-nav #menu-main-menu > li.children-showing ul a, .main-nav #menu-shop-navigation > li.children-showing ul a, .shop-nav #menu-main-menu > li.children-showing ul a, .shop-nav #menu-shop-navigation > li.children-showing ul a {
width: 100%;
}
.main-nav #menu-main-menu > li.children-showing .toggle-sub-nav {
.main-nav #menu-main-menu > li.children-showing .toggle-sub-nav, .main-nav #menu-shop-navigation > li.children-showing .toggle-sub-nav, .shop-nav #menu-main-menu > li.children-showing .toggle-sub-nav, .shop-nav #menu-shop-navigation > li.children-showing .toggle-sub-nav {
transform: rotate(180deg);
}
}
.main-nav #menu-main-menu ul {
.main-nav #menu-main-menu ul, .main-nav #menu-shop-navigation ul, .shop-nav #menu-main-menu ul, .shop-nav #menu-shop-navigation ul {
display: none;
}
.main-nav .toggle-sub-nav {
.main-nav .toggle-sub-nav, .shop-nav .toggle-sub-nav {
width: 16px;
height: 16px;
background-image: url("/wp-content/themes/mccans-theme/assets/chevron-down.svg");
@@ -12490,7 +12505,7 @@ input, label, textarea {
background-color: transparent;
}
@media (max-width: 991.98px) {
.main-nav .toggle-sub-nav {
.main-nav .toggle-sub-nav, .shop-nav .toggle-sub-nav {
width: 30px;
height: 30px;
position: absolute;
@@ -12539,7 +12554,7 @@ footer.site-footer nav#social-nav ul a {
}
footer.site-footer nav#social-nav ul a:hover {
background-color: #fff;
color: #ae1716;
color: #c80000;
}
footer.site-footer .logo-col {
max-width: 336px;
@@ -12695,7 +12710,7 @@ footer.sub-footer {
font-size: 20px;
}
.testimonials-section .testimonials .slick-dots li.slick-active button:before {
color: #ae1716;
color: #c80000;
}
.testimonials-section .testimonials .testimonial {
background: #fff;
@@ -13062,11 +13077,17 @@ div.product-tile a.learn-more, div.page-tile a.learn-more {
.page-tile h2, .page-tile .h2 {
text-align: left !important;
font-size: 32px !important;
line-height: 37px !important;
font-size: 24px !important;
line-height: 30px !important;
text-transform: uppercase;
margin: 1rem 0;
}
@media (min-width: 1200px) {
.page-tile h2, .page-tile .h2 {
font-size: 32px !important;
line-height: 37px !important;
}
}
.category-slice-top {
background-color: #f2f2f2;
@@ -13158,7 +13179,7 @@ div.product-tile a.learn-more, div.page-tile a.learn-more {
height: 500px;
}
.post-type-archive-location .location-tile h2, .post-type-archive-location .location-tile .h2 {
color: #ae1716;
color: #c80000;
text-transform: uppercase;
margin-bottom: 0;
}
@@ -13206,3 +13227,21 @@ div.product-tile a.learn-more, div.page-tile a.learn-more {
.search-results .tile-wrapper {
margin-bottom: 1.5rem;
}
.category-sub-cats-wrapper .sub-cats {
flex-wrap: wrap;
margin-top: 2rem;
}
.category-sub-cats-wrapper .sub-cats .page-tile {
width: 100%;
}
@media (min-width: 768px) {
.category-sub-cats-wrapper .sub-cats .page-tile {
width: calc(50% - 0.5rem);
}
}
@media (min-width: 992px) {
.category-sub-cats-wrapper .sub-cats .page-tile {
width: calc(25% - 0.75rem);
}
}

View File

@@ -1,4 +1,4 @@
{
"/app.js": "/app.js?id=8af0c9c0d989b79afe124f8138dc1a63",
"/app.css": "/app.css?id=830df460c7c9284d57346827424337f9"
"/app.css": "/app.css?id=a881c23833f0893c65814ff00ee9ff6e"
}

View File

@@ -8,5 +8,6 @@
echo site()->render("header", [
"accountHref" => get_permalink(73),
"menu" => site()->renderMenu("main-nav"),
"shopMenu" => site()->renderMenu("shop-nav"),
"searchTerm" => $_GET["s"] ?? "",
]);

View File

@@ -81,6 +81,15 @@ class McCansHelpers
};
}
public static function categoryBox()
{
return function ($template, $context, $args, $source) {
$stuff = $context->get($args);
return site()->render("page-tile", $stuff);
};
}
public static function renderBlock()
{
return function ($template, $context, $args, $source) {

View File

@@ -31,3 +31,5 @@
@import "locations";
@import "location";
@import "search";
@import "woocommerce-changes";

View File

@@ -65,7 +65,7 @@
&.slick-active {
button {
&:before {
color: $c-red;
color: $c-brightRed;
}
}
}

View File

@@ -45,7 +45,7 @@ footer.site-footer {
&:hover {
background-color: $c-white;
color: $c-red;
color: $c-brightRed;
}
}
}

View File

@@ -15,7 +15,7 @@
a.account-button {
border: 0;
text-transform: uppercase;
color: $c-red;
color: $c-brightRed;
font-weight: bold;
background: transparent;
text-decoration: none;
@@ -30,9 +30,26 @@
}
.main-nav {
z-index: 3;
padding: 2rem 0;
position: relative;
}
.shop-nav {
z-index: 2;
padding: 1rem 0;
#menu-shop-navigation {
justify-content: center;
width: 100%;
}
.menu-shop-navigation-container {
width: 100%;
}
}
.main-nav, .shop-nav {
position: relative;
.logo-wrapper {
max-width: 400px;
@@ -91,7 +108,7 @@
}
}
nav.main-nav {
nav.main-nav, nav.shop-nav {
display: none;
width: 100%;
@@ -106,7 +123,7 @@
}
}
.menu-main-menu-container {
.menu-main-menu-container, .menu-shop-navigation-container {
display: flex;
align-items: center;
@@ -119,7 +136,7 @@
}
}
#menu-main-menu {
#menu-main-menu, #menu-shop-navigation {
display: flex;
margin: 0;
padding: 0;

View File

@@ -32,7 +32,7 @@
}
h2 {
color: $c-red;
color: $c-brightRed;
text-transform: uppercase;
margin-bottom: 0;
}

View File

@@ -134,9 +134,14 @@ div.product-tile, div.page-tile {
h2 {
@extend .montserrat;
text-align: left !important;
font-size: 32px !important;
line-height: 37px !important;
font-size: 24px !important;
line-height: 30px !important;
text-transform: uppercase;
margin: 1rem 0;
@include media-breakpoint-up(xl) {
font-size: 32px !important;
line-height: 37px !important;
}
}
}

View File

@@ -6,7 +6,6 @@ $c-grey: #cbcbcb;
$c-midGrey: #acacac;
$c-textAlt: #505050;
$c-brightRed: #c80000;
$c-red: #ae1716;
$transition-time: 0.3s;

View File

@@ -0,0 +1,18 @@
.category-sub-cats-wrapper {
.sub-cats {
flex-wrap: wrap;
margin-top: 2rem;
.page-tile {
width: 100%;
@include media-breakpoint-up(md) {
width: calc(50% - 0.5rem);
}
@include media-breakpoint-up(lg) {
width: calc(25% - 0.75rem);
}
}
}
}

View File

@@ -61,3 +61,16 @@
</div>
</div>
</section>
<section class="shop-nav">
<div class="container-fluid">
<div class="row">
<div class="col">
<nav class="align-items-center gap-3 shop-nav">
{{{ shopMenu }}}
</nav>
</div>
</div>
</div>
</section>

6
tpl/hideProducts.tpl Normal file
View File

@@ -0,0 +1,6 @@
<style>
.woocommerce-wrapper {
display: none;
visibility: hidden;
}
</style>

View File

@@ -3,7 +3,7 @@
<img src="{{ thumbnail }}" alt="{{ title }}" />
</a>
<h2>
<a href="{{ url }}">{{{ title }}}</a>
<a href="{{ url }}">{{{ title }}}{{#if count}} ({{count}} Products){{/if}}</a>
</h2>
<a href="{{ url }}" class="learn-more">Learn More {{#assetContents arrow-right.svg}}</a>
</div>

View File

@@ -0,0 +1,14 @@
<section class="category-sub-cats-wrapper">
<div class="container">
<div class="row">
<div class="col">
<div class="sub-cats d-flex mb-5 gap-3">
{{#each children}}
{{#categoryBox this}}
{{/each}}
</div>
</div>
</div>
</div>
</section>

View File

@@ -0,0 +1,67 @@
<?php
namespace ofc;
use ReflectionClass;
class ActionsLoader
{
public static function load()
{
$actions_dir = get_template_directory() . '/actions';
if (!is_dir($actions_dir)) {
return;
}
foreach (scandir($actions_dir) as $file) {
if (pathinfo($file, PATHINFO_EXTENSION) !== 'php') {
continue;
}
$file_path = $actions_dir . '/' . $file;
require_once $file_path;
// Guess class name from file (assuming PSR-4 mapping matches)
// You can hardcode or use reflection if needed
$class_name = self::getClassFromFile($file);
if (!class_exists($class_name)) {
continue;
}
$reflection = new ReflectionClass($class_name);
if (!$reflection->isInstantiable()) {
continue;
}
$required_properties = ['hookName', 'priority'];
foreach ($required_properties as $prop) {
if (!$reflection->hasProperty($prop)) {
continue 2;
}
}
if (!$reflection->hasMethod('callback')) {
continue;
}
$instance = new $class_name();
if ($instance->wrapHookInInit()) {
add_action("init", function () use ($instance) {
add_action($instance->getHookName(), [$instance, 'callback'], $instance->getPriority());
}, $instance->getPriority());
continue;
}
add_action($instance->getHookName(), [$instance, 'callback'], $instance->getPriority());
}
}
private static function getClassFromFile($file)
{
$class_base = pathinfo($file, PATHINFO_FILENAME);
return 'Actions\\' . $class_base;
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace ofc;
abstract class RadAction implements RadActionInterface
{
protected string $hookName;
protected int $priority = 99;
protected bool $wrapInit = false;
public function getHookName(): string
{
return $this->hookName;
}
public function getPriority(): int
{
return $this->priority;
}
public function wrapHookInInit(): bool
{
return $this->wrapInit;
}
abstract public function callback();
}

View File

@@ -0,0 +1,10 @@
<?php
namespace ofc;
interface RadActionInterface
{
public function getHookName(): string;
public function getPriority(): int;
public function callback();
}

View File

@@ -1097,10 +1097,37 @@ class Site
return $output;
}
private function getTermChildren($term, $fields = [])
{
$args = [
'taxonomy' => $term->taxonomy,
'parent' => $term->term_id,
'hide_empty' => false,
'suppress_filter' => true,
];
$results = get_terms($args);
if ($fields == []) {
return $results;
}
$output = [];
foreach ($results as $term) {
$append = $this->getFieldsForTerm($fields, $term);
$output[] = $append;
}
return $output;
}
private function getFieldsForTerm(array $fields, $term)
{
$output = [];
foreach ($fields as $key) {
if (str_starts_with($key, "children")) {
$fields = explode(",", str_replace("children.", "", $key));
$output["children"] = site()->getTermChildren($term, $fields);
continue;
}
if ($key === "id" || $key === "ID" || $key === "term_id") {
$output[$key] = $term->term_id;
continue;
@@ -1131,7 +1158,14 @@ class Site
$output[$key] = get_field($key, $term->taxonomy . "_" . $term->term_id);
continue;
}
// try to get the property straight off the object?
$output[$key] = $term->$key;
// still nothing? check meta
if (is_null($output[$key])) {
$output[$key] = get_term_meta($term->term_id, $key, true);
}
}
return $output;
}
@@ -1498,23 +1532,30 @@ class Site
private function processActions()
{
ActionsLoader::load();
if (!isset($this->config["actions"]) || !is_array($this->config["actions"])) {
return;
}
foreach ($this->config["actions"] as $hookName => $callback) {
if (is_array($callback) && array_is_list($callback)) {
$priority = $callback[1];
$callback = $callback[0];
foreach ($this->config["actions"] as $hookName => $action) {
if (is_array($action) && array_is_list($action) && count($action) === 2) {
if (!is_numeric($action[1])) {
// invalid priority
continue;
}
$priority = $action[1];
$callback = $action[0];
add_action($hookName, $callback, $priority);
continue;
}
if (is_array($callback) && isset($callback["hook"]) && isset($callback["callback"])) {
add_action($callback["hook"], $callback["callback"], $callback["priority"] ?? 99);
if (is_array($action) && isset($action["hook"]) && isset($action["callback"])) {
add_action($action["hook"], $action["callback"], $action["priority"] ?? 99);
continue;
}
add_action($hookName, $callback, 99);
add_action($hookName, $action, 99);
}
}