-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwp-mxit.php
118 lines (99 loc) · 2.74 KB
/
wp-mxit.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
/**
* Plugin Name: WP Mxit
* Plugin URI:
* Description: Turn WordPress into a Mxit app.
* Version: 0.0.1
* Author: Glio
* Author URI: http://www.glio.co.za
* License: GPL2 GNU GPLv2+
*/
//TODO:
/**
* Analytics
* Referral link
* Expose query_posts args through settings
*/
//Mxit Header
function is_mxit() {
$headers = getallheaders();
if ((array_key_exists ( "X_MXIT_USERID_R", $headers ) ) || (array_key_exists ( "X-Mxit-Userid-R", $headers ) ) ) {
return true;
} else {
return false;
}
}
if (is_mxit()) {
add_filter( 'page_template', 'wp_mxit_page_template' );
add_filter( 'single_template', 'wp_mxit_single_template' );
add_filter( 'archive_template', 'wp_mxit_archive_template' );
add_filter( 'category_template', 'wp_mxit_category_template' );
add_filter( 'home_template', 'wp_mxit_home_template' );
}
// Parts
function get_mxit_header() {
$header_file = 'parts/mxit-header.php';
$mxit_header = plugin_dir_path( __FILE__ ) . $header_file;
return include $mxit_header;
}
function get_mxit_footer() {
$footer_file = 'parts/mxit-footer.php';
$mxit_footer = plugin_dir_path( __FILE__ ) . $footer_file;
return include $mxit_footer;
}
function get_mxit_nav() {
$nav_file = 'parts/mxit-nav.php';
$mxit_nav = plugin_dir_path( __FILE__ ) . $nav_file;
return include $mxit_nav;
}
function get_mxit_home() {
$home_file = 'templates/home.php';
$mxit_home = plugin_dir_path( __FILE__ ) . $home_file;
return include $mxit_home;
}
// Templates
function wp_mxit_home_template ($page_template) {
if (is_home() && is_front_page()) {
$page_template = dirname( __FILE__ ) . '/templates/home.php';
} else {
$page_template = dirname( __FILE__ ) . '/templates/archive.php';
}
return $page_template;
}
function wp_mxit_page_template( $page_template ) {
global $post;
if ( is_front_page() ) {
$page_template = dirname( __FILE__ ) . '/templates/front-page.php';
} else {
$page_template = dirname( __FILE__ ) . '/templates/page.php';
}
return $page_template;
}
function wp_mxit_single_template($single_template) {
global $post;
if ( is_single()) {
$single_template = dirname( __FILE__ ) . '/templates/single.php';
}
return $single_template;
}
function wp_mxit_archive_template( $archive_template ) {
global $post;
if ( is_archive() ) {
$archive_template = dirname( __FILE__ ) . '/templates/archive.php';
}
return $archive_template;
}
function wp_mxit_category_template( $taxonomy_template ) {
global $post;
if ( is_category() ) {
$category_template = dirname( __FILE__ ) . '/templates/archive.php';
}
return $category_template;
}
// Nav
register_nav_menus( array(
'mxit_nav' => 'Mxit Navigation',
) );
// Settings
include_once ( plugin_dir_path( __FILE__ ) . 'admin/settings.php');
?>