--- a/ultimate-addons-for-gutenberg/blocks-config/post-timeline/class-uagb-post-timeline.php
+++ b/ultimate-addons-for-gutenberg/blocks-config/post-timeline/class-uagb-post-timeline.php
@@ -1112,6 +1112,15 @@
global $post;
+ if ( post_password_required( $post ) ) {
+ ?>
+ <div class="uagb-timeline-desc-content">
+ <?php echo esc_html__( 'There is no excerpt because this is a protected post.', 'ultimate-addons-for-gutenberg' ); ?>
+ </div>
+ <?php
+ return;
+ }
+
$excerpt_length_fallback = UAGB_Block_Helper::get_fallback_number( $attributes['exerptLength'], 'exerptLength', $attributes['blockName'] );
$excerpt = UAGB_Helper::uagb_get_excerpt( $post->ID, $post->post_content, $excerpt_length_fallback );
--- a/ultimate-addons-for-gutenberg/blocks-config/post/class-uagb-post.php
+++ b/ultimate-addons-for-gutenberg/blocks-config/post/class-uagb-post.php
@@ -2201,6 +2201,15 @@
global $post;
+ if ( post_password_required( $post ) ) {
+ ?>
+ <div class='uagb-post__text uagb-post__excerpt'>
+ <?php echo esc_html__( 'There is no excerpt because this is a protected post.', 'ultimate-addons-for-gutenberg' ); ?>
+ </div>
+ <?php
+ return;
+ }
+
if ( 'full_post' === $attributes['displayPostContentRadio'] ) {
$excerpt = get_the_content();
} else {
--- a/ultimate-addons-for-gutenberg/classes/class-uagb-helper.php
+++ b/ultimate-addons-for-gutenberg/classes/class-uagb-helper.php
@@ -1403,6 +1403,10 @@
*/
public static function uagb_get_excerpt( $post_id, $content, $length_fallback ) {
+ if ( post_password_required( $post_id ) ) {
+ return __( 'There is no excerpt because this is a protected post.', 'ultimate-addons-for-gutenberg' );
+ }
+
// If there's an excerpt provided from meta, use it.
$excerpt = get_post_field( 'post_excerpt', $post_id );
--- a/ultimate-addons-for-gutenberg/classes/class-uagb-init-blocks.php
+++ b/ultimate-addons-for-gutenberg/classes/class-uagb-init-blocks.php
@@ -133,6 +133,7 @@
'show_in_admin_bar' => true,
'show_ui' => true,
'show_in_rest' => true,
+ 'rest_base' => 'spectra-popup',
'template_lock' => 'all',
'template' => array(
array( 'uagb/popup-builder', array() ),
@@ -159,24 +160,42 @@
'single' => true,
'type' => 'string',
'default' => 'unset',
- 'auth_callback' => '__return_true',
- 'show_in_rest' => true,
+ 'auth_callback' => function() {
+ return current_user_can( 'manage_options' );
+ },
+ 'show_in_rest' => array(
+ 'schema' => array(
+ 'type' => 'string',
+ ),
+ ),
);
$meta_args_popup_enabled = array(
'single' => true,
'type' => 'boolean',
'default' => false,
- 'auth_callback' => '__return_true',
- 'show_in_rest' => true,
+ 'auth_callback' => function() {
+ return current_user_can( 'manage_options' );
+ },
+ 'show_in_rest' => array(
+ 'schema' => array(
+ 'type' => 'boolean',
+ ),
+ ),
);
$meta_args_popup_repetition = array(
'single' => true,
'type' => 'number',
'default' => 1,
- 'auth_callback' => '__return_true',
- 'show_in_rest' => true,
+ 'auth_callback' => function() {
+ return current_user_can( 'manage_options' );
+ },
+ 'show_in_rest' => array(
+ 'schema' => array(
+ 'type' => 'number',
+ ),
+ ),
);
register_post_type( 'spectra-popup', $type_args );
@@ -195,6 +214,105 @@
add_filter( 'manage_spectra-popup_posts_columns', array( $spectra_popup_dashboard, 'popup_builder_admin_headings' ) );
add_action( 'manage_spectra-popup_posts_custom_column', array( $spectra_popup_dashboard, 'popup_builder_admin_content' ), 10, 2 );
+
+ // Add REST API access control for spectra-popup post type.
+ add_filter( 'rest_spectra-popup_query', array( __CLASS__, 'filter_rest_popup_query' ), 10, 2 );
+ add_filter( 'rest_prepare_spectra-popup', array( __CLASS__, 'filter_rest_popup_response' ), 10, 3 );
+ add_filter( 'rest_authentication_errors', array( __CLASS__, 'restrict_popup_rest_access' ), 99 );
+ }
+
+ /**
+ * Restrict REST API access to spectra-popup for non-authenticated users.
+ *
+ * @param WP_Error|null|bool $result Error from another authentication handler, null if not errors, true if authenticated.
+ * @return WP_Error|null|bool Modified result.
+ *
+ * @since 2.19.18
+ */
+ public static function restrict_popup_rest_access( $result ) {
+ // If there's already an error, return it.
+ if ( is_wp_error( $result ) ) {
+ return $result;
+ }
+
+ // Only apply to spectra-popup endpoints.
+ $route = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
+ if ( false === strpos( $route, '/wp/v2/spectra-popup' ) ) {
+ return $result;
+ }
+
+ // Allow authenticated admin users with manage_options.
+ if ( is_user_logged_in() && current_user_can( 'manage_options' ) ) {
+ return $result;
+ }
+
+ // Block unauthenticated users and non-admin users.
+ return new WP_Error(
+ 'rest_forbidden',
+ __( 'Sorry, you are not allowed to access popups.', 'ultimate-addons-for-gutenberg' ),
+ array( 'status' => rest_authorization_required_code() )
+ );
+ }
+
+ /**
+ * Filter REST API query to only include enabled popups for non-admin users.
+ *
+ * @param array $args Array of query arguments.
+ * @param WP_REST_Request $request REST request object.
+ * @return array Modified query arguments.
+ *
+ * @since 2.19.18
+ */
+ public static function filter_rest_popup_query( $args, $request ) {
+ // Allow admin users with manage_options to see all popups.
+ if ( current_user_can( 'manage_options' ) ) {
+ return $args;
+ }
+
+ // For non-admin users, only show enabled popups.
+ if ( ! isset( $args['meta_query'] ) ) {
+ $args['meta_query'] = array(); // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
+ }
+
+ $args['meta_query'][] = array(
+ 'key' => 'spectra-popup-enabled',
+ 'value' => true,
+ 'compare' => '=',
+ 'type' => 'BOOLEAN',
+ );
+
+ return $args;
+ }
+
+ /**
+ * Filter REST API response to hide disabled popups from non-admin users.
+ *
+ * @param WP_REST_Response $response Response object.
+ * @param WP_Post $post Post object.
+ * @param WP_REST_Request $request Request object.
+ * @return WP_REST_Response|WP_Error Modified response or error.
+ *
+ * @since 2.19.18
+ */
+ public static function filter_rest_popup_response( $response, $post, $request ) {
+ // Allow admin users with manage_options to see all popups.
+ if ( current_user_can( 'manage_options' ) ) {
+ return $response;
+ }
+
+ // Check if popup is enabled.
+ $popup_enabled = get_post_meta( $post->ID, 'spectra-popup-enabled', true );
+
+ // If popup is not enabled, return 403 error.
+ if ( ! $popup_enabled ) {
+ return new WP_Error(
+ 'rest_forbidden',
+ __( 'You do not have permission to view this popup.', 'ultimate-addons-for-gutenberg' ),
+ array( 'status' => 403 )
+ );
+ }
+
+ return $response;
}
/**
--- a/ultimate-addons-for-gutenberg/classes/class-uagb-loader.php
+++ b/ultimate-addons-for-gutenberg/classes/class-uagb-loader.php
@@ -133,7 +133,7 @@
define( 'UAGB_BASE', plugin_basename( UAGB_FILE ) );
define( 'UAGB_DIR', plugin_dir_path( UAGB_FILE ) );
define( 'UAGB_URL', plugins_url( '/', UAGB_FILE ) );
- define( 'UAGB_VER', '2.19.17' );
+ define( 'UAGB_VER', '2.19.18' );
define( 'UAGB_MODULES_DIR', UAGB_DIR . 'modules/' );
define( 'UAGB_MODULES_URL', UAGB_URL . 'modules/' );
define( 'UAGB_SLUG', 'spectra' );
--- a/ultimate-addons-for-gutenberg/ultimate-addons-for-gutenberg.php
+++ b/ultimate-addons-for-gutenberg/ultimate-addons-for-gutenberg.php
@@ -4,7 +4,7 @@
* Plugin URI: https://www.brainstormforce.com
* Author: Brainstorm Force
* Author URI: https://www.brainstormforce.com
- * Version: 2.19.17
+ * Version: 2.19.18
* Description: The Spectra extends the Gutenberg functionality with several unique and feature-rich blocks that help build websites faster.
* Text Domain: ultimate-addons-for-gutenberg
* Domain Path: /languages