-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.php
176 lines (147 loc) · 6.93 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
<?php
function portfolio_theme_setup() {
remove_action( 'wp_head', 'wp_generator' );
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'rel_canonical' );
add_action( 'init', 'register_custom_menu' );
add_action( 'init', 'portfolio_projects' );
add_action( 'init', 'portfolio_client_work' );
add_action( 'load-post.php', 'portfolio_project_url_meta_box_setup' );
add_action( 'load-post-new.php', 'portfolio_project_url_meta_box_setup' );
add_action( 'wp_enqueue_scripts', 'portfolio_enqueue_styles_and_scripts' );
add_filter( 'wp_default_scripts', 'change_default_jquery_behavior' );
}
function register_custom_menu() {
register_nav_menu( 'main-nav', 'Main Nav' );
}
function portfolio_projects() {
$labels = array(
'name' => _x( 'Projects', 'post type general name' ),
'singular_name' => _x( 'Project', 'post type singular name' ),
'add_new' => _x( 'Add New', 'book' ),
'add_new_item' => __( 'Add New Project' ),
'edit_item' => __( 'Edit Project' ),
'new_item' => __( 'New Project' ),
'all_items' => __( 'All Projects' ),
'view_item' => __( 'View Project' ),
'search_items' => __( 'Search Projects' ),
'not_found' => __( 'No Projects found' ),
'not_found_in_trash' => __( 'No Projects found in the Trash' ),
'parent_item_colon' => '',
'menu_name' => 'Projects'
);
$args = array(
'labels' => $labels,
'description' => 'Shows off some projects',
'public' => true,
'menu_position' => 5,
'supports' => array( 'title', 'editor' ),
'has_archive' => true
);
register_post_type( 'Projects', $args );
}
function portfolio_client_work() {
$labels = array(
'name' => _x( 'Client Work', 'post type general name' ),
'singular_name' => _x( 'ClientWork', 'post type singular name' ),
'add_new' => _x( 'Add New', 'book' ),
'add_new_item' => __( 'Add New Project' ),
'edit_item' => __( 'Edit Project' ),
'new_item' => __( 'New Project' ),
'all_items' => __( 'All Projects' ),
'view_item' => __( 'View Project' ),
'search_items' => __( 'Search Projects' ),
'not_found' => __( 'No Projects found' ),
'not_found_in_trash' => __( 'No Projects found in the Trash' ),
'parent_item_colon' => '',
'menu_name' => 'Client Work'
);
$args = array(
'labels' => $labels,
'description' => 'Shows off some client work',
'public' => true,
'exclude_from_search' => true,
'rewrite' => array( 'slug' => _x( 'TODO', 'URL slug', 'post type slug' ) ),
'menu_position' => 5,
'supports' => array( 'title', 'editor' ),
'has_archive' => true
);
register_post_type( 'Client Work', $args );
}
function portfolio_project_url_meta_box_setup() {
add_action( 'add_meta_boxes', 'portfolio_project_url_add_meta_box' );
add_action( 'add_meta_boxes', 'portfolio_project_url_clientwork_add_meta_box' );
add_action( 'save_post', 'portfolio_project_url_save_meta' );
}
function portfolio_project_url_add_meta_box() {
add_meta_box(
'portfolio-project-url',
esc_html__( 'Project URL', 'url' ),
'portfolio_project_url_meta_box',
'projects',
'normal',
'default'
);
}
function portfolio_project_url_clientwork_add_meta_box() {
add_meta_box(
'portfolio-project-url',
esc_html__( 'Project URL', 'url' ),
'portfolio_project_url_meta_box',
'client work',
'normal',
'default'
);
}
function portfolio_project_url_meta_box( $object, $box ) {
?>
<?php wp_nonce_field( basename( __FILE__ ), 'portfolio_project_url_nonce' ); ?>
<p>
<label for="portfolio-project-url"><?php _e( "Add a URL to the live project.", 'example' ); ?></label>
<br />
<input class="widefat" type="text" name="portfolio-project-url" id="portfolio-project-url" value="<?php echo esc_attr( get_post_meta( $object->ID, 'portfolio_project_url', true ) ); ?>" size="30" />
</p>
<?php
}
function portfolio_project_url_save_meta( $post_id ) {
if ( !isset( $_POST['portfolio_project_url_nonce'] ) || !wp_verify_nonce( $_POST['portfolio_project_url_nonce'], basename( __FILE__ ) ) ) {
return $post_id;
}
$new_meta_value = ( isset( $_POST['portfolio-project-url'] ) ? sanitize_text_field( $_POST['portfolio-project-url'] ) : '' );
$meta_key = 'portfolio_project_url';
$meta_value = get_post_meta( $post_id, $meta_key, true );
if ( $new_meta_value && '' == $meta_value ) {
add_post_meta( $post_id, $meta_key, $new_meta_value, true );
}
elseif ( $new_meta_value && $new_meta_value != $meta_value ) {
update_post_meta( $post_id, $meta_key, $new_meta_value );
}
elseif ( '' == $new_meta_value && $meta_value ) {
delete_post_meta( $post_id, $meta_key, $meta_value );
}
}
function change_default_jquery_behavior( &$scripts ) {
if ( !is_admin() ) {
$scripts->remove( 'jquery' );
$scripts->add( 'jquery', false, array( 'jquery-core' ), '1.10.2' );
}
}
// enqueue styles and scripts
function portfolio_enqueue_styles_and_scripts() {
if ( !is_admin() ) {
// register styles
wp_register_style( 'base', get_stylesheet_uri(), array(), '1.0.1', 'all' );
// register scripts
wp_register_script( 'modernizr', get_template_directory_uri() . '/elements/js/libs/modernizr.custom.min.js', array(), '2.6.2', false );
wp_register_script( 'base', get_template_directory_uri() . '/elements/js/base.js', array( 'jquery' ), '1.0.1', true );
// enqueue styles and scripts
wp_enqueue_style( 'base' );
wp_enqueue_script( 'modernizr' );
wp_enqueue_script( 'base' );
// some conditional scripts
//wp_register_script( 'selectivzr', get_template_directory_uri() . '/elements/js/libs/selectivizr-min.js', array( 'jquery' ), '1.0.2', false );
}
}
add_action( 'after_setup_theme', 'portfolio_theme_setup' );
?>