Compare commits

..

4 Commits

6 changed files with 151 additions and 67 deletions

View File

@ -28,7 +28,7 @@
*/
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
if ( !defined( 'ABSPATH' ) ) {
exit;
}
@ -36,8 +36,8 @@ if ( ! defined( 'ABSPATH' ) ) {
* The Plugin
*/
if ( !class_exists('CognitoFormsPlugin') ) {
require_once dirname(__FILE__) . '/api.php';
if ( !class_exists( 'CognitoFormsPlugin' ) ) {
require_once dirname( __FILE__ ) . '/api.php';
class CognitoFormsPlugin {
// Initialization actions
@ -49,26 +49,26 @@ if ( !class_exists('CognitoFormsPlugin') ) {
// Supported shortcodes
private static $shortcodes = array(
'CognitoForms' => 'render_shortcode',
'cognitoforms' => 'render_shortcode'
'CognitoForms' => 'render_cognito_shortcode',
'cognitoforms' => 'render_cognito_shortcode'
);
// Registers plug-in actions
private function addActions($actions) {
foreach($actions as $action)
add_action($action, array($this, $action));
private function add_actions( $actions ) {
foreach ( $actions as $action )
add_action( $action, array( $this, $action ) );
}
// Registers plug-in filters
private function addFilters($filters) {
foreach($filters as $filter)
add_filter($filter, array($this, $filter));
private function add_filters( $filters ) {
foreach ( $filters as $filter )
add_filter( $filter, array( $this, $filter ) );
}
// Registers shortcodes
private function addShortcodes($shortcodes) {
foreach($shortcodes as $tag => $func)
add_shortcode($tag, array($this, $func));
private function add_shortcodes( $shortcodes ) {
foreach ( $shortcodes as $tag => $func )
add_shortcode( $tag, array( $this, $func ) );
}
// Checks if an option exists in the database
@ -88,8 +88,8 @@ if ( !class_exists('CognitoFormsPlugin') ) {
// Entrypoint
public function __construct() {
$this->addActions(self::$actions);
$this->addShortcodes(self::$shortcodes);
$this->add_actions( self::$actions );
$this->add_shortcodes( self::$shortcodes );
}
public function init() {
@ -104,7 +104,7 @@ if ( !class_exists('CognitoFormsPlugin') ) {
if( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) )
return;
register_setting('cognito_plugin', 'cognito_public_key');
add_option( 'cognito_public_key' );
// Remove old API keys from the database
$this->remove_options( array(
@ -115,7 +115,7 @@ if ( !class_exists('CognitoFormsPlugin') ) {
// If the flag to delete options was passed in, delete them
if ( isset( $_GET['cog_clear'] ) && $_GET['cog_clear'] == '1' ) {
delete_option('cognito_public_key');
delete_option( 'cognito_public_key' );
}
// Initialize TinyMCE Plugin
@ -124,7 +124,7 @@ if ( !class_exists('CognitoFormsPlugin') ) {
// Initialize block
public function block_init() {
$asset_file = include( plugin_dir_path( __FILE__ ) . 'dist/index.asset.php');
$asset_file = include( plugin_dir_path( __FILE__ ) . 'dist/index.asset.php' );
// Register global block styles
wp_register_style(
@ -164,22 +164,22 @@ if ( !class_exists('CognitoFormsPlugin') ) {
// Initialize classic editor (TinyMCE)
public function tinymce_init() {
if(get_user_option('rich_editing') == 'true') {
$this->addFilters( array(
'mce_buttons',
'mce_external_plugins'
if ( get_user_option( 'rich_editing' ) == 'true' ) {
$this->add_filters( array(
'tinymce_buttons',
'tinymce_external_plugins'
) );
}
}
// Set up TinyMCE buttons
public function mce_buttons( $buttons ) {
public function tinymce_buttons( $buttons ) {
array_push($buttons, '|', 'cognito');
return $buttons;
}
// Set up TinyMCE plug-in
public function mce_external_plugins( $plugin_array ) {
public function tinymce_external_plugins( $plugin_array ) {
$plugin_array['cognito_mce_plugin'] = plugins_url( '/tinymce/plugin.js', __FILE__ );
return $plugin_array;
}
@ -193,12 +193,12 @@ if ( !class_exists('CognitoFormsPlugin') ) {
}
// Called when a 'CognitoForms' shortcode is encountered, renders form embed script
public function render_shortcode($atts, $content = null, $code = '') {
public function render_cognito_shortcode( $atts, $content = null, $code = '' ) {
// Default to key setting, unless overridden in shortcode (allows for modules from multiple orgs)
$key = empty($atts['key']) ? get_option('cognito_public_key') : $atts['key'];
if (empty($atts['id']) || empty($key)) return '';
$key = empty( $atts['key'] ) ? get_option( 'cognito_public_key' ) : $atts['key'];
if ( empty( $atts['id'] ) || empty( $key ) ) return '';
return CognitoAPI::get_form_embed_script($key, $atts['id']);
return CognitoAPI::get_form_embed_script( $key, $atts['id'] );
}
// Entrypoint for Cognito Forms access

View File

@ -23,11 +23,12 @@
},
"dependencies": {
"@types/classnames": "^2.2.10",
"@types/node": "^17.0.17",
"@types/node": "^17.0.18",
"@types/react": "^17.0.39",
"@types/react-dom": "^17.0.11",
"@types/wordpress__block-editor": "^6.0.5",
"@types/wordpress__blocks": "^9.1.1",
"@types/wordpress__components": "^19.3.0",
"@wordpress/block-editor": "^8.1.1",
"@wordpress/blocks": "^11.2.1",
"@wordpress/components": "^19.4.0",
@ -38,7 +39,7 @@
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-scripts": "5.0.0",
"sass-loader": "^12.4.0",
"sass-loader": "^12.5.0",
"style-loader": "^3.3.1",
"svg-react-loader": "^0.4.6",
"ts-loader": "^9.2.6",
@ -48,8 +49,8 @@
"webpack-cli": "^4.9.2"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.11.0",
"@typescript-eslint/parser": "^5.11.0",
"@typescript-eslint/eslint-plugin": "^5.12.0",
"@typescript-eslint/parser": "^5.12.0",
"eslint-plugin-jest": "^26.1.0",
"esm": "^3.2.25",
"gulp": "^4.0.2",

View File

@ -36,10 +36,11 @@ class SelectDialog extends React.Component<IDialogProps> {
onRequestClose={ () => this.props.setOpen( false ) }
shouldCloseOnClickOutside={ false }
>
<FocusableIframe
<iframe
style={ { width: '500px', height: '500px', display: 'block' } }
src={ `${ baseUrl }/integrations/cms` }
></FocusableIframe>
title="Choose a Form"
></iframe>
</Modal>
);
}

View File

@ -9,7 +9,6 @@ import {
PanelRow,
ExternalLink,
Button,
Icon,
} from '@wordpress/components';
import { edit, external } from '@wordpress/icons';
import { useState } from '@wordpress/element';
@ -75,19 +74,29 @@ const Edit: React.FC<BlockEditProps<IBlockAttributes>> = ( { attributes, setAttr
/>
</div>
:
// No form has been selected yet, so render the placeholder
// No form has been selected yet, so render the placeholder.
<div>
<Placeholder
icon={ CogIcon }
label="Cognito Forms"
instructions="Choose an existing form to embed or create a new one."
>
<div>
<Button isPrimary onClick={ () => setSelectDialogOpen( true ) }>
<div style={ { display: 'flex' } }>
<Button
variant="primary"
onClick={ () => setSelectDialogOpen( true ) }
>
Select Form
</Button>
<Button isTertiary href={ `${ baseUrl }/forms/new` } target="_blank">
New Form&thinsp;<Icon icon={ external } size={ 16 }></Icon>
<Button
href={ `${ baseUrl }/forms/new` }
target="_blank"
icon={ external }
iconPosition="right"
iconSize={ 16 }
variant="secondary"
>
New Form
</Button>
</div>
</Placeholder>

View File

@ -6,7 +6,6 @@
*
*/
// Remove modal padding
.wp-block-cognito-forms-cognito-embed {
.components-placeholder__label svg {
height: 24px;
@ -51,9 +50,15 @@
}
}
// Remove modal padding
.cognito-modal {
.components-modal__content {
padding: initial;
height: fit-content;
}
.components-modal__content::before {
display: none;
}
.components-modal__content .components-modal__header {

118
yarn.lock
View File

@ -2313,10 +2313,10 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.8.tgz#50d680c8a8a78fe30abe6906453b21ad8ab0ad7b"
integrity sha512-YofkM6fGv4gDJq78g4j0mMuGMkZVxZDgtU0JRdx6FgiJDG+0fY0GKVolOV8WqVmEhLCXkQRjwDdKyPxJp/uucg==
"@types/node@^17.0.17":
version "17.0.17"
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.17.tgz#a8ddf6e0c2341718d74ee3dc413a13a042c45a0c"
integrity sha512-e8PUNQy1HgJGV3iU/Bp2+D/DXh3PYeyli8LgIwsQcs1Ar1LoaWHSIT6Rw+H2rNJmiq6SNWiDytfx8+gYj7wDHw==
"@types/node@^17.0.18":
version "17.0.18"
resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.18.tgz#3b4fed5cfb58010e3a2be4b6e74615e4847f1074"
integrity sha512-eKj4f/BsN/qcculZiRSujogjvp5O/k4lOW5m35NopjZM/QwLOR075a8pJW5hD+Rtdm2DaCVPENS6KtSQnUD6BA==
"@types/normalize-package-data@^2.4.0":
version "2.4.1"
@ -2528,6 +2528,20 @@
downshift "^6.0.15"
re-resizable "^6.4.0"
"@types/wordpress__components@^19.3.0":
version "19.3.0"
resolved "https://registry.yarnpkg.com/@types/wordpress__components/-/wordpress__components-19.3.0.tgz#dee6824925f124913fc18c9be74ca12fb9ddff8e"
integrity sha512-3LT89kmkFGfiymt36fnnTWelg2oea/UIkXmpRyYMTZe3Wt4GOTWrnmI8l6SpMQ1UKWNaqUXa6WZ6g/i9dGrhZQ==
dependencies:
"@types/react" "*"
"@types/tinycolor2" "*"
"@types/wordpress__components" "*"
"@types/wordpress__notices" "*"
"@types/wordpress__rich-text" "*"
"@wordpress/element" "^3.0.0"
downshift "^6.0.15"
re-resizable "^6.4.0"
"@types/wordpress__data@*":
version "4.6.10"
resolved "https://registry.yarnpkg.com/@types/wordpress__data/-/wordpress__data-4.6.10.tgz#46007271427ccc7fe75d01d697a5c7fb43e7b8bb"
@ -2605,14 +2619,14 @@
semver "^7.3.5"
tsutils "^3.21.0"
"@typescript-eslint/eslint-plugin@^5.11.0":
version "5.11.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.11.0.tgz#3b866371d8d75c70f9b81535e7f7d3aa26527c7a"
integrity sha512-HJh33bgzXe6jGRocOj4FmefD7hRY4itgjzOrSs3JPrTNXsX7j5+nQPciAUj/1nZtwo2kAc3C75jZO+T23gzSGw==
"@typescript-eslint/eslint-plugin@^5.12.0":
version "5.12.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.12.0.tgz#bb46dd7ce7015c0928b98af1e602118e97df6c70"
integrity sha512-fwCMkDimwHVeIOKeBHiZhRUfJXU8n6xW1FL9diDxAyGAFvKcH4csy0v7twivOQdQdA0KC8TDr7GGRd3L4Lv0rQ==
dependencies:
"@typescript-eslint/scope-manager" "5.11.0"
"@typescript-eslint/type-utils" "5.11.0"
"@typescript-eslint/utils" "5.11.0"
"@typescript-eslint/scope-manager" "5.12.0"
"@typescript-eslint/type-utils" "5.12.0"
"@typescript-eslint/utils" "5.12.0"
debug "^4.3.2"
functional-red-black-tree "^1.0.1"
ignore "^5.1.8"
@ -2669,14 +2683,14 @@
"@typescript-eslint/typescript-estree" "4.33.0"
debug "^4.3.1"
"@typescript-eslint/parser@^5.11.0":
version "5.11.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.11.0.tgz#b4fcaf65513f9b34bdcbffdda055724a5efb7e04"
integrity sha512-x0DCjetHZYBRovJdr3U0zG9OOdNXUaFLJ82ehr1AlkArljJuwEsgnud+Q7umlGDFLFrs8tU8ybQDFocp/eX8mQ==
"@typescript-eslint/parser@^5.12.0":
version "5.12.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.12.0.tgz#0ca669861813df99ce54916f66f524c625ed2434"
integrity sha512-MfSwg9JMBojMUoGjUmX+D2stoQj1CBYTCP0qnnVtu9A+YQXVKNtLjasYh+jozOcrb/wau8TCfWOkQTiOAruBog==
dependencies:
"@typescript-eslint/scope-manager" "5.11.0"
"@typescript-eslint/types" "5.11.0"
"@typescript-eslint/typescript-estree" "5.11.0"
"@typescript-eslint/scope-manager" "5.12.0"
"@typescript-eslint/types" "5.12.0"
"@typescript-eslint/typescript-estree" "5.12.0"
debug "^4.3.2"
"@typescript-eslint/parser@^5.5.0":
@ -2705,6 +2719,14 @@
"@typescript-eslint/types" "5.11.0"
"@typescript-eslint/visitor-keys" "5.11.0"
"@typescript-eslint/scope-manager@5.12.0":
version "5.12.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.12.0.tgz#59619e6e5e2b1ce6cb3948b56014d3a24da83f5e"
integrity sha512-GAMobtIJI8FGf1sLlUWNUm2IOkIjvn7laFWyRx7CLrv6nLBI7su+B7lbStqVlK5NdLvHRFiJo2HhiDF7Ki01WQ==
dependencies:
"@typescript-eslint/types" "5.12.0"
"@typescript-eslint/visitor-keys" "5.12.0"
"@typescript-eslint/scope-manager@5.9.1":
version "5.9.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.9.1.tgz#6c27be89f1a9409f284d95dfa08ee3400166fe69"
@ -2713,12 +2735,12 @@
"@typescript-eslint/types" "5.9.1"
"@typescript-eslint/visitor-keys" "5.9.1"
"@typescript-eslint/type-utils@5.11.0":
version "5.11.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.11.0.tgz#58be0ba73d1f6ef8983d79f7f0bc2209b253fefe"
integrity sha512-wDqdsYO6ofLaD4DsGZ0jGwxp4HrzD2YKulpEZXmgN3xo4BHJwf7kq49JTRpV0Gx6bxkSUmc9s0EIK1xPbFFpIA==
"@typescript-eslint/type-utils@5.12.0":
version "5.12.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.12.0.tgz#aaf45765de71c6d9707c66ccff76ec2b9aa31bb6"
integrity sha512-9j9rli3zEBV+ae7rlbBOotJcI6zfc6SHFMdKI9M3Nc0sy458LJ79Os+TPWeBBL96J9/e36rdJOfCuyRSgFAA0Q==
dependencies:
"@typescript-eslint/utils" "5.11.0"
"@typescript-eslint/utils" "5.12.0"
debug "^4.3.2"
tsutils "^3.21.0"
@ -2741,6 +2763,11 @@
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.11.0.tgz#ba345818a2540fdf2755c804dc2158517ab61188"
integrity sha512-cxgBFGSRCoBEhvSVLkKw39+kMzUKHlJGVwwMbPcTZX3qEhuXhrjwaZXWMxVfxDgyMm+b5Q5b29Llo2yow8Y7xQ==
"@typescript-eslint/types@5.12.0":
version "5.12.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.12.0.tgz#5b4030a28222ee01e851836562c07769eecda0b8"
integrity sha512-JowqbwPf93nvf8fZn5XrPGFBdIK8+yx5UEGs2QFAYFI8IWYfrzz+6zqlurGr2ctShMaJxqwsqmra3WXWjH1nRQ==
"@typescript-eslint/types@5.9.1":
version "5.9.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.9.1.tgz#1bef8f238a2fb32ebc6ff6d75020d9f47a1593c6"
@ -2772,6 +2799,19 @@
semver "^7.3.5"
tsutils "^3.21.0"
"@typescript-eslint/typescript-estree@5.12.0":
version "5.12.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.12.0.tgz#cabf545fd592722f0e2b4104711e63bf89525cd2"
integrity sha512-Dd9gVeOqt38QHR0BEA8oRaT65WYqPYbIc5tRFQPkfLquVEFPD1HAtbZT98TLBkEcCkvwDYOAvuSvAD9DnQhMfQ==
dependencies:
"@typescript-eslint/types" "5.12.0"
"@typescript-eslint/visitor-keys" "5.12.0"
debug "^4.3.2"
globby "^11.0.4"
is-glob "^4.0.3"
semver "^7.3.5"
tsutils "^3.21.0"
"@typescript-eslint/typescript-estree@5.9.1":
version "5.9.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.9.1.tgz#d5b996f49476495070d2b8dd354861cf33c005d6"
@ -2785,7 +2825,19 @@
semver "^7.3.5"
tsutils "^3.21.0"
"@typescript-eslint/utils@5.11.0", "@typescript-eslint/utils@^5.10.0":
"@typescript-eslint/utils@5.12.0":
version "5.12.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.12.0.tgz#92fd3193191621ab863add2f553a7b38b65646af"
integrity sha512-k4J2WovnMPGI4PzKgDtQdNrCnmBHpMUFy21qjX2CoPdoBcSBIMvVBr9P2YDP8jOqZOeK3ThOL6VO/sy6jtnvzw==
dependencies:
"@types/json-schema" "^7.0.9"
"@typescript-eslint/scope-manager" "5.12.0"
"@typescript-eslint/types" "5.12.0"
"@typescript-eslint/typescript-estree" "5.12.0"
eslint-scope "^5.1.1"
eslint-utils "^3.0.0"
"@typescript-eslint/utils@^5.10.0":
version "5.11.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.11.0.tgz#d91548ef180d74c95d417950336d9260fdbe1dc5"
integrity sha512-g2I480tFE1iYRDyMhxPAtLQ9HAn0jjBtipgTCZmd9I9s11OV8CTsG+YfFciuNDcHqm4csbAgC2aVZCHzLxMSUw==
@ -2813,6 +2865,14 @@
"@typescript-eslint/types" "5.11.0"
eslint-visitor-keys "^3.0.0"
"@typescript-eslint/visitor-keys@5.12.0":
version "5.12.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.12.0.tgz#1ac9352ed140b07ba144ebf371b743fdf537ec16"
integrity sha512-cFwTlgnMV6TgezQynx2c/4/tx9Tufbuo9LPzmWqyRC3QC4qTGkAG1C6pBr0/4I10PAI/FlYunI3vJjIcu+ZHMg==
dependencies:
"@typescript-eslint/types" "5.12.0"
eslint-visitor-keys "^3.0.0"
"@typescript-eslint/visitor-keys@5.9.1":
version "5.9.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.9.1.tgz#f52206f38128dd4f675cf28070a41596eee985b7"
@ -12998,7 +13058,7 @@ sanitize.css@*:
resolved "https://registry.yarnpkg.com/sanitize.css/-/sanitize.css-13.0.0.tgz#2675553974b27964c75562ade3bd85d79879f173"
integrity sha512-ZRwKbh/eQ6w9vmTjkuG0Ioi3HBwPFce0O+v//ve+aOq1oeCy7jMV2qzzAlpsNuqpqCBjjriM1lbtZbF/Q8jVyA==
sass-loader@^12.1.0, sass-loader@^12.3.0, sass-loader@^12.4.0:
sass-loader@^12.1.0, sass-loader@^12.3.0:
version "12.4.0"
resolved "https://registry.yarnpkg.com/sass-loader/-/sass-loader-12.4.0.tgz#260b0d51a8a373bb8e88efc11f6ba5583fea0bcf"
integrity sha512-7xN+8khDIzym1oL9XyS6zP6Ges+Bo2B2xbPrjdMHEYyV3AQYhd/wXeru++3ODHF0zMjYmVadblSKrPrjEkL8mg==
@ -13006,6 +13066,14 @@ sass-loader@^12.1.0, sass-loader@^12.3.0, sass-loader@^12.4.0:
klona "^2.0.4"
neo-async "^2.6.2"
sass-loader@^12.5.0:
version "12.5.0"
resolved "https://registry.yarnpkg.com/sass-loader/-/sass-loader-12.5.0.tgz#8010243734ade76371db8ba3df3cb40295f2b81c"
integrity sha512-POCQch5T2PFYOaHGJJgPoVaxJ76Ks+OIqKsDv2ErD53HE/WdPRehkVqdc5Qbt2fD2iGmgIRILDgQGbSHjmPrCA==
dependencies:
klona "^2.0.4"
neo-async "^2.6.2"
sass@^1.35.2:
version "1.48.0"
resolved "https://registry.yarnpkg.com/sass/-/sass-1.48.0.tgz#b53cfccc1b8ab4be375cc54f306fda9d4711162c"