下面代碼在 WordPress Admin Bar 增加一個(gè)當(dāng)前日志的快速刪除鏈接,復(fù)制到當(dāng)前的主題的 functions.php 文件即可:
<span class="sh_symbol"><?</span>php <span style="color: rgb(165, 42, 42); font-weight: normal; font-style. normal; " class="sh_keyword">function</span> <span style="color: rgb(0, 0, 0); font-weight: bold; font-style. normal; " class="sh_function">my_add_admin_bar_trash_menu</span><span class="sh_symbol">()</span> <span class="sh_cbracket">{</span> global $wp_admin_bar<span class="sh_symbol">;</span> <span style="color: rgb(165, 42, 42); font-weight: normal; font-style. normal; " class="sh_keyword">if</span> <span class="sh_symbol">(</span> <span class="sh_symbol">!</span><span style="color: rgb(0, 0, 0); font-weight: bold; font-style. normal; " class="sh_function">is_super_admin</span><span class="sh_symbol">()</span> <span class="sh_symbol">||</span> <span class="sh_symbol">!</span><span style="color: rgb(0, 0, 0); font-weight: bold; font-style. normal; " class="sh_function">is_admin_bar_showing</span><span class="sh_symbol">()</span> <span class="sh_symbol">)</span> <span style="color: rgb(165, 42, 42); font-weight: normal; font-style. normal; " class="sh_keyword">return</span><span class="sh_symbol">;</span> $current_object <span class="sh_symbol">=</span> <span style="color: rgb(0, 0, 0); font-weight: bold; font-style. normal; " class="sh_function">get_queried_object</span><span class="sh_symbol">();</span> <span style="color: rgb(165, 42, 42); font-weight: normal; font-style. normal; " class="sh_keyword">if</span> <span class="sh_symbol">(</span> <span style="color: rgb(0, 0, 0); font-weight: bold; font-style. normal; " class="sh_function">empty</span><span class="sh_symbol">(</span>$current_object<span class="sh_symbol">)</span> <span class="sh_symbol">)</span> <span style="color: rgb(165, 42, 42); font-weight: normal; font-style. normal; " class="sh_keyword">return</span><span class="sh_symbol">;</span> <span style="color: rgb(165, 42, 42); font-weight: normal; font-style. normal; " class="sh_keyword">if</span> <span class="sh_symbol">(</span> <span class="sh_symbol">!</span><span style="color: rgb(0, 0, 0); font-weight: bold; font-style. normal; " class="sh_function">empty</span><span class="sh_symbol">(</span> $current_object<span class="sh_symbol">-></span>post_type <span class="sh_symbol">)</span> <span class="sh_symbol">&&</span> <span class="sh_symbol">(</span> $post_type_object <span class="sh_symbol">=</span> <span style="color: rgb(0, 0, 0); font-weight: bold; font-style. normal; " class="sh_function">get_post_type_object</span><span class="sh_symbol">(</span> $current_object<span class="sh_symbol">-></span>post_type <span class="sh_symbol">)</span> <span class="sh_symbol">)</span> <span class="sh_symbol">&&</span> <span style="color: rgb(0, 0, 0); font-weight: bold; font-style. normal; " class="sh_function">current_user_can</span><span class="sh_symbol">(</span> $post_type_object<span class="sh_symbol">-></span>cap<span class="sh_symbol">-></span>edit_post<span class="sh_symbol">,</span> $current_object<span class="sh_symbol">-></span>ID <span class="sh_symbol">)</span> <span class="sh_symbol">)</span> <span class="sh_cbracket">{</span> $wp_admin_bar<span class="sh_symbol">-></span><span style="color: rgb(0, 0, 0); font-weight: bold; font-style. normal; " class="sh_function">add_menu</span><span class="sh_symbol">(</span> <span style="color: rgb(0, 0, 0); font-weight: bold; font-style. normal; " class="sh_function">array</span><span class="sh_symbol">(</span> <span style="color: rgb(255, 0, 255); font-weight: normal; font-style. normal; " class="sh_string">'id'</span> <span class="sh_symbol">=></span> <span style="color: rgb(255, 0, 255); font-weight: normal; font-style. normal; " class="sh_string">'delete'</span><span class="sh_symbol">,</span> <span style="color: rgb(255, 0, 255); font-weight: normal; font-style. normal; " class="sh_string">'title'</span> <span class="sh_symbol">=></span> <span style="color: rgb(0, 0, 0); font-weight: bold; font-style. normal; " class="sh_function">__</span><span class="sh_symbol">(</span><span style="color: rgb(255, 0, 255); font-weight: normal; font-style. normal; " class="sh_string">'Move to Trash'</span><span class="sh_symbol">),</span> <span style="color: rgb(255, 0, 255); font-weight: normal; font-style. normal; " class="sh_string">'href'</span> <span class="sh_symbol">=></span> <span style="color: rgb(0, 0, 0); font-weight: bold; font-style. normal; " class="sh_function">get_delete_post_link</span><span class="sh_symbol">(</span>$current_object<span class="sh_symbol">-></span>term_id<span class="sh_symbol">)</span> <span class="sh_symbol">)</span> <span class="sh_symbol">);</span> <span class="sh_cbracket">}</span> <span class="sh_cbracket">}</span> <span style="color: rgb(0, 0, 0); font-weight: bold; font-style. normal; " class="sh_function">add_action</span><span class="sh_symbol">(</span> <span style="color: rgb(255, 0, 255); font-weight: normal; font-style. normal; " class="sh_string">'admin_bar_menu'</span><span class="sh_symbol">,</span> <span style="color: rgb(255, 0, 255); font-weight: normal; font-style. normal; " class="sh_string">'my_add_admin_bar_trash_menu'</span><span class="sh_symbol">,</span> <span style="color: rgb(255, 0, 255); font-weight: normal; font-style. normal; " class="sh_number">35</span> <span class="sh_symbol">);</span> <span class="sh_symbol">?></span>