init_hooks();
}
/**
* Initialize hooks
*/
private function init_hooks() {
// Register shortcodes
add_shortcode('hvac_announcements_timeline', array($this, 'render_timeline_shortcode'));
add_shortcode('hvac_announcements_list', array($this, 'render_list_shortcode'));
add_shortcode('hvac_google_drive_embed', array($this, 'render_google_drive_shortcode'));
// Filter for UAGB post timeline to include our post type
add_filter('uagb_post_timeline_query_args', array($this, 'modify_uagb_query'), 10, 2);
// Enqueue scripts when shortcode is used
add_action('wp_enqueue_scripts', array($this, 'maybe_enqueue_scripts'));
}
/**
* Render announcements timeline shortcode
*
* @param array $atts Shortcode attributes
* @return string
*/
public function render_timeline_shortcode($atts) {
// Check permissions
if (!HVAC_Announcements_Permissions::current_user_can_read()) {
return '
' . __('You do not have permission to view announcements.', 'hvac') . '
';
}
$atts = shortcode_atts(array(
'posts_per_page' => 10,
'orderby' => 'date',
'order' => 'DESC',
), $atts);
// Query announcements
$args = array(
'post_type' => HVAC_Announcements_CPT::get_post_type(),
'posts_per_page' => intval($atts['posts_per_page']),
'orderby' => sanitize_text_field($atts['orderby']),
'order' => sanitize_text_field($atts['order']),
'post_status' => 'publish',
);
$query = new WP_Query($args);
ob_start();
?>
have_posts()) : ?>
have_posts()) : $query->the_post(); ?>
max_num_pages > 1) : ?>
' . __('You do not have permission to view announcements.', 'hvac') . '';
}
$atts = shortcode_atts(array(
'posts_per_page' => 5,
'show_excerpt' => 'yes',
'show_date' => 'yes',
'show_author' => 'no',
), $atts);
// Query announcements
$args = array(
'post_type' => HVAC_Announcements_CPT::get_post_type(),
'posts_per_page' => intval($atts['posts_per_page']),
'orderby' => 'date',
'order' => 'DESC',
'post_status' => 'publish',
);
$query = new WP_Query($args);
ob_start();
?>
have_posts()) : ?>
have_posts()) : $query->the_post(); ?>
-
' . __('You do not have permission to view training resources.', 'hvac') . '';
}
$atts = shortcode_atts(array(
'url' => 'https://drive.google.com/drive/folders/1-SDHGR9Ix6BmUVTHa3wI99K0rwfWL-vs?usp=drive_link',
'height' => '600',
'width' => '100%',
), $atts);
// Convert sharing URL to embed URL
$embed_url = $this->convert_drive_url_to_embed($atts['url']);
ob_start();
?>
post_type !== HVAC_Announcements_CPT::get_post_type()) {
return '';
}
// Check permissions
if (!HVAC_Announcements_Permissions::current_user_can_read()) {
return '';
}
// Only allow viewing of published posts unless user is a master trainer
if ($post->post_status !== 'publish' && !HVAC_Announcements_Permissions::is_master_trainer()) {
return '';
}
ob_start();
?>
ID)) : ?>
ID, 'large'); ?>
post_content); ?>
ID, HVAC_Announcements_CPT::get_category_taxonomy());
$tags = wp_get_post_terms($post->ID, HVAC_Announcements_CPT::get_tag_taxonomy());
if (!empty($categories) || !empty($tags)) :
?>
post_content, 'hvac_announcements_timeline') ||
has_shortcode($post->post_content, 'hvac_announcements_list')
)) {
// Enqueue the view script
wp_enqueue_script(
'hvac-announcements-view',
plugin_dir_url(dirname(__FILE__)) . 'assets/js/hvac-announcements-view.js',
array('jquery'),
defined('HVAC_VERSION') ? HVAC_VERSION : '1.0.0',
true
);
// Localize script
wp_localize_script('hvac-announcements-view', 'hvac_ajax', array(
'ajax_url' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('hvac_announcements_nonce'),
));
// Also enqueue the CSS
wp_enqueue_style(
'hvac-announcements',
plugin_dir_url(dirname(__FILE__)) . 'assets/css/hvac-announcements.css',
array(),
defined('HVAC_VERSION') ? HVAC_VERSION : '1.0.0'
);
}
}
}