purge_all_cache();
}
}, 10, 2);
}
}
public static function add_toolbar_items( $admin_bar ){
$admin_bar->add_menu([
'id' => 'ld-edit-header-footer',
'title' => 'Edit Header & Footer',
'href' => esc_url( admin_url( 'edit.php?post_type=liquid-header' ) ),
'meta' => [
'title' => __( 'Edit Header & Footer', 'aihub-core'),
],
]);
$header_and_footer = array_merge(self::get_available_custom_post('liquid-header'), self::get_available_custom_post('liquid-footer'));
foreach ( $header_and_footer as $item ){
if ( liquid_get_custom_header_id() == $item['id'] || liquid_get_custom_footer_id() == $item['id'] ){
$current = '';
} else {
$current = '';
}
$admin_bar->add_menu(
[
'id' => 'ld-edit-header-footer-' . $item['id'],
'parent' => 'ld-edit-header-footer',
'title' => sprintf( '%s - %s %s', $item['title'], $item['type'], $current ),
'href' => \Elementor\Plugin::$instance->documents->get( $item['id'] )->get_edit_url(),
'meta' => [
'title' => $item['title'],
'target' => '_blank',
'class' => 'ld_edit_header_footer ' . strtolower( $item['type'] ),
],
]
);
}
}
static function cache_purge_action_css() {
echo('');
}
static function cache_purge_action_js() {
wp_add_inline_script( 'admin-bar', '
const ajaxurl = "' . admin_url('admin-ajax.php') . '";
jQuery("li#wp-admin-bar-ld-purge-assets-cache .ab-item").on("click", function (e) {
e.preventDefault();
const link = e.target;
const data = {
"action": "hub_cache_purge",
"type" : link.parentElement.classList.value,
"id" : ' . get_the_ID() . '
};
link.classList.add("lqd-is-loading");
jQuery.post(ajaxurl, data, function (response) {
link.classList.remove("lqd-is-loading");
window.location.reload();
});
});
');
}
static function cache_purge_action_js_admin() {
?>
purge_all_cache();
}
private static function get_available_custom_post( $type ) {
$posts = get_posts( array(
'post_type' => $type,
'posts_per_page' => -1,
) );
$options = [];
$type = $type === 'liquid-header' ? 'Header' : 'Footer';
foreach ( $posts as $post ) {
$options[] = [ 'id' => $post->ID, 'title' => $post->post_title, 'type' => $type ];
}
return $options;
}
}
LQD_AdminBarMenu::init();