Skip to content

Commit

Permalink
V1.6.1 - Merge pull request #20 from JoryHogeveen/dev
Browse files Browse the repository at this point in the history
1.6.1 (pre WP 4.7)
  • Loading branch information
JoryHogeveen authored Nov 16, 2016
2 parents 59c1364 + 0cdf0e6 commit 3de7b11
Show file tree
Hide file tree
Showing 17 changed files with 1,649 additions and 897 deletions.
214 changes: 107 additions & 107 deletions assets/css/view-admin-as.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions assets/css/view-admin-as.min.css

Large diffs are not rendered by default.

272 changes: 188 additions & 84 deletions assets/js/view-admin-as.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions assets/js/view-admin-as.min.js

Large diffs are not rendered by default.

43 changes: 22 additions & 21 deletions includes/class-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Jory Hogeveen <info@keraweb.nl>
* @package view-admin-as
* @since 1.6
* @version 1.6
* @version 1.6.1
*/

! defined( 'VIEW_ADMIN_AS_DIR' ) and die( 'You shall not pass!' );
Expand All @@ -17,9 +17,9 @@ final class VAA_API
/**
* Check if the user is a superior admin
*
* @since 1.5.3
* @since 1.6 Moved to this class from main class
* @access public
* @since 1.5.3
* @since 1.6 Moved to this class from main class
* @access public
* @static
* @api
*
Expand All @@ -34,9 +34,9 @@ public static function is_superior_admin( $user_id ) {
/**
* Get the superior admin ID's (filter since 1.5.2)
*
* @since 1.5.3
* @since 1.6 Moved to this class from main class
* @access public
* @since 1.5.3
* @since 1.6 Moved to this class from main class
* @access public
* @static
* @api
*
Expand Down Expand Up @@ -121,12 +121,12 @@ final public static function set_array_data( $array, $var, $key = false, $append
/**
* Is our custom toolbar showing?
*
* @since 1.6
* @access public
* @since 1.6
* @access public
* @static
* @api
*
* @return bool
* @return bool
*/
public static function is_vaa_toolbar_showing() {

Expand All @@ -139,25 +139,26 @@ public static function is_vaa_toolbar_showing() {
/**
* Appends the "reset-view" parameter to the current URL
*
* @since 1.6
* @access public
* @since 1.6
* @access public
* @static
* @api
*
* @param string $url (optional) Use a defined url create the reset link
* @param bool $all (optional) Reset all views link?
* @return string
* @param string $url (optional) Use a defined url create the reset link
* @param bool $all (optional) Reset all views link?
* @return string
*/
public static function get_reset_link( $url = '', $all = false ) {

if ( empty( $url ) ) {
$url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
// Check for existing query vars
$url_comp = parse_url( $url );
// Check protocol
$url = ( ( is_ssl() ) ? 'https://' : 'http://' ) . $url;
}

// Check for existing query vars
$url_comp = parse_url( $url );

$reset = 'reset-view';
if ( $all ) {
$reset = 'reset-all-views';
Expand All @@ -169,13 +170,13 @@ public static function get_reset_link( $url = '', $all = false ) {
/**
* Removes the "reset-view" or "reset-all-views" parameter to the current URL
*
* @since 1.6
* @access public
* @since 1.6
* @access public
* @static
* @api
*
* @param string $url (optional) Use a defined url to remove the reset link
* @return string
* @param string $url (optional) Use a defined url to remove the reset link
* @return string
*/
public static function remove_reset_link( $url = '' ) {

Expand Down
9 changes: 6 additions & 3 deletions includes/class-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ abstract class VAA_View_Admin_As_Class_Base
* Protected to make sure it isn't declared elsewhere
*
* @since 1.5.3
* @param object $vaa (optional) Pass VAA object
* @since 1.6 $vaa param
* @access protected
* @param VAA_View_Admin_As $vaa (optional) Pass VAA object
*/
protected function __construct( $vaa = null ) {
// Load resources
Expand All @@ -87,12 +88,14 @@ protected function __construct( $vaa = null ) {
* init function to store data from the main class and enable functionality based on the current view
*
* @since 1.5
* @since 1.6 $vaa param
* @access public
* @param VAA_View_Admin_As $vaa (optional) Pass VAA object
* @return void
*/
final public function load_vaa( $vaa ) {
final public function load_vaa( $vaa = null ) {
$this->vaa = $vaa;
if ( null == $vaa ) {
if ( ! is_object( $vaa ) || 'VAA_View_Admin_As' != get_class( $vaa ) ) {
$this->vaa = View_Admin_As( $this );
}
$this->store = $this->vaa->store();
Expand Down
69 changes: 45 additions & 24 deletions includes/class-compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Jory Hogeveen <info@keraweb.nl>
* @package view-admin-as
* @since 1.6
* @version 1.6
* @version 1.6.1
*/

! defined( 'VIEW_ADMIN_AS_DIR' ) and die( 'You shall not pass!' );
Expand All @@ -17,18 +17,22 @@ final class VAA_View_Admin_As_Compat extends VAA_View_Admin_As_Class_Base
/**
* The single instance of the class.
*
* @since 1.6
* @var VAA_View_Admin_As_Compat
* @since 1.6
* @static
* @var VAA_View_Admin_As_Compat
*/
private static $_instance = null;

/**
* Populate the instance
* @since 1.6
* @since 1.6
* @since 1.6.1 $vaa param
* @access protected
* @param VAA_View_Admin_As $vaa
*/
protected function __construct() {
protected function __construct( $vaa ) {
self::$_instance = $this;
parent::__construct();
parent::__construct( $vaa );
}

/**
Expand All @@ -41,28 +45,44 @@ protected function __construct() {
*/
public function init() {

if ( false !== $this->store->get_viewAs() ) {
// WooCommerce
remove_filter( 'show_admin_bar', 'wc_disable_admin_bar', 10 );
}

// Pods 2.x (only needed for the role selector)
if ( $this->store->get_viewAs('role') ) {
add_filter( 'pods_is_admin', array( $this, 'pods_caps_check' ), 10, 3 );
}
add_action( 'vaa_view_admin_as_init', array( $this, 'init_after' ) );

/**
* Add our caps to the members plugin
* @since 1.6
* @since 1.6
*/
add_filter( 'members_get_capabilities', array( $this, 'add_capabilities' ) );
add_action( 'members_register_cap_groups', array( $this, 'members_register_cap_group' ) );

// Get caps from other plugins
/**
* Get caps from other plugins
* @since 1.5
*/
add_filter( 'view_admin_as_get_capabilities', array( $this, 'get_capabilities' ) );

}

/**
* Fix compatibility issues on load
* Called from 'vaa_view_admin_as_init' hook (after loading all data)
*
* @since 1.6.1
* @access public
* @return void
*/
public function init_after() {

/*if ( false !== $this->store->get_viewAs() ) {
// WooCommerce
remove_filter( 'show_admin_bar', 'wc_disable_admin_bar', 10 );
}*/

if ( $this->store->get_viewAs('role') ) {
// Pods 2.x (only needed for the role selector)
add_filter( 'pods_is_admin', array( $this, 'pods_caps_check' ), 10, 3 );
}
}

/**
* Get's current capabilities and merges with capabilities from other plugins
*
Expand Down Expand Up @@ -125,9 +145,10 @@ public function pods_caps_check( $bool, $cap, $capability ) {
}

$role_caps = $this->store->get_roles( $this->store->get_viewAs('role') )->capabilities;
if ( ! array_key_exists( $cap, $role_caps ) || ( 1 != $role_caps[$cap] ) ) {
if ( ! array_key_exists( $cap, $role_caps ) || ( 1 != $role_caps[ $cap ] ) ) {
return false;
}

return true;
}

Expand All @@ -138,7 +159,7 @@ public function pods_caps_check( $bool, $cap, $capability ) {
* @access public
* @see init()
*/
public function members_register_cap_group () {
public function members_register_cap_group() {

if ( function_exists( 'members_register_cap_group' ) ) {
// Register the vaa group.
Expand All @@ -161,17 +182,17 @@ public function members_register_cap_group () {
* @since 1.6
* @access public
* @static
* @param object|bool $caller The referrer class
* @return VAA_View_Admin_As_Compat|bool
* @param VAA_View_Admin_As $caller The referrer class
* @return VAA_View_Admin_As_Compat
*/
public static function get_instance( $caller = false ) {
public static function get_instance( $caller = null ) {
if ( is_object( $caller ) && 'VAA_View_Admin_As' == get_class( $caller ) ) {
if ( is_null( self::$_instance ) ) {
self::$_instance = new self();
self::$_instance = new self( $caller );
}
return self::$_instance;
}
return false;
return null;
}

} // end class
Loading

0 comments on commit 3de7b11

Please sign in to comment.