<?php
/**
 * Plugin Name: Ultimate Member Widgets for Elementor – Login Form, Register Form & User Directory
 * Description: Style Ultimate Member login, register, password reset & member directories with Elementor drag-and-drop. No code required.
 * Plugin URI: http://userelements.com/ultimate-member-elementor
 * Version: 2.7
 * Author: userelements
 * Author URI: http://userelements.com/
 * License: GPL v2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Requires at least: 6.0
 * Requires PHP: 8.0 
 * Requires Plugins: elementor, ultimate-member
 * Text Domain: ultimate-member-widgets-for-elementor
 * Domain Path: /languages

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program 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, USA
*/

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

if ( defined( 'UMEP_VERSION' ) ) {
	add_action(
		'admin_notices',
		static function () {
			if ( ! current_user_can( 'manage_options' ) ) {
				return;
			}
			require_once __DIR__ . '/modules/helpers/UM_Admin_Helpers.php';
			$deactivate_url = \UM_Elementor\Helpers\UM_Admin_Helpers::get_deactivate_plugin_url(
				\UM_Elementor\Helpers\UM_Admin_Helpers::PRO_PLUGIN_BASENAME
			);
			echo '<div class="notice notice-error"><p>';
			esc_html_e( 'Ultimate Member Widgets for Elementor (Pro) is active. Deactivate Pro or deactivate this free plugin — they cannot run together.', 'ultimate-member-widgets-for-elementor' );
			echo ' <a href="' . esc_url( $deactivate_url ) . '" class="button button-secondary">' . esc_html__( 'Deactivate Pro plugin', 'ultimate-member-widgets-for-elementor' ) . '</a>';
			echo '</p></div>';
		}
	);
	return;
}

if ( ! function_exists( 'umwfe_fs' ) ) {

    function umwfe_fs() {
        global $umwfe_fs;

        if ( ! isset( $umwfe_fs ) ) {
            require_once dirname( __FILE__ ) . '/vendor/freemius/start.php';

            $umwfe_fs = fs_dynamic_init( array(
                'id'                  => '29010',
                'slug'                => 'ultimate-member-widgets-for-elementor',
                'type'                => 'plugin',
                'public_key'          => 'pk_651feeba355bacd6522090f4c1a22',
                'is_premium'          => false,
                'has_addons'          => false,
                'has_paid_plans'      => true,
                'is_org_compliant'    => true,
                'menu'                => array(
                    'first-path'     => 'admin.php?page=um-elementor-settings',
                    'account'        => false,
                    'support'        => false,
                ),
            ) );
        }

        return $umwfe_fs;
    }

    umwfe_fs();
    do_action( 'umwfe_fs_loaded' );
}

if ( ! defined( 'UM_USER_ELEMENTOR_PATH' ) ) {
    define( 'UM_USER_ELEMENTOR_PATH', plugin_dir_path( __FILE__ ) );
}

if ( ! defined( 'UM_USER_ELEMENTOR_URL' ) ) {
    define( 'UM_USER_ELEMENTOR_URL', plugins_url( '/', __FILE__ ) );
}

if ( ! defined( 'UM_ELEMENTOR_VERSION' ) ) {
    define( 'UM_ELEMENTOR_VERSION', '2.7' );
}

require_once UM_USER_ELEMENTOR_PATH . 'inc/class-um-elementor-ajax-widget-settings.php';
require_once UM_USER_ELEMENTOR_PATH . 'inc/elementor-um-essential.php';
require_once UM_USER_ELEMENTOR_PATH . 'inc/class-user-query-engine.php';
require_once UM_USER_ELEMENTOR_PATH . 'inc/admin-settings.php';
require_once UM_USER_ELEMENTOR_PATH . 'modules/helpers/UM_Core_Pages.php';
require_once UM_USER_ELEMENTOR_PATH . 'modules/helpers/UM_Admin_Helpers.php';
require_once UM_USER_ELEMENTOR_PATH . 'modules/helpers/UM_Editor_Placeholder.php';
require_once UM_USER_ELEMENTOR_PATH . 'modules/helpers/UM_Logged_In_Login.php';

register_activation_hook( __FILE__, static function () {
	if ( defined( 'UMEP_VERSION' ) ) {
		return;
	}
	update_option( 'um_elementor_show_setup_notice', '1', false );
} );

add_action( 'plugins_loaded', 'user_elementor_um_init' );

/**
 * Initialize
 */
if ( ! function_exists( 'user_elementor_um_init' ) ) {
	function user_elementor_um_init() {

	    // Check if Elementor installed and activated
	    if ( ! did_action( 'elementor/loaded' ) ) {
	        add_action( 'admin_notices', 'user_elementor_um_dependency_notice' );
	        return;
	    }

		if ( ! version_compare( PHP_VERSION, '8.0', '>=' ) ) {
			add_action( 'admin_notices', 'user_elementor_um_php_version_notice' );
			return;
		}

        require_once UM_USER_ELEMENTOR_PATH . 'inc/wp-user-list-ajax-handlers.php';
        require_once UM_USER_ELEMENTOR_PATH . 'inc/um-user-list-ajax-handlers.php';

		add_action( 'elementor/elements/categories_registered', 'user_elementor_um_category' );
		add_action( 'wp_enqueue_scripts', 'user_elementor_um_enqueue_styles' );
        add_action( 'elementor/editor/after_enqueue_scripts', 'user_elementor_um_enqueue_editor_scripts' );
        add_action( 'elementor/widgets/register', 'user_elementor_um_register_widgets' );
		add_action( 'init', [ 'WP_User_List_Ajax', 'init' ] );
	}
}
