forked from simplebits/Pears
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pattern-pears-plugin.php
89 lines (65 loc) · 2.35 KB
/
pattern-pears-plugin.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
<?php
/*
Plugin Name: Pattern Pears Plugin
Description: Dan Cederholm's Pears theme as a plugin, for use on existing sites. Uses a 'pears' custom post type and a 'pattern category' taxonomy to keep things separate.
Version: 0.1
Author: Hinerangi Courtenay
Author URI: http://skymaiden.com/
License: GPLv2
*/
/**
* Activation
*/
register_activation_hook( __FILE__, 'pattern_pears_install' );
function pattern_pears_install() {
// future activation stuff like set default options
}
/**
* Add custom post type
*/
require_once( plugin_dir_path( __FILE__ ) . '/inc/pattern-pears-posttype.php' );
/**
* Add meta boxes
*/
require_once( plugin_dir_path( __FILE__ ) . '/inc/pattern-pears-metabox.php' );
/**
* Add custom taxonomy
*/
require_once( plugin_dir_path( __FILE__ ) . '/inc/pattern-pears-taxonomy.php' );
/**
* Enqueue front-end styles and scripts
*/
add_action( 'wp_enqueue_scripts', 'pattern_pears_assets_front' );
function pattern_pears_assets_front() {
if( get_post_type() == 'pattern_pear' ) {
wp_enqueue_style( 'pears.screen', plugins_url( '/css/screen.less', __FILE__ ), array() , false , 'screen' );
add_filter('style_loader_tag', 'enqueue_less_styles');
wp_enqueue_script( 'pears.less', plugins_url( '/js/less.js', __FILE__ ), array(), false, false );
wp_enqueue_script( 'pears.js', plugins_url( '/js/pears.js', __FILE__ ), array('jquery'), false, true );
}
}
/* Find and replace the 'rel' attribute for Less stylesheet */
function enqueue_less_styles( $tag ) {
return preg_replace( "/='stylesheet' id='pears.screen-css'/", "='stylesheet/less' id='pears.screen-css'", $tag );
}
/**
* Use custom template
*/
add_action('template_redirect', 'pattern_pears_set_template');
function pattern_pears_set_template() {
$template_single_path = plugin_dir_path( __FILE__ ) . '/inc/pattern-pears-template-single.php';
$template_path = plugin_dir_path( __FILE__ ) . '/inc/pattern-pears-template.php';
if ( get_post_type() == 'pattern_pear' ) {
if ( is_singular() ) {
if( file_exists( $template_single_path ) ) {
include( $template_single_path );
exit;
}
} else {
if( file_exists( $template_path ) ) {
include( $template_path );
exit;
}
}
}
}