| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | namespace MetForm; |
|---|
| 4 | |
|---|
| 5 | use MetForm\Core\Integrations\Onboard\Attr; |
|---|
| 6 | use MetForm\Core\Integrations\Onboard\Onboard; |
|---|
| 7 | |
|---|
| 8 | defined('ABSPATH') || exit; |
|---|
| 9 | |
|---|
| 10 | final class Plugin { |
|---|
| 11 | |
|---|
| 12 | private static $instance; |
|---|
| 13 | |
|---|
| 14 | private $entries; |
|---|
| 15 | private $global_settings; |
|---|
| 16 | |
|---|
| 17 | public function __construct() |
|---|
| 18 | { |
|---|
| 19 | Autoloader::run(); |
|---|
| 20 | add_action( 'wp_head', array( $this, 'add_meta_for_search_excluded' ) ); |
|---|
| 21 | add_action( 'init', array ($this, 'metform_permalink_setup')); |
|---|
| 22 | add_action("metform/pro_awareness/before_grid_contents", ['\MetForm\Utils\Util', 'banner_consent']); |
|---|
| 23 | add_action( 'wp_ajax_metform_admin_action', ['\MetForm\Utils\Util', 'metform_admin_action'] ); |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | public function version() |
|---|
| 27 | { |
|---|
| 28 | return '3.9.8'; |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | public function package_type() |
|---|
| 32 | { |
|---|
| 33 | return apply_filters( 'metform/core/package_type', 'free' ); |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | public function plugin_url() |
|---|
| 37 | { |
|---|
| 38 | return trailingslashit(plugin_dir_url(__FILE__)); |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | public function plugin_dir() |
|---|
| 42 | { |
|---|
| 43 | return trailingslashit(plugin_dir_path(__FILE__)); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | public function core_url() |
|---|
| 47 | { |
|---|
| 48 | return $this->plugin_url() . 'core/'; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | public function core_dir() |
|---|
| 52 | { |
|---|
| 53 | return $this->plugin_dir() . 'core/'; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | public function base_url() |
|---|
| 57 | { |
|---|
| 58 | return $this->plugin_url() . 'base/'; |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | public function base_dir() |
|---|
| 62 | { |
|---|
| 63 | return $this->plugin_dir() . 'base/'; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | public function utils_url() |
|---|
| 67 | { |
|---|
| 68 | return $this->plugin_url() . 'utils/'; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | public function utils_dir() |
|---|
| 72 | { |
|---|
| 73 | return $this->plugin_dir() . 'utils/'; |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | public function widgets_url() |
|---|
| 77 | { |
|---|
| 78 | return $this->plugin_url() . 'widgets/'; |
|---|
| 79 | } |
|---|
| 80 | |
|---|
| 81 | public function widgets_dir() |
|---|
| 82 | { |
|---|
| 83 | return $this->plugin_dir() . 'widgets/'; |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | public function public_url() |
|---|
| 87 | { |
|---|
| 88 | return $this->plugin_url() . 'public/'; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | public function public_dir() |
|---|
| 92 | { |
|---|
| 93 | return $this->plugin_dir() . 'public/'; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | public function account_url(){ |
|---|
| 97 | return 'https://account.wpmet.com'; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | public function i18n() |
|---|
| 101 | { |
|---|
| 102 | load_plugin_textdomain('metform', false, dirname(plugin_basename(__FILE__)) . '/languages/'); |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | public function init() |
|---|
| 106 | { |
|---|
| 107 | /** |
|---|
| 108 | * ---------------------------------------- |
|---|
| 109 | * Ask for rating ⭐⭐⭐⭐⭐ |
|---|
| 110 | * A rating notice will appear depends on |
|---|
| 111 | * @set_first_appear_day methods |
|---|
| 112 | * ---------------------------------------- |
|---|
| 113 | */ |
|---|
| 114 | if( ! isset($_GET['redirect_from']) || ! $_GET['redirect_from'] == 'mf_promo_banner'){ |
|---|
| 115 | |
|---|
| 116 | Onboard::instance()->init(); |
|---|
| 117 | |
|---|
| 118 | if(isset($_GET['met-onboard-steps']) && isset($_GET['met-onboard-steps-nonce']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_GET['met-onboard-steps-nonce'])),'met-onboard-steps-action')) { |
|---|
| 119 | Attr::instance(); |
|---|
| 120 | } |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | if( get_option('rewrite_rules') == '' && isset($_GET['redirect_from']) && $_GET['redirect_from'] == 'mf_promo_banner'){ |
|---|
| 124 | |
|---|
| 125 | add_action('init', function() { |
|---|
| 126 | Utils\Util::change_permalink(); |
|---|
| 127 | }); |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | // Load Text Domain Just In Time error Notice issue fix |
|---|
| 131 | add_filter('doing_it_wrong_trigger_error', function($doing_it_wrong, $function_name) { |
|---|
| 132 | if ('_load_textdomain_just_in_time' === $function_name) { |
|---|
| 133 | return false; |
|---|
| 134 | } |
|---|
| 135 | return $doing_it_wrong; |
|---|
| 136 | }, 10, 2); |
|---|
| 137 | |
|---|
| 138 | $filter_string = ''; // elementskit,metform-pro |
|---|
| 139 | $filter_string .= ((!in_array('elementskit/elementskit.php', apply_filters('active_plugins', get_option('active_plugins')))) ? '' : ',elementskit'); |
|---|
| 140 | $filter_string .= (!class_exists('\MetForm\Plugin') ? '' : ',metform'); |
|---|
| 141 | $filter_string .= (!class_exists('\MetForm_Pro\Plugin') ? '' : ',metform-pro'); |
|---|
| 142 | |
|---|
| 143 | if ( is_admin() && \MetForm\Utils\Util::get_settings( 'metform_user_consent_for_banner', 'yes' ) == 'yes' ) { |
|---|
| 144 | |
|---|
| 145 | //Rating notice |
|---|
| 146 | \Wpmet\Libs\Rating::instance('metform') |
|---|
| 147 | ->set_plugin_logo('https://ps.w.org/metform/assets/icon-128x128.png') |
|---|
| 148 | ->set_plugin('Metform', 'https://wpmet.com/wordpress.org/rating/metform') |
|---|
| 149 | ->set_allowed_screens('edit-metform-entry') |
|---|
| 150 | ->set_allowed_screens('edit-metform-form') |
|---|
| 151 | ->set_allowed_screens('metform_page_metform_get_help') |
|---|
| 152 | ->set_priority(30) |
|---|
| 153 | ->set_first_appear_day(7) |
|---|
| 154 | ->set_condition(true) |
|---|
| 155 | ->call(); |
|---|
| 156 | |
|---|
| 157 | // banner |
|---|
| 158 | \Wpmet\Libs\Banner::instance('metform') |
|---|
| 159 | ->set_filter(ltrim($filter_string, ',')) |
|---|
| 160 | ->set_api_url('https://api.wpmet.com/public/jhanda') |
|---|
| 161 | ->set_plugin_screens('edit-metform-form') |
|---|
| 162 | ->set_plugin_screens('edit-metform-entry') |
|---|
| 163 | ->set_plugin_screens('metform_page_metform-menu-settings') |
|---|
| 164 | ->call(); |
|---|
| 165 | |
|---|
| 166 | /** |
|---|
| 167 | * Show WPMET stories widget in dashboard |
|---|
| 168 | */ |
|---|
| 169 | \Wpmet\Libs\Stories::instance('metform') |
|---|
| 170 | |
|---|
| 171 | ->set_filter($filter_string) |
|---|
| 172 | ->set_plugin('Metform', 'https://wpmet.com/plugin/metform/') |
|---|
| 173 | ->set_api_url('https://api.wpmet.com/public/stories/') |
|---|
| 174 | ->call(); |
|---|
| 175 | |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | /** |
|---|
| 179 | * Pro awareness feature; |
|---|
| 180 | */ |
|---|
| 181 | |
|---|
| 182 | $is_pro_active = ''; |
|---|
| 183 | |
|---|
| 184 | if (!in_array('metform-pro/metform-pro.php', apply_filters('active_plugins', get_option('active_plugins')))) { |
|---|
| 185 | $is_pro_active = 'Go Premium'; |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | $pro_awareness = \Wpmet\Libs\Pro_Awareness::instance('metform'); |
|---|
| 189 | if(version_compare($pro_awareness->get_version(), '1.2.0', '>=')) { |
|---|
| 190 | $pro_awareness |
|---|
| 191 | ->set_parent_menu_slug('metform-menu') |
|---|
| 192 | ->set_pro_link( |
|---|
| 193 | (in_array('metform-pro/metform-pro.php', apply_filters('active_plugins', get_option('active_plugins')))) ? '' : |
|---|
| 194 | 'https://wpmet.com/metform-pricing' |
|---|
| 195 | ) |
|---|
| 196 | ->set_plugin_file('metform/metform.php') |
|---|
| 197 | ->set_default_grid_thumbnail($this->utils_url() . '/pro-awareness/assets/images/support.png') |
|---|
| 198 | ->set_page_grid([ |
|---|
| 199 | 'url' => 'https://wpmet.com/fb-group', |
|---|
| 200 | 'title' => 'Join the Community', |
|---|
| 201 | 'thumbnail' => $this->utils_url() . '/pro-awareness/assets/images/community.png', |
|---|
| 202 | 'description' => 'Join our Facebook group to get 20% discount coupon on premium products. Follow us to get more exciting offers.' |
|---|
| 203 | |
|---|
| 204 | ]) |
|---|
| 205 | ->set_page_grid([ |
|---|
| 206 | 'url' => 'https://www.youtube.com/playlist?list=PL3t2OjZ6gY8NoB_48DwWKUDRtBEuBOxSc', |
|---|
| 207 | 'title' => 'Video Tutorials', |
|---|
| 208 | 'thumbnail' => $this->utils_url() . '/pro-awareness/assets/images/videos.png', |
|---|
| 209 | 'description' => 'Learn the step by step process for developing your site easily from video tutorials.' |
|---|
| 210 | ]) |
|---|
| 211 | ->set_page_grid([ |
|---|
| 212 | 'url' => 'https://wpmet.com/plugin/metform/roadmaps#ideas', |
|---|
| 213 | 'title' => 'Request a feature', |
|---|
| 214 | 'thumbnail' => $this->utils_url() . '/pro-awareness/assets/images/request.png', |
|---|
| 215 | 'description' => 'Have any special feature in mind? Let us know through the feature request.' |
|---|
| 216 | ]) |
|---|
| 217 | ->set_page_grid([ |
|---|
| 218 | 'url' => 'https://wpmet.com/doc/metform/', |
|---|
| 219 | 'title' => 'Documentation', |
|---|
| 220 | 'thumbnail' => $this->utils_url() . 'pro-awareness/assets/images/documentation.png', |
|---|
| 221 | 'description' => 'Detailed documentation to help you understand the functionality of each feature.' |
|---|
| 222 | ]) |
|---|
| 223 | ->set_page_grid([ |
|---|
| 224 | 'url' => 'https://wpmet.com/plugin/metform/roadmaps/', |
|---|
| 225 | 'title' => 'Public Roadmap', |
|---|
| 226 | 'thumbnail' => $this->utils_url() . 'pro-awareness/assets/images/roadmaps.png', |
|---|
| 227 | 'description' => 'Check our upcoming new features, detailed development stories and tasks' |
|---|
| 228 | ]) |
|---|
| 229 | |
|---|
| 230 | ->set_plugin_row_meta('Documentation', 'https://help.wpmet.com/docs-cat/metform/', ['target' => '_blank']) |
|---|
| 231 | ->set_plugin_row_meta('Facebook Community', 'https://wpmet.com/fb-group', ['target' => '_blank']) |
|---|
| 232 | ->set_plugin_row_meta('Rate the plugin ★★★★★', 'https://wordpress.org/support/plugin/metform/reviews/#new-post', ['target' => '_blank']) |
|---|
| 233 | ->set_plugin_action_link('Settings', admin_url() . 'admin.php?page=metform-menu-settings') |
|---|
| 234 | ->set_plugin_action_link($is_pro_active, 'https://wpmet.com/plugin/metform/pricing/', ['target' => '_blank', 'style' => 'color: #FCB214; font-weight: bold;']) |
|---|
| 235 | ->call(); |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | $apps_img_path = $this->public_url() . 'assets/img/apps-page/'; |
|---|
| 239 | |
|---|
| 240 | /** |
|---|
| 241 | * Show apps menu for others wpmet plugins |
|---|
| 242 | */ |
|---|
| 243 | \Wpmet\Libs\Apps::instance()->init('metform') |
|---|
| 244 | ->set_parent_menu_slug('metform-menu') |
|---|
| 245 | ->set_submenu_name('Our Plugins') |
|---|
| 246 | ->set_section_title('Unleash the Full Potential of Elementor and WordPress!') |
|---|
| 247 | ->set_section_description('Install other plugins from us and take your website to the next level for absolutely free!') |
|---|
| 248 | ->set_items_per_row(4) |
|---|
| 249 | ->set_plugins( |
|---|
| 250 | [ |
|---|
| 251 | 'elementskit-lite/elementskit-lite.php' => [ |
|---|
| 252 | 'name' => esc_html__('ElementsKit', 'metform'), |
|---|
| 253 | 'url' => 'https://wordpress.org/plugins/elementskit-lite/', |
|---|
| 254 | 'icon' => $apps_img_path. 'elementskit.gif', |
|---|
| 255 | 'desc' => esc_html__('All-in-one Elementor addon trusted by 1 Million+ users, makes your website builder process easier with ultimate freedom.', 'metform'), |
|---|
| 256 | 'docs' => 'https://wpmet.com/doc/elementskit/', |
|---|
| 257 | ], |
|---|
| 258 | 'getgenie/getgenie.php' => [ |
|---|
| 259 | 'name' => esc_html__('GetGenie', 'metform'), |
|---|
| 260 | 'url' => 'https://wordpress.org/plugins/getgenie/', |
|---|
| 261 | 'icon' => $apps_img_path.'getgenie.gif', |
|---|
| 262 | 'desc' => esc_html__('Your personal AI assistant for content and SEO. Write content that ranks on Google with NLP keywords and SERP analysis data.', 'metform'), |
|---|
| 263 | 'docs' => 'https://getgenie.ai/docs/', |
|---|
| 264 | ], |
|---|
| 265 | 'gutenkit-blocks-addon/gutenkit-blocks-addon.php' => [ |
|---|
| 266 | 'name' => esc_html__('GutenKit', 'metform'), |
|---|
| 267 | 'url' => 'https://wordpress.org/plugins/gutenkit-blocks-addon/', |
|---|
| 268 | 'icon' => $apps_img_path. 'guten-kit.png', |
|---|
| 269 | 'desc' => esc_html__('Gutenberg blocks, patterns, and templates that extend the page-building experience using the WordPress block editor.', 'metform'), |
|---|
| 270 | 'docs' => 'https://wpmet.com/doc/gutenkit/', |
|---|
| 271 | ], |
|---|
| 272 | 'shopengine/shopengine.php' => [ |
|---|
| 273 | 'name' => esc_html__('ShopEngine', 'metform'), |
|---|
| 274 | 'url' => 'https://wordpress.org/plugins/shopengine/', |
|---|
| 275 | 'icon' => $apps_img_path. 'shopengine.gif', |
|---|
| 276 | 'desc' => esc_html__('Complete WooCommerce solution for Elementor to fully customize any pages including cart, checkout, shop page, and so on. |
|---|
| 277 | ', 'metform'), |
|---|
| 278 | 'docs' => 'https://wpmet.com/doc/shopengine/', |
|---|
| 279 | ], |
|---|
| 280 | 'emailkit/EmailKit.php' => [ |
|---|
| 281 | 'name' => esc_html__('EmailKit', 'metform'), |
|---|
| 282 | 'url' => 'https://wordpress.org/plugins/emailkit/', |
|---|
| 283 | 'icon' => $apps_img_path . 'emailkit.png', |
|---|
| 284 | 'desc' => esc_html__('Advanced email customizer for WooCommerce and WordPress. Build, customize, and send emails from WordPress to boost your sales!', 'metform'), |
|---|
| 285 | 'docs' => 'https://wpmet.com/doc/emailkit/', |
|---|
| 286 | ], |
|---|
| 287 | 'wp-social/wp-social.php' => [ |
|---|
| 288 | 'name' => esc_html__('Wp Social', 'metform'), |
|---|
| 289 | 'url' => 'https://wordpress.org/plugins/wp-social/', |
|---|
| 290 | 'icon' => $apps_img_path . 'wp-social.png', |
|---|
| 291 | 'desc' => esc_html__('Add social share, login, and engagement counter — unified solution for all social media with tons of different styles for your website.', 'metform'), |
|---|
| 292 | 'docs' => 'https://wpmet.com/doc/wp-social/', |
|---|
| 293 | ], |
|---|
| 294 | 'wp-ultimate-review/wp-ultimate-review.php' => [ |
|---|
| 295 | 'name' => esc_html__('WP Ultimate Review', 'metform'), |
|---|
| 296 | 'url' => 'https://wordpress.org/plugins/wp-ultimate-review/', |
|---|
| 297 | 'icon' => $apps_img_path . 'ultimate-review.png', |
|---|
| 298 | 'desc' => esc_html__('Collect and showcase reviews on your website to build brand credibility and social proof with the easiest solution.', 'metform'), |
|---|
| 299 | 'docs' => 'https://wpmet.com/doc/wp-ultimate-review/', |
|---|
| 300 | ], |
|---|
| 301 | 'wp-fundraising-donation/wp-fundraising.php' => [ |
|---|
| 302 | 'name' => esc_html__('FundEngine', 'metform'), |
|---|
| 303 | 'url' => 'https://wordpress.org/plugins/wp-fundraising-donation/', |
|---|
| 304 | 'icon' => $apps_img_path . 'fundengine.png', |
|---|
| 305 | 'desc' => esc_html__('Create fundraising, crowdfunding, and donation websites with PayPal and Stripe payment gateway integration.', 'metform'), |
|---|
| 306 | 'docs' => 'https://wpmet.com/doc/fundengine/', |
|---|
| 307 | ], |
|---|
| 308 | 'blocks-for-shopengine/shopengine-gutenberg-addon.php' => [ |
|---|
| 309 | 'name' => esc_html__('Blocks for ShopEngine', 'metform'), |
|---|
| 310 | 'url' => 'https://wordpress.org/plugins/blocks-for-shopengine/', |
|---|
| 311 | 'icon' => $apps_img_path . 'shopengine.gif', |
|---|
| 312 | 'desc' => esc_html__('All in one WooCommerce solution for Gutenberg! Build your WooCommerce pages in a block editor with full customization.', 'metform'), |
|---|
| 313 | 'docs' => 'https://wpmet.com/doc/shopengine/', |
|---|
| 314 | ], |
|---|
| 315 | 'genie-image-ai/genie-image-ai.php' => [ |
|---|
| 316 | 'name' => esc_html__('Genie Image', 'metform'), |
|---|
| 317 | 'url' => 'https://wordpress.org/plugins/genie-image-ai/', |
|---|
| 318 | 'icon' => $apps_img_path . 'genie-image.png', |
|---|
| 319 | 'desc' => esc_html__('AI-powered text-to-image generator for WordPress with OpenAI’s DALL-E 2 technology to generate high-quality images in one click.', 'metform'), |
|---|
| 320 | 'docs' => 'https://getgenie.ai/docs/', |
|---|
| 321 | ], |
|---|
| 322 | ] |
|---|
| 323 | ) |
|---|
| 324 | ->call(); |
|---|
| 325 | |
|---|
| 326 | if( class_exists('WooCommerce') && !class_exists('EmailKit') && !did_action('edit_with_emailkit_loaded') && class_exists('\Wpmet\Libs\Emailkit') && \MetForm\Utils\Util::get_settings( 'metform_user_consent_for_banner', 'yes' ) == 'yes') { |
|---|
| 327 | new \Wpmet\Libs\Emailkit(); |
|---|
| 328 | } |
|---|
| 329 | |
|---|
| 330 | // Check if Elementor installed and activated. |
|---|
| 331 | if (!did_action('elementor/loaded')) { |
|---|
| 332 | $this->missing_elementor(); |
|---|
| 333 | return; |
|---|
| 334 | } |
|---|
| 335 | // Check for required Elementor version. |
|---|
| 336 | if (!version_compare(ELEMENTOR_VERSION, '3.0.1', '>=')) { |
|---|
| 337 | $this->failed_elementor_version(); |
|---|
| 338 | // add_action('admin_notices', array($this, 'failed_elementor_version')); |
|---|
| 339 | return; |
|---|
| 340 | } |
|---|
| 341 | |
|---|
| 342 | // pro available notice |
|---|
| 343 | if (!file_exists(WP_PLUGIN_DIR . '/metform-pro/metform-pro.php')) { |
|---|
| 344 | $this->available_metform_pro(); |
|---|
| 345 | // add_action('admin_notices', [$this, 'available_metform_pro']); |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | if (current_user_can('manage_options')) { |
|---|
| 349 | add_action('admin_menu', [$this, 'admin_menu']); |
|---|
| 350 | } |
|---|
| 351 | |
|---|
| 352 | add_action('elementor/editor/before_enqueue_scripts', [$this, 'edit_view_scripts']); |
|---|
| 353 | add_action( 'elementor/editor/after_enqueue_scripts', [$this, 'metform_editor_script'] ); |
|---|
| 354 | |
|---|
| 355 | add_action('init', [$this, 'i18n']); |
|---|
| 356 | |
|---|
| 357 | add_action('admin_enqueue_scripts', [$this, 'js_css_admin']); |
|---|
| 358 | add_action('wp_enqueue_scripts', [$this, 'js_css_public']); |
|---|
| 359 | |
|---|
| 360 | $my_theme = wp_get_theme(); |
|---|
| 361 | if(current_user_can('manage_options') && $my_theme->get('Name') == 'Cleano'){ |
|---|
| 362 | add_action( 'admin_enqueue_scripts', [$this, 'cleanoThemeConflict'], 100 ); |
|---|
| 363 | } |
|---|
| 364 | |
|---|
| 365 | add_action('elementor/frontend/before_enqueue_scripts', [$this, 'elementor_js']); |
|---|
| 366 | |
|---|
| 367 | add_action('elementor/editor/before_enqueue_styles', [$this, 'elementor_css']); |
|---|
| 368 | |
|---|
| 369 | add_action('admin_footer', [$this, 'footer_data']); |
|---|
| 370 | |
|---|
| 371 | Core\Forms\Base::instance()->init(); |
|---|
| 372 | Controls\Base::instance()->init(); |
|---|
| 373 | $this->entries = Core\Entries\Base::instance(); |
|---|
| 374 | |
|---|
| 375 | Widgets\Manifest::instance()->init(); |
|---|
| 376 | |
|---|
| 377 | // settings page |
|---|
| 378 | Core\Admin\Base::instance()->init(); |
|---|
| 379 | |
|---|
| 380 | Core\Forms\Auto_Increment_Entry::instance(); |
|---|
| 381 | } |
|---|
| 382 | |
|---|
| 383 | function metform_editor_script(){ |
|---|
| 384 | wp_enqueue_script('editor-panel-script', $this->public_url() . '/assets/js/editor-panel.js', ['jquery'], $this->version(), true); |
|---|
| 385 | } |
|---|
| 386 | |
|---|
| 387 | function js_css_public() |
|---|
| 388 | { |
|---|
| 389 | $this->global_settings = \MetForm\Core\Admin\Base::instance()->get_settings_option(); |
|---|
| 390 | $is_form_cpt = ('metform-form' === get_post_type()); |
|---|
| 391 | |
|---|
| 392 | wp_register_style('metform-ui', $this->public_url() . 'assets/css/metform-ui.css', false, $this->version()); |
|---|
| 393 | |
|---|
| 394 | wp_register_style('metform-style', $this->public_url() . 'assets/css/style.css', false, $this->version()); |
|---|
| 395 | |
|---|
| 396 | wp_register_style('text-editor-style', $this->public_url() . 'assets/css/text-editor.css', false, $this->version()); |
|---|
| 397 | |
|---|
| 398 | wp_register_script('htm', $this->public_url() . 'assets/js/htm.js', null, $this->version(), true); |
|---|
| 399 | |
|---|
| 400 | wp_register_script('metform-app', $this->public_url() . 'assets/js/app.js', ['htm', 'jquery', 'wp-element'], $this->version(), true); |
|---|
| 401 | |
|---|
| 402 | wp_localize_script('metform-app', 'mf', [ |
|---|
| 403 | 'postType' => get_post_type(), |
|---|
| 404 | 'restURI' => get_rest_url(null, 'metform/v1/forms/views/'), |
|---|
| 405 | 'minMsg1' => __("Minimum length should be ","metform"), |
|---|
| 406 | 'Msg2' => __(" character long.","metform"), |
|---|
| 407 | 'maxMsg1' => __("Maximum length should be ","metform"), |
|---|
| 408 | 'maxNum' => __("Maximum number should be ","metform"), |
|---|
| 409 | 'minNum' => __("Minimum number should be ","metform"), |
|---|
| 410 | ]); |
|---|
| 411 | |
|---|
| 412 | // Recaptcha Support Script. |
|---|
| 413 | wp_register_script( 'recaptcha-support', $this->public_url() . 'assets/js/recaptcha-support.js', ['jquery'], $this->version(), true ); |
|---|
| 414 | |
|---|
| 415 | |
|---|
| 416 | // begins pro feature |
|---|
| 417 | // begins for mf-simple-repeater |
|---|
| 418 | wp_register_style('asRange', $this->public_url() . 'assets/css/asRange.min.css', false, $this->version()); |
|---|
| 419 | wp_register_script('asRange', $this->public_url() . 'assets/js/jquery-asRange.min.js', [], $this->version(), true); |
|---|
| 420 | wp_enqueue_script('cute-alert', $this->public_url() . 'assets/lib/cute-alert/cute-alert.js', [], $this->version(), true); |
|---|
| 421 | wp_register_style('mf-select2', $this->public_url() . 'assets/css/select2.min.css', false, $this->version()); |
|---|
| 422 | wp_register_script('mf-select2', $this->public_url() . 'assets/js/select2.min.js', [], $this->version(), true); |
|---|
| 423 | // ends for mf-simple-repeater |
|---|
| 424 | |
|---|
| 425 | wp_register_script('recaptcha-v2', 'https://google.com/recaptcha/api.js?render=explicit', [], null, true); |
|---|
| 426 | |
|---|
| 427 | if (isset($this->global_settings['mf_recaptcha_version']) && ($this->global_settings['mf_recaptcha_version'] == 'recaptcha-v3') && isset($this->global_settings['mf_recaptcha_site_key_v3']) && ($this->global_settings['mf_recaptcha_site_key_v3'] != '')) { |
|---|
| 428 | wp_register_script('recaptcha-v3', 'https://www.google.com/recaptcha/api.js?render=' . $this->global_settings['mf_recaptcha_site_key_v3'], [], $this->version(), false); |
|---|
| 429 | } |
|---|
| 430 | |
|---|
| 431 | if (isset($this->global_settings['mf_google_map_api_key']) && ($this->global_settings['mf_google_map_api_key'] != '')) { |
|---|
| 432 | wp_register_script('maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $this->global_settings['mf_google_map_api_key'] . '&libraries=places&&callback=mfMapLocation', [], '', true); |
|---|
| 433 | } |
|---|
| 434 | |
|---|
| 435 | // for date, time, simple repeater |
|---|
| 436 | wp_deregister_style('flatpickr'); // flatpickr stylesheet |
|---|
| 437 | wp_register_style('flatpickr', $this->public_url() . 'assets/css/flatpickr.min.css', false, $this->version()); // flatpickr stylesheet |
|---|
| 438 | wp_enqueue_style('cute-alert', $this->public_url() . 'assets/lib/cute-alert/style.css', false, $this->version()); |
|---|
| 439 | // ends pro feature |
|---|
| 440 | |
|---|
| 441 | |
|---|
| 442 | wp_enqueue_style('text-editor-style'); |
|---|
| 443 | |
|---|
| 444 | if($is_form_cpt){ |
|---|
| 445 | wp_enqueue_style('metform-ui'); |
|---|
| 446 | wp_enqueue_style('metform-style'); |
|---|
| 447 | wp_enqueue_script('htm'); |
|---|
| 448 | wp_enqueue_script('metform-app'); |
|---|
| 449 | } |
|---|
| 450 | |
|---|
| 451 | do_action('metform/onload/enqueue_scripts'); |
|---|
| 452 | } |
|---|
| 453 | |
|---|
| 454 | |
|---|
| 455 | |
|---|
| 456 | public function edit_view_scripts() |
|---|
| 457 | { |
|---|
| 458 | wp_enqueue_style('metform-ui', $this->public_url() . 'assets/css/metform-ui.css', false, $this->version()); |
|---|
| 459 | wp_enqueue_style('metform-admin-style', $this->public_url() . 'assets/css/admin-style.css', false, null); |
|---|
| 460 | |
|---|
| 461 | wp_enqueue_script('metform-ui', $this->public_url() . 'assets/js/ui.min.js', [], $this->version(), true); |
|---|
| 462 | wp_enqueue_script('metform-admin-script', $this->public_url() . 'assets/js/admin-script.js', [], null, true); |
|---|
| 463 | |
|---|
| 464 | wp_add_inline_script('metform-admin-script', " |
|---|
| 465 | var metform_api = { |
|---|
| 466 | resturl: '" . get_rest_url() . "' |
|---|
| 467 | } |
|---|
| 468 | "); |
|---|
| 469 | } |
|---|
| 470 | |
|---|
| 471 | public function elementor_js() |
|---|
| 472 | { |
|---|
| 473 | } |
|---|
| 474 | |
|---|
| 475 | public function elementor_css() |
|---|
| 476 | { |
|---|
| 477 | if ('metform-form' == get_post_type()) { |
|---|
| 478 | wp_enqueue_style('metform-category-top', $this->public_url() . 'assets/css/category-top.css', false, $this->version()); |
|---|
| 479 | } |
|---|
| 480 | } |
|---|
| 481 | |
|---|
| 482 | |
|---|
| 483 | |
|---|
| 484 | /** |
|---|
| 485 | * @function - {cleanoThemeConflict} |
|---|
| 486 | * @description - this function is used to remove conflict of bootstrap between metform & cleano theme. |
|---|
| 487 | */ |
|---|
| 488 | function cleanoThemeConflict() { |
|---|
| 489 | |
|---|
| 490 | $screen = get_current_screen(); |
|---|
| 491 | if(in_array($screen->id, ['edit-metform-form', 'metform_page_mt-form-settings', 'metform-entry', 'metform_page_metform-menu-settings'])){ |
|---|
| 492 | wp_dequeue_script( 'bootstrap' ); |
|---|
| 493 | } |
|---|
| 494 | } |
|---|
| 495 | |
|---|
| 496 | |
|---|
| 497 | function js_css_admin() |
|---|
| 498 | { |
|---|
| 499 | |
|---|
| 500 | |
|---|
| 501 | wp_enqueue_style( 'mf-wp-dashboard', $this->core_url() . 'admin/css/mf-wp-dashboard.css', [], $this->version() ); |
|---|
| 502 | |
|---|
| 503 | $screen = get_current_screen(); |
|---|
| 504 | |
|---|
| 505 | if (in_array($screen->id, ['edit-metform-form', 'metform_page_mt-form-settings', 'metform-entry', 'metform_page_metform-menu-settings'])) { |
|---|
| 506 | wp_enqueue_style('metform-admin-fonts', $this->public_url() . 'assets/admin-fonts.css', false, $this->version()); |
|---|
| 507 | wp_enqueue_style('metform-ui', $this->public_url() . 'assets/css/metform-ui.css', false, $this->version()); |
|---|
| 508 | wp_enqueue_style('metform-admin-style', $this->public_url() . 'assets/css/admin-style.css', false, null); |
|---|
| 509 | |
|---|
| 510 | wp_enqueue_script('metform-ui', $this->public_url() . 'assets/js/ui.min.js', [], $this->version(), true); |
|---|
| 511 | wp_enqueue_script('metform-admin-script', $this->public_url() . 'assets/js/admin-script.js', [], null, true); |
|---|
| 512 | wp_localize_script('metform-admin-script', 'metform_api', ['resturl' => get_rest_url(), 'admin_url' => get_admin_url()]); |
|---|
| 513 | } |
|---|
| 514 | |
|---|
| 515 | if ($screen->id == 'edit-metform-entry' || $screen->id == 'metform-entry') { |
|---|
| 516 | wp_enqueue_style('metform-ui', $this->public_url() . 'assets/css/metform-ui.css', false, $this->version()); |
|---|
| 517 | wp_enqueue_script('metform-entry-script', $this->public_url() . 'assets/js/admin-entry-script.js', [], $this->version(), true); |
|---|
| 518 | } |
|---|
| 519 | } |
|---|
| 520 | |
|---|
| 521 | /** |
|---|
| 522 | * Excluding Metform form from search engine. |
|---|
| 523 | * |
|---|
| 524 | */ |
|---|
| 525 | public function add_meta_for_search_excluded() { |
|---|
| 526 | |
|---|
| 527 | |
|---|
| 528 | |
|---|
| 529 | if ( in_array(get_post_type(), ['metform-form']) ) { |
|---|
| 530 | echo '<meta name="robots" content="noindex,nofollow" />', "\n"; |
|---|
| 531 | } |
|---|
| 532 | } |
|---|
| 533 | |
|---|
| 534 | public function footer_data() |
|---|
| 535 | { |
|---|
| 536 | |
|---|
| 537 | $screen = get_current_screen(); |
|---|
| 538 | |
|---|
| 539 | if ($screen->id == 'edit-metform-entry') { |
|---|
| 540 | $args = [ |
|---|
| 541 | 'post_type' => 'metform-form', |
|---|
| 542 | 'post_status' => 'publish', |
|---|
| 543 | 'numberposts' => -1, |
|---|
| 544 | ]; |
|---|
| 545 | |
|---|
| 546 | $forms = get_posts($args); |
|---|
| 547 | //phpcs:ignore WordPress.Security.NonceVerification -- Nonce can't be added in CPT URL |
|---|
| 548 | $get_form_id = isset($_GET['form_id']) ? sanitize_key($_GET['form_id']) : ''; |
|---|
| 549 | ?> |
|---|
| 550 | <div id='metform-formlist' style='display:none;'><select name='mf_form_id' id='metform-form_id'> |
|---|
| 551 | <option value='all' <?php echo esc_attr(((($get_form_id == 'all') || ($get_form_id == '')) ? 'selected=selected' : '')); ?>>All</option> |
|---|
| 552 | <?php |
|---|
| 553 | |
|---|
| 554 | foreach ($forms as $form) { |
|---|
| 555 | $form_list[$form->ID] = $form->post_title; |
|---|
| 556 | ?> |
|---|
| 557 | <option value="<?php echo esc_attr($form->ID); ?>" <?php echo esc_attr(($get_form_id == $form->ID) ? 'selected=selected' : ''); ?>><?php echo esc_html($form->post_title); ?></option> |
|---|
| 558 | <?php |
|---|
| 559 | } |
|---|
| 560 | echo "</select></div>"; |
|---|
| 561 | } |
|---|
| 562 | } |
|---|
| 563 | |
|---|
| 564 | function admin_menu() |
|---|
| 565 | { |
|---|
| 566 | add_menu_page( |
|---|
| 567 | esc_html__('MetForm', 'metform'), |
|---|
| 568 | esc_html__('MetForm', 'metform'), |
|---|
| 569 | 'read', |
|---|
| 570 | 'metform-menu', |
|---|
| 571 | '', |
|---|
| 572 | $this->core_url() . 'admin/images/icon-menu.png', |
|---|
| 573 | 5 |
|---|
| 574 | ); |
|---|
| 575 | } |
|---|
| 576 | |
|---|
| 577 | public function missing_elementor() |
|---|
| 578 | { |
|---|
| 579 | //phpcs:disable WordPress.Security.NonceVerification -- Can't set nonce. Cause it's fire on 'plugins_loaded' hook |
|---|
| 580 | if (isset($_GET['activate'])) { |
|---|
| 581 | unset($_GET['activate']); |
|---|
| 582 | } |
|---|
| 583 | //phpcs:enable |
|---|
| 584 | if (file_exists(WP_PLUGIN_DIR . '/elementor/elementor.php')) { |
|---|
| 585 | $btn['text'] = esc_html__('Activate Elementor', 'metform'); |
|---|
| 586 | $btn['id'] = 'unsupported-elementor-version'; |
|---|
| 587 | $btn['class'] = 'button-primary'; |
|---|
| 588 | $btn['url'] = wp_nonce_url('plugins.php?action=activate&plugin=elementor/elementor.php&plugin_status=all&paged=1', 'activate-plugin_elementor/elementor.php'); |
|---|
| 589 | } else { |
|---|
| 590 | $btn['id'] = 'unsupported-elementor-version'; |
|---|
| 591 | $btn['class'] = 'button-primary'; |
|---|
| 592 | $btn['text'] = esc_html__('Install Elementor', 'metform'); |
|---|
| 593 | $btn['url'] = wp_nonce_url(self_admin_url('update.php?action=install-plugin&plugin=elementor'), 'install-plugin_elementor'); |
|---|
| 594 | } |
|---|
| 595 | // translators: MetForm plugin version requirement. %s is the required Elementor version. |
|---|
| 596 | $message = sprintf(esc_html__('MetForm requires Elementor version %1$s+, which is currently NOT RUNNING.', 'metform'), '2.6.0'); |
|---|
| 597 | |
|---|
| 598 | \Oxaim\Libs\Notice::instance('metform', 'unsupported-elementor-version') |
|---|
| 599 | ->set_dismiss('global', (3600 * 24 * 15)) |
|---|
| 600 | ->set_message($message) |
|---|
| 601 | ->set_button($btn) |
|---|
| 602 | ->call(); |
|---|
| 603 | } |
|---|
| 604 | |
|---|
| 605 | public function available_metform_pro() |
|---|
| 606 | { |
|---|
| 607 | //phpcs:disable WordPress.Security.NonceVerification -- Can't set nonce. Cause it's fire on 'plugins_loaded' hook |
|---|
| 608 | if (isset($_GET['activate'])) { |
|---|
| 609 | unset($_GET['activate']); |
|---|
| 610 | } |
|---|
| 611 | //phpcs:enable |
|---|
| 612 | $btn['text'] = esc_html__('MetForm Pro', 'metform'); |
|---|
| 613 | $btn['url'] = esc_url('https://products.wpmet.com/metform/'); |
|---|
| 614 | $btn['class'] = 'button-primary'; |
|---|
| 615 | |
|---|
| 616 | $message = sprintf(esc_html__('We have MetForm Pro version. Check out our pro feature.', 'metform'), '2.6.0'); |
|---|
| 617 | \Oxaim\Libs\Notice::instance('metform', 'unsupported-metform-pro-version') |
|---|
| 618 | ->set_dismiss('global', (3600 * 24 * 15)) |
|---|
| 619 | ->set_message($message) |
|---|
| 620 | ->set_button($btn) |
|---|
| 621 | ->call(); |
|---|
| 622 | } |
|---|
| 623 | |
|---|
| 624 | |
|---|
| 625 | public function failed_elementor_version() |
|---|
| 626 | { |
|---|
| 627 | |
|---|
| 628 | $btn['text'] = esc_html__('Update Elementor', 'metform'); |
|---|
| 629 | // translators: MetForm plugin version requirement. %s is the required Elementor version. |
|---|
| 630 | $btn['url'] = sprintf(esc_html__('MetForm requires Elementor version %1$s+, which is currently NOT RUNNING.', 'metform'), '2.6.0'); |
|---|
| 631 | $btn['class'] = 'button-primary'; |
|---|
| 632 | |
|---|
| 633 | $message = sprintf(esc_html__('We have MetForm Pro version. Check out our pro feature.', 'metform'), '2.6.0'); |
|---|
| 634 | \Oxaim\Libs\Notice::instance('metform', 'unsupported-elementor-version') |
|---|
| 635 | ->set_dismiss('global', (3600 * 24 * 15)) |
|---|
| 636 | ->set_message($message) |
|---|
| 637 | ->set_button($btn) |
|---|
| 638 | ->call(); |
|---|
| 639 | } |
|---|
| 640 | |
|---|
| 641 | public function flush_rewrites() |
|---|
| 642 | { |
|---|
| 643 | $form_cpt = new Core\Forms\Cpt(); |
|---|
| 644 | $form_cpt->flush_rewrites(); |
|---|
| 645 | } |
|---|
| 646 | |
|---|
| 647 | |
|---|
| 648 | public static function instance() |
|---|
| 649 | { |
|---|
| 650 | if (!self::$instance) { |
|---|
| 651 | self::$instance = new self(); |
|---|
| 652 | } |
|---|
| 653 | return self::$instance; |
|---|
| 654 | } |
|---|
| 655 | |
|---|
| 656 | public function metform_permalink_setup(){ |
|---|
| 657 | |
|---|
| 658 | Utils\Util::permalink_setup(); |
|---|
| 659 | } |
|---|
| 660 | |
|---|
| 661 | |
|---|
| 662 | } |
|---|