-
Notifications
You must be signed in to change notification settings - Fork 14
/
functions.php
207 lines (182 loc) · 7.15 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
<?php
/**
* Libraries
*/
require_once 'assets/libraries/class-tgm-plugin-activation.php';
/**
* Constants
*/
define( 'PROPERTY_EXCERPT_LENGTH', 22 );
define( 'AGENCY_EXCERPT_LENGTH', 20 );
/**
* Custom excerpt length
*
* @param $length
* @return int
*/
function realia_bootstrap_excerpt_length( $length ) {
global $post;
if ( $post->post_type == 'property' ) {
return PROPERTY_EXCERPT_LENGTH;
} elseif ( $post->post_type == 'agency' ) {
return AGENCY_EXCERPT_LENGTH;
}
return $length;
}
add_filter('excerpt_length', 'realia_bootstrap_excerpt_length' );
/**
* Enqueue scripts & styles
*
* @return void
*/
function realia_bootstrap_enqueue_files() {
wp_register_script( 'bootstrap-collapse', get_template_directory_uri() . '/assets/libraries/bootstrap/javascripts/bootstrap/collapse.js' );
wp_enqueue_script( 'bootstrap-collapse' );
wp_register_style( 'realia-bootstrap', get_template_directory_uri() . '/assets/css/realia-bootstrap.css' );
wp_enqueue_style( 'realia-bootstrap' );
wp_register_style( 'style', get_stylesheet_directory_uri() . '/style.css' );
wp_enqueue_style( 'style' );
}
add_action( 'wp_enqueue_scripts', 'realia_bootstrap_enqueue_files' );
/**
* Additional after theme setup functions
*
* @return void
*/
function realia_bootstrap_after_theme_setup() {
add_theme_support( 'realia-custom-styles' );
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'custom-header', array() );
add_theme_support( 'custom-background' );
add_theme_support( 'menus' );
add_theme_support( 'title-tag' );
if ( ! isset( $content_width ) ) {
$content_width = 1170;
}
}
add_action( 'after_setup_theme', 'realia_bootstrap_after_theme_setup' );
/**
* Register menus
*
* @return void
*/
function realia_bootstrap_menus() {
register_nav_menu( 'primary', __( 'Primary', 'realia-bootstrap' ) );
}
add_action( 'init', 'realia_bootstrap_menus' );
/**
* Custom widget areas
*
* @return void
*/
function realia_bootstrap_sidebars() {
register_sidebar( array( 'name' => __( 'Primary', 'realia-bootstrap' ), 'id' => 'sidebar-1', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>' ) );
register_sidebar( array( 'name' => __( 'Top Fullwidth', 'realia-bootstrap' ), 'id' => 'sidebar-top-fullwidth', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>' ) );
register_sidebar( array( 'name' => __( 'Top', 'realia-bootstrap' ), 'id' => 'sidebar-top', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>' ) );
register_sidebar( array( 'name' => __( 'Content Top', 'realia-bootstrap' ), 'id' => 'sidebar-content-top', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>' ) );
register_sidebar( array( 'name' => __( 'Content Bottom', 'realia-bootstrap' ), 'id' => 'sidebar-content-bottom', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>' ) );
register_sidebar( array( 'name' => __( 'Bottom', 'realia-bootstrap' ), 'id' => 'sidebar-bottom', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>' ) );
register_sidebar( array( 'name' => __( 'Footer First', 'realia-bootstrap' ), 'id' => 'footer-first', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>' ) );
register_sidebar( array( 'name' => __( 'Footer Second', 'realia-bootstrap' ), 'id' => 'footer-second', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>' ) );
register_sidebar( array( 'name' => __( 'Footer Third', 'realia-bootstrap' ), 'id' => 'footer-third', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>' ) );
register_sidebar( array( 'name' => __( 'Footer Fourth', 'realia-bootstrap' ), 'id' => 'footer-fourth', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>' ) );
register_sidebar( array( 'name' => __( 'Footer Bottom Left', 'realia-bootstrap' ), 'id' => 'footer-bottom-left', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>' ) );
register_sidebar( array( 'name' => __( 'Footer Bottom Right', 'realia-bootstrap' ), 'id' => 'footer-bottom-right', 'before_widget' => '<div id="%1$s" class="widget %2$s">', 'after_widget' => '</div>' ) );
}
add_action( 'widgets_init', 'realia_bootstrap_sidebars' );
/**
* Disable admin's bar top margin
*
* @return void
*/
function realia_bootstrap_disable_admin_bar_top_margin() {
remove_action( 'wp_head', '_admin_bar_bump_cb' );
}
add_action( 'get_header', 'realia_bootstrap_disable_admin_bar_top_margin' );
/**
* Read more for post excerpt
*
* @param $more
* @return void|string
*/
function realia_bootstrap_excerpt_read_more( $more ) {
global $post;
if ( $post->post_type == 'property' || $post->post_type == 'agency' ) {
return null;
}
return '<a class="post-read-more" href="'. get_permalink( $post->ID ) . '">' . __( 'Read more', 'megareal' ) . '</a>';
}
add_filter( 'excerpt_more', 'realia_bootstrap_excerpt_read_more' );
/**
* Registers sessions
*
* @return void
*/
function realia_bootstrap_register_session(){
if( ! session_id() ) {
session_start();
}
}
add_action( 'init', 'realia_bootstrap_register_session' );
/**
* Customizations
*
* @param $wp_customize
* @return void
*/
function realia_bootstrap_customizations( $wp_customize ) {
$wp_customize->add_section( 'realia_bootstrap_general', array( 'title' => __( 'Realia Bootstrap General', 'realia-bootstrap' ), 'priority' => 0 ) );
$wp_customize->add_setting( 'realia_bootstrap_general_logo', array( 'sanitize_callback' => 'sanitize_text_field' ) );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'header_logo', array(
'label' => __( 'Logo', 'realia-bootstrap' ),
'section' => 'realia_bootstrap_general',
'settings' => 'realia_bootstrap_general_logo',
'description' => __( 'Logo displayed in header. By default it has some opacity added by CSS which will change after hover.', 'realia-bootstrap' ),
) ) );
}
add_action( 'customize_register', 'realia_bootstrap_customizations' );
/**
* Register plugins
*
* @return void
*/
function realia_bootstrap_register_required_plugins() {
$plugins = array(
array(
'name' => 'Realia',
'slug' => 'realia',
'is_automatic' => true,
'required' => true,
),
);
tgmpa( $plugins );
}
add_action( 'tgmpa_register', 'realia_bootstrap_register_required_plugins' );
/**
* Class Realia_Bootstrap_Menu_Walker
*/
class Realia_Bootstrap_Menu_Walker extends Walker_Nav_Menu {
/**
* Custom parent menu item class
*
* @param string $output
* @param int $depth
* @param array $args
* @return void
*/
public function start_lvl( &$output, $depth = 0, $args = array() ) {
$indent = str_repeat("\t", $depth);
$output .= "\n$indent<ul class=\"dropdown-menu sub-menu\">\n";
}
}
function realia_remove_responsive_images( $attr ) {
if( isset( $attr['sizes'] ) ) {
unset( $attr['sizes'] );
}
if( isset( $attr['srcset'] ) ) {
unset( $attr['srcset'] );
}
return $attr;
}
add_filter( 'wp_get_attachment_image_attributes', 'realia_remove_responsive_images', 9999 );