Skip to content

Commit

Permalink
v1.8.3 - Merge pull request #102 from JoryHogeveen/dev
Browse files Browse the repository at this point in the history
v1.8.3
  • Loading branch information
JoryHogeveen authored Dec 5, 2018
2 parents c0b10cd + f43056e commit ed84c95
Show file tree
Hide file tree
Showing 21 changed files with 209 additions and 98 deletions.
2 changes: 1 addition & 1 deletion assets/js/view-admin-as.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ if ( 'undefined' === typeof VAA_View_Admin_As ) {
// @since 1.8.2 Enhance height calc + provide trigger for content changes
$( '.vaa-resizable', $vaa ).each( function() {
var $this = $(this),
maxHeight = parseInt( $this.css( 'max-heights' ), 10 ),
maxHeight = parseInt( $this.css( 'max-height' ), 10 ),
height, innerHeight, newHeight;

// Check for empty containers.
Expand Down
2 changes: 1 addition & 1 deletion assets/js/view-admin-as.min.js

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions includes/class-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,27 @@ public static function get_superior_admins() {
return $superior_admins;
}

/**
* Get the current active view. Returns `null` if no view (type) is active.
*
* @see \VAA_View_Admin_As_Store::get_view()
*
* @since 1.8.3
* @access public
* @static
* @api
*
* @param string $type View type. Will return `null` if this view type is not active.
* @return mixed
*/
public static function get_current_view( $type = null ) {
$store = view_admin_as()->store();
if ( $store ) {
return $store->get_view( $type );
}
return null;
}

/**
* Check if the provided data is the same as the current view.
*
Expand Down Expand Up @@ -240,6 +261,30 @@ public static function is_user_modified() {
return false;
}

/**
* Set the current view.
*
* @see \VAA_View_Admin_As_Controller::update()
* @see \VAA_View_Admin_As_Controller::update_view()
*
* @since 1.8.3
* @access public
* @static
* @api
*
* @param array $view The view.
* @return bool
*/
public static function update_view( $view ) {
$controller = view_admin_as()->controller();
if ( $controller ) {
$view = array_intersect_key( $view, array_flip( $controller->get_view_types() ) );
$success = $controller->update( $view );
return ( true === $success );
}
return false;
}

/**
* Is any toolbar showing?
* Do not use this before the `init` hook.
Expand Down
17 changes: 11 additions & 6 deletions includes/class-compat.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,10 @@ public function get_vaa_capabilities( $caps = array() ) {
public function get_wordpress_capabilities( $caps = array() ) {

// @since 1.7.1 Store available capabilities existing in roles.
foreach ( $this->store->get_roles() as $key => $role ) {
foreach ( $this->store->get_roles() as $role ) {
if ( is_array( $role->capabilities ) ) {
foreach ( $role->capabilities as $cap => $grant ) {
$caps[ (string) $cap ] = $cap;
}
$role_caps = array_keys( $role->capabilities );
$caps = array_merge( array_combine( $role_caps, $role_caps ), $caps );
}
}

Expand All @@ -212,6 +211,7 @@ public function get_wordpress_capabilities( $caps = array() ) {
/**
* Other WordPress capabilities.
* @since 1.7.4 WordPress 4.9 capabilities.
* @since 1.8.3 WordPress 4.9.6 privacy capabilities.
*/
if ( VAA_API::validate_wp_version( '4.9' ) ) {
$caps['activate_plugin'] = 'activate_plugin';
Expand All @@ -220,6 +220,11 @@ public function get_wordpress_capabilities( $caps = array() ) {
$caps['install_languages'] = 'install_languages';
$caps['update_languages'] = 'update_languages';
}
if ( VAA_API::validate_wp_version( '4.9.6' ) ) {
$caps['erase_others_personal_data'] = 'erase_others_personal_data';
$caps['export_others_personal_data'] = 'export_others_personal_data';
$caps['manage_privacy_options'] = 'manage_privacy_options';
}

/**
* Network capabilities.
Expand Down Expand Up @@ -444,8 +449,8 @@ public function filter_ure_capabilities_groups_tree( $groups ) {
* @access public
* @see \VAA_View_Admin_As_Compat::init()
* @see \URE_Capabilities_Groups_Manager::get_cap_groups()
* @param array $groups Current capability groups
* @param string $cap_id Capability identifier
* @param array $groups Current capability groups.
* @param string $cap_id Capability identifier.
* @return array
*/
public function filter_ure_custom_capability_groups( $groups, $cap_id ) {
Expand Down
97 changes: 54 additions & 43 deletions includes/class-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,19 @@ public function ajax_view_admin_as() {

$data = $this->validate_data_keys( $data );

// Stop selecting the same view!
if ( $this->is_current_view( $data ) ) {
wp_send_json_error(
array(
'type' => 'message',
'text' => esc_html__( 'This view is already selected!', VIEW_ADMIN_AS_DOMAIN ),
)
);
}

$success = false;
if ( ! empty( $data ) ) {
$success = $this->ajax_handler( $data );
$success = $this->update( $data );
}

if ( true === $success ) {
Expand All @@ -162,35 +172,30 @@ public function ajax_view_admin_as() {
die();
}

wp_send_json_error( array(
'type' => 'error',
'text' => esc_html__( 'Something went wrong, please try again.', VIEW_ADMIN_AS_DOMAIN ),
) );
wp_send_json_error(
array(
'type' => 'error',
'text' => esc_html__( 'Something went wrong, please try again.', VIEW_ADMIN_AS_DOMAIN ),
)
);
die();
}

/**
* AJAX handler.
* Applies the data input.
* Applies the data input to update views and settings.
*
* @since 1.7.0
* @since 1.8.3 Renamed from `ajax_handler` + made public.
* @param array $data Post data.
* @return array|bool
*/
private function ajax_handler( $data ) {
public function update( $data ) {
$success = false;
$view_types = array();

// Stop selecting the same view!
if ( $this->is_current_view( $data ) ) {
wp_send_json_error( array(
'type' => 'message',
'text' => esc_html__( 'This view is already selected!', VIEW_ADMIN_AS_DOMAIN ),
) );
}
$data = $this->validate_data_keys( $data );

/**
* Ajax return filters.
* Update data return filters.
*
* @see `view_admin_as_update_view_{$key}`
* @see `view_admin_as_handle_ajax_{$key}`
Expand All @@ -200,21 +205,21 @@ private function ajax_handler( $data ) {
* @param mixed $value View data value.
* @param string $key View data key.
* @return bool|array {
* In case of array. Uses wp_json_return() structure.
* In case of array. Uses wp_json_return() when AJAX is used.
* @type bool $success Send JSON success or error?
* @type array $data {
* Optional extra data to send with the JSON return.
* In case of a view the page normally refreshes.
* @type string $redirect (URL) Redirect the user? (Only works on success).
* @type string $display Options: notice A notice type in the admin bar
* popup A popup/overlay with content
* @type string $type Options: success Ureka! (green) - Default when $success is true
* error Send an error (red) - Default when $success is false
* message Just a message (blue)
* warning Send a warning (orange)
* @type string $text The text to show
* @type array $list Show multiple messages (Popup only)
* @type string $textarea Textarea content (Popup only)
* @type string $display Options: `notice` A notice type in the admin bar.
* `popup` A popup/overlay with content.
* @type string $type Options: `success` Ureka! (green) - Default when $success is true.
* `error` Send an error (red) - Default when $success is false.
* `message` Just a message (blue).
* `warning` Send a warning (orange).
* @type string $text The text to show.
* @type array $list Show multiple messages (Popup only).
* @type string $textarea Textarea content (Popup only).
* }
* }
*/
Expand All @@ -224,6 +229,7 @@ private function ajax_handler( $data ) {

$success = apply_filters( 'view_admin_as_update_view_' . $key, null, $value, $key );
} else {
// @todo 1.9 Rename this to `view_admin_as_update_{$key}`
$success = apply_filters( 'view_admin_as_handle_ajax_' . $key, null, $value, $key );
}
if ( true !== $success ) {
Expand Down Expand Up @@ -353,10 +359,12 @@ public function get_view_types() {
_deprecated_hook( 'view_admin_as_view_types', 1.8, 'view_admin_as()->register_view_type()' );
}

$view_types = array_unique( array_merge(
array_filter( $dep_view_types, 'is_string' ),
$view_types
) );
$view_types = array_unique(
array_merge(
array_filter( $dep_view_types, 'is_string' ),
$view_types
)
);
}

return $view_types;
Expand Down Expand Up @@ -416,11 +424,12 @@ private function get_view() {
*
* @since 1.3.4
* @since 1.6.0 Moved from `VAA_View_Admin_As`.
* @since 1.8.3 Made public.
* @access public
*
* @return bool
*/
private function update_view() {
public function update_view() {
$data = $this->validate_view_data( $this->store->get_view() );
if ( $data ) {
$meta = $this->store->get_userMeta( 'views' );
Expand Down Expand Up @@ -454,8 +463,8 @@ private function update_view() {
*/
public function reset_view( $user_login = null, $user = null ) {

// function is not triggered by the wp_login action hook.
if ( null === $user ) {
// Function is not triggered by the wp_login action hook.
$user = $this->store->get_curUser();
}
if ( ! empty( $user->ID ) ) {
Expand Down Expand Up @@ -492,8 +501,8 @@ public function reset_view( $user_login = null, $user = null ) {
*/
public function cleanup_views( $user_login = null, $user = null ) {

// function is not triggered by the wp_login action hook.
if ( null === $user ) {
// Function is not triggered by the wp_login action hook.
$user = $this->store->get_curUser();
}
if ( ! empty( $user->ID ) ) {
Expand Down Expand Up @@ -534,8 +543,8 @@ public function cleanup_views( $user_login = null, $user = null ) {
*/
public function reset_all_views( $user_login = null, $user = null ) {

// function is not triggered by the wp_login action hook.
if ( null === $user ) {
// Function is not triggered by the wp_login action hook.
$user = $this->store->get_curUser();
}
if ( ! empty( $user->ID ) ) {
Expand Down Expand Up @@ -568,14 +577,16 @@ public function validate_data_keys( $data ) {
return array();
}

$allowed_keys = array_unique( array_merge(
// View types.
$this->get_view_types(),
// Module keys.
array_keys( $this->vaa->get_modules() ),
// VAA core keys.
array( 'setting', 'user_setting', 'reset' )
) );
$allowed_keys = array_unique(
array_merge(
// View types.
$this->get_view_types(),
// Module keys.
array_keys( $this->vaa->get_modules() ),
// VAA core keys.
array( 'setting', 'user_setting', 'reset' )
)
);

$data = array_intersect_key( $data, array_flip( $allowed_keys ) );

Expand Down
3 changes: 1 addition & 2 deletions includes/class-store.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public function get_curUserSession() {
}

/**
* Get view data (meta).
* Get view data.
* @since 1.7.0
* @param string $key Key for array.
* @return mixed
Expand All @@ -269,7 +269,6 @@ public function get_view( $key = null ) {

/**
* Get view type data
*
* @since 1.7.0
* @param string $type Type key.
* @param string $key (optional) Type data key.
Expand Down
8 changes: 4 additions & 4 deletions includes/class-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,11 @@ public function init_user_modifications() {
/**
* View update handler (Ajax probably), called from main handler.
*
* @since 1.8.0 Renamed from `ajax_handler()`
* @since 1.8.0 Renamed from `ajax_handler()`.
* @access public
* @param null $null Null.
* @param array $data The ajax data for this module.
* @param string $type The view type.
* @param null $null Null.
* @param array $data The ajax data for this module.
* @param string $type The view type.
* @return bool
*/
public function update_view( $null, $data, $type = null ) {
Expand Down
4 changes: 2 additions & 2 deletions includes/class-vaa.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ final class VAA_View_Admin_As
private $view_types = array();

/**
* Class registry
* Class registry.
*
* @since 1.8.0
* @var array
Expand Down Expand Up @@ -251,7 +251,7 @@ private function run() {
$this->welcome_notice();
}

// Fix some compatibility issues, more to come!
// Third party compatibility.
VAA_View_Admin_As_Compat::get_instance( $this )->init();

/**
Expand Down
Loading

0 comments on commit ed84c95

Please sign in to comment.