Skip to content

Instantly share code, notes, and snippets.

@codeminelab
codeminelab / gist:fda5ebb2cb5edb243f9e43f365e01b52
Created December 8, 2020 15:40
Calendar Anything - iCal if end time empty set 1 hour later from start time
add_filter('cmcal_ical_event', 'cmcal_ical_event_default_1_hour', 100, 3);
function cmcal_ical_event_default_1_hour($ical_event, $event_id, $calendar_id) {
// Event is NOT All Day
if (strpos($ical_event["DTSTART"], "T") !== false) {
$DTEND = DateTime::createFromFormat('Ymd\THis', $ical_event["DTEND"]);
$DTEND_time = $DTEND->format("His");
//Hour is not set
if ($DTEND_time == "000000") {
$DTSTART = DateTime::createFromFormat('Ymd\THis', $ical_event["DTSTART"]);
@codeminelab
codeminelab / gist:d3f9ba5492c1d9a0466d07fc707f0755
Last active November 23, 2020 15:19
Calendar anything - Javascript add_filter (cmcal_event_visible, cmcal_settings_before_init) for calendar settings and event visibility
/**
* Add shortcode for multiweeks calendar
*/
add_shortcode('paramount_calendar_weeks', 'paramount_calendar_weeks_shortcode');
function paramount_calendar_weeks_shortcode($atts) {
$studio_id = $atts["studio-id"];
// if (empty($studio_id)) {
// return '';
add_filter('cmcal_calendar_posts_query', 'calendar_return_specific_category', 10, 2);
function calendar_return_specific_category($query_args, $calendar_id) {
// restrict this option for a specific calendar
if ($calendar_id == '128') {
// Show only posts created by author id -> 2
$query_args["author__in"] = array( 2 );
}
return $query_args;
}
@codeminelab
codeminelab / gist:867a501383085d484a7f81d900a19665
Created June 9, 2020 12:25
Calendar Anything - Set national holidays as non-business days
add_action('wp_enqueue_scripts', 'cmcal_events_same_time_reorder', 9999);
add_action('admin_enqueue_scripts', 'cmcal_events_same_time_reorder', 9999);
function cmcal_events_same_time_reorder() {
//128 is the calendar id
$output = 'document.addEventListener("DOMContentLoaded", function () {
var non_business_days = ["2020-06-08", "2020-06-10", "2020-07-22"];
non_business_days.forEach(set_non_business_days);
@codeminelab
codeminelab / gist:cc34f47abd6cbc37eb4fe96517272949
Created May 19, 2020 13:18
Calendar anything - Send the author to edit the event directly when clicking event
add_filter('cmcal_event_data', 'cmcal_event_data_custom', 10, 3);
function cmcal_event_data_custom($data, $calendar_id, $id) {
if (current_user_can('edit_posts')) { // only show the options to users that can edit the post
if ($calendar_id == '128') { // restrict this option for a specific calendar
$data['url'] = admin_url('/post.php?post=' . $id . '&action=edit');
$data['url_new_window'] = 'true';
}
}
return $data;
@codeminelab
codeminelab / gist:8040bf4a249d6fbae30fa7c8cdb103c4
Created April 23, 2020 08:51
WordPress Tooltip Ultimate - Do not render tooltip on specific pages
add_filter('check_if_render_live_tooltip', 'render_live_tooltip_pages', 10, 2);
function render_live_tooltip_pages($render_tooltip, $id) {
//Apply only for specific tooltip id
if ($id == '733') {
$post_ids_not_to_render = array(102, 142);
if (is_page($post_ids_not_to_render) || is_single($post_ids_not_to_render)) {
//Do not render tooltip
return false;
} else {
@codeminelab
codeminelab / gist:9501be423a59396c28da799cf3ea7795
Last active February 20, 2020 08:03
Calendar anything japanese fix for day numbers suffix character
add_action('wp_enqueue_scripts', 'cmcal_custom_script', 9999);
function cmcal_custom_script(){
$output = "function cmcal_custom_title(start, end, locale, view, calendar_id) {
if (view == 'dayGridMonth') {
jQuery('#cmcal_calendar_' + calendar_id + ' .fc-day-number').each(function () {
var day = jQuery(this).html();
var day_new = day.replace('日', '');
jQuery(this).html(day_new);
@codeminelab
codeminelab / gist:2909da092fc892361042051809395628
Last active March 4, 2020 17:54
Calendar anything fix for event multiple categories and coloring
add_filter('cmcal_calendar_event', 'cmcal_calendar_set_color', 10, 2);
function cmcal_calendar_set_color($event, $calendar_id) {
$event_properties = $event->properties;
$event_id = $event_properties["id"];
// replace 'event-categories' with your taxonomy slug
$terms = get_the_terms($event_id, 'event-categories');
if (!empty($terms)) {
foreach ($terms as $term) {
@codeminelab
codeminelab / gist:5687731d233f3541d40d2f43c64db0f3
Last active December 17, 2019 14:30
Woocommerce products visibility: hide category + show tag change operator from OR to AND
// Hide category and tag at the same time, uses an OR operator. Use the code below to change it to AND.
add_filter('wcpv_where', 'wcpv_where_custom', 10, 2);
function wcpv_where_custom($subquery, $query) {
$subquery = preg_replace('/AND/', '', $subquery, 1);
$subquery = str_replace('OR', 'AND', $subquery);
$subquery = 'AND ' . $subquery;
return $subquery;
}
@codeminelab
codeminelab / gist:c441a635c7eee07697455c8a6328e1cb
Created November 26, 2019 11:30
WordPress Tooltips Ultimate - Hotspot backend draggable image fix
add_action('admin_enqueue_scripts', 'hotspot_draggable_fix', 9999999999);
function hotspot_draggable_fix($enqueue_imagesloaded) {
$tooltip_styles = '.wpcmtt_hotspot_container .drag_element.ui-draggable {
width: unset !important;
}';
wp_add_inline_style('wpcmtt-hotspot-backend-css', $tooltip_styles);
}