Skip to content

Commit 8d8dec3

Browse files
committed
added permalink notice, updated URL on Shifter Local
1 parent 41d8b4c commit 8d8dec3

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

wp-serverless-api.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@
77
Description: WordPress REST API to JSON File
88
*/
99

10+
function enable_permalinks_notice() {
11+
?>
12+
<div class="notice notice-warning">
13+
<p><?php _e( 'WP Serverless Redirects requires Permalinks. <a href="/wp-admin/options-permalink.php">Enable Permalinks</a>'); ?></p>
14+
</div>
15+
<?php
16+
}
17+
18+
if ( !get_option('permalink_structure') ) {
19+
add_action( 'admin_notices', 'enable_permalinks_notice' );
20+
}
1021

1122
function compile_db(
1223
$routes = array(
@@ -19,7 +30,12 @@ function compile_db(
1930
$db_array = array();
2031

2132
foreach ($routes as $route) {
22-
$url = 'https://demo.wp-api.org/wp-json/wp/v2/' . $route;
33+
if (getenv("SHIFTER_ACCESS_TOKEN") === false) {
34+
$url = 'https://demo.wp-api.org/wp-json/wp/v2/' . $route;
35+
} else {
36+
$url = '/wp-json/wp/v2/' . $route;
37+
}
38+
2339
$jsonData = json_decode( file_get_contents($url) );
2440

2541
$db_array[$route] = (array) $jsonData;
@@ -55,13 +71,4 @@ function build_db()
5571
save_db($db);
5672
}
5773

58-
add_action( 'save_post', 'build_db' );
59-
60-
/**
61-
* Create JSON on Activation
62-
*/
63-
register_activation_hook( __FILE__, 'pluginprefix_install' );
64-
function pluginprefix_install()
65-
{
66-
build_db();
67-
}
74+
add_action( 'save_post', 'build_db' );

0 commit comments

Comments
 (0)