/
functions.php
110 lines (84 loc) · 2.62 KB
/
functions.php
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
<?php
/**
*
* Enqueue scripts and styles for admin panel.
*
*/
function admin_css() {
echo '
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet" type="text/css">
<style>
body, td, textarea, input, select { font-family: "Roboto"; }
#wpadminbar a { font-family: "Roboto"; }
#wpadminbar { padding: 8px 0; background: #26292c; }
#wpcontent { margin-top: 15px; }
#wpbody { padding-top: 20px; }
#adminmenu li { padding: 2px 0; }
span.ab-label { font-family: "Roboto" !important; }
</style>';
}
add_action('admin_head', 'admin_css');
function custom_theme_setup() {
add_theme_support( 'post-thumbnails' );
}
add_action( 'after_setup_theme', 'custom_theme_setup' );
/**
*
* Enqueue scripts and styles.
*
*/
function sourgems_scripts() {
// Load our main stylesheet.
wp_enqueue_style( 'style', get_stylesheet_uri() );
wp_enqueue_script( 'jquery' );
wp_register_script( 'sourgems-script', get_template_directory_uri() . '/app.js', array(), '20150910', true );
wp_enqueue_script( 'sourgems-script' );
//localize data for script
wp_localize_script( 'sourgems-script', 'AUTH', array(
'root' => esc_url_raw( rest_url() ),
'nonce' => wp_create_nonce( 'wp_rest' ),
'current_user_id' => get_current_user_id()
)
);
}
add_action( 'wp_enqueue_scripts', 'sourgems_scripts' );
function my_rest_prepare_post( $data, $post, $request ) {
$_data = $data->data;
$thumbnail_id = get_post_thumbnail_id( $post->ID );
$thumbnail = wp_get_attachment_image_src( $thumbnail_id );
$_data['featured_image_thumbnail_url'] = $thumbnail[0];
$categories = get_categories();
$_data['all_categories'] = $categories;
unset( $_data['author'] );
unset( $_data['comment_status'] );
unset( $_data['ping_status'] );
unset( $_data['modified'] );
unset( $_data['modified_gmt'] );
unset( $_data['date_gmt'] );
unset( $_data['guid'] );
unset( $_data['slug'] );
unset( $_data['sticky'] );
$tags_arr = array();
foreach ( $_data['tags'] as $tagID ) {
$tag = get_tag($tagID);
// add name field to the array
$tags_arr[] = array(
'ID' => $tagID,
'name' => $tag->name
);
}
$_data['tags'] = $tags_arr; // assign the new tags array to the JSON field
$categories_arr = array();
foreach ( $_data['categories'] as $catID ) {
// add name field to the array
$categories_arr[] = array(
'ID' => $catID,
'name' => get_cat_name($catID)
);
}
$_data['categories'] = $categories_arr; // assign the new tags array to the JSON field
$data->data = $_data;
return $data;
}
add_filter( 'rest_prepare_post', 'my_rest_prepare_post', 10, 3 );
?>