Skip to content

Commit

Permalink
added custom action and filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Florenz T. Daus committed May 27, 2018
1 parent 9e2cbf2 commit 37bd4e4
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions includes/class-gemarj-rbac.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function __construct( $args ) {
) );
/*Update settings*/
add_action( 'admin_post_gemarj_rbac_update_options', array( $this, 'gemarj_rbac_update_options_handle_post' ) );
add_shortcode( 'gemarj-rbac', array( $this, 'register_shortcode' ) );
add_shortcode( 'gm-rbac', array( $this, 'register_shortcode' ) );

}

Expand Down Expand Up @@ -206,6 +206,7 @@ function () {


public function register_shortcode( $attributes, $content ) {
do_action( 'gm_before_check_action', array( 'attributes' => $attributes, 'content' => $content ) );
$currentLoggedInUser = wp_get_current_user();
$allowerdToViewContent = false;
if ( isset( $attributes['role'] ) && ! empty( $attributes['role'] ) ) {
Expand Down Expand Up @@ -241,17 +242,18 @@ public function register_shortcode( $attributes, $content ) {
}
}
}
do_action( 'gm_after_check_action', array( 'attributes' => $attributes, 'content' => $content ) );
/*if allowed to view*/
if ( $allowerdToViewContent ) {
do_action( 'gm_before_render_action', array( 'attributes' => $attributes, 'content' => $content ) );
return $content;
} else {
if ( isset( $attributes['errorMessage'] ) && ! empty( $attributes['errorMessage'] ) ) {
return sanitize_text_field( $attributes['errorMessage'] );
} else {
$defaultErrorMessage = get_option( 'gemarj-rbac-error-message', 'You are not allowed to view this content' );

return $defaultErrorMessage;
$errorMessage = get_option( 'gemarj-rbac-error-message', 'You are not allowed to view this content' );
if ( isset( $attributes['errormessage'] ) && ! empty( $attributes['errormessage'] ) ) {
$errorMessage = sanitize_text_field( $attributes['errormessage'] );
}
$errorMessage = apply_filters( 'gm_error_message_filter', $errorMessage );
return $errorMessage;
}
}

Expand Down

0 comments on commit 37bd4e4

Please sign in to comment.