-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
106 lines (91 loc) · 2.74 KB
/
functions.php
File metadata and controls
106 lines (91 loc) · 2.74 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
<?php
/**
* WP Into React theme functions and definitions
*
* @package WP_Into_React
*/
if (! defined('WP_INTO_REACT_VERSION')) {
define('WP_INTO_REACT_VERSION', '1.0.0');
}
/**
* Sets up theme defaults and registers support for various WordPress features.
*/
function wp_into_react_setup()
{
// Add default posts and comments RSS feed links to head.
add_theme_support('automatic-feed-links');
// Let WordPress manage the document title.
add_theme_support('title-tag');
// Enable support for Post Thumbnails on posts and pages.
add_theme_support('post-thumbnails');
// Switch default core markup to valid HTML5.
add_theme_support(
'html5',
[
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
'style',
'script',
]
);
// Add theme support for selective refresh for widgets.
add_theme_support('customize-selective-refresh-widgets');
}
add_action('after_setup_theme', 'wp_into_react_setup');
/**
* Enqueue scripts and styles.
*/
function wp_into_react_scripts()
{
// Enqueue theme stylesheet.
wp_enqueue_style('wp-into-react-style', get_stylesheet_uri(), array(), WP_INTO_REACT_VERSION);
$asset_file = plugin_dir_path(__FILE__) . 'build/index.asset.php';
if (! file_exists($asset_file)) {
return;
}
$asset = include $asset_file;
// Enqueue React built files when they become available
if (file_exists(get_template_directory() . '/build/index.css')) {
wp_enqueue_style(
'wp-into-react-index',
get_template_directory_uri() . '/build/index.css',
array_filter(
$asset['dependencies'],
function ($style) {
return wp_style_is($style, 'registered');
}
),
$asset['version']
);
}
if (file_exists(get_template_directory() . '/build/index.js')) {
wp_enqueue_script(
'wp-into-react-index',
get_template_directory_uri() . '/build/index.js',
$asset['dependencies'],
$asset['version'],
['in_footer' => true]
);
}
}
add_action('wp_enqueue_scripts', 'wp_into_react_scripts');
/**
* Add React-specific data to be available in JavaScript
*/
function wp_into_react_script_data()
{
wp_localize_script(
'wp-into-react-index',
'wpIntoReactData',
array(
'restUrl' => esc_url_raw(rest_url()),
'nonce' => wp_create_nonce('wp_rest'),
'siteName' => get_bloginfo('name'),
'siteUrl' => esc_url_raw(home_url()),
)
);
}
add_action('wp_enqueue_scripts', 'wp_into_react_script_data');