Bring back support for legacy shortcodes
This commit is contained in:
@@ -37,6 +37,8 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
*/
|
||||
|
||||
if ( !class_exists('CognitoFormsPlugin') ) {
|
||||
require_once dirname(__FILE__) . '/api.php';
|
||||
|
||||
class CognitoFormsPlugin {
|
||||
// Initialization actions
|
||||
private static $actions = array(
|
||||
@@ -45,6 +47,12 @@ if ( !class_exists('CognitoFormsPlugin') ) {
|
||||
'init'
|
||||
);
|
||||
|
||||
// Supported shortcodes
|
||||
private static $shortcodes = array(
|
||||
'CognitoForms' => 'render_shortcode',
|
||||
'cognitoforms' => 'render_shortcode'
|
||||
);
|
||||
|
||||
// Registers plug-in actions
|
||||
private function addActions($actions) {
|
||||
foreach($actions as $action)
|
||||
@@ -57,9 +65,31 @@ if ( !class_exists('CognitoFormsPlugin') ) {
|
||||
add_filter($filter, array($this, $filter));
|
||||
}
|
||||
|
||||
// Registers shortcodes
|
||||
private function addShortcodes($shortcodes) {
|
||||
foreach($shortcodes as $tag => $func)
|
||||
add_shortcode($tag, array($this, $func));
|
||||
}
|
||||
|
||||
// Checks if an option exists in the database
|
||||
private function option_exists( $option_name, $site_wide = false ) {
|
||||
global $wpdb;
|
||||
return $wpdb->query( $wpdb->prepare( "SELECT * FROM ". ($site_wide ? $wpdb->base_prefix : $wpdb->prefix). "options WHERE option_name ='%s' LIMIT 1", $option_name ) );
|
||||
}
|
||||
|
||||
// Removes a list of options if they exist
|
||||
private function remove_options( $options ) {
|
||||
foreach ($options as $option) {
|
||||
if ( $this->option_exists( $option ) ) {
|
||||
delete_option( $option );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Entrypoint
|
||||
public function __construct() {
|
||||
$this->addActions(self::$actions);
|
||||
$this->addShortcodes(self::$shortcodes);
|
||||
}
|
||||
|
||||
public function init() {
|
||||
@@ -71,7 +101,22 @@ if ( !class_exists('CognitoFormsPlugin') ) {
|
||||
|
||||
// Initialize plug-in
|
||||
public function admin_init() {
|
||||
if(!current_user_can('edit_posts') && !current_user_can('edit_pages')) return;
|
||||
if( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) )
|
||||
return;
|
||||
|
||||
register_setting('cognito_plugin', 'cognito_public_key');
|
||||
|
||||
// Remove old API keys from the database
|
||||
$this->remove_options( array(
|
||||
'cognito_api_key',
|
||||
'cognito_admin_key',
|
||||
'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_public_key');
|
||||
}
|
||||
|
||||
// Initialize TinyMCE Plugin
|
||||
$this->tinymce_init();
|
||||
@@ -147,6 +192,15 @@ if ( !class_exists('CognitoFormsPlugin') ) {
|
||||
add_submenu_page( 'Cognito', 'Templates', 'Templates', 'manage_options', 'CognitoTemplates', array( $this, 'main_page' ) );
|
||||
}
|
||||
|
||||
// Called when a 'CognitoForms' shortcode is encountered, renders form embed script
|
||||
public function render_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 '';
|
||||
|
||||
return CognitoAPI::get_form_embed_script($key, $atts['id']);
|
||||
}
|
||||
|
||||
// Entrypoint for Cognito Forms access
|
||||
public function main_page() {
|
||||
include 'templates/main.php';
|
||||
|
Reference in New Issue
Block a user