-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfunctions.php
188 lines (173 loc) · 5.32 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
<?php
/**
* Functions: list
*
* @version 2020.09.1
* @package wp-theme-openglam
*/
/* Theme Constants (to speed up some common things) ------*/
define( 'HOME_URI', get_bloginfo( 'url' ) );
define( 'PRE_HOME_URI', get_bloginfo( 'url' ) . '/wp-content/themes' );
define( 'SITE_NAME', get_bloginfo( 'name' ) );
define( 'THEME_URI', get_template_directory_uri() );
define( 'THEME_IMG', THEME_URI . '/assets/img' );
define( 'THEME_CSS', THEME_URI . '/assets/css' );
define( 'THEME_FONTS', THEME_URI . '/assets/fonts' );
define( 'THEME_JS', THEME_URI . '/assets/js' );
/**
* Calling related files
*/
include TEMPLATEPATH . '/inc/customizer.php';
include TEMPLATEPATH . '/inc/site.php';
include TEMPLATEPATH . '/inc/widgets.php';
/**
* Images
* ------
* */
// Add theme suppor for post thumbnails
add_theme_support( 'post-thumbnails' );
// Define custom thumbnail sizes
add_image_size( 'squared', 300, 300, true );
add_image_size( 'landscape-small', 550, 300, true );
add_image_size( 'landscape-medium', 740, 416, true );
add_image_size( 'landscape-featured', 1100, 170, true );
/**
* THEME SIDEBARS
* Default sidebars availables
*/
$mandatory_sidebars = array(
'Footer' => array(
'name' => 'footer',
)
);
foreach ( $mandatory_sidebars as $sidebar => $id_sidebar ) {
register_sidebar(
array(
'name' => $sidebar,
'id' => $id_sidebar['name'],
'before_widget' => '<section id="%1$s" class="widget %2$s">' . "\n",
'after_widget' => '</section>',
'before_title' => '<header class="widget-header"><h3 class="widget-title">',
'after_title' => '</h3></header>',
)
);
}
/**
* Theme singleton class
* ---------------------
* Stores various theme and site specific info and groups custom methods
**/
class Site {
private static $instance;
const id = __CLASS__;
const theme_ver = '2020.04.1';
private function __construct() {
$this->actions_manager();
}
public function __get( $key ) {
return isset( $this->$key ) ? $this->$key : null;
}
public function __isset( $key ) {
return isset( $this->$key );
}
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
$c = __CLASS__;
self::$instance = new $c();
}
return self::$instance;
}
public function __clone() {
trigger_error( 'Clone is not allowed.', E_USER_ERROR );
}
/**
* Setup theme actions, both in the front and back end
* */
public function actions_manager() {
add_action( 'after_setup_theme', array( $this, 'setup_theme' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'init', array( $this, 'init_functions' ) );
add_action( 'init', array( $this, 'register_menus_locations' ) );
add_action( 'admin_init', array( $this, 'openglam_add_editor_styles' ) );
}
public function init_functions() {
add_post_type_support( 'page', 'excerpt' );
}
public function setup_theme() {
$available_post_formats = array( 'gallery', 'image', 'video' );
add_theme_support( 'post-formats', $available_post_formats );
add_theme_support( 'post-thumbnails' );
add_theme_support( 'menus' );
add_theme_support( 'responsive-embeds' );
add_theme_support( 'editor-styles');
add_theme_support( 'editor-color-palette', array(
array(
'name' => __( 'Light Yellow', 'openglam' ),
'slug' => 'og-light-yellow',
'color' => '#FFF2DF',
),
array(
'name' => __( 'Light Orange', 'openglam' ),
'slug' => 'og-light-orange',
'color' => '#FFEFEB',
),
array(
'name' => __( 'Light Green', 'openglam' ),
'slug' => 'og-light-green',
'color' => '#E6F4F1',
),
array(
'name' => __( 'Green', 'openglam' ),
'slug' => 'og-green',
'color' => '#0D7D72',
),
array(
'name' => __( 'Orange', 'openglam' ),
'slug' => 'og-orange',
'color' => '#CC3A00',
),
array(
'name' => __( 'Brown', 'openglam' ),
'slug' => 'og-brown',
'color' => '#BD7800',
),
) );
}
public function register_menus_locations() {
$theme_menus = array(
'main-navigation' => 'Main navigation',
'footer-navigation' => 'Footer navigation',
'404-navigation' => '404 Navigation',
);
register_nav_menus( $theme_menus );
}
public function get_post_thumbnail_url( $postid = null, $size = 'landscape-medium' ) {
if ( is_null( $postid ) ) {
global $post;
$postid = $post->ID;
}
$thumb_id = get_post_thumbnail_id( $postid );
$img_src = wp_get_attachment_image_src( $thumb_id, $size );
return $img_src ? current( $img_src ) : '';
}
public function openglam_add_editor_styles() {
add_editor_style( 'assets/css/editor-styles.css' );
}
public function enqueue_styles() {
// Front-end styles
wp_enqueue_style( 'gfonts', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap' );
wp_enqueue_style( 'vocabulary_fonts', 'https://unpkg.com/@creativecommons/fonts/css/fonts.css', self::theme_ver );
wp_enqueue_style( 'cc_base_style', THEME_CSS . '/styles.css', self::theme_ver );
}
function enqueue_scripts() {
// front-end scripts
wp_enqueue_script( 'jquery', true );
wp_enqueue_script( 'vocabulary', THEME_JS . '/script.js', array('jquery'), self::theme_ver, true );
}
}
/**
* Instantiate the class object
* */
$_s = Site::get_instance();