Skip to content

Commit 462e09c

Browse files
authored
Merge pull request #1 from UNC-Libraries/block-display
Block display
2 parents 933fd79 + 08c4e92 commit 462e09c

25 files changed

+1199
-997
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.idea
2+
.DS_Store

README.md

+23-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22

33
Embed opening hours for any given location from LibCal into WordPress via short codes.
44

5-
![Opening hours displayed in a published post](assets/screenshot-1.png)
5+
### Table View
6+
![Opening hours displayed in a table](assets/screenshot-1.png)
7+
8+
### Grid View
9+
![Opening hours displayed as a grid](assets/grid-view-multiple-weeks.png)
10+
11+
### Stacked View
12+
![Opening hours displayed as a grid](assets/stacked-view-multiple-weeks.png)
13+
14+
### Today Only View
15+
![Opening hours displayed as a grid](assets/today-only-view.png)
616

717
## Installation
818

@@ -25,15 +35,25 @@ Embed the `[wplibcalhours]` short code into your posts and pages.
2535

2636
The short code has the following configuration options.
2737

28-
- `location` ... The name of the location that you want to display opening hours for. *(mandatory)*
29-
- `num_weeks` ... The number of weeks of opening hours to display. Accepted values are `1`, `2` and `3`. Defaults to `3`. *(optional)*.
38+
- `location` ... The name of the location that you want to display opening hours for. *(mandatory)*
39+
- `display_type` ... The layout of hours information. Options are `table`, `grid` and `stacked`. Defaults to `grid`. *(optional)*
40+
- `num_weeks` ... The number of weeks of opening hours to display. Accepted values are `1`, `2` and `3`. Defaults to `3`. *(optional)*
41+
- `show_status_icon` ... Show status icon for whether a library is open. Defaults to `true`. *(optional)*
42+
- `today_only` ... Show hours for the current day only. Note if this is set to `true` it supersedes the `num_week` option. Defaults to `false`. *(optional)*
3043

3144
### Examples
3245

3346
`[wplibcalhours location="Parnassus Library"]` - This will print the opening hours for the "Parnassus Library" location for the next three weeks (starting today).
3447

3548
`[wplibcalhours location="Parnassus Library" num_weeks=1]` - Prints the opening hours for the "Parnassus Library" for the next week (starting today).
3649

50+
`[wplibcalhours location="Art (Sloane) Library" display_type="grid"]` - Prints the opening hours for the "Art" in a grid layout (starting today).
51+
52+
`[wplibcalhours location="Art (Sloane) Library" display_type="stacked"]` - Prints the opening hours for the "Art Library" in a stacked layout (starting today).
53+
54+
`[wplibcalhours location="Art (Sloane) Library" today_only=true]` - Prints the opening hours for the "Art Library" for today.
55+
56+
`[wplibcalhours location="Art (Sloane) Library" today_only=true show_status_icon=false]` - Prints the opening hours for the "Art Library" for today without the open/closed status icon.
3757
## API
3858

3959
This plugin also exposes opening hours via a read-only, public API endpoint.

admin/class-wplibcalhours-admin.php

