This repository has been archived by the owner on Jun 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
functions.php
118 lines (92 loc) · 3.04 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
<?php
function add_files() {
wp_enqueue_style('main_website_styles', get_stylesheet_uri());
}
add_action('wp_enqueue_scripts', 'add_files');
function theme_features() {
add_theme_support('title-tag');
add_theme_support('post-thumbnails');
add_image_size('homepage-banner', 2000, 705, true);
add_image_size('project-banner', 1024, 396, true);
add_image_size('project-thumbnail', 400, 300, true);
add_image_size('project-spotlight', 492, 277, true);
add_image_size('profile-picture', 120, 120, true);
}
add_action('after_setup_theme', 'theme_features');
function post_types() {
// Project Post Type
register_post_type('project', array(
'supports' => array( 'title', 'thumbnail'),
'public' => true,
'labels' => array(
'name' => 'Projects',
'add_new_item' => 'Add New Project',
'edit_item' => 'Edit Project',
'all_items' => 'All Projects',
'singular_name' => 'Project',
),
'menu_icon' => 'dashicons-welcome-widgets-menus',
));
}
add_action('init', 'post_types');
function menu_remove () {
remove_menu_page('edit.php');
remove_menu_page('edit-comments.php');
remove_menu_page('upload.php');
}
add_action('admin_menu', 'menu_remove');
function remove_content_editor () {
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
if( !isset( $post_id ) ) return;
$pagename = get_the_title($post_id);
if($pagename == 'Home'){
remove_post_type_support('page', 'editor');
}
}
add_action('admin_init', 'remove_content_editor');
function shorten_text($text, $length){
if(strlen($text)<$length+10) return $text; //don't cut if too short
$break_pos = strpos($text, ' ', $length); //find next space after desired length
$visible = substr($text, 0, $break_pos);
return balanceTags($visible) . '...';
}
function get_next_meetup () {
$response = wp_remote_get( 'https://api.meetup.com/Triangle-Code-for-America/events' );
if( is_wp_error( $response ) ) {
return false;
}
$body = wp_remote_retrieve_body( $response );
$data = json_decode( $body );
if( !empty( $data ) ) {
foreach ($data as &$meetup) {
if (substr( $meetup->name, 0, 15 ) === 'Code for Durham') {
return $meetup;
}
}
return false;
} else {
return false;
}
}
add_action('init', 'get_next_meetup');
function get_site_and_image($link) {
if ($link) {
$url = $link["url"];
$domain = parse_url($url, PHP_URL_HOST);
preg_match('/^(?:[^@\n]+@)?(?:www\.)?([^:\/\n?]+)\.\w*/', $domain, $matches, PREG_OFFSET_CAPTURE);
$site = $matches[1][0];
$images = array(
'meetup' => 'meetup.png',
'twitter' => 'twitter.svg',
'facebook' => 'facebook.svg',
'open-nc.slack' => 'slack.svg',
'github' => 'github.svg',
);
return array(
'site' => $site,
'image' => $images[$site],
);
}
}
add_action('init', 'get_site_and_image');
?>