Skip to content

Commit 41d8b4c

Browse files
committed
added activation hook
1 parent 35182ff commit 41d8b4c

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

wp-serverless-api.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function compile_db(
1919
$db_array = array();
2020

2121
foreach ($routes as $route) {
22-
$url = esc_url( home_url( '/' ) ) . 'wp-json/wp/v2/' . $route;
22+
$url = 'https://demo.wp-api.org/wp-json/wp/v2/' . $route;
2323
$jsonData = json_decode( file_get_contents($url) );
2424

2525
$db_array[$route] = (array) $jsonData;
@@ -55,4 +55,13 @@ function build_db()
5555
save_db($db);
5656
}
5757

58-
add_action( 'save_post', 'build_db' );
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+
}

0 commit comments

Comments
 (0)