-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
261 lines (215 loc) · 6.42 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<?php
/**
* Created hooks:
* "_footer_inline_js" -> hook for inserting inline JS into footer; content is wrapped in jQuery document ready wrap, just make global variable $script and add to it
*/
if ( ! isset( $content_width ) ) $content_width = 960;
#define textdomain for translations
if(!defined('__TEXTDOMAIN__'))
define('__TEXTDOMAIN__', 'ihawmate');
if(!defined('__LOAD_GALLERY_'))
define('__LOAD_GALLERY_', false);
function template_setup()
{
#Load custom CSS into TINYmce editor
add_editor_style();
#Load languages to use
load_theme_textdomain(__TEXTDOMAIN__, get_stylesheet_directory() . DIRECTORY_SEPARATOR .'languages');
#Remove unused links
remove_theme_support('automatic-feed-links');
#Register navigation
register_nav_menu( 'primary', __( 'Hlavní navigace', __TEXTDOMAIN__ ) );
add_theme_support( 'html5', array(
'search-form', 'comment-form', 'comment-list',
) );
}
add_action ('after_setup_theme', 'template_setup', 11);
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'rsd_link');
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'feed_links', 2 );
/**
* Function loads minifying libraries
* Minify CSS - CssMin::minify(string)
* Minify JS - JSMin::minify(string)
* To minify HTML you need to only include this library
*/
function _minify()
{
require_once(dirname(__FILE__).'/php/minify.php');
require_once(dirname(__FILE__).'/php/cssmin.php');
require_once(dirname(__FILE__).'/php/jsmin.php');
}
/**
* @param $value
* @return mixed
*/
function ihawmate_filter_plugin_updates( $value ) {
$plugins = apply_filters('ihawmate_plugins_to_filter_updates', array());
if(sizeof($plugins) > 0)
{
foreach($plugins as $plugin)
if(isset($value->response[$plugin]))
unset( $value->response[$plugin] );
}
return $value;
}
add_filter( 'site_transient_update_plugins', 'ihawmate_filter_plugin_updates' );
/**
* Function removes pages from admin menu
* To make this work, create another function "_admin_pages_to_remove" returning array of pages to be removed
* Array value construction array("slug.ext")
*/
function ihawmate_remove_admin_pages() {
$pages = apply_filters('ihawmate_admin_pages_to_remove', array());
if(sizeof($pages) > 0)
{
foreach($pages as $page)
remove_menu_page($page);
}
}
add_action( 'admin_menu', 'ihawmate_remove_admin_pages' );
/**
*
*/
function ihawmate_remove_subpages() {
$subpages = apply_filters('ihawmate_admin_subpages_to_remove', array());
if(sizeof($subpages) > 0)
{
foreach($subpages as $parentSlug => $subpage)
remove_submenu_page($parentSlug, $subpage);
}
}
add_action( 'admin_menu', 'ihawmate_remove_subpages' );
/**
*
*/
function ihawmate_remove_admin_bar_pages(){
global $wp_admin_bar;
$pages_to_remove = apply_filters('ihawmate_admin_bar_pages_to_remove', array());
if(sizeof($pages_to_remove) > 0)
{
foreach($pages_to_remove as $page)
$wp_admin_bar->remove_menu($page);
}
}
add_action( 'wp_before_admin_bar_render', 'ihawmate_remove_admin_bar_pages' );
/**
*
*/
function ihawmate_html_head() {
}
add_action('wp_head', 'ihawmate_html_head', 1);
/**
*
*/
function ihawmate_site_title() {
global $page, $paged;
if ( $paged >= 2 || $page >= 2 )
echo sprintf( __( 'Stránka %s', __TEXTDOMAIN__ ), max( $paged, $page ) ).' | ';
echo esc_attr( wp_title( '|', true, 'right' ) );
echo esc_attr(get_bloginfo( 'name' ));
}
#Load default css
function ihawmate_default_css() {
wp_enqueue_style('default', get_stylesheet_uri(), FALSE, NULL, 'all');
}
add_action('wp_print_styles', 'ihawmate_default_css');
/**
* Function loads the prettyPhoto gallery automatically with dependance on post content
* If the post has shortcode gallery or has image wrapped in anchor
* @return void
*/
function post_gallery_init()
{
if(__LOAD_GALLERY_)
{
global $post;
if(is_loaded_post_object())
if (strpos($post->post_content,'[gallery') !== false || strpos($post->post_content,'<img') !== false)
prettyPhoto_init();
}
}
add_action('wp', 'post_gallery_init');
/**
* Initialize scripts and style for prettyPhoto gallery
* @return void
*/
function prettyPhoto_init(){
add_action('wp_enqueue_scripts', 'prettyPhoto_js_init');
add_action('wp_print_styles', 'prettyPhoto_css_init');
add_action('wp_footer', '_add_inline_js', 20);
}
#add prettyphoto scripts to queue
function prettyPhoto_js_init(){
wp_deregister_script('jquery');
wp_enqueue_script('jquery', get_template_directory_uri().'/js/jquery-1.8.3.min.js', FALSE, NULL, true);
wp_enqueue_script('prettyPhoto', get_template_directory_uri().'/js/jquery.prettyPhoto.js', array('jquery'), NULL, true);
}
#add prettyphoto css to queue
function prettyPhoto_css_init(){
wp_enqueue_style('prettyphoto', get_template_directory_uri().'/css/prettyphoto.css', FALSE, NULL, 'screen');
}
#Functions checks, if is loaded the variable $post and if it is a object
function is_loaded_post_object()
{
global $post;
return is_object($post);
}
/**
* Functions serves to get the ID of the very first parent of the page if page has deeper structure
* @var $page_id integer ID of the page we want the very first parent
* @return integer
*/
function get_root_parent_id( $page_id ) {
global $wpdb;
$parent = $wpdb->get_var( "SELECT post_parent FROM $wpdb->posts WHERE post_type='page' AND post_status='publish' AND ID = '$page_id'" );
if( $parent == 0 ) return $page_id;
else return get_root_parent_id( $parent );
}
/**
*
*/
function _get_image_url($id, $size){
$image = wp_get_attachment_image_src($id, $size);
return $image[0];
}
/**
*
*/
if(isset($_GET['noadminbar']) && $_GET['noadminbar'] == true)
add_action('show_admin_bar', '__return_false');
/**
*
*/
function add_page_slug_to_body_class($classes) {
if(is_loaded_post_object()) {
global $post;
$classes[] = 'page-'.$post->post_name;
}
return $classes;
}
add_filter('body_class', 'add_page_slug_to_body_class');
/**
*
*/
function _get_postOBJ_value($post_id, $key){
$post = get_post($post_id);
return $post->$key;
}
/**
* Functions returns pages
*/
function get_Page_Siblings($id_post = 0, $id_parent = 0){
$final = ($id_parent !== 0 ? $id_parent : $id_post);
return get_pages(
array(
'child_of' => $final,
'parent' => $final,
'numberposts' => -1,
'sort_column' => 'menu_order',
'sort_order' => 'ASC',
'post_type' => get_post_type()
)
);
}