Skip to content

Commit

Permalink
Fixed an issue where code editor scripts is not loaded for non-admin …
Browse files Browse the repository at this point in the history
…user.
  • Loading branch information
barthc committed Aug 9, 2024
1 parent bcc86de commit 9be9634
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions class-gwiz-gf-code-chest.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,6 @@ public function init() {

load_plugin_textdomain( $this->_slug, false, basename( dirname( __file__ ) ) . '/languages/' );

if ( current_user_can( 'administrator' ) ) {
add_filter( 'gform_tooltips', array( $this, 'tooltips' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_editor_script' ) );
add_action( 'gform_post_save_feed_settings', array( $this, 'save_code_chest_settings' ), 10, 4 );
add_filter( 'gform_noconflict_scripts', array( $this, 'noconflict_scripts' ) );
add_filter( 'gform_noconflict_styles', array( $this, 'noconflict_styles' ) );

// 11 so that this comes right after and can override the legacy Custom JS plugin setting config.
add_filter( 'gform_form_settings_fields', array( $this, 'replace_custom_js_setting' ), 11, 2 );
}

add_filter( 'gform_register_init_scripts', array( $this, 'register_init_script' ), 99, 1 );
add_filter( 'gform_register_init_scripts', array( $this, 'maybe_register_custom_js_scripts_first' ), 100, 1 );

Expand All @@ -240,6 +229,18 @@ public function init() {
add_action( 'gform_post_form_duplicated', array( $this, 'duplicate_form_feeds' ), 10, 2 );
}

public function init_admin() {
parent::init_admin();

add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_editor_script' ) );
add_action( 'gform_post_save_feed_settings', array( $this, 'save_code_chest_settings' ), 10, 4 );
add_filter( 'gform_noconflict_scripts', array( $this, 'noconflict_scripts' ) );
add_filter( 'gform_noconflict_styles', array( $this, 'noconflict_styles' ) );

// 11 so that this comes right after and can override the legacy Custom JS plugin setting config.
add_filter( 'gform_form_settings_fields', array( $this, 'replace_custom_js_setting' ), 11, 2 );
}

public function enqueue_editor_script() {
if ( GFForms::get_page() !== 'form_settings_gf-code-chest' ) {
return;
Expand Down Expand Up @@ -423,17 +424,6 @@ public function get_custom_css( $form ) {
return rgar( $settings, 'code_chest_css' );
}

/**
* Registers tooltips with Gravity Forms. Needed for some things like radio choices.
*
* @param $tooltips array Existing tooltips.
*
* @return array
*/
public function tooltips( $tooltips ) {
return $tooltips;
}

public function feed_settings_fields() {
$form_id = rgget( 'id' );
$form = GFAPI::get_form( $form_id );
Expand Down

0 comments on commit 9be9634

Please sign in to comment.