Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- # Allow a quicker means of editing the page's Contact Form 7 entry.
- if(defined('WPCF7_VERSION')){
- add_action('admin_bar_menu', function($menu){
- global $post, $wpdb, $current_screen;
- # In admin panel: check if we're editing an existing CF7 entry.
- if(is_admin() && @('toplevel_page_wpcf7' === $GLOBALS['current_screen']->id)){
- if($page = $wpdb->get_row($wpdb->prepare('SELECT * FROM '.$wpdb->posts.' WHERE (post_type = \'page\' OR post_type = \'post\') AND post_content LIKE \'%%[contact-form-7 id="%d"%%\'', $_GET['post']))){
- $type = get_post_type_object($page->post_type);
- $menu->add_node(array(
- 'id' => 'edit-wpcf7-page',
- 'title' => $type->labels->edit_item,
- 'href' => get_edit_post_link($page->ID),
- 'meta' => array('class' => 'ab-icon-edit', 'title' => 'Edit the page using this contact form')
- ));
- }
- return;
- }
- # Sanity check: bail if there's no $post global available.
- if(!$post) return;
- # Post's content contains at least one CF7 shortcode; parse it and grab its ID.
- if(preg_match('#\[contact-form-7[^\]]+id="(\d+)"[^\]]*\]#', $post->post_content, $matches)){
- $id = $matches[1];
- $menu->add_node(array(
- 'id' => 'edit-wpcf7',
- 'title' => 'Contact Form',
- 'href' => admin_url('admin.php?page=wpcf7&post=' . $id . '&action=edit'),
- 'meta' => array('class' => 'ab-icon-email')
- ));
- }
- }, 90);
- # DOM juice for adding icons to inserted admin-bar links.
- add_action('wp_after_admin_bar_render', function(){
- ?>
- <style type="text/css">.ab-icon-email > a::before{content: "\F466"; top: 2px;}.ab-icon-edit > a::before{content:"\F464"; top: 2px;}</style>
- <?php
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement