-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstaticprops.php
More file actions
118 lines (102 loc) · 3.35 KB
/
staticprops.php
File metadata and controls
118 lines (102 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/**
* Plugin Name: Staticprops.com
* Description: This plugin facilitates wordpress integration with SSG (Static Site Generators).
* Author: Staticprops.com
* Author URI: https://github.com/dazuaz/staticprops
* License: GPL V2
* Text Domain: staticprops
* Version: 0.1.1
*/
/**
* API route that genarates all paths avaliable.
* Usefull for generating all avaliable paths
*
* @param array $data Options for the function.
* @return string|null Post title for the latest, * or null if none.
*/
if (!defined('ABSPATH')) {
exit();
}
function custom_font()
{
echo "
<link rel='stylesheet' href='https://rsms.me/inter/inter.css' />
";
}
add_action('admin_head', 'custom_font');
/**
* Disallow indexing of your site
*/
add_action('pre_option_blog_public', '__return_zero');
global $staticprops;
require_once __DIR__ . '/custom-apis/site-api.php';
require_once __DIR__ . '/custom-apis/paths-api.php';
/**
* Function to register our new routes from the controller.
*/
function register_site_api_controller()
{
$site = new SiteApi();
$paths = new PathsApi();
$site->register_routes();
$paths->register_routes();
}
add_action('rest_api_init', 'register_site_api_controller');
/**
* Change post preview link
* This allows to integrate with the front and pass preview params
*
* TODO https://github.com/WordPress/gutenberg/issues/13998
* @param WP_post $post The post in preview
* @return string $preview_link the modified link
*/
// function the_preview_fix(WP_Post $post) {
// $slug = basename(get_permalink());
// $secret = getenv('FRONTEND_PREVIEW_SECRET');
// $user_url = "https://observatorio.now.sh";
// $user_preview = "api/preview";
// $preview_link = "$user_url/$user_preview?secret=$secret&slug=$slug";
// // TODO The best approach might be to pass a key and let the front end fetch the latest post here
// return $preview_link;
// }
// add_filter( 'preview_post_link', 'the_preview_fix');
function mailtrap($phpmailer)
{
$phpmailer->isSMTP();
$phpmailer->Host = 'smtp.mailtrap.io';
$phpmailer->SMTPAuth = true;
$phpmailer->Port = 2525;
$phpmailer->Username = getenv('MAILTRAP_USER');
$phpmailer->Password = getenv('MAILTRAP_PASS');
}
if (getenv('WP_DEBUG')) {
add_action('phpmailer_init', 'mailtrap');
}
/**
* Editor CSS
* This css gets added to the Wordpress Editor Screen.
*
*/
// When enqueue block editor assets runs, also run our custom function
// add_action('enqueue_block_editor_assets', 'staticprops_override_display');
// function staticprops_override_display() {
// wp_enqueue_style(
// 'override-display', // a unique handle for your css
// plugins_url('staticprops/editor.css', dirname(__FILE__)), // url of the css file
// array('wp-edit-blocks'), // dependency to include CSS after Core CSS
// rand(111,9999) // version of your CSS
// );
// }
// We need some CSS to position the paragraph.
// TODO allow user to choose more options.
add_action( 'graphql_register_types', function() {
register_graphql_field( 'Post', 'rawContent', [
'type' => 'String',
'description' => __( 'The raw content without filters/decoding applied', 'staticprops.com' ),
'resolve' => function( \WPGraphQL\Model\Post $post ) {
$post_object = ! empty( $post->databaseId ) ? get_post( $post->databaseId ) : null;
return isset( $post_object->post_content ) ? $post_object->post_content : null;
}
]);
});