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
29 changes: 29 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Deploy to SiteGround
on:
push:
branches: [stg, main]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
deploy-prod:
name: Deploy to Production
if: github.ref == 'refs/heads/main'
uses: macrosbysara/shared-github-actions/.github/workflows/deploy-theme.yml@main
with:
REMOTE: "macrosbysara.com" # Remote folder to deploy to
theme_name: "macros-by-sara"
flags: "-azr --delete"
secrets: inherit

deploy-stg:
name: Deploy to Staging
if: github.ref == 'refs/heads/stg'
uses: macrosbysara/shared-github-actions/.github/workflows/deploy-theme.yml@main
with:
REMOTE: staging6.macrosbysara.com
theme_name: "macros-by-sara"
flags: "-azvr --delete"
secrets: inherit
49 changes: 49 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for Xdebug 3.0 (Local)",
"type": "php",
"request": "launch",
"port": 9003,
"xdebugSettings": {
"max_children": 128,
"max_data": 1024,
"max_depth": 3,
"show_hidden": 1
},
"pathMappings": {
"/Users/kjroelke/Local Sites/macros-by-sara/app/public/wp-content/themes/macros-by-sara": "${workspaceFolder}"
}
},
{
"name": "Listen for Xdebug (Local)",
"type": "php",
"request": "launch",
"port": 9000,
"xdebugSettings": {
"max_children": 128,
"max_data": 1024,
"max_depth": 3,
"show_hidden": 1
},
"pathMappings": {
"/Users/kjroelke/Local Sites/macros-by-sara/app/public/wp-content/themes/macros-by-sara": "${workspaceFolder}"
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000,
"xdebugSettings": {
"max_children": 128,
"max_data": 1024,
"max_depth": 3,
"show_hidden": 1
}
}
]
}
16 changes: 15 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,21 @@
"editor.useTabStops": true,
"prettier.useTabs": false
},
"cSpell.words": [ "cpts", "Linktree", "macrosbysara", "wpcf" ],
"cSpell.words": [
"alignfull",
"alignwide",
"atts",
"azvr",
"bloginfo",
"choctawnationofoklahoma",
"cpts",
"Linktree",
"macrosbysara",
"remoteip",
"trackbacks",
"wght",
"wpcf"
],
"css.format.spaceAroundSelectorSeparator": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "always",
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.0.0 - [November 1, 2025]

- New Theme!

## 1.3.2 - [October 29, 2025]

- Chore: Add lints and configs
Expand Down
5 changes: 1 addition & 4 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import globals from 'globals';
import { fixupConfigRules, includeIgnoreFile } from '@eslint/compat';
import wordpressConfig from '@wordpress/eslint-plugin';

// eslint-disable-next-line import/no-unresolved
import { globalIgnores, defineConfig } from 'eslint/config';

