-
Notifications
You must be signed in to change notification settings - Fork 1
/
oye_notification.php
193 lines (169 loc) · 7.27 KB
/
oye_notification.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
/**
* The plugin bootstrap file
*
* This file is read by WordPress to generate the plugin information in the plugin
* admin area. This file also includes all of the dependencies used by the plugin,
* registers the activation and deactivation functions, and defines a function
* that starts the plugin.
*
* @link http://jeoga.com/
* @since 1.0.0
* @package oye-notification
*
* @wordpress-plugin
* Plugin Name: Oye Notification
* Plugin URI: https://github.com/mrkhanakia/wp_oye_notification.git
* Description: Show Notification Bar on your website.
* Version: 1.0.0
* Author: Aman Khanakia
* Author URI: http://jeoga.com/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: oye-notification
* Domain Path: /languages
*/
// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Currently pligin version.
* Start at version 1.0.0 and use SemVer - https://semver.org
* Rename this for your plugin and update it as you release new versions.
*/
define( 'OYE_NOTIFICATION', 'oye-notification' );
define( 'OYE_NOTIFICATION_VERSION', '1.0.0' );
/**
* The code that runs during plugin activation.
* This action is documented in includes/class-oye-notification-activator.php
*/
function activate_plugin_name() {
// require_once plugin_dir_path( __FILE__ ) . 'includes/class-oye-notification-activator.php';
// Plugin_Name_Activator::activate();
}
/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-oye-notification-deactivator.php
*/
function deactivate_plugin_name() {
// require_once plugin_dir_path( __FILE__ ) . 'includes/class-oye-notification-deactivator.php';
// Plugin_Name_Deactivator::deactivate();
}
register_activation_hook( __FILE__, 'activate_plugin_name' );
register_deactivation_hook( __FILE__, 'deactivate_plugin_name' );
/**
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
// require plugin_dir_path( __FILE__ ) . 'includes/class-oye-notification.php';
/**
* Begins execution of the plugin.
*
* Since everything within the plugin is registered via hooks,
* then kicking off the plugin from this point in the file does
* not affect the page life cycle.
*
* @since 1.0.0
*/
require plugin_dir_path( __FILE__) . 'vendor/autoload.php';
function rms_enqueue_script() {
wp_enqueue_script( OYE_NOTIFICATION, plugin_dir_url( __FILE__ ) . 'public/js/oye-notification-public.js', array( 'jquery' ), OYE_NOTIFICATION_VERSION, false );
wp_enqueue_style( OYE_NOTIFICATION, plugin_dir_url( __FILE__ ) . 'public/css/oye-notification-public.css', array(), OYE_NOTIFICATION_VERSION, 'all' );
}
add_action( 'wp_enqueue_scripts', 'rms_enqueue_script' );
function run_oye_notification() {
// Our custom post type function
function create_posttype() {
register_post_type( 'notification_bar',
array(
'labels' => array(
'name' => 'Notification Bar',
),
'menu_position' => 15,
'supports' => array( 'title', 'custom-fields' ),
'rewrite' => array( 'slug' => false, 'with_front' => false ),
'has_archive' => true,
'public' => false, // it's not public, it shouldn't have it's own permalink, and so on
'publicly_queriable' => true, // you should be able to query it
'show_ui' => true, // you should be able to edit it in wp-admin
)
);
}
// Hooking up our function to theme setup
add_action( 'init', 'create_posttype' );
add_filter( 'rwmb_meta_boxes', 'mb_composer_example_register_meta_boxes' );
function mb_composer_example_register_meta_boxes( $meta_boxes ) {
$meta_boxes[] = array(
'id' => 'notification_data',
'title' => __('Notification Section', ''),
'pages' => array('notification_bar'),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'name' => __('Notification Text', ''),
'id' => "notification_bar_text",
'type' => 'textarea',
'desc' => __(''),
),
array(
'name' => __('Notification Start Date', ''),
'id' => "notification_bar_startdate",
'type' => 'date',
'desc' => __(''),
),
array(
'name' => __('Notification End Date', ''),
'id' => "notification_bar_enddate",
'type' => 'date',
'desc' => __(''),
),
array(
'name' => __('Notification Background Color', ''),
'id' => "notification_bar_background",
'type' => 'color',
'desc' => __(''),
),
array(
'name' => __('Notification Text Color', ''),
'id' => "notification_bar_textcolor",
'type' => 'color',
'desc' => __(''),
),
),
);
return $meta_boxes;
}
function render_template() {
$args = array( 'post_type' => 'notification_bar', 'posts_per_page' => 20,'orderby' => 'menu_order', 'post_status' => 'publish');
$posts = get_posts($args);
$loader = new \Twig_Loader_Filesystem(plugin_dir_path( __FILE__).'public/views');
$twig = new \Twig_Environment($loader, array(
// 'cache' => '/path/to/compilation_cache',
));
$template = $twig->load('notification-bar.twig');
foreach ($posts as $key => $post) {
$meta_data = get_post_meta( $post->ID);
$template_args = [
'notification_bar_text' => get_post_meta($post->ID, 'notification_bar_text', true),
'notification_bar_startdate' => get_post_meta($post->ID, 'notification_bar_startdate', true),
'notification_bar_enddate' => get_post_meta($post->ID, 'notification_bar_enddate', true),
'notification_bar_background' => get_post_meta($post->ID, 'notification_bar_background', true),
'notification_bar_textcolor' => get_post_meta($post->ID, 'notification_bar_textcolor', true),
];
// var_dump($template_args);
$mydate = date('Y-m-d');
if ($template_args['notification_bar_text']
&& $template_args['notification_bar_startdate']
&& $template_args['notification_bar_enddate']
&& $template_args['notification_bar_startdate'] <= $mydate
&& $mydate <= $template_args['notification_bar_enddate']
&& $template_args['notification_bar_startdate'] <= $template_args['notification_bar_enddate']) {
echo $template->render($template_args);
}
}
}
add_action( 'wp_footer', 'render_template');
}
run_oye_notification();