Skip to content

Commit

Permalink
add/remove secret realtime in view
Browse files Browse the repository at this point in the history
  • Loading branch information
doekenorg committed Mar 7, 2024
1 parent f8b8f20 commit f477b0d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
17 changes: 17 additions & 0 deletions assets/js/admin-views.js
Original file line number Diff line number Diff line change
Expand Up @@ -2789,6 +2789,23 @@
}
} );

const $embedShortcodeEl = $( '#gv-embed-shortcode' );
$( '#gravityview_se_is_secure' ).on( 'change', function () {
let embedShortcode = $embedShortcodeEl.val();
if ( !embedShortcode ) {
return;
}

if ( $( this ).is( ':checked' ) ) {
embedShortcode = embedShortcode.replace( /]$/, ` secret="${ $embedShortcodeEl.data( 'secret' ) }"]` );

} else {
embedShortcode = embedShortcode.replace( / secret="[^"]+"/, '' );
}

$embedShortcodeEl.val( embedShortcode );
} );

// Expose globally methods to initialize/destroy tooltips and to display dialog window
window.gvAdminActions = {
initTooltips: viewConfiguration.init_tooltips,
Expand Down
2 changes: 1 addition & 1 deletion assets/js/admin-views.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions future/includes/class-gv-view.php
Original file line number Diff line number Diff line change
Expand Up @@ -1836,12 +1836,12 @@ protected function apply_legacy_join_is_approved_query_conditions( \GF_Query $qu
*
* @return string|null The view's secret.
*/
final public function get_validation_secret(): ?string {
final public function get_validation_secret( bool $is_forced = false ): ?string {
// Cannot use the setting variable because it can be overwritten from the short code.
$settings = get_post_meta( $this->ID, '_gravityview_template_settings', true );
$is_secure = (bool) rgar( $settings, 'is_secure', false );

if ( ! $is_secure || ! class_exists( GravityKitFoundation::class ) ) {
if ( ( ! $is_secure && ! $is_forced ) || ! class_exists( GravityKitFoundation::class ) ) {
return null;
}

Expand Down
5 changes: 3 additions & 2 deletions includes/admin/metaboxes/views/shortcode-hint.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@

$view = \GV\View::from_post( $post );
$shortcode = $view->get_shortcode();
$secret = $view->get_validation_secret( true );
?>
<div class="misc-pub-section gv-shortcode misc-pub-section-last">
<i class="dashicons dashicons-editor-code"></i>
<span id="gv-embed-shortcode"><?php esc_html_e( 'Embed Shortcode', 'gk-gravityview' ); ?></span>
<span id="gv-embed-shortcode-label"><?php esc_html_e( 'Embed Shortcode', 'gk-gravityview' ); ?></span>
<div>
<input aria-labelledby="gv-embed-shortcode" type="text" readonly="readonly" value="<?php echo esc_attr( $shortcode ); ?>" class="code widefat" />
<input id="gv-embed-shortcode" aria-labelledby="gv-embed-shortcode-label" type="text" readonly="readonly" value="<?php echo esc_attr( $shortcode ); ?>" class="code widefat" data-secret="<?php echo esc_attr( $secret ); ?>" />
<span class="howto"><?php echo esc_html__( 'Add this shortcode to a post or page to embed this view.', 'gk-gravityview' ) . ' ' . esc_html__( 'Click to copy', 'gk-gravityview' ); ?>.</span>
<span class="copied"><?php esc_html_e( 'Copied!', 'gk-gravityview' ); ?></span>
</div>
Expand Down

0 comments on commit f477b0d

Please sign in to comment.