Add gravity flow demo
This commit is contained in:
713
backend/wordpress/wp-content/plugins/view-admin-as/ui/class-admin-bar.php
Executable file
713
backend/wordpress/wp-content/plugins/view-admin-as/ui/class-admin-bar.php
Executable file
@@ -0,0 +1,713 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - Admin Bar UI
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin Bar UI for View Admin As.
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 1.5
|
||||
* @version 1.8
|
||||
* @uses \VAA_View_Admin_As_Base Extends class
|
||||
*/
|
||||
final class VAA_View_Admin_As_Admin_Bar extends VAA_View_Admin_As_Base
|
||||
{
|
||||
/**
|
||||
* The single instance of the class.
|
||||
*
|
||||
* @since 1.5
|
||||
* @static
|
||||
* @var \VAA_View_Admin_As_Admin_Bar
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* Admin bar root item ID.
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @static
|
||||
* @var string
|
||||
*/
|
||||
public static $root = 'vaa';
|
||||
|
||||
/**
|
||||
* Admin bar parent item ID.
|
||||
*
|
||||
* @since 1.7.4
|
||||
* @static
|
||||
* @var string
|
||||
*/
|
||||
public static $parent = 'top-secondary';
|
||||
|
||||
/**
|
||||
* Construct function.
|
||||
* Protected to make sure it isn't declared elsewhere.
|
||||
*
|
||||
* @since 1.5
|
||||
* @since 1.6.1 $vaa param
|
||||
* @access protected
|
||||
* @param \VAA_View_Admin_As $vaa The main VAA object.
|
||||
*/
|
||||
protected function __construct( $vaa ) {
|
||||
self::$_instance = $this;
|
||||
parent::__construct( $vaa );
|
||||
|
||||
if ( $this->is_vaa_enabled() ) {
|
||||
$this->add_action( 'vaa_view_admin_as_init', array( $this, 'vaa_init' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* init function to store data from the main class and enable functionality based on the current view.
|
||||
*
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @see 'vaa_view_admin_as_init' action
|
||||
* @return void
|
||||
*/
|
||||
public function vaa_init() {
|
||||
|
||||
$priority = 10;
|
||||
$location = $this->store->get_userSettings( 'admin_menu_location' );
|
||||
if ( $location && in_array( $location, $this->store->get_allowedUserSettings( 'admin_menu_location' ), true ) ) {
|
||||
self::$parent = $location;
|
||||
if ( 'my-account' === $location ) {
|
||||
$priority = -10;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Set the priority in which the adminbar root node is added.
|
||||
* @since 1.7.4
|
||||
* @param int $priority
|
||||
* @param string $parent The main VAA node parent.
|
||||
* @return int
|
||||
*/
|
||||
$priority = (int) apply_filters( 'vaa_admin_bar_priority', $priority, self::$parent );
|
||||
|
||||
// Add the default nodes to the WP admin bar.
|
||||
$this->add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), $priority );
|
||||
$this->add_action( 'vaa_toolbar_menu', array( $this, 'admin_bar_menu' ), 10, 2 );
|
||||
|
||||
// Add the global nodes to the admin bar.
|
||||
$this->add_action( 'vaa_admin_bar_menu', array( $this, 'admin_bar_menu_info' ), 1 );
|
||||
$this->add_action( 'vaa_admin_bar_menu', array( $this, 'admin_bar_menu_settings' ), 2 );
|
||||
$this->add_action( 'vaa_admin_bar_settings_after', array( $this, 'admin_bar_menu_view_types' ), 1, 2 );
|
||||
$this->add_action( 'vaa_admin_bar_settings_after', array( $this, 'admin_bar_menu_modules' ), 2, 2 );
|
||||
|
||||
if ( ! is_network_admin() ) {
|
||||
|
||||
if ( $this->current_user_can( 'view_admin_as_combinations' ) ) {
|
||||
// View combinations.
|
||||
$this->add_action( 'vaa_admin_bar_menu', array( $this, 'admin_bar_menu_combine' ), 8, 2 );
|
||||
}
|
||||
|
||||
// There are no outside visitors on network pages.
|
||||
// Add the visitor view nodes under roles with a fallback to users.
|
||||
$this->add_action( 'vaa_admin_bar_roles_after', array( $this, 'admin_bar_menu_visitor' ), 10, 2 );
|
||||
$this->add_action( 'vaa_admin_bar_users_before', array( $this, 'admin_bar_menu_visitor' ), 10, 2 );
|
||||
// Fallback action for when there are no roles or users available.
|
||||
$this->add_action( 'vaa_admin_bar_menu', array( $this, 'admin_bar_menu_visitor' ), 31 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the toolbar title for the main VAA node.
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @access private
|
||||
* @see \VAA_View_Admin_As_Admin_Bar::admin_bar_menu()
|
||||
* @return string
|
||||
*/
|
||||
private function get_admin_bar_menu_title() {
|
||||
if ( ! $this->store->get_view() ) {
|
||||
return __( 'Default view (Off)', VIEW_ADMIN_AS_DOMAIN );
|
||||
}
|
||||
|
||||
$titles = array();
|
||||
|
||||
if ( $this->store->get_view( 'visitor' ) ) {
|
||||
$titles[] = __( 'Site visitor', VIEW_ADMIN_AS_DOMAIN );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter what to show when a view is applied.
|
||||
*
|
||||
* @hooked
|
||||
* 5: user
|
||||
* 8: role
|
||||
* 10: group (Groups)
|
||||
* 10: rua_level (Restrict User Access)
|
||||
* 80: caps
|
||||
* 90: locale
|
||||
* 999: role defaults (appends an icon)
|
||||
*
|
||||
* @since 1.7.5
|
||||
*
|
||||
* @param array $titles The current title(s).
|
||||
* @param array $view The view data.
|
||||
*
|
||||
* @return array|string
|
||||
*/
|
||||
$titles = apply_filters( 'vaa_admin_bar_view_titles', $titles, (array) $this->store->get_view() );
|
||||
|
||||
if ( is_array( $titles ) ) {
|
||||
if ( 1 < count( $titles ) ) {
|
||||
// @todo Help icon for view info?
|
||||
// Translators: Context is a list of view types. Not the verb.
|
||||
$title = __( 'View', VIEW_ADMIN_AS_DOMAIN ) . ': ' . implode( ', ', $titles );
|
||||
} else {
|
||||
$type = key( $titles );
|
||||
$name = reset( $titles );
|
||||
$title = __( 'Viewing as', VIEW_ADMIN_AS_DOMAIN );
|
||||
if ( $type ) {
|
||||
$title .= ' ' . $type;
|
||||
}
|
||||
$title .= ': ';
|
||||
if ( $name ) {
|
||||
$title .= $name;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$title = (string) $titles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter what to show when a view is applied.
|
||||
* This filter is hooked after the initial parsing of view titles.
|
||||
*
|
||||
* @since 1.6
|
||||
* @since 1.7.5 Renamed from `vaa_admin_bar_viewing_as_title`.
|
||||
* @param string $title The current title.
|
||||
* @param string $view The view data.
|
||||
* @return string
|
||||
*/
|
||||
$title = apply_filters( 'vaa_admin_bar_title', $title, (array) $this->store->get_view() );
|
||||
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add admin bar menu items.
|
||||
*
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The root item ID/Name. If set it will overwrite the user setting.
|
||||
* @return void
|
||||
*/
|
||||
public function admin_bar_menu( $admin_bar, $root = '' ) {
|
||||
|
||||
$icon = 'dashicons-hidden';
|
||||
$tooltip = __( 'View Admin As', VIEW_ADMIN_AS_DOMAIN );
|
||||
|
||||
if ( $this->store->get_view() ) {
|
||||
$icon = 'dashicons-visibility';
|
||||
$tooltip .= ' - ' . __( 'View active', VIEW_ADMIN_AS_DOMAIN );
|
||||
}
|
||||
|
||||
$title = $this->get_admin_bar_menu_title();
|
||||
|
||||
if ( empty( $root ) ) {
|
||||
$root = self::$parent;
|
||||
}
|
||||
|
||||
// Add menu item.
|
||||
$admin_bar->add_node( array(
|
||||
'id' => self::$root,
|
||||
'parent' => $root,
|
||||
'title' => '<span class="ab-label">' . $title . '</span>' . VAA_View_Admin_As_Form::do_icon(
|
||||
$icon,
|
||||
array( 'class' => 'alignright' )
|
||||
),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'title' => $tooltip,
|
||||
'tabindex' => '0',
|
||||
),
|
||||
) );
|
||||
|
||||
/**
|
||||
* Add items as first.
|
||||
*
|
||||
* @since 1.5
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string self::$root The current root item.
|
||||
* @param string self::$root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_menu_before', $admin_bar, self::$root, self::$root );
|
||||
|
||||
// Add reset button.
|
||||
if ( $this->store->get_view() ) {
|
||||
$name = 'reset-view';
|
||||
if ( 'single' === $this->store->get_userSettings( 'view_mode' ) ) {
|
||||
$name = 'reload';
|
||||
}
|
||||
$admin_bar->add_node( array(
|
||||
'id' => self::$root . '-reset',
|
||||
'parent' => self::$root,
|
||||
'title' => VAA_View_Admin_As_Form::do_button( array(
|
||||
'name' => self::$root . '-' . $name,
|
||||
'label' => __( 'Reset to default', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'class' => 'button-secondary',
|
||||
) ),
|
||||
'href' => VAA_API::get_reset_link(),
|
||||
'meta' => array(
|
||||
'title' => esc_attr__( 'Reset to default', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'class' => 'vaa-reset-item vaa-button-container',
|
||||
),
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add items.
|
||||
*
|
||||
* @since 1.5
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string self::$root The current root item.
|
||||
* @param string self::$root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_menu', $admin_bar, self::$root, self::$root );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add admin bar menu info items.
|
||||
*
|
||||
* @hooked
|
||||
* 1: Info
|
||||
* 2: Settings
|
||||
* 5: Role Defaults module
|
||||
* 6: Role Manager module
|
||||
* 8: View combinations
|
||||
* 9: Languages view
|
||||
* 10: Capabilities view
|
||||
* 20: Roles view
|
||||
* 30: Users view
|
||||
* 31: Visitor view
|
||||
* 40: RUA & Groups view modules
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @see 'vaa_admin_bar_menu' action
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @return void
|
||||
*/
|
||||
public function admin_bar_menu_info( $admin_bar ) {
|
||||
|
||||
$root = self::$root . '-info';
|
||||
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root,
|
||||
'parent' => self::$root,
|
||||
'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-info' ) . __( 'Info', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'vaa-has-icon',
|
||||
'tabindex' => '0',
|
||||
),
|
||||
) );
|
||||
|
||||
$admin_bar->add_group( array(
|
||||
'id' => $root . '-about',
|
||||
'parent' => $root,
|
||||
'meta' => array(
|
||||
'class' => 'ab-sub-secondary',
|
||||
),
|
||||
) );
|
||||
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'parent' => $root . '-about',
|
||||
'id' => $root . '-about-version',
|
||||
'title' => __( 'Version', VIEW_ADMIN_AS_DOMAIN ) . ': ' . VIEW_ADMIN_AS_VERSION,
|
||||
'href' => false,
|
||||
)
|
||||
);
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'parent' => $root . '-about',
|
||||
'id' => $root . '-about-author',
|
||||
'title' => 'Keraweb • Jory Hogeveen',
|
||||
'href' => 'https://profiles.wordpress.org/keraweb/',
|
||||
'meta' => array(
|
||||
'target' => '_blank',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Add items at the beginning of the info group.
|
||||
*
|
||||
* @since 1.6
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
* @param string self::$root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_info_before', $admin_bar, $root, self::$root );
|
||||
|
||||
// Add the general admin links.
|
||||
if ( VAA_API::exists_callable( array( $this->vaa->get_ui( 'ui' ), 'get_links' ), true ) ) {
|
||||
$info_links = $this->vaa->get_ui( 'ui' )->get_links();
|
||||
|
||||
$admin_bar->add_group( array(
|
||||
'id' => $root . '-links',
|
||||
'parent' => $root,
|
||||
) );
|
||||
|
||||
foreach ( $info_links as $id => $link ) {
|
||||
$admin_bar->add_node( array(
|
||||
'parent' => $root . '-links',
|
||||
'id' => $root . '-' . $id,
|
||||
'title' => VAA_View_Admin_As_Form::do_icon( $link['icon'] ) . $link['description'],
|
||||
'href' => esc_url( $link['url'] ),
|
||||
'meta' => array(
|
||||
'class' => 'auto-height vaa-has-icon',
|
||||
'target' => '_blank',
|
||||
),
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add items at the end of the info group.
|
||||
*
|
||||
* @since 1.6
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
* @param string self::$root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_info_after', $admin_bar, $root, self::$root );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Add admin bar menu settings items.
|
||||
*
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @see 'vaa_admin_bar_menu' action
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @return void
|
||||
*/
|
||||
public function admin_bar_menu_settings( $admin_bar ) {
|
||||
|
||||
$root = self::$root . '-settings';
|
||||
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root,
|
||||
'parent' => self::$root,
|
||||
'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-admin-settings' ) . __( 'Settings', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'vaa-has-icon',
|
||||
'tabindex' => '0',
|
||||
),
|
||||
) );
|
||||
|
||||
/**
|
||||
* Add items at the beginning of the settings group.
|
||||
*
|
||||
* @since 1.5
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
* @param string self::$root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_settings_before', $admin_bar, $root, self::$root );
|
||||
|
||||
// Add user setting nodes.
|
||||
include VIEW_ADMIN_AS_DIR . 'ui/templates/adminbar-settings-user.php';
|
||||
|
||||
/**
|
||||
* Add items at the end of the settings group.
|
||||
*
|
||||
* @since 1.5
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
* @param string self::$root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_settings_after', $admin_bar, $root, self::$root );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add admin bar menu view type items.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @see 'vaa_admin_bar_menu' action
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
* @return void
|
||||
*/
|
||||
public function admin_bar_menu_view_types( $admin_bar, $root ) {
|
||||
|
||||
if ( ! VAA_API::is_super_admin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$view_types = $this->vaa->get_view_types();
|
||||
|
||||
// Do not render the view_types group if there are no view types to show.
|
||||
if ( ! $view_types ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$admin_bar->add_group( array(
|
||||
'id' => self::$root . '-view_types',
|
||||
'parent' => $root,
|
||||
'meta' => array(
|
||||
'class' => 'ab-sub-secondary',
|
||||
),
|
||||
) );
|
||||
|
||||
$root = self::$root . '-view_types';
|
||||
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root . '-title',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-visibility' ) . __( 'View types', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'vaa-has-icon ab-vaa-title ab-vaa-toggle active',
|
||||
'tabindex' => '0',
|
||||
),
|
||||
) );
|
||||
|
||||
$parent = $root;// . '-title';
|
||||
|
||||
$view_type_nodes = array();
|
||||
|
||||
foreach ( $view_types as $type ) {
|
||||
|
||||
$view_type_node = array(
|
||||
'name' => $root . '-' . $type->get_type(),
|
||||
'value' => $type->is_enabled(),
|
||||
'compare' => true,
|
||||
'label' => $type->get_label(),
|
||||
'auto_js' => array(
|
||||
'setting' => 'setting',
|
||||
'key' => 'view_types',
|
||||
'values' => array(
|
||||
$type->get_type() => array(
|
||||
'values' => array(
|
||||
'enabled' => array(),
|
||||
),
|
||||
),
|
||||
),
|
||||
'refresh' => true,
|
||||
),
|
||||
'auto_showhide' => true,
|
||||
);
|
||||
|
||||
if ( $type->get_description() ) {
|
||||
$view_type_node['description'] = $type->get_description();
|
||||
$view_type_node['help'] = true;
|
||||
}
|
||||
|
||||
$view_type_nodes[ $type->get_priority() ][] = array(
|
||||
'id' => $root . '-' . $type->get_type(),
|
||||
'parent' => $parent,
|
||||
'title' => VAA_View_Admin_As_Form::do_checkbox( $view_type_node ),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'auto-height',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
ksort( $view_type_nodes );
|
||||
foreach ( $view_type_nodes as $nodes ) {
|
||||
foreach ( $nodes as $node ) {
|
||||
$admin_bar->add_node( $node );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add items to the view_types group.
|
||||
*
|
||||
* @since 1.7.1
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
* @param string self::$root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_view_types', $admin_bar, $root, self::$root );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add admin bar menu modules items.
|
||||
*
|
||||
* @since 1.7.1
|
||||
* @access public
|
||||
* @see 'vaa_admin_bar_menu' action
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
* @return void
|
||||
*/
|
||||
public function admin_bar_menu_modules( $admin_bar, $root ) {
|
||||
|
||||
// Do not render the modules group if there are no modules to show.
|
||||
if ( ! has_action( 'vaa_admin_bar_modules' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$admin_bar->add_group( array(
|
||||
'id' => self::$root . '-modules',
|
||||
'parent' => $root,
|
||||
'meta' => array(
|
||||
'class' => 'ab-sub-secondary',
|
||||
),
|
||||
) );
|
||||
|
||||
$root = self::$root . '-modules';
|
||||
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root . '-title',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-admin-plugins' ) . __( 'Modules', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'vaa-has-icon ab-vaa-title ab-vaa-toggle active',
|
||||
'tabindex' => '0',
|
||||
),
|
||||
) );
|
||||
|
||||
/**
|
||||
* Add items to the modules group.
|
||||
*
|
||||
* @since 1.7.1
|
||||
* @see 'admin_bar_menu' action
|
||||
* @link https://codex.wordpress.org/Class_Reference/WP_Admin_Bar
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root The current root item.
|
||||
* @param string self::$root The main root item.
|
||||
*/
|
||||
do_action( 'vaa_admin_bar_modules', $admin_bar, $root, self::$root );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add admin bar menu visitor view.
|
||||
*
|
||||
* @since 1.6.2
|
||||
* @access public
|
||||
* @see 'vaa_admin_bar_menu' action
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root (optional) The root item.
|
||||
* @return void
|
||||
*/
|
||||
public function admin_bar_menu_visitor( $admin_bar, $root = '' ) {
|
||||
static $done;
|
||||
if ( $done ) return;
|
||||
|
||||
$main_root = self::$root;
|
||||
$class = 'vaa-visitor-item vaa-has-icon';
|
||||
|
||||
if ( empty( $root ) || $root === $main_root ) {
|
||||
|
||||
$admin_bar->add_group( array(
|
||||
'id' => $main_root . '-visitor',
|
||||
'parent' => $main_root,
|
||||
'meta' => array(
|
||||
'class' => 'ab-sub-secondary',
|
||||
),
|
||||
) );
|
||||
|
||||
$root = $main_root . '-visitor';
|
||||
$class .= ' ab-vaa-title';
|
||||
} else {
|
||||
$class .= ' vaa-menupop';
|
||||
}
|
||||
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $main_root . '-visitor-view',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_icon( 'dashicons-universal-access' )
|
||||
. VAA_View_Admin_As_Form::do_view_title( __( 'Site visitor', VIEW_ADMIN_AS_DOMAIN ), 'visitor', true ),
|
||||
'href' => '#',
|
||||
'meta' => array(
|
||||
'title' => esc_attr__( 'View as site visitor', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'class' => $class,
|
||||
),
|
||||
) );
|
||||
|
||||
$done = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add admin bar menu for view combinations.
|
||||
* Combine views node as last item in the default group.
|
||||
*
|
||||
* @since 1.8
|
||||
* @access public
|
||||
* @see 'vaa_admin_bar_menu' action
|
||||
* @param \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @param string $root (optional) The root item.
|
||||
* @return void
|
||||
*/
|
||||
public function admin_bar_menu_combine( $admin_bar, $root = '' ) {
|
||||
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root . '-combine-views',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_checkbox( array(
|
||||
'name' => $root . '-combine-views',
|
||||
'label' => __( 'Combine views', VIEW_ADMIN_AS_DOMAIN ),
|
||||
) ) . VAA_View_Admin_As_Form::do_button( array(
|
||||
'name' => $root . '-combine-views-apply',
|
||||
'label' => __( 'Apply', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'class' => 'button-primary ab-vaa-conditional vaa-alignright',
|
||||
'attr' => array(
|
||||
'vaa-condition-target' => '#' . $root . '-combine-views',
|
||||
),
|
||||
) ) . '<ul id="vaa-combine-views-selection" class="ab-sub-secondary ab-vaa-results" style="display: none;"></ul>',
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'title' => esc_attr__( 'Make view combinations', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'class' => 'vaa-button-container',
|
||||
),
|
||||
) );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Main Instance.
|
||||
*
|
||||
* Ensures only one instance of this class is loaded or can be loaded.
|
||||
*
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @static
|
||||
* @param \VAA_View_Admin_As $caller The referrer class
|
||||
* @return \VAA_View_Admin_As_Admin_Bar $this
|
||||
*/
|
||||
public static function get_instance( $caller = null ) {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self( $caller );
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
} // End class VAA_View_Admin_As_Admin_Bar.
|
||||
166
backend/wordpress/wp-content/plugins/view-admin-as/ui/class-toolbar.php
Executable file
166
backend/wordpress/wp-content/plugins/view-admin-as/ui/class-toolbar.php
Executable file
@@ -0,0 +1,166 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - Toolbar UI
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
if ( ! class_exists( 'WP_Admin_Bar' ) && file_exists( ABSPATH . WPINC . '/class-wp-admin-bar.php' ) ) {
|
||||
require_once ABSPATH . WPINC . '/class-wp-admin-bar.php';
|
||||
}
|
||||
|
||||
if ( class_exists( 'WP_Admin_Bar' ) ) {
|
||||
|
||||
/**
|
||||
* Toolbar UI for View Admin As.
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 1.6
|
||||
* @version 1.8
|
||||
* @see wp-includes/class-wp-admin-bar.php
|
||||
* @uses \WP_Admin_Bar Extends class
|
||||
*/
|
||||
final class VAA_View_Admin_As_Toolbar extends WP_Admin_Bar
|
||||
{
|
||||
/**
|
||||
* The single instance of the class.
|
||||
*
|
||||
* @since 1.6
|
||||
* @static
|
||||
* @var \VAA_View_Admin_As_Toolbar
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* Is this toolbar being rendered?
|
||||
*
|
||||
* @since 1.6
|
||||
* @static
|
||||
* @var bool
|
||||
*/
|
||||
public static $showing = false;
|
||||
|
||||
/**
|
||||
* View Admin As store.
|
||||
*
|
||||
* @since 1.6
|
||||
* @var \VAA_View_Admin_As_Store
|
||||
*/
|
||||
private $vaa_store = null;
|
||||
|
||||
/**
|
||||
* Construct function.
|
||||
* Protected to make sure it isn't declared elsewhere.
|
||||
*
|
||||
* @since 1.6
|
||||
* @since 1.6.1 $vaa param
|
||||
* @access protected
|
||||
* @param \VAA_View_Admin_As $vaa The main VAA object.
|
||||
*/
|
||||
protected function __construct( $vaa ) {
|
||||
self::$_instance = $this;
|
||||
$this->vaa_store = view_admin_as()->store();
|
||||
|
||||
view_admin_as()->hooks()->add_action( 'vaa_view_admin_as_init', array( $this, 'vaa_init' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Init function that initializes this plugin after the main VAA class is loaded.
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @see 'vaa_view_admin_as_init' action
|
||||
* @return void
|
||||
*/
|
||||
public function vaa_init() {
|
||||
// @since 1.7.6 Changed hook from `init` to `wp_loaded` (later).
|
||||
view_admin_as()->hooks()->add_action( 'wp_loaded', array( $this, 'vaa_toolbar_init' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Init function for the toolbar.
|
||||
*
|
||||
* @since 1.6
|
||||
* @since 1.6.2 Check for customizer preview.
|
||||
* @since 1.7.6 Add customizer support by only enabling it in the container, not the preview window.
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function vaa_toolbar_init() {
|
||||
// Stop if the admin bar is already showing or we're in the customizer preview window.
|
||||
if ( is_admin_bar_showing() || ( ! is_admin() && is_customize_preview() ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ( is_customize_preview() && ! $this->vaa_store->get_userSettings( 'hide_customizer' ) ) ||
|
||||
( ! is_admin() && ! $this->vaa_store->get_userSettings( 'hide_front' ) ) ||
|
||||
$this->vaa_store->get_view()
|
||||
) {
|
||||
|
||||
self::$showing = true;
|
||||
|
||||
view_admin_as()->hooks()->add_action( 'wp_footer', array( $this, 'vaa_toolbar_render' ), 100 );
|
||||
view_admin_as()->hooks()->add_action( 'customize_controls_print_footer_scripts', array( $this, 'vaa_toolbar_render' ), 100 );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render our toolbar using the render function from WP_Admin_bar.
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function vaa_toolbar_render() {
|
||||
|
||||
$this->add_group( array(
|
||||
'id' => 'top-secondary',
|
||||
'meta' => array(
|
||||
'class' => 'ab-top-secondary',
|
||||
),
|
||||
) );
|
||||
|
||||
// Load our admin bar nodes and force the location.
|
||||
do_action( 'vaa_toolbar_menu', $this, 'top-secondary' );
|
||||
|
||||
/**
|
||||
* Add classes to the toolbar menu (front only).
|
||||
* @since 1.6
|
||||
* @param array $array Empty array.
|
||||
* @return array
|
||||
*/
|
||||
$toolbar_classes = apply_filters( 'view_admin_as_toolbar_classes', array() );
|
||||
echo '<div id="vaa_toolbar" class="' . esc_attr( implode( ' ', $toolbar_classes ) ) . '">';
|
||||
|
||||
$this->render();
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Main Instance.
|
||||
*
|
||||
* Ensures only one instance of this class is loaded or can be loaded.
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @static
|
||||
* @param \VAA_View_Admin_As $caller The referrer class.
|
||||
* @return \VAA_View_Admin_As_Toolbar $this
|
||||
*/
|
||||
public static function get_instance( $caller = null ) {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self( $caller );
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
} // End class VAA_View_Admin_As_Toolbar.
|
||||
|
||||
} // End if().
|
||||
398
backend/wordpress/wp-content/plugins/view-admin-as/ui/class-ui.php
Executable file
398
backend/wordpress/wp-content/plugins/view-admin-as/ui/class-ui.php
Executable file
@@ -0,0 +1,398 @@
|
||||
<?php
|
||||
/**
|
||||
* View Admin As - Main UI class
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
* UI hooks for View Admin As.
|
||||
*
|
||||
* @author Jory Hogeveen <info@keraweb.nl>
|
||||
* @package View_Admin_As
|
||||
* @since 1.6
|
||||
* @since 1.7 Renamed from VAA_View_Admin_As_Admin
|
||||
* @version 1.8
|
||||
* @uses \VAA_View_Admin_As_Base Extends class
|
||||
*/
|
||||
final class VAA_View_Admin_As_UI extends VAA_View_Admin_As_Base
|
||||
{
|
||||
/**
|
||||
* The single instance of the class.
|
||||
*
|
||||
* @since 1.6
|
||||
* @static
|
||||
* @var \VAA_View_Admin_As_UI
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* Plugin links.
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @var array[]
|
||||
*/
|
||||
private $links = array();
|
||||
|
||||
/**
|
||||
* Construct function.
|
||||
*
|
||||
* @since 1.6
|
||||
* @since 1.6.1 $vaa param
|
||||
* @access protected
|
||||
* @param \VAA_View_Admin_As $vaa The main VAA object.
|
||||
*/
|
||||
protected function __construct( $vaa ) {
|
||||
self::$_instance = $this;
|
||||
parent::__construct( $vaa );
|
||||
|
||||
$this->add_action( 'wp_meta', array( $this, 'action_wp_meta' ) );
|
||||
$this->add_action( 'plugin_row_meta', array( $this, 'action_plugin_row_meta' ), 10, 2 );
|
||||
$this->add_filter( 'removable_query_args', array( $this, 'filter_removable_query_args' ) );
|
||||
|
||||
$this->add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
||||
$this->add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
||||
// @since 1.7.6.1 Add scripts to the customizer container hook.
|
||||
$this->add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
|
||||
|
||||
$this->add_filter( 'wp_die_handler', array( $this, 'filter_wp_die_handler' ) );
|
||||
|
||||
/**
|
||||
* Compat with front and WP version lower than 4.2.0.
|
||||
* @since 1.6.4
|
||||
* @link https://developer.wordpress.org/reference/functions/wp_admin_canonical_url/
|
||||
*/
|
||||
if ( ! is_admin() || ! VAA_API::validate_wp_version( '4.2' ) ) {
|
||||
$this->add_action( 'wp_head', array( $this, 'remove_query_args' ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a 'View Admin As: Reset view' link to the Meta sidebar widget if the admin bar is hidden.
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @access public
|
||||
*/
|
||||
public function action_wp_meta() {
|
||||
if ( ! VAA_API::is_toolbar_showing() && $this->store->get_view() ) {
|
||||
$link = __( 'View Admin As', VIEW_ADMIN_AS_DOMAIN ) . ': ' . __( 'Reset view', VIEW_ADMIN_AS_DOMAIN );
|
||||
$url = VAA_API::get_reset_link();
|
||||
echo '<li id="vaa_reset_view"><a href="' . esc_url( $url ) . '">' . esc_html( $link ) . '</a></li>';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show row meta on the plugin screen.
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @see \WP_Plugins_List_Table::single_row()
|
||||
* @param array[] $links The existing links.
|
||||
* @param string $file The plugin file.
|
||||
* @return array
|
||||
*/
|
||||
public function action_plugin_row_meta( $links, $file ) {
|
||||
if ( VIEW_ADMIN_AS_BASENAME === $file ) {
|
||||
$icon_attr = array(
|
||||
'style' => array(
|
||||
'font-size: inherit;',
|
||||
'line-height: inherit;',
|
||||
'display: inline;',
|
||||
'vertical-align: text-top;',
|
||||
),
|
||||
);
|
||||
foreach ( $this->get_links() as $id => $link ) {
|
||||
$title = VAA_View_Admin_As_Form::do_icon( $link['icon'], $icon_attr ) . ' ' . esc_html( $link['title'] );
|
||||
$links[ $id ] = '<a href="' . esc_url( $link['url'] ) . '" target="_blank">' . $title . '</a>';
|
||||
}
|
||||
}
|
||||
return $links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Plugin links.
|
||||
*
|
||||
* @since 1.6.1
|
||||
* @since 1.6.2 Added Slack channel link
|
||||
* @return array[]
|
||||
*/
|
||||
public function get_links() {
|
||||
if ( ! empty( $this->links ) ) {
|
||||
return $this->links;
|
||||
}
|
||||
|
||||
$this->links = array(
|
||||
'support' => array(
|
||||
'title' => __( 'Support', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Need support?', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'icon' => 'dashicons-sos',
|
||||
'url' => 'https://wordpress.org/support/plugin/view-admin-as/',
|
||||
),
|
||||
'slack' => array(
|
||||
'title' => __( 'Slack', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Quick help via Slack', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'icon' => 'dashicons-format-chat',
|
||||
'url' => 'https://keraweb.slack.com/messages/plugin-vaa/',
|
||||
),
|
||||
'review' => array(
|
||||
'title' => __( 'Review', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Give 5 stars on WordPress.org!', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'icon' => 'dashicons-star-filled',
|
||||
'url' => 'https://wordpress.org/support/plugin/view-admin-as/reviews/',
|
||||
),
|
||||
'translate' => array(
|
||||
'title' => __( 'Translate', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Help translating this plugin!', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'icon' => 'dashicons-translation',
|
||||
'url' => 'https://translate.wordpress.org/projects/wp-plugins/view-admin-as',
|
||||
),
|
||||
'issue' => array(
|
||||
'title' => __( 'Report issue', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Have ideas or a bug report?', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'icon' => 'dashicons-lightbulb',
|
||||
'url' => 'https://github.com/JoryHogeveen/view-admin-as/issues',
|
||||
),
|
||||
'docs' => array(
|
||||
'title' => __( 'Documentation', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Documentation', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'icon' => 'dashicons-book-alt',
|
||||
'url' => 'https://github.com/JoryHogeveen/view-admin-as/wiki',
|
||||
),
|
||||
'github' => array(
|
||||
'title' => __( 'GitHub', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Follow development on GitHub', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'icon' => 'dashicons-editor-code',
|
||||
'url' => 'https://github.com/JoryHogeveen/view-admin-as/tree/dev',
|
||||
),
|
||||
'donate' => array(
|
||||
'title' => __( 'Donate', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Buy me a coffee!', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'icon' => 'dashicons-smiley',
|
||||
'url' => 'https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=YGPLMLU7XQ9E8&lc=US&item_name=View%20Admin%20As&item_number=JWPP%2dVAA¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest',
|
||||
),
|
||||
'plugins' => array(
|
||||
'title' => __( 'Plugins', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Check out my other plugins', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'icon' => 'dashicons-admin-plugins',
|
||||
'url' => 'https://profiles.wordpress.org/keraweb/#content-plugins',
|
||||
),
|
||||
);
|
||||
|
||||
return $this->links;
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the list of query arguments which get removed from admin area URLs in WordPress.
|
||||
*
|
||||
* @since 1.6.4
|
||||
* @access public
|
||||
* @link https://core.trac.wordpress.org/ticket/23367
|
||||
*
|
||||
* @param array $args List of removable query arguments.
|
||||
* @return array Updated list of removable query arguments.
|
||||
*/
|
||||
public function filter_removable_query_args( $args ) {
|
||||
return array_merge( $args, array(
|
||||
'reset-view',
|
||||
'reset-all-views',
|
||||
'view_admin_as',
|
||||
'_vaa_nonce',
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove query arguments from the url.
|
||||
* Same logic as WP uses since v4.2.0.
|
||||
*
|
||||
* @since 1.6.4
|
||||
* @see wp_admin_canonical_url()
|
||||
* @return void
|
||||
*/
|
||||
public function remove_query_args() {
|
||||
$removable_query_args = $this->filter_removable_query_args( array() );
|
||||
|
||||
if ( empty( $removable_query_args ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$request_uri = $_SERVER['REQUEST_URI'];
|
||||
// @since 1.7.6 Some plugins overwrite `REQUEST_URI` and set it to `ORIG_REQUEST_URI`.
|
||||
if ( ! empty( $_SERVER['ORIG_REQUEST_URI'] ) ) {
|
||||
$request_uri = $_SERVER['ORIG_REQUEST_URI'];
|
||||
}
|
||||
|
||||
// Ensure we're using an absolute URL.
|
||||
$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $request_uri );
|
||||
$filtered_url = remove_query_arg( $removable_query_args, $current_url );
|
||||
?>
|
||||
<link id="wp-vaa-canonical" rel="canonical" href="<?php echo esc_url( $filtered_url ); ?>" />
|
||||
<script>
|
||||
if ( window.history.replaceState ) {
|
||||
window.history.replaceState( null, null, document.getElementById( 'wp-vaa-canonical' ).href + window.location.hash );
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Add necessary scripts and styles.
|
||||
*
|
||||
* @since 0.1
|
||||
* @since 1.7 Moved to this class from main class.
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function enqueue_scripts() {
|
||||
// Only enqueue scripts if the admin bar is enabled otherwise they have no use.
|
||||
if ( ! VAA_API::is_toolbar_showing() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Use non-minified versions.
|
||||
$suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
|
||||
// Prevent browser cache.
|
||||
$version = ( defined( 'WP_DEBUG' ) && WP_DEBUG ) ? time() : $this->store->get_version();
|
||||
|
||||
wp_enqueue_style(
|
||||
'vaa_view_admin_as_style',
|
||||
VIEW_ADMIN_AS_URL . 'assets/css/view-admin-as' . $suffix . '.css',
|
||||
array( 'admin-bar' ),
|
||||
$version
|
||||
);
|
||||
wp_enqueue_script(
|
||||
'vaa_view_admin_as_script',
|
||||
VIEW_ADMIN_AS_URL . 'assets/js/view-admin-as' . $suffix . '.js',
|
||||
array( 'jquery', 'admin-bar' ),
|
||||
$version,
|
||||
true // load in footer.
|
||||
);
|
||||
|
||||
/**
|
||||
* Add data to the VAA script localization.
|
||||
* @since 1.7
|
||||
* @param array $array Empty array (Will be overwritten with VAA core data so use unique keys).
|
||||
* @return array
|
||||
*/
|
||||
$script_localization = array_merge(
|
||||
(array) apply_filters( 'view_admin_as_script_localization', array() ),
|
||||
array(
|
||||
// Data.
|
||||
'ajaxurl' => admin_url( 'admin-ajax.php' ),
|
||||
'siteurl' => get_site_url(),
|
||||
'settings' => $this->store->get_settings(),
|
||||
'settings_user' => $this->store->get_userSettings(),
|
||||
'view' => $this->store->get_view(),
|
||||
'view_types' => $this->vaa->controller()->get_view_types(),
|
||||
// Other.
|
||||
'_loader_icon' => VIEW_ADMIN_AS_URL . 'assets/img/loader.gif',
|
||||
'_debug' => ( defined( 'WP_DEBUG' ) ) ? (bool) WP_DEBUG : false,
|
||||
'_vaa_nonce' => $this->store->get_nonce( true ),
|
||||
// i18n.
|
||||
'__no_users_found' => esc_html__( 'No users found.', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'__key_already_exists' => esc_html__( 'Key already exists.', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'__success' => esc_html__( 'Success', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'__confirm' => esc_html__( 'Are you sure?', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'__download' => esc_html__( 'Download', VIEW_ADMIN_AS_DOMAIN ),
|
||||
)
|
||||
);
|
||||
|
||||
wp_localize_script( 'vaa_view_admin_as_script', 'VAA_View_Admin_As', $script_localization );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add options to the access denied page when the user has selected a view and did something this view is not allowed.
|
||||
*
|
||||
* @since 1.3
|
||||
* @since 1.5.1 Check for SSL (Moved to VAA_API).
|
||||
* @since 1.6 More options and better description.
|
||||
* @since 1.7 Moved to this class from main class.
|
||||
* @since 1.8 Renamed from die_handler().
|
||||
* @access public
|
||||
* @see wp_die()
|
||||
*
|
||||
* @param callable $callback WP die callback.
|
||||
* @return callable $callback WP die callback.
|
||||
*/
|
||||
public function filter_wp_die_handler( $callback ) {
|
||||
|
||||
// Only do something if a view is selected.
|
||||
if ( ! $this->store->get_view() ) {
|
||||
return $callback;
|
||||
}
|
||||
|
||||
$options = array();
|
||||
|
||||
if ( is_network_admin() ) {
|
||||
$options[] = array(
|
||||
'text' => __( 'Go to network dashboard', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'url' => network_admin_url(),
|
||||
);
|
||||
} else {
|
||||
$options[] = array(
|
||||
'text' => __( 'Go to dashboard', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'url' => admin_url(),
|
||||
);
|
||||
$options[] = array(
|
||||
'text' => __( 'Go to homepage', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'url' => get_bloginfo( 'url' ),
|
||||
);
|
||||
}
|
||||
|
||||
// Reset url.
|
||||
$options[] = array(
|
||||
'text' => __( 'Reset the view', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'url' => VAA_API::get_reset_link(),
|
||||
);
|
||||
|
||||
/**
|
||||
* Add or remove options to the die/error handler pages.
|
||||
*
|
||||
* @since 1.6.2
|
||||
* @param array $options {
|
||||
* Required array of arrays.
|
||||
* @type array {
|
||||
* @type string $text The text to show.
|
||||
* @type string $url The link.
|
||||
* }
|
||||
* }
|
||||
* @return array[]
|
||||
*/
|
||||
$options = apply_filters( 'view_admin_as_error_page_options', $options );
|
||||
?>
|
||||
<div>
|
||||
<h3><?php esc_html_e( 'View Admin As', VIEW_ADMIN_AS_DOMAIN ); ?>:</h3>
|
||||
<?php esc_html_e( 'The view you have selected is not permitted to access this page, please choose one of the options below.', VIEW_ADMIN_AS_DOMAIN ); ?>
|
||||
<ul>
|
||||
<?php foreach ( $options as $option ) { ?>
|
||||
<li><a href="<?php echo $option['url']; ?>"><?php echo $option['text']; ?></a></li>
|
||||
<?php } ?>
|
||||
</ul>
|
||||
</div>
|
||||
<hr>
|
||||
<?php
|
||||
return $callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main Instance.
|
||||
*
|
||||
* Ensures only one instance of this class is loaded or can be loaded.
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @static
|
||||
* @param \VAA_View_Admin_As $caller The referrer class.
|
||||
* @return \VAA_View_Admin_As_UI $this
|
||||
*/
|
||||
public static function get_instance( $caller = null ) {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self( $caller );
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
} // End class VAA_View_Admin_As_UI.
|
||||
2
backend/wordpress/wp-content/plugins/view-admin-as/ui/index.php
Executable file
2
backend/wordpress/wp-content/plugins/view-admin-as/ui/index.php
Executable file
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
//Nothing to see here
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
/**
|
||||
* Add caps actions.
|
||||
*
|
||||
* @since 1.7
|
||||
* @version 1.7.4
|
||||
*
|
||||
* @var \VAA_View_Admin_As_Caps $this
|
||||
* @var \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @var string $root The current root item.
|
||||
* @var string $main_root The main VAA root item.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
if ( isset( $admin_bar ) && $admin_bar instanceof WP_Admin_Bar && isset( $root ) ) {
|
||||
|
||||
if ( ! isset( $main_root ) ) {
|
||||
$main_root = $root;
|
||||
}
|
||||
if ( ! isset( $parent ) ) {
|
||||
$parent = $root;
|
||||
}
|
||||
|
||||
// Text filter
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-filtercaps',
|
||||
'parent' => $parent,
|
||||
'title' => VAA_View_Admin_As_Form::do_input(
|
||||
array(
|
||||
'name' => $root . '-filtercaps',
|
||||
'placeholder' => esc_attr__( 'Filter', VIEW_ADMIN_AS_DOMAIN ),
|
||||
)
|
||||
),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'ab-vaa-input ab-vaa-filter filter-caps vaa-column-one-half vaa-column-first',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
// Select filter
|
||||
$role_select_options = array(
|
||||
array(
|
||||
'value' => 'default',
|
||||
'label' => __( 'Default', VIEW_ADMIN_AS_DOMAIN ),
|
||||
),
|
||||
);
|
||||
// View filter
|
||||
if ( $this->store->get_view() ) {
|
||||
$data_caps = wp_json_encode( $this->store->get_selectedCaps() );
|
||||
$role_select_options[] = array(
|
||||
'compare' => 'vaa',
|
||||
'label' => '= ' . __( 'Current view', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'attr' => array(
|
||||
'data-caps' => $data_caps,
|
||||
),
|
||||
);
|
||||
$role_select_options[] = array(
|
||||
'compare' => 'reversed-vaa',
|
||||
'label' => '≠ ' . __( 'Current view', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'attr' => array(
|
||||
'data-caps' => $data_caps,
|
||||
'data-reverse' => '1',
|
||||
),
|
||||
);
|
||||
}
|
||||
// Role filters
|
||||
foreach ( $this->store->get_roles() as $role_key => $role ) {
|
||||
$data_caps = wp_json_encode( $role->capabilities );
|
||||
$role_select_options[] = array(
|
||||
'compare' => esc_attr( $role_key ),
|
||||
'label' => '= ' . $this->store->get_rolenames( $role_key ),
|
||||
'attr' => array(
|
||||
'data-caps' => $data_caps,
|
||||
),
|
||||
);
|
||||
$role_select_options[] = array(
|
||||
'compare' => 'reversed-' . esc_attr( $role_key ),
|
||||
'label' => '≠ ' . $this->store->get_rolenames( $role_key ),
|
||||
'attr' => array(
|
||||
'data-caps' => $data_caps,
|
||||
'data-reverse' => '1',
|
||||
),
|
||||
);
|
||||
}
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-selectrolecaps',
|
||||
'parent' => $parent,
|
||||
'title' => VAA_View_Admin_As_Form::do_select(
|
||||
array(
|
||||
'name' => $root . '-selectrolecaps',
|
||||
'values' => $role_select_options,
|
||||
)
|
||||
),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'ab-vaa-select select-role-caps vaa-column-one-half vaa-column-last',
|
||||
'html' => '',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
// Select/deselect
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-bulkselectcaps',
|
||||
'parent' => $parent,
|
||||
'title' => VAA_View_Admin_As_Form::do_button(
|
||||
array(
|
||||
'name' => 'select-all-caps',
|
||||
'label' => __( 'Select', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'classes' => 'button-secondary',
|
||||
)
|
||||
) . ' ' . VAA_View_Admin_As_Form::do_button(
|
||||
array(
|
||||
'name' => 'deselect-all-caps',
|
||||
'label' => __( 'Deselect', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'classes' => 'button-secondary',
|
||||
)
|
||||
),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'ab-vaa-input vaa-button-container vaa-clear-float',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
} else {
|
||||
_doing_it_wrong( __FILE__, esc_html__( 'No toolbar resources found.', VIEW_ADMIN_AS_DOMAIN ), '1.7' );
|
||||
} // End if().
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* Add caps items.
|
||||
*
|
||||
* @since 1.7
|
||||
* @version 1.8
|
||||
*
|
||||
* @var \VAA_View_Admin_As_Caps $this
|
||||
* @var \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @var string $root The current root item.
|
||||
* @var string $main_root The main VAA root item.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
if ( isset( $admin_bar ) && $admin_bar instanceof WP_Admin_Bar && isset( $root ) ) {
|
||||
|
||||
if ( ! isset( $main_root ) ) {
|
||||
$main_root = $root;
|
||||
}
|
||||
if ( ! isset( $parent ) ) {
|
||||
$parent = $root;
|
||||
}
|
||||
|
||||
$caps_items = '';
|
||||
foreach ( $this->store->get_caps() as $cap => $granted ) {
|
||||
$class = 'vaa-cap-item';
|
||||
$checked = (bool) $granted;
|
||||
// check if we've selected a capability view and we've changed some capabilities.
|
||||
$selected_caps = $this->store->get_view( $this->type );
|
||||
if ( isset( $selected_caps[ $cap ] ) ) {
|
||||
$checked = (bool) $selected_caps[ $cap ];
|
||||
}
|
||||
// Check for this capability in any view set.
|
||||
if ( $this->vaa->view()->current_view_can( $cap ) ) {
|
||||
$class .= ' current';
|
||||
}
|
||||
// The list of capabilities.
|
||||
$caps_items .=
|
||||
'<div class="ab-item ' . $class . '">'
|
||||
. VAA_View_Admin_As_Form::do_checkbox(
|
||||
array(
|
||||
'name' => 'vaa_cap_' . esc_attr( $cap ),
|
||||
'value' => $checked,
|
||||
'compare' => true,
|
||||
'checkbox_value' => esc_attr( $cap ),
|
||||
'label' => $cap,
|
||||
)
|
||||
)
|
||||
. '</div>';
|
||||
}
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-select-options',
|
||||
'parent' => $parent,
|
||||
'title' => $caps_items,
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'ab-vaa-multipleselect vaa-auto-max-height',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
} else {
|
||||
_doing_it_wrong( __FILE__, esc_html__( 'No toolbar resources found.', VIEW_ADMIN_AS_DOMAIN ), '1.7' );
|
||||
} // End if().
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* Add role items.
|
||||
*
|
||||
* @since 1.8
|
||||
* @version 1.8
|
||||
*
|
||||
* @var \VAA_View_Admin_As_Languages $this
|
||||
* @var \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @var string $root The current root item.
|
||||
* @var string $main_root The main VAA root item.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
if ( isset( $admin_bar ) && $admin_bar instanceof WP_Admin_Bar && isset( $root ) ) {
|
||||
|
||||
if ( ! isset( $main_root ) ) {
|
||||
$main_root = $root;
|
||||
}
|
||||
|
||||
$parent = $root . '-languages';
|
||||
|
||||
foreach ( $this->store->get_languages() as $locale => $language ) {
|
||||
$href = VAA_API::get_vaa_action_link( array( $this->type => $locale ), $this->store->get_nonce( true ) );
|
||||
$class = 'vaa-' . $this->type . '-item';
|
||||
$title = $this->get_view_title( $locale );
|
||||
|
||||
$view_title = ( $locale !== $title ) ? '<code>' . $locale . '</code> | ' . $language : $locale;
|
||||
|
||||
$view_title = VAA_View_Admin_As_Form::do_view_title( $view_title, $this, $locale );
|
||||
|
||||
// Check if this role is the current view.
|
||||
if ( VAA_API::is_current_view( $locale, $this->type ) ) {
|
||||
$class .= ' current';
|
||||
if ( 1 === count( $this->store->get_view() ) ) {
|
||||
$href = false;
|
||||
}
|
||||
}
|
||||
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-' . $this->type . '-' . $locale,
|
||||
'parent' => $parent,
|
||||
'title' => $view_title,
|
||||
'href' => $href,
|
||||
'meta' => array(
|
||||
// Translators: %s stands for the translated role name.
|
||||
'title' => sprintf( __( 'View as %s', VIEW_ADMIN_AS_DOMAIN ), $title ),
|
||||
'class' => $class,
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
} // End foreach().
|
||||
|
||||
} else {
|
||||
_doing_it_wrong( __FILE__, esc_html__( 'No toolbar resources found.', VIEW_ADMIN_AS_DOMAIN ), '1.7' );
|
||||
} // End if().
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
/**
|
||||
* Add role items.
|
||||
*
|
||||
* @since 1.7
|
||||
* @version 1.8
|
||||
*
|
||||
* @var \VAA_View_Admin_As_Roles $this
|
||||
* @var \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @var string $root The current root item.
|
||||
* @var string $main_root The main VAA root item.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
if ( isset( $admin_bar ) && $admin_bar instanceof WP_Admin_Bar && isset( $root ) ) {
|
||||
|
||||
if ( ! isset( $main_root ) ) {
|
||||
$main_root = $root;
|
||||
}
|
||||
if ( ! isset( $parent ) ) {
|
||||
$parent = $root;
|
||||
}
|
||||
|
||||
foreach ( $this->store->get_roles() as $role_key => $role ) {
|
||||
$href = VAA_API::get_vaa_action_link( array( $this->type => $role_key ), $this->store->get_nonce( true ) );
|
||||
$class = 'vaa-' . $this->type . '-item';
|
||||
$title = $this->get_view_title( $role );
|
||||
|
||||
$view_title = VAA_View_Admin_As_Form::do_view_title( $title, $this, $role_key );
|
||||
|
||||
/**
|
||||
* Check if the users need to be grouped under their roles.
|
||||
* @var \VAA_View_Admin_As_Users $user_view_type
|
||||
*/
|
||||
$user_view_type = view_admin_as()->get_view_types( 'user' );
|
||||
if ( $user_view_type instanceof VAA_View_Admin_As_Users && $user_view_type->group_user_roles() ) {
|
||||
// Used to align items properly when some roles don't have users.
|
||||
$class .= ' vaa-menupop';
|
||||
// Check if the current view is a user with this role.
|
||||
if ( $this->store->get_view( 'user' ) &&
|
||||
in_array( $role_key, $this->store->get_selectedUser()->roles, true )
|
||||
) {
|
||||
$class .= ' current-parent';
|
||||
}
|
||||
// If there are users with this role, add a counter.
|
||||
$user_count = 0;
|
||||
foreach ( $this->store->get_users() as $user ) {
|
||||
if ( in_array( $role_key, $user->roles, true ) ) {
|
||||
$user_count ++;
|
||||
}
|
||||
}
|
||||
if ( 0 < $user_count ) {
|
||||
$view_title = $view_title . ' <span class="user-count ab-italic">(' . $user_count . ')</span>';
|
||||
}
|
||||
}
|
||||
|
||||
// Check if this role is the current view.
|
||||
if ( VAA_API::is_current_view( $role_key, $this->type ) ) {
|
||||
$class .= ' current';
|
||||
if ( 1 === count( $this->store->get_view() ) ) {
|
||||
$href = false;
|
||||
}
|
||||
}
|
||||
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-' . $this->type . '-' . $role_key,
|
||||
'parent' => $parent,
|
||||
'title' => $view_title,
|
||||
'href' => $href,
|
||||
'meta' => array(
|
||||
// Translators: %s stands for the translated role name.
|
||||
'title' => sprintf( __( 'View as %s', VIEW_ADMIN_AS_DOMAIN ), $title ),
|
||||
'class' => $class,
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
} // End foreach().
|
||||
|
||||
} else {
|
||||
_doing_it_wrong( __FILE__, esc_html__( 'No toolbar resources found.', VIEW_ADMIN_AS_DOMAIN ), '1.7' );
|
||||
} // End if().
|
||||
@@ -0,0 +1,250 @@
|
||||
<?php
|
||||
/**
|
||||
* Add user setting items.
|
||||
*
|
||||
* @since 1.7.2
|
||||
* @version 1.8
|
||||
*
|
||||
* @var \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @var string $root The current root item.
|
||||
* @var string $main_root The main VAA root item.
|
||||
*
|
||||
* Settings order:
|
||||
* - admin_menu_location
|
||||
* - view_mode
|
||||
* - disable_super_admin
|
||||
* - hide_front
|
||||
* - freeze_locale
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
if ( isset( $this ) &&
|
||||
isset( $this->store ) &&
|
||||
isset( $admin_bar ) && $admin_bar instanceof WP_Admin_Bar &&
|
||||
isset( $root )
|
||||
) {
|
||||
|
||||
/**
|
||||
* admin_menu_location setting.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-admin-menu-location',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_select(
|
||||
array(
|
||||
'name' => $root . '-admin-menu-location',
|
||||
'value' => $this->store->get_userSettings( 'admin_menu_location' ),
|
||||
'label' => __( 'Location', VIEW_ADMIN_AS_DOMAIN ) . ': ',
|
||||
'description' => __( 'Change the location of this menu node', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'help' => true,
|
||||
'values' => array(
|
||||
array(
|
||||
'compare' => 'top-secondary',
|
||||
'label' => __( 'Default', VIEW_ADMIN_AS_DOMAIN ),
|
||||
),
|
||||
array(
|
||||
'compare' => 'my-account',
|
||||
'label' => __( 'My account', VIEW_ADMIN_AS_DOMAIN ),
|
||||
),
|
||||
),
|
||||
'auto_js' => array(
|
||||
'setting' => 'user_setting',
|
||||
'key' => 'admin_menu_location',
|
||||
'refresh' => true,
|
||||
),
|
||||
'auto_showhide' => true,
|
||||
)
|
||||
),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'auto-height',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* view_mode setting.
|
||||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-view-mode',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_radio(
|
||||
array(
|
||||
'name' => $root . '-view-mode',
|
||||
'value' => $this->store->get_userSettings( 'view_mode' ),
|
||||
'values' => array(
|
||||
array(
|
||||
'compare' => 'browse',
|
||||
'label' => __( 'Browse mode', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Store view and use WordPress with this view', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'help' => true,
|
||||
),
|
||||
array(
|
||||
'compare' => 'single',
|
||||
'label' => __( 'Single switch mode', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Choose view on every pageload. This setting doesn\'t store views', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'help' => true,
|
||||
),
|
||||
),
|
||||
'auto_js' => array(
|
||||
'setting' => 'user_setting',
|
||||
'key' => 'view_mode',
|
||||
'refresh' => false,
|
||||
),
|
||||
'auto_showhide' => true,
|
||||
)
|
||||
),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'auto-height',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* Disable super admin checks while switched.
|
||||
*
|
||||
* @since 1.7.3
|
||||
* @since 1.8 Don't use VAA_API since users that are super admins but don't have full access could
|
||||
* still want to use this setting.
|
||||
* Also check if the installation is a network.
|
||||
*/
|
||||
if ( is_multisite() && is_super_admin( view_admin_as()->store()->get_curUser()->ID ) ) {
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-disable-super-admin',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_checkbox(
|
||||
array(
|
||||
'name' => $root . '-disable-super-admin',
|
||||
'value' => $this->store->get_userSettings( 'disable_super_admin' ),
|
||||
'compare' => true,
|
||||
'label' => __( 'Disable super admin', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Disable super admin status while switched to another view', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'help' => true,
|
||||
'auto_js' => array(
|
||||
'setting' => 'user_setting',
|
||||
'key' => 'disable_super_admin',
|
||||
'refresh' => ( $this->store->get_view() ) ? true : false,
|
||||
),
|
||||
'auto_showhide' => true,
|
||||
)
|
||||
),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'auto-height',
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* hide_front setting.
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-hide-front',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_checkbox(
|
||||
array(
|
||||
'name' => $root . '-hide-front',
|
||||
'value' => $this->store->get_userSettings( 'hide_front' ),
|
||||
'compare' => true,
|
||||
'label' => __( 'Hide on frontend', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Hide on frontend when no view is selected and the admin bar is not shown', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'help' => true,
|
||||
'auto_js' => array(
|
||||
'setting' => 'user_setting',
|
||||
'key' => 'hide_front',
|
||||
'refresh' => false,
|
||||
),
|
||||
'auto_showhide' => true,
|
||||
)
|
||||
),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'auto-height',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* hide_customizer setting.
|
||||
*
|
||||
* @since 1.7.6
|
||||
*/
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-hide-customizer',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_checkbox(
|
||||
array(
|
||||
'name' => $root . '-hide-customizer',
|
||||
'value' => $this->store->get_userSettings( 'hide_customizer' ),
|
||||
'compare' => true,
|
||||
'label' => __( 'Hide on customizer', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Hide on customizer when no view is selected', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'help' => true,
|
||||
'auto_js' => array(
|
||||
'setting' => 'user_setting',
|
||||
'key' => 'hide_customizer',
|
||||
'refresh' => VAA_API::is_customizer_admin(),
|
||||
),
|
||||
'auto_showhide' => true,
|
||||
)
|
||||
),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'auto-height',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
/**
|
||||
* freeze_locale setting.
|
||||
* Force own locale on view, WP 4.7+ only.
|
||||
*
|
||||
* @see https://github.com/JoryHogeveen/view-admin-as/issues/21
|
||||
* @since 1.6.1
|
||||
*/
|
||||
if ( VAA_API::validate_wp_version( '4.7' ) ) {
|
||||
$admin_bar->add_node(
|
||||
array(
|
||||
'id' => $root . '-freeze-locale',
|
||||
'parent' => $root,
|
||||
'title' => VAA_View_Admin_As_Form::do_checkbox(
|
||||
array(
|
||||
'name' => $root . '-freeze-locale',
|
||||
'value' => $this->store->get_userSettings( 'freeze_locale' ),
|
||||
'compare' => true,
|
||||
'label' => __( 'Freeze locale', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'description' => __( 'Force your own locale setting to the current view', VIEW_ADMIN_AS_DOMAIN ),
|
||||
'help' => true,
|
||||
'auto_js' => array(
|
||||
'setting' => 'user_setting',
|
||||
'key' => 'freeze_locale',
|
||||
'refresh' => ( $this->store->get_view( 'user' ) ) ? true : false,
|
||||
),
|
||||
'auto_showhide' => true,
|
||||
)
|
||||
),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'auto-height',
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
} // End if().
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Add user actions.
|
||||
*
|
||||
* @since 1.8
|
||||
* @version 1.8
|
||||
*
|
||||
* @var \VAA_View_Admin_As_Users $this
|
||||
* @var \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @var string $root The current root item.
|
||||
* @var string $main_root The main VAA root item.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
if ( isset( $admin_bar ) && $admin_bar instanceof WP_Admin_Bar && isset( $root ) ) {
|
||||
|
||||
if ( ! isset( $main_root ) ) {
|
||||
$main_root = $root;
|
||||
}
|
||||
if ( ! isset( $parent ) ) {
|
||||
$parent = $root;
|
||||
}
|
||||
|
||||
if ( ! isset( $title_submenu ) ) {
|
||||
$title_submenu = false;
|
||||
}
|
||||
|
||||
if ( $title_submenu || $this->ajax_search || $this->group_user_roles() ) {
|
||||
|
||||
$title = '';
|
||||
if ( $this->group_user_roles() ) {
|
||||
$title = VAA_View_Admin_As_Form::do_description( __( 'Users are grouped under their roles', VIEW_ADMIN_AS_DOMAIN ) );
|
||||
}
|
||||
$admin_bar->add_node( array(
|
||||
'id' => $root . '-searchusers',
|
||||
'parent' => $root,
|
||||
'title' => $title . VAA_View_Admin_As_Form::do_input( array(
|
||||
'name' => $root . '-searchusers',
|
||||
'placeholder' => __( 'Search', VIEW_ADMIN_AS_DOMAIN ),
|
||||
) ),
|
||||
'href' => false,
|
||||
'meta' => array(
|
||||
'class' => 'ab-vaa-search search-users' . ( ( $this->ajax_search ) ? ' search-ajax' : '' ),
|
||||
'html' => '<ul id="vaa-searchuser-results" class="ab-sub-secondary vaa-auto-max-height ab-submenu ab-vaa-results"></ul>',
|
||||
),
|
||||
) );
|
||||
}
|
||||
|
||||
} else {
|
||||
_doing_it_wrong( __FILE__, esc_html__( 'No toolbar resources found.', VIEW_ADMIN_AS_DOMAIN ), '1.7' );
|
||||
} // End if().
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
/**
|
||||
* Add user items.
|
||||
*
|
||||
* @since 1.7
|
||||
* @version 1.8
|
||||
*
|
||||
* @var \VAA_View_Admin_As_Users $this
|
||||
* @var \WP_Admin_Bar $admin_bar The toolbar object.
|
||||
* @var string $root The current root item.
|
||||
* @var string $main_root The main VAA root item.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'VIEW_ADMIN_AS_DIR' ) ) {
|
||||
die();
|
||||
}
|
||||
|
||||
if ( isset( $admin_bar ) && $admin_bar instanceof WP_Admin_Bar && isset( $root ) ) {
|
||||
|
||||
if ( ! isset( $main_root ) ) {
|
||||
$main_root = $root;
|
||||
}
|
||||
if ( ! isset( $parent ) ) {
|
||||
$parent = $root;
|
||||
}
|
||||
|
||||
if ( ! isset( $title_submenu ) ) {
|
||||
$title_submenu = false;
|
||||
}
|
||||
|
||||
foreach ( $this->store->get_users() as $user ) {
|
||||
// Reset parent for each loop due to groupUserRoles.
|
||||
$item_parent = $parent;
|
||||
$href = VAA_API::get_vaa_action_link( array( $this->type => $user->ID ), $this->store->get_nonce( true ) );
|
||||
$class = 'vaa-' . $this->type . '-item';
|
||||
$title = $this->get_view_title( $user );
|
||||
|
||||
$view_title = VAA_View_Admin_As_Form::do_view_title( $title, $this, $user->ID );
|
||||
|
||||
/**
|
||||
* Add the user roles to the user title?
|
||||
* Only available if users are not grouped under their roles.
|
||||
*
|
||||
* @since 1.8
|
||||
* @param bool $true True by default.
|
||||
* @param \WP_User $user The user object.
|
||||
* @return bool
|
||||
*/
|
||||
if ( ! $this->group_user_roles() && apply_filters( 'vaa_admin_bar_view_title_' . $this->type . '_show_roles', true, $user ) ) {
|
||||
// Users displayed as normal.
|
||||
$user_roles = array();
|
||||
// Add the roles of this user in the name.
|
||||
foreach ( $user->roles as $role ) {
|
||||
$user_roles[] = $this->store->get_rolenames( $role );
|
||||
}
|
||||
$view_title = $view_title . ' <span class="user-role ab-italic">(' . implode( ', ', $user_roles ) . ')</span>';
|
||||
}
|
||||
|
||||
// Check if this user is the current view.
|
||||
if ( VAA_API::is_current_view( $user->ID, $this->type ) ) {
|
||||
$class .= ' current';
|
||||
if ( 1 === count( $this->store->get_view() ) ) {
|
||||
$href = false;
|
||||
}
|
||||
}
|
||||
|
||||
$user_node = array(
|
||||
'id' => $root . '-' . $this->type . '-' . $user->ID,
|
||||
'parent' => $item_parent,
|
||||
'title' => $view_title,
|
||||
'href' => $href,
|
||||
'meta' => array(
|
||||
// Translators: %s stands for the user display name.
|
||||
'title' => sprintf( __( 'View as %s', VIEW_ADMIN_AS_DOMAIN ), $title ),
|
||||
'class' => $class,
|
||||
),
|
||||
);
|
||||
|
||||
if ( $this->group_user_roles() ) {
|
||||
// Users grouped under roles.
|
||||
foreach ( $user->roles as $role ) {
|
||||
$user_role_node = $user_node;
|
||||
$item_parent = $main_root . '-roles-role-' . $role;
|
||||
$group = $item_parent . '-users';
|
||||
if ( ! $admin_bar->get_node( $group ) ) {
|
||||
$admin_bar->add_group( array(
|
||||
'id' => $group,
|
||||
'parent' => $item_parent,
|
||||
'meta' => array(
|
||||
'class' => 'vaa-auto-max-height',
|
||||
),
|
||||
) );
|
||||
}
|
||||
$user_role_node['id'] .= '-' . $role;
|
||||
$user_role_node['parent'] = $group;
|
||||
$admin_bar->add_node( $user_role_node );
|
||||
}
|
||||
} else {
|
||||
$admin_bar->add_node( $user_node );
|
||||
}
|
||||
|
||||
} // End foreach().
|
||||
|
||||
} else {
|
||||
_doing_it_wrong( __FILE__, esc_html__( 'No toolbar resources found.', VIEW_ADMIN_AS_DOMAIN ), '1.7' );
|
||||
} // End if().
|
||||
@@ -0,0 +1,2 @@
|
||||
<?php
|
||||
//Nothing to see here
|
||||
Reference in New Issue
Block a user