Making WordPress.org

Changeset 2372


Ignore:
Timestamp:
01/26/2016 08:15:53 PM (9 years ago)
Author:
drewapicture
Message:

DevHub: Add an 'Edit Explanation' Toolbar link to front-end reference pages if an explanation of any status exists for that reference.

Fixes #1534.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/explanations.php

    r2153 r2372  
    4141        add_action( 'edit_form_after_title',   array( $this, 'post_to_expl_controls'  )      );
    4242        add_action( 'edit_form_top',           array( $this, 'expl_to_post_controls'  )      );
     43        add_action( 'admin_bar_menu',          array( $this, 'toolbar_edit_link'      ), 100 );
    4344
    4445        // Script and styles.
     
    171172
    172173    /**
     174     * Adds an 'Edit Explanation' link to the Toolbar on parsed post type single pages.
     175     *
     176     * @access public
     177     *
     178     * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance.
     179     */
     180    public function toolbar_edit_link( $wp_admin_bar ) {
     181        global $wp_the_query;
     182
     183        $screen = $wp_the_query->get_queried_object();
     184
     185        if ( is_admin() || empty( $screen->post_type ) || ! is_singular( $this->post_types ) ) {
     186            return;
     187        }
     188
     189        if ( ! empty( $screen->post_type ) ) {
     190            // Proceed only if there's an explanation for the current reference post type.
     191            if ( $explanation = \DevHub\get_explanation( $screen ) ) {
     192                $post_type = get_post_type_object( $this->exp_post_type );
     193
     194                $wp_admin_bar->add_menu( array(
     195                    'id'    => 'edit-explanation',
     196                    'title' => $post_type->labels->edit_item,
     197                    'href'  => get_edit_post_link( $explanation )
     198                ) );
     199            }
     200        }
     201    }
     202
     203    /**
    173204     * Output the Explanation status controls.
    174205     *
Note: See TracChangeset for help on using the changeset viewer.