2021-06-16 23:05:18 -04:00
|
|
|
<?php
|
|
|
|
/*
|
|
|
|
Plugin Name: Cognito Forms
|
|
|
|
Plugin URI: http://wordpress.org/plugins/cognito-forms/
|
2022-01-13 18:26:04 -05:00
|
|
|
Description: Cognito Forms is a free online form builder that integrates seamlessly with WordPress. Create contact forms, registrations forms, surveys, and more!
|
2021-06-16 23:05:18 -04:00
|
|
|
Version: 2.0.0
|
|
|
|
Author: Cognito Apps
|
|
|
|
Author URI: https://www.cognitoforms.com
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Cognito Forms WordPress Plugin.
|
|
|
|
*
|
|
|
|
* The Cognito Forms WordPress Plugin is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License, version 2, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* The Cognito Forms WordPress Plugin is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Exit if accessed directly.
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The Plugin
|
|
|
|
*/
|
|
|
|
|
|
|
|
if ( !class_exists('CognitoFormsPlugin') ) {
|
|
|
|
class CognitoFormsPlugin {
|
|
|
|
// Initialization actions
|
|
|
|
private static $actions = array(
|
2021-12-23 15:50:33 -05:00
|
|
|
'admin_init',
|
2022-01-13 18:26:04 -05:00
|
|
|
'admin_menu',
|
|
|
|
'init'
|
2021-06-16 23:05:18 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
// Registers plug-in actions
|
|
|
|
private function addActions($actions) {
|
|
|
|
foreach($actions as $action)
|
|
|
|
add_action($action, array($this, $action));
|
|
|
|
}
|
|
|
|
|
2022-01-22 22:17:27 -05:00
|
|
|
// Registers plug-in filters
|
2021-12-23 15:50:33 -05:00
|
|
|
private function addFilters($filters) {
|
|
|
|
foreach($filters as $filter)
|
|
|
|
add_filter($filter, array($this, $filter));
|
|
|
|
}
|
|
|
|
|
2021-06-16 23:05:18 -04:00
|
|
|
// Entrypoint
|
|
|
|
public function __construct() {
|
|
|
|
$this->addActions(self::$actions);
|
|
|
|
}
|
|
|
|
|
2022-01-22 22:17:27 -05:00
|
|
|
public function init() {
|
|
|
|
// Initialize Gutenberg Block
|
|
|
|
$this->block_init();
|
|
|
|
}
|
|
|
|
|
2021-12-23 15:50:33 -05:00
|
|
|
// Initialize plug-in
|
|
|
|
public function admin_init() {
|
|
|
|
if(!current_user_can('edit_posts') && !current_user_can('edit_pages')) return;
|
|
|
|
|
|
|
|
register_setting('cognito_plugin', 'cognito_api_key');
|
|
|
|
register_setting('cognito_plugin', 'cognito_admin_key');
|
|
|
|
register_setting('cognito_plugin', 'cognito_public_key');
|
|
|
|
register_setting('cognito_plugin', 'cognito_organization');
|
|
|
|
|
|
|
|
// If the flag to delete options was passed-in, delete them
|
|
|
|
if (isset($_GET['cog_clear']) && $_GET['cog_clear'] == '1') {
|
|
|
|
delete_option('cognito_api_key');
|
|
|
|
delete_option('cognito_admin_key');
|
|
|
|
delete_option('cognito_public_key');
|
|
|
|
delete_option('cognito_organization');
|
|
|
|
}
|
|
|
|
|
2022-01-22 22:17:27 -05:00
|
|
|
// Initialize TinyMCE Plugin
|
|
|
|
$this->tinymce_init();
|
2022-01-13 18:26:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize block
|
|
|
|
public function block_init() {
|
|
|
|
$dir = dirname( __FILE__ );
|
|
|
|
|
|
|
|
$asset_file = include( plugin_dir_path( __FILE__ ) . 'dist/index.asset.php');
|
|
|
|
|
|
|
|
// Register global block styles
|
|
|
|
wp_register_style(
|
|
|
|
'cognito-block-global-css', // Handle.
|
|
|
|
plugins_url( 'dist/style.css', __FILE__ ),
|
|
|
|
is_admin() ? array( 'wp-editor' ) : null, // Dependency to include the CSS after it.
|
|
|
|
null // filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.style.build.css' ) // Version: File modification time.
|
|
|
|
);
|
|
|
|
|
|
|
|
// Register block editor script for backend
|
|
|
|
wp_register_script(
|
|
|
|
'cognito-block-editor-js',
|
|
|
|
plugins_url( 'dist/index.js', __FILE__ ),
|
|
|
|
$asset_file['dependencies'],
|
|
|
|
$asset_file['version']
|
|
|
|
);
|
|
|
|
|
|
|
|
// Register block editor styles for backend.
|
|
|
|
wp_register_style(
|
|
|
|
'cognito-block-editor-css', // Handle.
|
|
|
|
plugins_url( 'dist/editor.css', __FILE__ ), // Block editor CSS.
|
|
|
|
array( 'wp-edit-blocks' ), // Dependency to include the CSS after it.
|
|
|
|
null // filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.editor.build.css' ) // Version: File modification time.
|
|
|
|
);
|
|
|
|
|
|
|
|
register_block_type(
|
|
|
|
'cognito-forms/cognito-embed', array(
|
|
|
|
// Enqueue global block styles on both frontend and backend
|
|
|
|
'style' => 'cognito-block-global-css',
|
|
|
|
// Enqueue block js in the editor only
|
|
|
|
'editor_script' => 'cognito-block-editor-js',
|
|
|
|
// Enqueue editor block styles in the editor only
|
|
|
|
'editor_style' => 'cognito-block-editor-css'
|
|
|
|
) );
|
|
|
|
}
|
|
|
|
|
2022-01-22 22:17:27 -05:00
|
|
|
// Initialize classic editor (TinyMCE)
|
|
|
|
public function tinymce_init() {
|
|
|
|
if(get_user_option('rich_editing') == 'true') {
|
|
|
|
$this->addFilters(array(
|
|
|
|
'mce_buttons',
|
|
|
|
'mce_external_plugins'
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set up TinyMCE buttons
|
2021-12-23 15:50:33 -05:00
|
|
|
public function mce_buttons($buttons) {
|
|
|
|
array_push($buttons, '|', 'cognito');
|
|
|
|
return $buttons;
|
|
|
|
}
|
|
|
|
|
2022-01-22 22:17:27 -05:00
|
|
|
// Initialize TinyMCE plug-in
|
|
|
|
public function mce_external_plugins( $plugin_array ) {
|
|
|
|
$plugin_array['cognito_mce_plugin'] = plugins_url( '/tinymce/plugin.js', __FILE__ );
|
|
|
|
return $plugin_array;
|
2021-12-23 15:50:33 -05:00
|
|
|
}
|
|
|
|
|
2021-06-16 23:05:18 -04:00
|
|
|
// Initialize administration menu (left-bar)
|
|
|
|
public function admin_menu() {
|
2022-01-22 23:09:18 -05:00
|
|
|
add_menu_page('Cognito Forms', 'Cognito Forms', 'manage_options', 'Cognito', array($this, 'main_page'), "data:image/svg+xml;base64," . base64_encode( '<?xml version="1.0" encoding="UTF-8"?><svg id="icon" version="1.1" viewBox="0 0 18 18" xmlns="http://www.w3.org/2000/svg"><path fill="black" d="m8.0125 1.0813-0.41402 2.2771a5.9329 5.9329 0 0 0-1.5823 0.6472l-1.8893-1.292-1.3777 1.3158 1.2183 1.9987a5.5187 5.5187 0 0 0-0.65672 1.5942l-2.2295 0.40212v1.9987l2.2652 0.41402a6.0913 6.0913 0 0 0 0.671 1.5847l-1.2682 1.8512 1.3777 1.4491 1.875-1.2896a5.9573 5.9573 0 0 0 1.5966 0.68052l0.40212 2.2057h1.9868l0.40212-2.2652a6.5543 6.5543 0 0 0 1.6323-0.6591l1.8512 1.2801 1.4134-1.4015-1.292-1.8631a6.6517 6.6517 0 0 0 0.69479-1.6323l2.2295-0.40212v-1.9868l-2.2295-0.39023a6.3472 6.3472 0 0 0-0.68289-1.6204l1.2801-1.8512-1.4134-1.4253-1.8512 1.3158a10.087 10.087 0 0 0-1.6085-0.6591l-0.41402-2.2771zm1.0731 3.6667a3.8984 3.8984 0 0 1 2.96 1.2183 3.8375 3.8375 0 0 1 0.81614 1.2183 3.0944 3.0944 0 0 1 0.2308 0.71859l-2.4365 0.44019a1.6203 1.6203 0 0 0-1.6561-1.1826 1.6325 1.6325 0 0 0-1.2183 0.52347 1.9492 1.9492 0 0 0-0.52347 1.3158 1.8639 1.8639 0 0 0 0.52347 1.3396 1.6203 1.6203 0 0 0 1.2183 0.51158 1.669 1.669 0 0 0 1.2183-0.44971 1.8396 1.8396 0 0 0 0.40212-0.6829l1.875 0.35453 0.60913 0.13325-0.18084 0.49968a4.6781 4.6781 0 0 1-1.0113 1.4729 3.935 3.935 0 0 1-2.9124 1.0612 4.1421 4.1421 0 0 1-4.1902-4.045v-0.19511a4.069 4.069 0 0 1 1.2183-3.0338 4.1177 4.1177 0 0 1 3.0576-1.2183z" stroke-width="1.2183"/></svg>' ) );
|
2021-06-16 23:05:18 -04:00
|
|
|
add_submenu_page('Cognito', 'Cognito Forms', 'View Forms', 'manage_options', 'Cognito', array($this, 'main_page'));
|
|
|
|
add_submenu_page('Cognito', 'Create Form', 'New Form', 'manage_options', 'CognitoCreateForm', array($this, 'main_page'));
|
|
|
|
add_submenu_page('Cognito', 'Templates', 'Templates', 'manage_options', 'CognitoTemplates', array($this, 'main_page'));
|
2021-12-23 15:50:33 -05:00
|
|
|
|
|
|
|
add_options_page('Cognito Options', 'Cognito Forms', 'manage_options', 'CognitoOptions', array($this, 'options_page'));
|
2021-06-16 23:05:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Entrypoint for Cognito Forms access
|
2021-12-23 15:50:33 -05:00
|
|
|
public function main_page() {
|
2021-06-16 23:05:18 -04:00
|
|
|
include 'templates/main.php';
|
|
|
|
}
|
2021-12-23 15:50:33 -05:00
|
|
|
|
|
|
|
public function options_page() {
|
|
|
|
include 'templates/options.php';
|
|
|
|
}
|
2021-06-16 23:05:18 -04:00
|
|
|
}
|
2022-01-22 22:17:27 -05:00
|
|
|
|
2021-06-16 23:05:18 -04:00
|
|
|
new CognitoFormsPlugin;
|
2021-12-23 15:50:33 -05:00
|
|
|
}
|