This repository has been archived by the owner on Oct 11, 2023. It is now read-only.
/
ce-custom-functionality.php
130 lines (112 loc) · 3.63 KB
/
ce-custom-functionality.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
<?php
/**
* Plugin Name: Continuing Education Custom Functionality
* Plugin URI: https://github.com/BellevueCollege/ce-custom-functionality
* Description: Custom functions for Continuing Education
* Author: Bellevue College Integration Team
* Version: 2.0 #{versionStamp}#
* Author URI: http://www.bellevuecollege.edu
* GitHub Plugin URI: BellevueCollege/ce-custom-functionality
*
* @package cecf
*/
defined( 'ABSPATH' ) || exit;
/** Plugin Configuration Model */
require_once 'ce-plugin-config.php';
/** Settings Interface */
require_once 'ce-plugin-settings.php';
/** Programs Custom Post Type */
require_once 'post-types/ceprograms.php';
/** Cross Reference Taxonomy */
require_once 'taxonomies/ce-program-cross-ref.php';
/** The guts of the thing */
require_once 'ce-custom-functions.php';
/** Widget */
require_once 'ce-widget.php';
/**
* Main Class - Register All The Things!
*/
class CE_Custom_Functionality {
/**
* Constructor
*/
public function __construct() {
add_action( 'rest_api_init', array( $this, 'rest_register_routes' ) ); // initiate REST API.
add_action(
'widgets_init',
function() {
register_widget( 'ce_widget' );
}
); // register widget.
add_action( 'mayflower_register_sidebar', array( $this, 'ce_register_widget_area' ), 10 );
add_filter( 'mayflower_active_sidebar', array( $this, 'ce_active_widget_area' ), 1, 10 );
add_action( 'mayflower_display_sidebar', array( $this, 'ce_display_widget_area' ), 10 );
}
/**
* CE Initiate REST API
*
* Register the REST routes
*/
/** @var int $rest_version Version Number. */
public static $rest_version = '1'; // initiate version of this REST API
// register rest endpoints and provide callback to the handler
function rest_register_routes() {
$version = self::$rest_version;
$namespace = 'ce/v' . $version; // declares the home route of the REST API
// registered route tells the API to respond to a given request with a callback function
// this is one route with one endpoint method GET requesting a parameter ID on the URL
register_rest_route(
$namespace,
'/courses/(?P<id>\d+)',
array(
'methods' => 'GET',
'callback' => array( 'CE_Custom_Functions', 'cecf_rest_course_info' ),
'args' => array(
'id' => array(
'validate_callback' => function( $param, $request, $key ) {
return is_numeric( $param );
},
),
),
)
);
}
/**
* CE Programs Widget Area
*
* Add widget area to Mayflower sidebar
*/
// Register new widget area
public static function ce_register_widget_area() {
register_sidebar(
array(
'name' => __( 'CE Programs Widget Area', 'mayflower' ),
'id' => 'ceprograms-widget-area',
'description' => __( 'This is the CE Programs widget area. Items will appear on CE Programs custom post type pages.', 'mayflower' ),
'before_widget' => '<div class="wp-widget wp-widget-ceprograms %2$s">',
'after_widget' => '</div>',
'before_title' => '<h2 class="widget-title content-padding">',
'after_title' => '</h2>',
)
);
}
// Filter active sidebar function to insert new sidebar
public static function ce_active_widget_area( $active ) {
if ( is_singular( CE_Plugin_Settings::get_ce_post_type() ) ) {
return true;
} elseif ( $active ) {
return true;
} else {
return false;
}
}
// Display new widget area
public static function ce_display_widget_area() {
if ( is_active_sidebar( 'ceprograms-widget-area' ) ) :
if ( is_singular( CE_Plugin_Settings::get_ce_post_type() ) ) :
dynamic_sidebar( 'ceprograms-widget-area' );
endif;
endif;
}
}
$ce_custom_functionality = new CE_Custom_Functionality();