import { FlatCompat } from '@eslint/eslintrc';
import path from 'path';
import { fileURLToPath, URL } from 'url';
Expand All @@ -29,7 +26,7 @@ export default defineConfig( [
)
),
{
files: [ 'wp-content/themes/**/src/js/**/*.{js,ts,jsx,tsx}' ],
files: [ 'src/js/**/*.{js,ts,jsx,tsx}' ],
languageOptions: {
globals: globals.browser,
},
Expand Down
52 changes: 48 additions & 4 deletions inc/theme/class-gutenberg-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,66 @@ class Gutenberg_Handler {
* Constructor
*/
public function __construct() {
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_assets' ) );
add_action( 'after_setup_theme', array( $this, 'theme_supports' ) );
add_action( 'init', array( $this, 'register_theme_blocks' ) );
}

/**
* Enqueue the block editor assets that control the layout of the Block Editor.
*/
public function enqueue_block_assets() {
$files = array(
'editDefaultBlocks' => 'script',
'editor' => 'style',
);
foreach ( $files as $handle => $type ) {
$assets = require_once get_stylesheet_directory() . "/build/admin/{$handle}.asset.php";
if ( 'style' === $type || 'both' === $type ) {
wp_enqueue_style(
$handle,
get_stylesheet_directory_uri() . "/build/admin/{$handle}.css",
$assets['dependencies'],
$assets['version']
);
}
if ( 'script' === $type || 'both' === $type ) {
wp_enqueue_script(
$handle,
get_stylesheet_directory_uri() . "/build/admin/{$handle}.js",
$assets['dependencies'],
$assets['version'],
array( 'strategy' => 'defer' )
);
}
}
}

/**
* Add theme supports for Gutenberg features
*/
public function theme_supports() {
$opt_in_features = array(
'disable-custom-colors',
'responsive-embeds',
'disable-custom-gradients',
'disable-custom-font-sizes',
);

foreach ( $opt_in_features as $feature ) {
add_theme_support( $feature );
}

$opt_out_features = array(
'core-block-patterns',
);
foreach ( $opt_out_features as $feature ) {
remove_theme_support( $feature );
}
}

/**
* Register any theme-specific blocks
*/
public function register_theme_blocks() {
// Load blocks
$blocks_path = get_template_directory() . '/build';
wp_register_block_types_from_metadata_collection( $blocks_path . '/js/blocks', $blocks_path . '/blocks-manifest.php' );
}
}
182 changes: 182 additions & 0 deletions inc/theme/class-rest-router.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
<?php
/**
* Rest Router
*
* @package MacrosBySara
*/

namespace MacrosBySara;

use WP_REST_Controller;
use WP_REST_Request;
use WP_REST_Response;
use WP_REST_Server;

/**
* Class: Rest Router
*/
class Rest_Router extends WP_REST_Controller {
/**
* Constructor.
*/
public function __construct() {
$this->namespace = 'mbs/v1';
add_action( 'rest_api_init', array( $this, 'register_routes' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_interest_form_script' ), 100 );
}

/**
* Register routes.
*/
public function register_routes() {
register_rest_route(
$this->namespace . '/forms',
'/interest-form',
array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array( $this, 'handle_interest_form' ),
'permission_callback' => array( $this, 'allow_public_access' ),
'args' => array(
'firstName' => array(
'required' => true,
'sanitize_callback' => 'sanitize_text_field',
),
'lastName' => array(
'required' => true,
'sanitize_callback' => 'sanitize_text_field',
),
'email' => array(
'required' => true,
'sanitize_callback' => 'sanitize_email',
'validate_callback' => 'is_email',
),
'interest' => array(
'required' => true,
'sanitize_callback' => 'sanitize_text_field',
'validate_callback' => function ( $param ) {
$valid_options = array(
'macros',
'habits',
'one-time-macros',
'fitness',
);
return in_array( $param, $valid_options, true );
},
),
),
)
);
}

/**
* Example endpoint callback.
*
* @param WP_REST_Request $request The REST request.
* @return WP_REST_Response The REST response.
*/
public function handle_interest_form( WP_REST_Request $request ): WP_REST_Response {
$first_name = $request->get_param( 'firstName' );
$last_name = $request->get_param( 'lastName' );
$email = $request->get_param( 'email' );
$interest = $request->get_param( 'interest' );
$data = array(
'code' => 'success',
'message' => 'Interest form submitted successfully!',
'data' => array(
'status' => 200,
'firstName' => $first_name,
'lastName' => $last_name,
'email' => $email,
'interest' => $interest,
),
);
return rest_ensure_response( $data );
}

/**
* Enqueue interest form script with localized REST API data.
*/
public function enqueue_interest_form_script() {
wp_localize_script(
'global',
'mbsRestApi',
array(
'root' => esc_url_raw( rest_url() . $this->namespace ),
'nonce' => wp_create_nonce( 'wp_rest' ),
)
);
wp_enqueue_script(
'cloudflare',
'https://challenges.cloudflare.com/turnstile/v0/api.js',
array( 'global' ),
null, // phpcs:ignore WordPress.WP.EnqueuedResourceParameters.MissingVersion
array(
'strategy' => 'async',
)
);
}

/**
* Allow public access to the endpoint.
*
* @param WP_REST_Request $request The REST request.
* @return bool
*/
public function allow_public_access( WP_REST_Request $request ): bool {
if ( ! defined( 'CF_TURNSTILE_SECRET' ) || empty( CF_TURNSTILE_SECRET ) ) {
return false;
}
$nonce = null;
$headers = $request->get_headers();
if ( isset( $headers['x_wp_nonce'] ) ) {
$nonce = $headers['x_wp_nonce'];
}
$verified = wp_verify_nonce( $nonce[0], 'wp_rest' );
if ( ! $verified ) {
return false;
}
if ( ! isset( $_POST['cf-turnstile-response'] ) ) {
return false;
}
return $this->cloudflare_validation(
sanitize_text_field( $_POST['cf-turnstile-response'] ?? '' )
);
}


/**
* Validate Cloudflare Turnstile response.
*
* @param string $token The Turnstile token from the client.
* @param string|null $remoteip Optional. The user's IP address.
* @return bool True if validation is successful, false otherwise.
*/
private function cloudflare_validation( string $token, ?string $remoteip = null ): bool {
$url = 'https://challenges.cloudflare.com/turnstile/v0/siteverify';

$data = array(
'secret' => CF_TURNSTILE_SECRET,
'response' => $token,
);

if ( $remoteip ) {
$data['remoteip'] = $remoteip;
}

$response = wp_remote_post(
$url,
array(
'headers' => array( 'Content-Type' => 'application/x-www-form-urlencoded' ),
'body' => $data,
'timeout' => 10,
)
);
if ( is_wp_error( $response ) ) {
return false;
}

$response = wp_remote_retrieve_body( $response );
$response_data = json_decode( $response, true );
return $response_data['success'] ?? false;
}
}
Loading