0
snips.php
44 lines 1.7 kB view raw
1//might need to remove the word "code" so dumb servers dont block it 2add_action('admin_bar_menu', function($wp_admin_bar) { 3 if (!current_user_can('add_users')) return; 4 5 global $wpdb; 6 $wp_admin_bar->add_node([ 7 'id' => 'custom_code_snippets', 8 'title' => '<span class="ab-icon dashicons dashicons-editor-code"></span> Snippets', 9 'href' => '#', 10 'meta' => ['class' => 'custom-code-snippets'] 11 ]); 12 13 $snippets = $wpdb->get_results($wpdb->prepare( 14 "SELECT id, name, code FROM {$wpdb->prefix}snippets WHERE active = %d ORDER BY name ASC", 1 15 )); 16 foreach ($snippets as $snippet) { 17 $prefix = (trim($snippet->code)[0] ?? '') === '<' ? '[html]' : '[php]'; 18 $wp_admin_bar->add_node([ 19 'id' => "snippet-{$snippet->id}", 20 'title' => esc_html("{$snippet->name} {$prefix}"), 21 'parent' => 'custom_code_snippets', 22 'href' => admin_url("admin.php?page=edit-snippet&id={$snippet->id}"), 23 'meta' => ['class' => 'snippet-item', 'title' => 'Code'] 24 ]); 25 } 26 27 foreach (get_posts([ 28 'post_type' => 'elementor_snippet', 29 'numberposts' => -1, 30 'post_status' => 'publish' 31 ]) as $esnippet) { 32 $wp_admin_bar->add_node([ 33 'id' => "snippet_{$esnippet->ID}", 34 'title' => esc_html("{$esnippet->post_title} [html]"), 35 'parent' => 'custom_code_snippets', 36 'href' => admin_url("post.php?post={$esnippet->ID}&action=edit&classic-editor"), 37 'meta' => ['title' => 'Elementor'] 38 ]); 39 } 40}, 100); 41 42add_filter( 'action_scheduler_retention_period', function() { 43 return 7 * DAY_IN_SECONDS; 44});