-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_calendar.php
78 lines (66 loc) · 2.53 KB
/
view_calendar.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
<?php
/*
Plugin Name: View Calendar
Description: Тестовый плагин смены шаблона
License: Free
*/
class ViewCalendar
{
private $plugin_name = 'View Calendar';
private $plugin_slug = 'calendar_template';
private $options;
public function __construct() {
$this->options = get_option( $this->plugin_slug . '_options' );
add_action( 'admin_menu', array( $this, 'adminMenu' ) );
add_action( 'admin_init', array( $this, 'registerSettings' ) );
add_shortcode( 'link_to_calendar', array( $this, 'shortcode' ) );
add_action( 'template_redirect', array( $this, 'getTemplate' ), 5 );
register_activation_hook( __FILE__, array( $this, 'activate' ) );
}
public function adminMenu() {
add_options_page( $this->plugin_name, $this->plugin_name, 'manage_options', $this->plugin_slug, array( $this, 'optionsPage' ) );
add_filter( 'plugin_action_links', array( $this, 'optionsLinks' ), 10, 2 );
}
public function optionsLinks( $actions, $plugin_file ) {
if ( $plugin_file == plugin_basename( __FILE__ ) ) {
$settings_link = '<a href="options-general.php?page=' . esc_attr( $this->plugin_slug ) . '">' . __( 'Settings', $this->plugin_slug ) . '</a>';
array_unshift( $actions, $settings_link );
}
return $actions;
}
public function registerSettings() {
register_setting( $this->plugin_slug, $this->plugin_slug . '_options' );
}
function registerScript()
{
wp_register_script( 'jquery-calendar', plugins_url( '/js/lib/jquery.min.js', __FILE__ ), array(), true );
wp_register_script( 'moment', plugins_url( '/js/lib/moment.min.js', __FILE__ ), array(), true );
wp_register_script( 'fullcalendar', plugins_url( '/js/fullcalendar.js', __FILE__ ), array(), true );
wp_register_script( 'calendar', plugins_url( '/js/calendar.js', __FILE__ ), array(), true );
wp_enqueue_script(array('jquery-calendar','moment', 'fullcalendar', 'calendar'));
wp_register_style( 'calendar-style', plugins_url( '/css/fullcalendar.css', __FILE__ ), array(), true );
wp_enqueue_style( 'calendar-style' );
}
public function getTemplate() {
if ( $this->checkMyTemplate() ) {
$this->registerScript();
include( plugin_dir_path( __FILE__ ) . 'calendar.php' );
exit();
}
}
private function checkMyTemplate() {
return isset( $_GET['view'] ) && $_GET['view'] == calendar;
}
public function optionsPage() {
?>
<div class="wrap">
<h2><?php echo esc_html( $this->plugin_name ); ?></h2>
</div>
<?php
}
}
new ViewCalendar;
function Calendar_shortcode_link() {
$new_calendar = new ViewCalendar;
echo $new_calendar->shortcode();
}