Skip to content

Commit 1be7dcb

Browse files
author
Joseph Fusco
committed
Initial commit
0 parents  commit 1be7dcb

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# WP Theme Lock
2+
3+
An mu-plugin that forces a WordPress theme to always be active. Intended for a [Headless WordPress](https://www.gatsbyjs.com/docs/glossary/headless-wordpress/) setup.
4+
5+
## Config
6+
7+
Out of the box, this mu-plugin expects [wp-headless-theme](https://github.com/masonitedoors/wp-headless-theme) to be installed.
8+
9+
You can set your own theme using the available filter in a separate mu-plugin.
10+
11+
```php
12+
add_filter( 'wp_theme_lock', function() {
13+
return 'twentytwenty'; // Theme directory to lock.
14+
});
15+
```

composer.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "masonitedoors/wp-theme-lock",
3+
"description": "An mu-plugin that forces a WordPress theme to always be active. Requires https://github.com/masonitedoors/wp-headless-theme.",
4+
"type": "wordpress-muplugin",
5+
"license": "MIT",
6+
"authors": [
7+
{
8+
"name": "Joseph Fusco",
9+
"homepage": "https://github.com/josephfusco",
10+
"role": "Developer"
11+
}
12+
],
13+
"require": {
14+
"php": ">=7"
15+
}
16+
}

wp-theme-lock.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Plugin Name: WP Force Theme
4+
* Plugin URI: https://github.com/masonitedoors/wp-force-theme/
5+
* Description: Forces WordPress to always load the wp-headless-theme.
6+
* Version: 1.0.0
7+
* Author: Masonite
8+
* Author URI: https://www.masonite.com/
9+
* License: MIT License
10+
*/
11+
12+
add_action(
13+
'setup_theme',
14+
function() {
15+
$theme_directory_name = apply_filters( 'wp_force_theme', 'wp-headless-theme' );
16+
17+
/**
18+
* Filters the name of the current theme.
19+
*/
20+
add_filter( 'template', function() use ( $theme_directory_name ) {
21+
return $theme_directory_name;
22+
});
23+
24+
/**
25+
* Filters the name of current stylesheet.
26+
*/
27+
add_filter( 'stylesheet', function() use ( $theme_directory_name ) {
28+
return $theme_directory_name;
29+
});
30+
},
31+
-1
32+
);

0 commit comments

Comments
 (0)