Skip to content

Commit d508813

Browse files
release: fixes
- Fixed media upload UI in modal view - Enhanced security
2 parents 13f6499 + e80b74e commit d508813

3 files changed

Lines changed: 41 additions & 16 deletions

File tree

composer.lock

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

inc/server/class-dynamic-content-server.php

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ public function register_routes() {
124124
},
125125
),
126126
),
127-
'permission_callback' => function () {
128-
return true;
127+
'permission_callback' => function ( $request ) {
128+
return $this->check_permission( $request->get_param( 'context' ) );
129129
},
130130
),
131131
)
@@ -140,14 +140,39 @@ public function register_routes() {
140140
'callback' => function( $request ) {
141141
return Dynamic_Content::instance()->apply_data( $request->get_params() );
142142
},
143-
'permission_callback' => function () {
144-
return true;
143+
'permission_callback' => function ( $request ) {
144+
return $this->check_permission( $request->get_param( 'context' ) );
145145
},
146146
),
147147
)
148148
);
149149
}
150150

151+
/**
152+
* Check permission to perform the request.
153+
*
154+
* @param int $post_id Post ID.
155+
*
156+
* @return bool
157+
*/
158+
public function check_permission( $post_id = 0 ) {
159+
if ( empty( $post_id ) ) {
160+
return false;
161+
}
162+
163+
$post = get_post( $post_id );
164+
if ( ! $post ) {
165+
return false;
166+
}
167+
168+
// Allow only if the post is published or the user has permission to view it.
169+
if ( 'publish' === $post->post_status || current_user_can( 'edit_post', $post_id ) ) {
170+
return true;
171+
}
172+
173+
return false;
174+
}
175+
151176
/**
152177
* Get Dynamic Image
153178
*

src/pro/blocks/modal/edit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ const Edit = ({
241241
}
242242
},
243243
[
244-
[ 'core/image', { height: '150px' }],
244+
[ 'core/image'],
245245
[ 'core/heading', { placeholder: __( 'Modal Title', 'otter-pro' ) }],
246246
[ 'core/paragraph', { placeholder: __( 'Modal Content', 'otter-pro' ) }]
247247
]

0 commit comments

Comments
 (0)