Making WordPress.org


Ignore:
Timestamp:
02/18/2017 11:39:32 AM (10 years ago)
Author:
ocean90
Message:

Translate: Render WordPress' toolbar on front end.

Since GlotPress has its own header/footer actions we have to call WordPress' render callbacks on them.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-customizations/inc/class-plugin.php

    r4325 r4923  
    4545                add_filter( 'wporg_translate_language_pack_theme_args', array( $this, 'set_version_for_twentyseventeen_language_pack' ), 10, 2 );
    4646
     47                // Toolbar.
     48                add_action( 'admin_bar_menu', array( $this, 'add_profile_settings_to_admin_bar' ) );
     49                add_action( 'admin_bar_init', array( $this, 'show_admin_bar' ) );
     50                add_action( 'add_admin_bar_menus', array( $this, 'remove_admin_bar_menus' ) );
     51
     52                add_action( 'template_redirect', array( $this, 'jetpack_stats' ), 1 );
     53
    4754                // Load the API endpoints.
    4855                add_action( 'rest_api_init', array( __NAMESPACE__ . '\REST_API\Base', 'load_endpoints' ) );
     
    5158                        $this->register_cli_commands();
    5259                }
     60        }
     61
     62        /**
     63         * Adds support for Jetpack Stats.
     64         */
     65        public function jetpack_stats() {
     66                if ( ! function_exists( 'stats_hide_smile_css' ) ) {
     67                        return;
     68                }
     69
     70                add_action( 'gp_head', 'stats_hide_smile_css' );
     71                add_action( 'gp_head', 'stats_admin_bar_head', 100 );
     72                add_action( 'gp_footer', 'stats_footer', 101 );
     73        }
     74
     75        /**
     76         * Renders the toolbar.
     77         */
     78        public function show_admin_bar() {
     79                add_action( 'gp_head', 'wp_admin_bar_header' );
     80                add_action( 'gp_head', '_admin_bar_bump_cb' );
     81
     82                gp_enqueue_script( 'admin-bar' );
     83                gp_enqueue_style( 'admin-bar' );
     84
     85                add_action( 'gp_footer', 'wp_admin_bar_render', 1000 );
     86        }
     87
     88        /**
     89         * Adds the linkt to profile settings to the user actions toolbar menu.
     90         *
     91         * @param \WP_Admin_Bar $wp_admin_bar
     92         */
     93        public function add_profile_settings_to_admin_bar( $wp_admin_bar ) {
     94                $logout_node = $wp_admin_bar->get_node( 'logout' );
     95                $wp_admin_bar->remove_node( 'logout' );
     96
     97                $wp_admin_bar->add_node( [
     98                        'parent' => 'user-actions',
     99                        'id'     => 'gp-profile-settings',
     100                        'title'  => 'Translate Settings',
     101                        'href'   => gp_url( '/settings' ),
     102                ] );
     103
     104                if ( $logout_node ) {
     105                        $wp_admin_bar->add_node( $logout_node ); // Ensures that logout is the last action.
     106                }
     107        }
     108
     109        /**
     110         * Removes default toolbar menus which are not needed.
     111         */
     112        public function remove_admin_bar_menus() {
     113                remove_action( 'admin_bar_menu', 'wp_admin_bar_search_menu', 4 );
     114                remove_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 60 );
     115                remove_action( 'admin_bar_menu', 'wp_admin_bar_new_content_menu', 70 );
     116                remove_action( 'admin_bar_menu', 'wp_admin_bar_edit_menu', 80 );
    53117        }
    54118
Note: See TracChangeset for help on using the changeset viewer.