flex-import
Last commit date
assets
1 year ago
includes
1 year ago
templates
1 year ago
flex-import.php
1 year ago
readme.txt
1 year ago
flex-import.php
163 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Plugin Name: Flex Import |
| 4 | * Plugin URI: |
| 5 | * Description: A plugin to import demo content for Elementor templates. |
| 6 | * Version: 1.4 |
| 7 | * Requires at least: 5.2 |
| 8 | * Requires PHP: 7.2 |
| 9 | * Author: flextheme |
| 10 | * Author URI: |
| 11 | * License: GPL v2 or later |
| 12 | * License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 13 | * Text Domain: flex-import |
| 14 | * Requires Plugins: elementor, elementskit-lite |
| 15 | */ |
| 16 | |
| 17 | if (!defined('ABSPATH')) { |
| 18 | exit; // Exit if accessed directly. |
| 19 | } |
| 20 | |
| 21 | define('FLEXIMP_PLUGIN_FILE', plugin_dir_path(__FILE__)); |
| 22 | define('FLEXIMP_MAIN_URL', 'https://license.flextheme.net/'); |
| 23 | define('FLEXIMP_LICENSE_URL', 'https://app.flextheme.net/api/public/'); |
| 24 | define('FLEXIMP_JSON_DATA_URL', 'https://license.flextheme.net/index.php/wp-json/flex-theme/v2/'); |
| 25 | define('FLEXIMP_PLUGIN_DIR_FILE', plugin_dir_url(__FILE__)); |
| 26 | define('FLEXIMP_VER', '1.4'); |
| 27 | |
| 28 | |
| 29 | // Include the core class |
| 30 | require_once plugin_dir_path(__FILE__) . 'includes/class-template-importer.php'; |
| 31 | |
| 32 | //dynamic css |
| 33 | function fleximp_enqueue_dynamic_imported_css() |
| 34 | { |
| 35 | // if (is_front_page()) { |
| 36 | $css_url = get_option('fleximp_dynamic_template_css'); |
| 37 | |
| 38 | if (!empty($css_url)) { |
| 39 | wp_enqueue_style( |
| 40 | 'fleximp-dynamic-imported-css', |
| 41 | esc_url($css_url), |
| 42 | array(), |
| 43 | null |
| 44 | ); |
| 45 | } |
| 46 | // } |
| 47 | } |
| 48 | add_action('wp_enqueue_scripts', 'fleximp_enqueue_dynamic_imported_css'); |
| 49 | |
| 50 | |
| 51 | // Initialize the plugin |
| 52 | function fleximp_init() |
| 53 | { |
| 54 | $importer = new FLEXIMP_Template_Importer(); |
| 55 | $importer->init(); |
| 56 | } |
| 57 | add_action('plugins_loaded', 'fleximp_init'); |
| 58 | |
| 59 | |
| 60 | function fleximp_register_nav_menus() |
| 61 | { |
| 62 | $is_premium_user = get_option('fleximp_is_premium', false); |
| 63 | |
| 64 | if ($is_premium_user) { |
| 65 | register_nav_menus(array( |
| 66 | 'primary-menu' => __('Primary Menu', 'flex-import'), |
| 67 | )); |
| 68 | } |
| 69 | } |
| 70 | add_action('after_setup_theme', 'fleximp_register_nav_menus'); |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | add_action('init', 'create_custom_cf7_forms'); |
| 76 | |
| 77 | function create_custom_cf7_forms() |
| 78 | { |
| 79 | $is_premium_user = get_option('fleximp_is_premium', false); |
| 80 | if (!$is_premium_user) { |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | $forms = array( |
| 85 | array( |
| 86 | 'title' => 'Newsletter', |
| 87 | 'content' => '<div class="flex-footer-form"> |
| 88 | <div class="flex-business-theme-input"> [email* your-email class:email placeholder "Email"]</div> |
| 89 | <div class="flex-business-theme-input"> [submit class:flex-submit-btn1 "Submit Now"]</div> |
| 90 | </div>', |
| 91 | 'hash' => 'b256161' |
| 92 | ), |
| 93 | array( |
| 94 | 'title' => 'Contact Page Form', |
| 95 | 'shortcode_title' => 'Contact form 1', |
| 96 | 'content' => '<div class="row"> |
| 97 | <div class="flex-business-input"> |
| 98 | <div class="flex-business-theme-input">[text* text-111 class:name placeholder "Name"]</div> |
| 99 | <div class="flex-business-theme-input">[tel* tel-24 class:phone placeholder "Phone"]</div> |
| 100 | </div> |
| 101 | <div class="flex-business-input"> |
| 102 | <div class="flex-business-theme-input">[email* email-398 class:email placeholder"Email"]</div> |
| 103 | <div class="flex-business-theme-input">[text text-159 class:service placeholder"services"]</div> |
| 104 | </div> |
| 105 | <div class="flex-business-msg"> |
| 106 | <div class="flex-business-theme-input"> [text text-521 class:msg placeholder"Message"]</div> |
| 107 | </div> |
| 108 | <div class="flex-business-btn"> |
| 109 | <div class="flex-business-theme-input"> [submit class:flex-submit-btn "Submit Now"]</div> |
| 110 | </div> |
| 111 | </div>', |
| 112 | 'hash' => '80c5c1a' |
| 113 | ), |
| 114 | ); |
| 115 | |
| 116 | foreach ($forms as $form_data) { |
| 117 | $title = $form_data['title']; |
| 118 | $existing_form = get_page_by_title($title, OBJECT, 'wpcf7_contact_form'); |
| 119 | |
| 120 | if ($existing_form) { |
| 121 | continue; // Skip if form with same title already exists |
| 122 | } |
| 123 | |
| 124 | $form_post = array( |
| 125 | 'post_title' => wp_strip_all_tags($title), |
| 126 | 'post_content' => $form_data['content'], |
| 127 | 'post_status' => 'publish', |
| 128 | 'post_type' => 'wpcf7_contact_form', |
| 129 | ); |
| 130 | |
| 131 | $form_id = wp_insert_post($form_post); |
| 132 | |
| 133 | if (is_wp_error($form_id) || !$form_id) { |
| 134 | continue; |
| 135 | } |
| 136 | |
| 137 | update_post_meta($form_id, '_form', $form_data['content']); |
| 138 | |
| 139 | $mail_data = array( |
| 140 | 'subject' => '[_site_title] "[your-subject]"', |
| 141 | 'sender' => '[_site_title] <support@wpelemento.com>', |
| 142 | 'body' => 'From: [your-name] <[your-email]> |
| 143 | Subject: [your-subject] |
| 144 | |
| 145 | Message Body: |
| 146 | [your-message] |
| 147 | |
| 148 | -- |
| 149 | This e-mail was sent from a contact form on [_site_title] ([_site_url])', |
| 150 | 'recipient' => '[_site_admin_email]', |
| 151 | 'additional_headers' => 'Reply-To: [your-email]', |
| 152 | 'attachments' => '', |
| 153 | 'use_html' => 0, |
| 154 | 'exclude_blank' => 0 |
| 155 | ); |
| 156 | |
| 157 | update_post_meta($form_id, '_mail', $mail_data); |
| 158 | update_post_meta($form_id, '_hash', $form_data['hash']); |
| 159 | |
| 160 | } |
| 161 | } |
| 162 | |
| 163 |