Erste-Projekt-von-Moh/functions.php
2025-04-22 18:18:42 +02:00

267 lines
9.3 KiB
PHP
Executable File

<?php
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
function custom_admin_menu_function()
{
global $menu, $current_user;
// Get the current user's information
$user_id = get_current_user_id();
$user_info = get_userdata($user_id);
$username = $user_info->user_login;
$user_avatar = get_avatar_url($user_id);
$pp_left_user_menu = array();
$pp_left_user_menu[] = array(
'<span class="pp-user-avatar"><img src="' . $user_avatar . '" alt="' . $username . '"></span><span class="pp-user-name">' . $username . '</span>',
'read',
'profile.php',
'', // Leave the ID empty, so it gets auto-generated
'pp-left-user' // Add any additional classes for the <li> element if needed
);
// Add Logout link with an extra class for the <li> element
// $pp_left_user_menu[] = array('Logout', 'read', wp_logout_url(), '', 'wp-menu-image');
// Add a separator between your custom items and the default items with an extra class for the <li> element
// $pp_left_user_menu[] = array('', 'read', 'separator1', '', 'wp-menu-separator');
// Merge your custom items with the existing menu items, placing your items at the top
$menu = array_merge($pp_left_user_menu, $menu);
}
add_action('admin_menu', 'custom_admin_menu_function');
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
function palettepro_remove_admin_footer()
{
return '';
}
add_filter('admin_footer_text', 'palettepro_remove_admin_footer', 999);
add_filter('update_footer', 'palettepro_remove_admin_footer', 999);
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
// Define the default options outside the function
$default_options = array(
'palettepro_logo_url' => '/assets/a.svg',
'palettepro_login_logo_url' => '/assets/a.svg',
'palettepro_login_bg_type' => 'color',
'palettepro_login_bg_color' => '#f0f0f1',
'palettepro_login_bg_gradient_start' => '#f0f0f1',
'palettepro_login_bg_gradient_end' => '#d6d6d6',
'palettepro_dashboard_background_color' => '#f0f0f1',
'palettepro_border_radius' => 0,
'palettepro_primary_color' => '#0073aa',
'palettepro_primary_button_bg_color' => '#0073aa',
'palettepro_secondary_button_bg_color' => '#e95095',
'palettepro_primary_button_hover_color' => '#7049ba',
'palettepro_secondary_button_hover_color' => '#e95095',
'palettepro_left_menu_bg_color' => '#f0f0f1',
'palettepro_left_menu_bg_items' => '#1D2327',
'palettepro_left_menu_item_text_color' => '#f2f6fc',
'palettepro_left_menu_item_text_hover' => '#f2f6fc',
'palettepro_left_menu_item_bg_color' => '#0073aa',
'palettepro_left_menu_item_bg_hover' => '#0073aa',
'palettepro_top_menu_bg_color' => '#1D2327'
);
// Function to reset the options to their default values
function reset_palettepro_options()
{
global $default_options; // Access the global default_options array
// Reset each option to its default value
foreach ($default_options as $option_name => $default_value) {
update_option($option_name, $default_value);
}
// Update the login logo and logo URLs with the default image
$plugin_dir = plugin_dir_url(__FILE__);
$default_logo_url = $plugin_dir . 'assets/logos/logo.svg';
$default_login_logo_url = $plugin_dir . 'assets/logos/logo.svg';
update_option('palettepro_logo_url', $default_logo_url);
update_option('palettepro_login_logo_url', $default_login_logo_url);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
// Add a support menu item to the top navigation bar with an icon
function pp_support_menu($wp_admin_bar)
{
$args = array(
'id' => 'palettePro',
'title' => '<span class="ab-icon dashicons-before dashicons-art"></span> palettePro',
'href' => admin_url('admin.php?page=palettepro'),
'parent' => 'top-secondary', // Add the parent menu item ID here
'meta' => array('class' => 'palettePro-menu-item')
);
$wp_admin_bar->add_node($args);
// Add dropdown menu items
$args_submenu1 = array(
'id' => 'submenu1',
'title' => '<span class="ab-icon dashicons-before dashicons-art"></span> palettePro',
'href' => '#', // Add your submenu 1 URL here
'parent' => 'palettePro',
'meta' => array('class' => 'pp-sub-menu1')
);
$wp_admin_bar->add_node($args_submenu1);
$args_submenu2 = array(
'id' => 'submenu2',
'title' => 'Submenu 2',
'href' => '#', // Add your submenu 2 URL here
'parent' => 'palettePro',
'meta' => array('class' => 'pp-sub-menu2')
);
$wp_admin_bar->add_node($args_submenu2);
}
add_action('admin_bar_menu', 'pp_support_menu', 10);
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
function palettepro_custom_login_logo()
{
$login_logo_url = get_option('palettepro_login_logo_url');
echo '<!-- Debug: Login Logo URL: ' . esc_url($login_logo_url) . ' -->';
$custom_logo_link = get_home_url(); // Change this to the desired URL
if (!empty($login_logo_url)) {
?>
<style type="text/css">
.login h1 a {
background-image: url('<?php echo esc_attr($login_logo_url); ?>') !important;
background-size: contain !important;
width: 100% !important;
height: 100px !important;
}
</style>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
var logoLink = document.querySelector('.login h1 a');
logoLink.href = '<?php echo esc_url($custom_logo_link); ?>';
});
</script>
<?php
}
}
add_action('login_enqueue_scripts', 'palettepro_custom_login_logo');
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
/***************************************************
* Display All Custom Post Type (At a Glance)
***************************************************/
add_action('dashboard_glance_items', 'at_glance_content_von_moh');
function at_glance_content_von_moh()
{
$args = array(
'public' => true,
'_builtin' => false
);
$output = 'object';
$operator = 'and';
$post_types = get_post_types($args, $output, $operator);
foreach ($post_types as $post_type) {
$num_posts = wp_count_posts($post_type->name);
$num = number_format_i18n($num_posts->publish);
$text = _n($post_type->labels->singular_name, $post_type->labels->name, intval($num_posts->publish));
if (current_user_can('edit_posts')) {
$output = '<a href="edit.php?post_type=' . $post_type->name . '">' . $num . ' ' . $text . '</a>';
echo '<li class="post-count ' . $post_type->name . '-count">' . $output . '</li>';
} else {
$output = '<span>' . $num . ' ' . $text . '</span>';
echo '<li class="post-count ' . $post_type->name . '-count">' . $output . '</li>';
}
}
}
/***************************************************
* Set Post Color By Status In WordPress Admin Panel
***************************************************/
add_action('admin_footer', 'posts_status_color_von_moh');
function posts_status_color_von_moh()
{
?>
<style>
.status-draft {
background: #ffffe0 !important;
}
.status-future {
background: #E9F2D3 !important;
}
.status-publish {
/* no background keep WordPress colors */
}
.status-pending {
background: #D3E4ED !important;
}
.status-private {
background: #FFECE6 !important;
}
.status-sticky {
background: #F9F9F9 !important;
}
.post-password-required {
background: #F7FCFE !important;
}
</style>
<?php
}