-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathfunctions.php
123 lines (97 loc) · 3.22 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
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
function my_scripts() {
wp_register_script(
'angularjs',
get_stylesheet_directory_uri() . '/bower_components/angular/angular.min.js'
);
wp_register_script(
'angularjs-route',
get_stylesheet_directory_uri() . '/bower_components/angular-route/angular-route.min.js'
);
wp_register_script(
'angularjs-sanitize',
get_stylesheet_directory_uri() . '/bower_components/angular-sanitize/angular-sanitize.min.js'
);
wp_register_script(
'angularjs-slick',
get_stylesheet_directory_uri() . '/bower_components/angular-slick/dist/slick.min.js'
);
wp_register_script(
'slick-carousel',
get_stylesheet_directory_uri() . '/bower_components/slick-carousel/slick/slick.min.js'
);
wp_register_script(
'my-jquery',
get_stylesheet_directory_uri() . '/bower_components/jquery/dist/jquery.min.js'
);
wp_enqueue_script(
'my-scripts',
get_stylesheet_directory_uri() . '/js/scripts.min.js',
array( 'my-jquery', 'angularjs', 'angularjs-route', 'angularjs-sanitize', 'slick-carousel', 'angularjs-slick' )
);
wp_enqueue_script(
'wp-service',
get_stylesheet_directory_uri() . '/js/WPService.min.js'
);
wp_enqueue_style(
'slick-css',
get_stylesheet_directory_uri() . '/bower_components/slick-carousel/slick/slick.css'
);
wp_enqueue_style(
'slick-theme-css',
get_stylesheet_directory_uri() . '/bower_components/slick-carousel/slick/slick-theme.css'
);
wp_localize_script(
'my-scripts',
'myLocalized',
array(
'partials' => trailingslashit( get_template_directory_uri() ) . 'partials/',
'nonce' => wp_create_nonce( 'wp_rest' )
)
);
}
add_action( 'wp_enqueue_scripts', 'my_scripts' );
function my_add_link_target( $html ) {
$html = preg_replace( '/(<a.*")>/', '$1 target="_self">', $html );
return $html;
}
add_filter( 'image_send_to_editor', 'my_add_link_target', 10 );
// add_filter('show_admin_bar', '__return_false');
function my_theme_setup() {
add_theme_support( 'post-thumbnails' );
}
add_action( 'after_setup_theme', 'my_theme_setup' );
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];
$data->data = $_data;
return $data;
}
add_filter( 'rest_prepare_post', 'my_rest_prepare_post', 10, 3 );
function my_rest_prepare_attachment( $data, $post, $request ) {
$_data = $data->data;
if ( 'image' == $_data['media_type'] )
$_data['is_image'] = true;
else
$_data['is_image'] = false;
$data->data = $_data;
return $data;
}
add_filter( 'rest_prepare_attachment', 'my_rest_prepare_attachment', 10, 3 );
function my_rest_post_query( $args, $request ) {
if ( isset( $request['filter'] ) && isset( $request['filter']['posts_per_page'] ) && ! empty( $request['filter']['posts_per_page'] ) ) {
if ( $request['filter']['posts_per_page'] > 0 ) {
$request['per_page'] = $request['filter']['posts_per_page'];
} else {
$count_query = new WP_Query();
unset( $query_args['paged'] );
$query_result = $count_query->query( $query_args );
$total_posts = $query_result->found_posts;
$request['per_page'] = $total_posts;
}
}
return $args;
}
add_filter( 'rest_post_query', 'my_rest_post_query', 10, 2 );