<?php
/*
Plugin Name: RM Core
Version: 1.4.0
License: GPL
Author: Right Mind team + (design.1)
==========================================================================
*/

// منع الوصول المباشر
if (!defined('ABSPATH')) {
    exit;
}

function ds1_custom_is_bool_tester($key){
	if(
		isset(ds1_mf_init_settings()[$key]) && 
		ds1_mf_init_settings()[$key]
	) {
		return true;
	}
}

function checkSettings($key) {
    return (isset(ds1_mf_init_settings()[$key]) && ds1_mf_init_settings()[$key] && !empty(ds1_mf_init_settings()[$key])) ? ds1_mf_init_settings()[$key] : false;
}
function ds1_checkSettings($key) {
   return checkSettings($key);
}

class RMCoreFunctions {
    public static function init_actions() {
        // define("DS1CDNBucket", 'https://s3.eu-west-3.amazonaws.com/single.files/mainsite/plugins/Ds1_more-function/admin_actions/support/');
        define("DS1CDNBucket", plugin_dir_url(__FILE__) . 'assets/');
        define("RM_dir_path", plugin_dir_path( __FILE__ ));
        // define("RM_dir_url", plugin_dir_url(__FILE__));
        define("RMCORE_LANG", "RMCORE_LANG");
        
        // load_textdomain( RMCORE_LANG, RM_dir_path . 'lang/' . get_locale() . '.mo');
        add_action('init', function () {
            load_plugin_textdomain(RMCORE_LANG, false, RM_dir_path . 'languages/');
        });


        require_once( RM_dir_path . 'general/settings.php');
        require_once( RM_dir_path . 'general/general_functions.php');
         
        require_once( RM_dir_path . 'general/register_types/post_type.php');
        require_once( RM_dir_path . 'general/register_types/taxonomy.php');
        require_once( RM_dir_path . 'general/register_types/modif_post_permalink.php');

        require_once( RM_dir_path . 'plugins-assets/acf.php');

        if ( function_exists( 'is_plugin_active' ) ) {
            require_once( RM_dir_path . 'plugins-assets/polylang/load.php');
        }
        
        if ( function_exists( 'wpcf7' ) ) {
            require_once( RM_dir_path . 'plugins-assets/wpcf7/load.php'); // TO EDIT *******
        }


        if(is_user_logged_in(  )) {
            if ( function_exists( 'wpcf7' ) ) {
                require_once( RM_dir_path . 'plugins-assets/wpcf7-db.php');
            }

            // Admin dashboard Main style
            require_once( RM_dir_path . 'admin/style.php');
            
            // Admin dashboard add/ remove meta_boxes &&  menus items
            require_once( RM_dir_path . 'admin/style_meta_boxes_and_menus.php');

            // Add page to upload custom font to upload folder
            require_once( RM_dir_path . 'admin/upload_fonts.php');

            // Support page if added to admin menu in settings.php
            require_once( RM_dir_path . 'admin/main_support_page.php');


            // Add filter by date to posts
            if( ds1_custom_is_bool_tester('elements_filter_date') ) {
                require_once( RM_dir_path . 'admin/filters/elements_filter_date.php');
            }

            if( ds1_checkSettings("elements_filter_more") ) {
                require_once( RM_dir_path . 'admin/filters/elements_filter_more.php');
            }

            // Add taxonomy filter to post type :: EXP. : locations filter to real-estate
            if(	checkSettings("elements_filter_taxonomy") ) {
                require_once( RM_dir_path . 'admin/filters/elements_filter_taxonomy.php');
            }

            // Add sesign elements to tiny_mce editor like custom font size ** Some elements are added to JS only, such as: Insert Dynamic Button
            if( ds1_custom_is_bool_tester('elements_tiny_mce') ) {
                require_once( RM_dir_path . 'admin/elements_tiny_mce.php');
            }

            // Custom post type (list table) columns
            if( ds1_checkSettings("types_table_columns") ) {
                require_once( RM_dir_path . 'admin/elements_types_table_columns.php');
            }

        }
        else {
            // Change default login page style
            require_once( RM_dir_path . 'admin/style_login.php');
        }

        // Custom login page (/login) :: [custom_login_form] && [custom_register_form] 
        if(ds1_custom_is_bool_tester('custom_login_page')) {
            require_once( RM_dir_path . 'admin/custom_login_page.php');
        }

        
        // csm
        require_once( RM_dir_path . 'csm/csm.php');
        
        // Front End .. 
        require_once( RM_dir_path . 'multi-langs/menus.php');
        require_once( RM_dir_path . 'frontend/load_fonts_and_colors.php');
        require_once( RM_dir_path . 'frontend/general_functions.php');

        require_once( RM_dir_path . 'frontend/custom_frontend_codes.php');
        require_once( RM_dir_path . 'frontend/shortcodes.php');

        if(ds1_custom_is_bool_tester('load_ds1_breadcrumb')) {
            require_once(RM_dir_path . 'frontend/breadcrumb.php');
        }

        if(ds1_custom_is_bool_tester('count_post_views' )) {
            require_once( RM_dir_path . 'frontend/count_post_views.php');
        }
        if(ds1_custom_is_bool_tester('rmbookmark')) {
            require_once( RM_dir_path . 'frontend/bookmark.php');
        }
        

    }
}

add_action( 'plugins_loaded', array( 'RMCoreFunctions', 'init_actions' ), 999999 );