Code Monkey home page Code Monkey logo

Comments (1)

maxwellrowe avatar maxwellrowe commented on June 12, 2024

Just a note that I got this working with latest Gravity Forms and WP by modifying the plugin.

Within the plugin files, go to /classes/Addon.php

  • Change line 167 from private to public function
    public function settings_iframe_embed_code( $field, $echo = true ) {

  • Commented out line 173
    //$attributes[] = 'readonly="readonly"';

It's a temporary fix, but seemed to work for us.

`<?php
/**

/**

  • The main add-on class.

  • Extends the Gravity Forms add-on class. Functionality that needs access to

  • the add-on API should be encapsulated since most methods and properties are

  • protected.

  • @Package GravityFormsIframe

  • @SInCE 2.0.0
    /
    class GravityFormsIframe_Addon extends GFAddOn {
    /
    *

    • Plugin instance.
    • @SInCE 2.0.0
    • @var GravityFormsIframe_Plugin
      */
      protected $plugin;

    /**

    • Members plugin integration.
    • @SInCE 2.0.0
    • @var array
      */
      protected $_capabilities = array( 'gravityforms_iframe' );

    /**

    • Form settings capability.
    • @SInCE 2.0.0
    • @var string
      */
      protected $_capabilities_form_settings = 'gravityforms_iframe';

    /**

    • Class constructor for setting up the add-on.

    • @SInCE 2.0.0

    • @see GFAddOn

    • @param GravityFormsIframe_Plugin $plugin Main plugin instance.
      */
      public function __construct( $plugin ) {
      $this->plugin = $plugin;

      $this->title = esc_html_( 'Gravity Forms Iframe Add-On', 'gravity-forms-iframe' );
      $this->short_title = esc_html_( 'Iframe', 'gravity-forms-iframe' );
      $this->_version = '2.0.1';
      $this->_slug = 'gfiframe';
      $this->_path = $this->plugin->get_basename();
      $this->_full_path = $this->plugin->get_file();

      parent::__construct();
      }

    /**

    • Register add-on scripts.

    • @SInCE 2.0.0

    • @return array
      */
      public function scripts() {
      $scripts = array(
      array(
      'handle' => 'gfiframe-settings',
      'src' => $this->plugin->get_url( 'assets/scripts/settings.js' ),
      'version' => $this->_version,
      'deps' => array( 'jquery' ),
      'enqueue' => array(
      array(
      'admin_page' => array( 'form_settings' ),
      'tab' => 'gfiframe',
      ),
      ),
      ),
      );

      return array_merge( parent::scripts(), $scripts );
      }

    /**

    • Declare the sections and fields for the iframe add-on.
    • @SInCE 2.0.0
    • @param array $form Form data.
    • @return array
      */
      public function form_settings_fields( $form ) {
      return array(
      array(
      'title' => esc_html__( 'Iframe Settings', 'gravity-forms-iframe' ),
      'description' => '',
      'fields' => array(
      array(
      'label' => esc_html__( 'Enable embedding', 'gravity-forms-iframe' ),
      'type' => 'checkbox',
      'name' => 'is_enabled',
      'onclick' => '',
      'tooltip' => '',
      'choices' => array(
      array(
      'label' => esc_html__( 'Allow this form to be embedded in an iframe', 'gravity-forms-iframe' ),
      'name' => 'is_enabled',
      ),
      ),
      ),
      array(
      'label' => esc_html__( 'Display title', 'gravity-forms-iframe' ),
      'type' => 'checkbox',
      'name' => 'display_title',
      'onclick' => '',
      'tooltip' => '',
      'choices' => array(
      array(
      'label' => esc_html__( 'Display title', 'gravity-forms-iframe' ),
      'name' => 'display_title',
      ),
      ),
      ),
      array(
      'label' => esc_html__( 'Display description', 'gravity-forms-iframe' ),
      'type' => 'checkbox',
      'name' => 'display_description',
      'tooltip' => '',
      'onclick' => '',
      'choices' => array(
      array(
      'label' => esc_html__( 'Display description', 'gravity-forms-iframe' ),
      'name' => 'display_description',
      ),
      ),
      ),
      array(
      'label' => esc_html__( 'Embed Code', 'gravity-forms-iframe' ),
      'type' => 'iframe_embed_code',
      'name' => 'embed_code',
      'tooltip' => '',
      'class' => 'fieldwidth-3 field-height-3',
      ),
      ),
      ),
      );
      }

    /**

    • Render a field for displaying the code to embed a form.

    • @SInCE 2.0.0

    • @param array $field Field array containing the configuration options of this field.

    • @param bool $echo Whether the field should be displayed.

    • @return string
      */
      public function settings_iframe_embed_code( $field, $echo = true ) {
      $form = $this->get_current_form();

      $field['type'] = 'iframe_embed_code';

      $attributes = $this->get_field_attributes( $field );
      //$attributes[] = 'readonly="readonly"';
      $attributes[] = 'onfocus="this.select();"';

      $iframe_url = home_url( '/gfembed/' );
      $iframe_url = add_query_arg( 'f', $form['id'], $iframe_url );
      $iframe_url = preg_replace( '#^http(s)?:#', '', $iframe_url );

      // Relative protocol.
      $script_url = preg_replace( '#^http(s)?:#', '', $this->plugin->get_url( 'assets/scripts/gfembed.min.js' ) );

      $value = '<iframe src="' . esc_url( $iframe_url ) . '" width="100%" height="500" frameBorder="0" class="gfiframe"></iframe>' . "\n";
      $value .= '<script src="' . esc_url( $script_url ) . '" type="text/javascript"></script>';

      $tooltip = '';
      if ( isset( $choice['tooltip'] ) ) {
      $tooltip = gform_tooltip( $choice['tooltip'], rgar( $choice, 'tooltip_class'), true );
      }

      $html = '<textarea ' . implode( ' ', $attributes ) . '>' . esc_textarea( $value ) . '</textarea>';

      if ( $echo ) {
      echo $html;
      }

      return $html;
      }
      }
      `

from gravity-forms-iframe.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.