+123-146
Original file line numberDiff line numberDiff line change
@@ -21,150 +21,127 @@
2121
* @author Stefan Topfstedt <[email protected]>
2222
*/
2323
class WpLibCalHours_Admin {
24-
25-
/**
26-
* The ID of this plugin.
27-
*
28-
* @since 1.0.0
29-
* @access private
30-
* @var string $plugin_name The ID of this plugin.
31-
*/
32-
private $plugin_name;
33-
34-
/**
35-
* The version of this plugin.
36-
*
37-
* @since 1.0.0
38-
* @access private
39-
* @var string $version The current version of this plugin.
40-
*/
41-
private $version;
42-
43-
/**
44-
* Initialize the class and set its properties.
45-
*
46-
* @since 1.0.0
47-
*
48-
* @param string $plugin_name The name of this plugin.
49-
* @param string $version The version of this plugin.
50-
*/
51-
public function __construct( $plugin_name, $version ) {
52-
53-
$this->plugin_name = $plugin_name;
54-
$this->version = $version;
55-
}
56-
57-
/**
58-
* Add an options page under the Settings submenu
59-
*
60-
* @since 1.0.0
61-
*/
62-
public function add_options_page() {
63-
$this->plugin_screen_hook_suffix = add_options_page(
64-
__( 'LibCal Hours Settings', 'wplibcalhours' ),
65-
__( 'LibCal Hours', 'wplibcalhours' ),
66-
'manage_options',
67-
$this->plugin_name,
68-
array( $this, 'display_options_page' )
69-
);
70-
}
71-
72-
/**
73-
* Render the options page for plugin
74-
*
75-
* @since 1.0.0
76-
*/
77-
public function display_options_page() {
78-
include_once 'partials/wplibcalhours-admin-display.php';
79-
}
80-
81-
/**
82-
* Register all related settings of this plugin
83-
*
84-
* @since 1.0.0
85-
*/
86-
public function register_setting() {
87-
$section_name = $this->plugin_name . '_general';
88-
add_settings_section(
89-
$section_name,
90-
null,
91-
null,
92-
$this->plugin_name
93-
);
94-
95-
$option_name = $this->plugin_name . '_api_url';
96-
add_settings_field(
97-
$option_name,
98-
__( 'LibCal API endpoint (URL)', 'wplibcalhours' ),
99-
array( $this, $option_name . '_cb' ),
100-
$this->plugin_name,
101-
$section_name,
102-
array( 'label_for' => $option_name )
103-
);
104-
register_setting( $this->plugin_name, $option_name, 'sanitize_text_field' );
105-
106-
$option_name = $this->plugin_name . '_ignore_cache';
107-
add_settings_field(
108-
$option_name,
109-
__( 'Ignore Cache', 'wplibcalhours' ),
110-
array( $this, $option_name . '_cb' ),
111-
$this->plugin_name,
112-
$section_name,
113-
array( 'label_for' => $option_name )
114-
);
115-
register_setting( $this->plugin_name, $option_name, 'intval' );
116-
}
117-
118-
/**
119-
* Render the LibCal API endpoint input for this plugin
120-
*
121-
* @since 1.0.0
122-
*/
123-
public function wplibcalhours_api_url_cb() {
124-
$option_name = $this->plugin_name . '_api_url';
125-
$url = get_option( $option_name );
126-
echo '<input type="url" class="regular-text" name="' . $option_name . '" id="' . $option_name . '" value="' . esc_attr( $url ) . '"> ';
127-
}
128-
129-
/**
130-
* Render the "Ignore Cache" checkbox field for this plugin.
131-
*
132-
* @since 1.0.0
133-
*/
134-
public function wplibcalhours_ignore_cache_cb() {
135-
$option_name = $this->plugin_name . '_ignore_cache';
136-
$ignore_cache = get_option( $option_name );
137-
echo '<input type="checkbox" name="' . $option_name . '" value="1" ' . checked( '1', $ignore_cache, false ) . '/>';
138-
}
139-
140-
/**
141-
* Filter-callback function that adds links to the list of links displayed on the plugins page.
142-
*
143-
* @param array $actions array List of existing links.
144-
*
145-
* @return array The updated list of links.
146-
*
147-
* @link https://codex.wordpress.org/Plugin_API/Filter_Reference/plugin_action_links_(plugin_file_name)
148-
*
149-
* @since 1.0.0
150-
*/
151-
public function add_action_links( $actions ) {
152-
$settings = '<a href="' . esc_attr( get_admin_url( null,
153-
'options-general.php?page=wplibcalhours' ) ) . '">' . __( 'Settings', 'General' ) . '</a>';
154-
array_unshift( $actions, $settings );
155-
156-
return $actions;
157-
}
158-
159-
/**
160-
* Update option callback on the "Ignore Cache" setting.
161-
* Clears out any LibCal data that may be in the transient cache if this option's value changes.
162-
*
163-
* @link https://developer.wordpress.org/reference/hooks/update_option_option/
164-
*
165-
* @since 1.0.0
166-
*/
167-
public function update_option_ignore_cache() {
168-
delete_transient( $this->plugin_name . '_data' );
169-
}
24+
/**
25+
* The ID of this plugin.
26+
* @access private
27+
* @var string $plugin_name The ID of this plugin.
28+
*/
29+
private string $plugin_name;
30+
31+
/**
32+
* The version of this plugin.
33+
* @access private
34+
* @var string $version The current version of this plugin.
35+
*/
36+
private string $version;
37+
38+
/**
39+
* Initialize the class and set its properties.
40+
* @param string $plugin_name The name of this plugin.
41+
* @param string $version The version of this plugin.
42+
*/
43+
public function __construct(string $plugin_name, string $version) {
44+
$this->plugin_name = $plugin_name;
45+
$this->version = $version;
46+
}
47+
48+
/**
49+
* Add an options page under the Settings submenu
50+
*/
51+
public function add_options_page() {
52+
$this->plugin_screen_hook_suffix = add_options_page(
53+
__('LibCal Hours Settings', 'wplibcalhours'),
54+
__('LibCal Hours', 'wplibcalhours'),
55+
'manage_options',
56+
$this->plugin_name,
57+
array($this, 'display_options_page')
58+
);
59+
}
60+
61+
/**
62+
* Render the options page for plugin
63+
*/
64+
public function display_options_page() {
65+
include_once 'partials/wplibcalhours-admin-display.php';
66+
}
67+
68+
/**
69+
* Register all related settings of this plugin
70+
*/
71+
public function register_setting() {
72+
$section_name = $this->plugin_name . '_general';
73+
add_settings_section(
74+
$section_name,
75+
null,
76+
null,
77+
$this->plugin_name
78+
);
79+
80+
$option_name = $this->plugin_name . '_api_url';
81+
add_settings_field(
82+
$option_name,
83+
__('LibCal API endpoint (URL)', 'wplibcalhours'),
84+
array($this, $option_name . '_cb'),
85+
$this->plugin_name,
86+
$section_name,
87+
array('label_for' => $option_name)
88+
);
89+
register_setting($this->plugin_name, $option_name, 'sanitize_text_field');
90+
91+
$option_name = $this->plugin_name . '_ignore_cache';
92+
add_settings_field(
93+
$option_name,
94+
__('Ignore Cache', 'wplibcalhours'),
95+
array($this, $option_name . '_cb'),
96+
$this->plugin_name,
97+
$section_name,
98+
array('label_for' => $option_name)
99+
);
100+
register_setting($this->plugin_name, $option_name, 'intval');
101+
}
102+
103+
/**
104+
* Render the LibCal API endpoint input for this plugin
105+
*/
106+
public function wplibcalhours_api_url_cb() {
107+
$option_name = $this->plugin_name . '_api_url';
108+
$url = get_option($option_name);
109+
echo '<input type="url" class="regular-text" name="' . $option_name . '" id="' . $option_name . '" value="' . esc_attr($url) . '"> ';
110+
}
111+
112+
/**
113+
* Render the "Ignore Cache" checkbox field for this plugin.
114+
*/
115+
public function wplibcalhours_ignore_cache_cb() {
116+
$option_name = $this->plugin_name . '_ignore_cache';
117+
$ignore_cache = get_option($option_name);
118+
echo '<input type="checkbox" name="' . $option_name . '" value="1" ' . checked('1', $ignore_cache, false) . '/>';
119+
}
120+
121+
/**
122+
* Filter-callback function that adds links to the list of links displayed on the plugins page.
123+
*
124+
* @param array $actions array List of existing links.
125+
*
126+
* @return array The updated list of links.
127+
*
128+
* @link https://codex.wordpress.org/Plugin_API/Filter_Reference/plugin_action_links_(plugin_file_name)
129+
*/
130+
public function add_action_links(array $actions) {
131+
$settings = '<a href="' . esc_attr(get_admin_url(null,
132+
'options-general.php?page=wplibcalhours')) . '">' . __('Settings', 'General') . '</a>';
133+
array_unshift($actions, $settings);
134+
135+
return $actions;
136+
}
137+
138+
/**
139+
* Update option callback on the "Ignore Cache" setting.
140+
* Clears out any LibCal data that may be in the transient cache if this option's value changes.
141+
*
142+
* @link https://developer.wordpress.org/reference/hooks/update_option_option/
143+
*/
144+
public function update_option_ignore_cache() {
145+
delete_transient($this->plugin_name . '_data');
146+
}
170147
}

