<?php
// Style : css + js files
add_action('admin_footer', function () {
    echo '<link rel="stylesheet" href="' .DS1CDNBucket . 'admin/admin.css">';
    echo '<script src="' . DS1CDNBucket . 'admin/admin.js"></script>';

    if(get_locale() == 'ar'){
        echo '<link href="https://fonts.googleapis.com/css2?family=Cairo:wght@400;700&display=swap" rel="stylesheet">';
    }


    // override admin colors and logo
        $color_primary_dark      = get_option('options_admin_color_primary_dark');
        $color_secondary_dark    = get_option('options_admin_color_secondary_dark');
        $color_primary_light     = get_option('options_admin_color_primary_light');
        $color_secondary_light   = get_option('options_admin_color_secondary_light');
        $color_text_dark_bg      = get_option('options_admin_color_text_dark_bg');
        $color_text_light_bg     = get_option('options_admin_color_text_light_bg');
        $main_admin_logo         = get_field('main_admin_logo','option');

        if (
            $color_primary_dark || $color_secondary_dark || $color_primary_light ||
            $color_secondary_light || $color_text_dark_bg || $color_text_light_bg || $main_admin_logo
        ) {
            echo $color_primary_dark . 'admin.cssadmin.cssadmin.css<style>:root {';

            if ($color_primary_dark) {
                echo '--color-primary-dark: ' . esc_html($color_primary_dark) . ';';
            }
            if ($color_secondary_dark) {
                echo '--color-secondary-dark: ' . esc_html($color_secondary_dark) . ';';
            }
            if ($color_primary_light) {
                echo '--color-primary-light: ' . esc_html($color_primary_light) . ';';
            }
            if ($color_secondary_light) {
                echo '--color-secondary-light: ' . esc_html($color_secondary_light) . ';';
            }
            if ($color_text_dark_bg) {
                echo '--color-text-dark-bg: ' . esc_html($color_text_dark_bg) . ';';
            }
            if ($color_text_light_bg) {
                echo '--color-text-light-bg: ' . esc_html($color_text_light_bg) . ';';
            }

            if ($main_admin_logo) {
                echo '--main-admin-logo: url(' . esc_url($main_admin_logo) . ');';
            }

            echo '}</style>';
        }
});

/* Stylesheet for logged in - frontside*/
add_action('wp_footer', 'Ds1_link_to_stylesheet');
function Ds1_link_to_stylesheet() {
    echo '<link rel="stylesheet" type="text/css" href="'. DS1CDNBucket . 'admin/frontend-user-style.css" />';
}

// Remove Elements

// Remove WP-logo in admin bar + Udate V. in footer + Admin footer
add_action( 'admin_menu', function(){
    remove_filter( 'update_footer', 'core_update_footer' );
});
add_filter( 'admin_footer_text', '__return_empty_string', 11 ); 

add_action( 'wp_before_admin_bar_render', function() {
    global $wp_admin_bar;	
    $wp_admin_bar->remove_menu('wp-logo');
    $wp_admin_bar->remove_menu('comments');
}, 7 );

// remove word from title in admin page
add_filter( 'admin_title',  function ( $admin_title ) {
    if(strpos($admin_title, '&#8212;')){
        $title = explode("&#8212;", $admin_title);
        return str_replace("&rsaquo;","&#64;", $title[0]);
    }
    if(strpos($admin_title, '&rsaquo;')){
        $title = explode("&rsaquo;", $admin_title);
        return $title[0];
    }
    else {
        return 'Admin area';
    }
} );

//Remove Admin Help Tabs
add_action( 'admin_head', function () {
    $screen = get_current_screen();
    $screen->remove_help_tabs();
} );





// custom message in Dahsboard 
add_action('wp_dashboard_setup', 'Ds1_my_custom_dashboard_widgets');
function Ds1_my_custom_dashboard_widgets() {
    global $wp_meta_boxes;	
    wp_add_dashboard_widget('ds1_custom_help_widget_welcome', __( "welcome", "moreFunc" ), 'custom_dashboard_help');
}
function custom_dashboard_help() {
    $dev_info = ( ds1_checkSettings("admin_custom_js") ) ? ds1_checkSettings("admin_custom_js") : [];

    $dev_name   = (isset($dev_info['dev_name']) && !empty($dev_info['dev_name'])) 	? sanitize_text_field($dev_info['dev_name']) : 'Right mind';
    $dev_url    = (isset($dev_info['dev_url']) && !empty($dev_info['dev_url'])) 	? esc_html($dev_info['dev_url']) : 'https://r-m.dev';
    $website_id = (isset($dev_info['website_id']) && !empty($dev_info['website_id']))? esc_html($dev_info['website_id']) : 'def';
    $message    = (isset($dev_info['message']) && !empty($dev_info['message'])) 	? wp_filter_post_kses($dev_info['message']) : '';

    echo '<p>'. __( "In case of any queries or requirements, please contact technical support Team for", "moreFunc" ).' <a target="_blank" href="'. $dev_url .'/?s=theme-support&website_id='. $website_id .'&sitename='. urlencode(get_home_url()) .'"> '.esc_html( $dev_name ).' </a> </p>';

    if($message) {
        echo '<br>';
        echo $message;
    }
}




// Change Post name and page type name
add_action( 'init', 'ds1_custom_change_post_object' );
function ds1_custom_change_post_object() {

    $get_post_type = get_post_type_object('post');
    $labels             = $get_post_type->labels;
	$labels->name       = __('Blog and News', RMCORE_LANG);
	$labels->singular_name  = __('Blog and News', RMCORE_LANG);
	$labels->menu_name  = __('Blog and News', RMCORE_LANG);
	$labels->name_admin_bar = __('Blog and News', RMCORE_LANG);

	$get_post_type = get_post_type_object('page');
    $labels = $get_post_type->labels;
	$labels->singular_name = __('Single pages', RMCORE_LANG);
	$labels->menu_name = __('Single pages', RMCORE_LANG);
}

// Change Tags to Keywords
function ds1_custom_change_tax_object_label() {
      global $wp_taxonomies;

      if(!isset($wp_taxonomies['post_tag'])){
          return;
      }
      $labels = &$wp_taxonomies['post_tag']->labels;
      $labels->name             = __('Keywords', RMCORE_LANG);
      $labels->singular_name    = __('Keywords', RMCORE_LANG);
      $labels->search_items     = __('Search Keywords', RMCORE_LANG);
      $labels->all_items        = __('Keywords', RMCORE_LANG);
      $labels->separate_items_with_commas   = __('Separate Keywords with commas', RMCORE_LANG);
      $labels->choose_from_most_used        = __('Choose from the most used Keywords', RMCORE_LANG);
      $labels->popular_items    = __('Popular Keywords', RMCORE_LANG);
      $labels->edit_item        = __('Edit Keyword Name', RMCORE_LANG);
      $labels->view_item        = __('View Keyword Name', RMCORE_LANG);
      $labels->update_item      = __('Update Keyword Name', RMCORE_LANG);
      $labels->add_new_item     = __('Add Your Keyword Name', RMCORE_LANG);
      $labels->new_item_name    = __('Your New Keywords Name', RMCORE_LANG);
}
add_action( 'init', 'ds1_custom_change_tax_object_label' );



// Hide plugins
add_filter('all_plugins', 'rm_core_hide_plugins_from_dashboard');

function rm_core_hide_plugins_from_dashboard ($plugins) {
    $current_user = wp_get_current_user();
    // شرط التحقق إن اسم المستخدم لا يبدأ بـ "support"
    if (strpos($current_user->user_login, 'support') !== 0) {
        // حدد الإضافات التي تريد إخفاءها (مصفوفة بأسماء ملفات الإضافات الرئيسية)
        $plugins_to_hide = [
            'mainwp-child/mainwp-child.php',
            'rm_speed_setup/rm_speed_setup.php',
            'limit-login-attempts-reloaded/limit-login-attempts-reloaded.php',
            'simple-cloudflare-turnstile/simple-cloudflare-turnstile.php',
            'user-role-editor/user-role-editor.php',
            'akismet/akismet.php',
            'classic-editor/classic-editor.php',
            'better-search-replace/better-search-replace.php',
            // 'advanced-custom-fields-pro/advanced-custom-fields-pro.php',
  
        ];
        foreach ($plugins_to_hide as $plugin_file) {
            if (isset($plugins[$plugin_file])) {
                unset($plugins[$plugin_file]);
            }
        }
    }
    return $plugins;
}