admin/partials/wplibcalhours-admin-display.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
<div class="wrap">
1616
<h2><?php echo esc_html( get_admin_page_title() ); ?></h2>
1717
<form action="options.php" method="post">
18-
<?php
19-
settings_fields( $this->plugin_name );
20-
do_settings_sections( $this->plugin_name );
21-
submit_button();
22-
?>
18+
<?php
19+
settings_fields( $this->plugin_name );
20+
do_settings_sections( $this->plugin_name );
21+
submit_button();
22+
?>
2323
</form>
2424
</div>

assets/grid-view-multiple-weeks.png

59.7 KB
Loading

assets/grid-view-shortcode.png

29.5 KB
Loading
90.4 KB
Loading

assets/stacked-view-shortcode.png

31.1 KB
Loading

assets/today-only-shortcode.png

26.7 KB
Loading

assets/today-only-view.png

22.7 KB
Loading

config/deploy.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
set :application, 'hours-of-operation'
2+
set :repo_url, 'https://github.com/UNC-Libraries/wplibcalhours.git'
3+
4+
set :linked_dirs, %w[vendor]
5+
6+
set :deploy_to, "/net/deploy/#{fetch(:stage)}/#{fetch(:application)}"
7+
8+
set :pty, true

config/deploy/qa.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
server 'www-dev.lib.unc.edu', roles: [:app], user: 'swallow'
2+
3+
set :branch, 'main'

0 commit comments

Comments
 (0)