Sindbad~EG File Manager
<?php
/**
* Twenty Twenty functions and definitions
*
* @link https://developer.wordpress.org/themes/basics/theme-functions/
*
* @package WordPress
* @subpackage Twenty_Twenty
* @since Twenty Twenty 1.0
*/
/**
* Table of Contents:
* Theme Support
* Required Files
* Register Styles
* Register Scripts
* Register Menus
* Custom Logo
* WP Body Open
* Register Sidebars
* Enqueue Block Editor Assets
* Enqueue Classic Editor Styles
* Block Editor Settings
*/
/**
* Sets up theme defaults and registers support for various WordPress features.
*
* Note that this function is hooked into the after_setup_theme hook, which
* runs before the init hook. The init hook is too late for some features, such
* as indicating support for post thumbnails.
*
* @since Twenty Twenty 1.0
*/
function twentytwenty_theme_support() {
// Add default posts and comments RSS feed links to head.
add_theme_support( 'automatic-feed-links' );
// Custom background color.
add_theme_support(
'custom-background',
array(
'default-color' => 'f5efe0',
)
);
// Set content-width.
global $content_width;
if ( ! isset( $content_width ) ) {
$content_width = 580;
}
/*
* Enable support for Post Thumbnails on posts and pages.
*
* @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
*/
add_theme_support( 'post-thumbnails' );
// Set post thumbnail size.
set_post_thumbnail_size( 1200, 9999 );
// Add custom image size used in Cover Template.
add_image_size( 'twentytwenty-fullscreen', 1980, 9999 );
// Custom logo.
$logo_width = 120;
$logo_height = 90;
// If the retina setting is active, double the recommended width and height.
if ( get_theme_mod( 'retina_logo', false ) ) {
$logo_width = floor( $logo_width * 2 );
$logo_height = floor( $logo_height * 2 );
}
add_theme_support(
'custom-logo',
array(
'height' => $logo_height,
'width' => $logo_width,
'flex-height' => true,
'flex-width' => true,
)
);
/*
* Let WordPress manage the document title.
* By adding theme support, we declare that this theme does not use a
* hard-coded <title> tag in the document head, and expect WordPress to
* provide it for us.
*/
add_theme_support( 'title-tag' );
/*
* Switch default core markup for search form, comment form, and comments
* to output valid HTML5.
*/
add_theme_support(
'html5',
array(
'search-form',
'comment-form',
'comment-list',
'gallery',
'caption',
'script',
'style',
'navigation-widgets',
)
);
// Add support for full and wide align images.
add_theme_support( 'align-wide' );
// Add support for responsive embeds.
add_theme_support( 'responsive-embeds' );
/*
* Adds starter content to highlight the theme on fresh sites.
* This is done conditionally to avoid loading the starter content on every
* page load, as it is a one-off operation only needed once in the customizer.
*/
if ( is_customize_preview() ) {
require get_template_directory() . '/inc/starter-content.php';
add_theme_support( 'starter-content', twentytwenty_get_starter_content() );
}
// Add theme support for selective refresh for widgets.
add_theme_support( 'customize-selective-refresh-widgets' );
/*
* Adds `async` and `defer` support for scripts registered or enqueued
* by the theme.
*/
$loader = new TwentyTwenty_Script_Loader();
if ( version_compare( $GLOBALS['wp_version'], '6.3', '<' ) ) {
add_filter( 'script_loader_tag', array( $loader, 'filter_script_loader_tag' ), 10, 2 );
} else {
add_filter( 'print_scripts_array', array( $loader, 'migrate_legacy_strategy_script_data' ), 100 );
}
}
add_action( 'after_setup_theme', 'twentytwenty_theme_support' );
/**
* REQUIRED FILES
* Include required files.
*/
require get_template_directory() . '/inc/template-tags.php';
// Handle SVG icons.
require get_template_directory() . '/classes/class-twentytwenty-svg-icons.php';
require get_template_directory() . '/inc/svg-icons.php';
// Handle Customizer settings.
require get_template_directory() . '/classes/class-twentytwenty-customize.php';
// Require Separator Control class.
require get_template_directory() . '/classes/class-twentytwenty-separator-control.php';
// Custom comment walker.
require get_template_directory() . '/classes/class-twentytwenty-walker-comment.php';
// Custom page walker.
require get_template_directory() . '/classes/class-twentytwenty-walker-page.php';
// Custom script loader class.
require get_template_directory() . '/classes/class-twentytwenty-script-loader.php';
// Non-latin language handling.
require get_template_directory() . '/classes/class-twentytwenty-non-latin-languages.php';
// Custom CSS.
require get_template_directory() . '/inc/custom-css.php';
/**
* Register block patterns and pattern categories.
*
* @since Twenty Twenty 2.8
*/
function twentytwenty_register_block_patterns() {
require get_template_directory() . '/inc/block-patterns.php';
}
add_action( 'init', 'twentytwenty_register_block_patterns' );
/**
* Register and Enqueue Styles.
*
* @since Twenty Twenty 1.0
* @since Twenty Twenty 2.6 Enqueue the CSS file for the variable font.
*/
function twentytwenty_register_styles() {
$theme_version = wp_get_theme()->get( 'Version' );
wp_enqueue_style( 'twentytwenty-style', get_stylesheet_uri(), array(), $theme_version );
wp_style_add_data( 'twentytwenty-style', 'rtl', 'replace' );
// Enqueue the CSS file for the variable font, Inter.
wp_enqueue_style( 'twentytwenty-fonts', get_theme_file_uri( '/assets/css/font-inter.css' ), array(), $theme_version, 'all' );
// Add output of Customizer settings as inline style.
$customizer_css = twentytwenty_get_customizer_css( 'front-end' );
if ( $customizer_css ) {
wp_add_inline_style( 'twentytwenty-style', $customizer_css );
}
// Add print CSS.
wp_enqueue_style( 'twentytwenty-print-style', get_template_directory_uri() . '/print.css', null, $theme_version, 'print' );
}
add_action( 'wp_enqueue_scripts', 'twentytwenty_register_styles' );
/**
* Register and Enqueue Scripts.
*
* @since Twenty Twenty 1.0
*/
function twentytwenty_register_scripts() {
$theme_version = wp_get_theme()->get( 'Version' );
if ( ( ! is_admin() ) && is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
/*
* This script is intentionally printed in the head because it involves the page header. The `defer` script loading
* strategy ensures that it does not block rendering; being in the head it will start loading earlier so that it
* will execute sooner once the DOM has loaded. The $args array is not used here to avoid unintentional footer
* placement in WP<6.3; the wp_script_add_data() call is used instead.
*/
wp_enqueue_script( 'twentytwenty-js', get_template_directory_uri() . '/assets/js/index.js', array(), $theme_version );
wp_script_add_data( 'twentytwenty-js', 'strategy', 'defer' );
}
add_action( 'wp_enqueue_scripts', 'twentytwenty_register_scripts' );
/**
* Fix skip link focus in IE11.
*
* This does not enqueue the script because it is tiny and because it is only for IE11,
* thus it does not warrant having an entire dedicated blocking script being loaded.
*
* @since Twenty Twenty 1.0
* @deprecated Twenty Twenty 2.3 Removed from wp_print_footer_scripts action.
*
* @link https://git.io/vWdr2
*/
function twentytwenty_skip_link_focus_fix() {
// The following is minified via `terser --compress --mangle -- assets/js/skip-link-focus-fix.js`.
?>
<script>
/(trident|msie)/i.test(navigator.userAgent)&&document.getElementById&&window.addEventListener&&window.addEventListener("hashchange",function(){var t,e=location.hash.substring(1);/^[A-z0-9_-]+$/.test(e)&&(t=document.getElementById(e))&&(/^(?:a|select|input|button|textarea)$/i.test(t.tagName)||(t.tabIndex=-1),t.focus())},!1);
</script>
<?php
}
/**
* Enqueue non-latin language styles.
*
* @since Twenty Twenty 1.0
*
* @return void
*/
function twentytwenty_non_latin_languages() {
$custom_css = TwentyTwenty_Non_Latin_Languages::get_non_latin_css( 'front-end' );
if ( $custom_css ) {
wp_add_inline_style( 'twentytwenty-style', $custom_css );
}
}
add_action( 'wp_enqueue_scripts', 'twentytwenty_non_latin_languages' );
/**
* Register navigation menus uses wp_nav_menu in five places.
*
* @since Twenty Twenty 1.0
*/
function twentytwenty_menus() {
$locations = array(
'primary' => __( 'Desktop Horizontal Menu', 'twentytwenty' ),
'expanded' => __( 'Desktop Expanded Menu', 'twentytwenty' ),
'mobile' => __( 'Mobile Menu', 'twentytwenty' ),
'footer' => __( 'Footer Menu', 'twentytwenty' ),
'social' => __( 'Social Menu', 'twentytwenty' ),
);
register_nav_menus( $locations );
}
add_action( 'init', 'twentytwenty_menus' );
/**
* Get the information about the logo.
*
* @since Twenty Twenty 1.0
*
* @param string $html The HTML output from get_custom_logo (core function).
* @return string
*/
function twentytwenty_get_custom_logo( $html ) {
$logo_id = get_theme_mod( 'custom_logo' );
if ( ! $logo_id ) {
return $html;
}
$logo = wp_get_attachment_image_src( $logo_id, 'full' );
if ( $logo ) {
// For clarity.
$logo_width = esc_attr( $logo[1] );
$logo_height = esc_attr( $logo[2] );
// If the retina logo setting is active, reduce the width/height by half.
if ( get_theme_mod( 'retina_logo', false ) ) {
$logo_width = floor( $logo_width / 2 );
$logo_height = floor( $logo_height / 2 );
$search = array(
'/width=\"\d+\"/iU',
'/height=\"\d+\"/iU',
);
$replace = array(
"width=\"{$logo_width}\"",
"height=\"{$logo_height}\"",
);
// Add a style attribute with the height, or append the height to the style attribute if the style attribute already exists.
if ( false === strpos( $html, ' style=' ) ) {
$search[] = '/(src=)/';
$replace[] = "style=\"height: {$logo_height}px;\" src=";
} else {
$search[] = '/(style="[^"]*)/';
$replace[] = "$1 height: {$logo_height}px;";
}
$html = preg_replace( $search, $replace, $html );
}
}
return $html;
}
add_filter( 'get_custom_logo', 'twentytwenty_get_custom_logo' );
if ( ! function_exists( 'wp_body_open' ) ) {
/**
* Shim for wp_body_open, ensuring backward compatibility with versions of WordPress older than 5.2.
*
* @since Twenty Twenty 1.0
*/
function wp_body_open() {
/** This action is documented in wp-includes/general-template.php */
do_action( 'wp_body_open' );
}
}
/**
* Include a skip to content link at the top of the page so that users can bypass the menu.
*
* @since Twenty Twenty 1.0
*/
function twentytwenty_skip_link() {
echo '<a class="skip-link screen-reader-text" href="#site-content">' .
/* translators: Hidden accessibility text. */
__( 'Skip to the content', 'twentytwenty' ) .
'</a>';
}
add_action( 'wp_body_open', 'twentytwenty_skip_link', 5 );
/**
* Register widget areas.
*
* @since Twenty Twenty 1.0
*
* @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
*/
function twentytwenty_sidebar_registration() {
// Arguments used in all register_sidebar() calls.
$shared_args = array(
'before_title' => '<h2 class="widget-title subheading heading-size-3">',
'after_title' => '</h2>',
'before_widget' => '<div class="widget %2$s"><div class="widget-content">',
'after_widget' => '</div></div>',
);
// Footer #1.
register_sidebar(
array_merge(
$shared_args,
array(
'name' => __( 'Footer #1', 'twentytwenty' ),
'id' => 'sidebar-1',
'description' => __( 'Widgets in this area will be displayed in the first column in the footer.', 'twentytwenty' ),
)
)
);
// Footer #2.
register_sidebar(
array_merge(
$shared_args,
array(
'name' => __( 'Footer #2', 'twentytwenty' ),
'id' => 'sidebar-2',
'description' => __( 'Widgets in this area will be displayed in the second column in the footer.', 'twentytwenty' ),
)
)
);
}
add_action( 'widgets_init', 'twentytwenty_sidebar_registration' );
/**
* Enqueue supplemental block editor styles.
*
* @since Twenty Twenty 1.0
* @since Twenty Twenty 2.4 Removed a script related to the obsolete Squared style of Button blocks.
* @since Twenty Twenty 2.6 Enqueue the CSS file for the variable font.
*/
function twentytwenty_block_editor_styles() {
$theme_version = wp_get_theme()->get( 'Version' );
// Enqueue the editor styles.
wp_enqueue_style( 'twentytwenty-block-editor-styles', get_theme_file_uri( '/assets/css/editor-style-block.css' ), array(), $theme_version, 'all' );
wp_style_add_data( 'twentytwenty-block-editor-styles', 'rtl', 'replace' );
// Add inline style from the Customizer.
$customizer_css = twentytwenty_get_customizer_css( 'block-editor' );
if ( $customizer_css ) {
wp_add_inline_style( 'twentytwenty-block-editor-styles', $customizer_css );
}
// Enqueue the CSS file for the variable font, Inter.
wp_enqueue_style( 'twentytwenty-fonts', get_theme_file_uri( '/assets/css/font-inter.css' ), array(), $theme_version, 'all' );
// Add inline style for non-latin fonts.
$custom_css = TwentyTwenty_Non_Latin_Languages::get_non_latin_css( 'block-editor' );
if ( $custom_css ) {
wp_add_inline_style( 'twentytwenty-block-editor-styles', $custom_css );
}
}
if ( is_admin() && version_compare( $GLOBALS['wp_version'], '6.3', '>=' ) ) {
add_action( 'enqueue_block_assets', 'twentytwenty_block_editor_styles', 1, 1 );
} else {
add_action( 'enqueue_block_editor_assets', 'twentytwenty_block_editor_styles', 1, 1 );
}
/**
* Enqueue classic editor styles.
*
* @since Twenty Twenty 1.0
* @since Twenty Twenty 2.6 Enqueue the CSS file for the variable font.
*/
function twentytwenty_classic_editor_styles() {
$classic_editor_styles = array(
'/assets/css/editor-style-classic.css',
'/assets/css/font-inter.css',
);
add_editor_style( $classic_editor_styles );
}
add_action( 'init', 'twentytwenty_classic_editor_styles' );
/**
* Output Customizer settings in the classic editor.
* Adds styles to the head of the TinyMCE iframe. Kudos to @Otto42 for the original solution.
*
* @since Twenty Twenty 1.0
*
* @param array $mce_init TinyMCE styles.
* @return array TinyMCE styles.
*/
function twentytwenty_add_classic_editor_customizer_styles( $mce_init ) {
$styles = twentytwenty_get_customizer_css( 'classic-editor' );
if ( ! $styles ) {
return $mce_init;
}
if ( ! isset( $mce_init['content_style'] ) ) {
$mce_init['content_style'] = $styles . ' ';
} else {
$mce_init['content_style'] .= ' ' . $styles . ' ';
}
return $mce_init;
}
add_filter( 'tiny_mce_before_init', 'twentytwenty_add_classic_editor_customizer_styles' );
/**
* Output non-latin font styles in the classic editor.
* Adds styles to the head of the TinyMCE iframe. Kudos to @Otto42 for the original solution.
*
* @param array $mce_init TinyMCE styles.
* @return array TinyMCE styles.
*/
function twentytwenty_add_classic_editor_non_latin_styles( $mce_init ) {
$styles = TwentyTwenty_Non_Latin_Languages::get_non_latin_css( 'classic-editor' );
// Return if there are no styles to add.
if ( ! $styles ) {
return $mce_init;
}
if ( ! isset( $mce_init['content_style'] ) ) {
$mce_init['content_style'] = $styles . ' ';
} else {
$mce_init['content_style'] .= ' ' . $styles . ' ';
}
return $mce_init;
}
add_filter( 'tiny_mce_before_init', 'twentytwenty_add_classic_editor_non_latin_styles' );
/**
* Block Editor Settings.
* Add custom colors and font sizes to the block editor.
*
* @since Twenty Twenty 1.0
*/
function twentytwenty_block_editor_settings() {
// Block Editor Palette.
$editor_color_palette = array(
array(
'name' => __( 'Accent Color', 'twentytwenty' ),
'slug' => 'accent',
'color' => twentytwenty_get_color_for_area( 'content', 'accent' ),
),
array(
'name' => _x( 'Primary', 'color', 'twentytwenty' ),
'slug' => 'primary',
'color' => twentytwenty_get_color_for_area( 'content', 'text' ),
),
array(
'name' => _x( 'Secondary', 'color', 'twentytwenty' ),
'slug' => 'secondary',
'color' => twentytwenty_get_color_for_area( 'content', 'secondary' ),
),
array(
'name' => __( 'Subtle Background', 'twentytwenty' ),
'slug' => 'subtle-background',
'color' => twentytwenty_get_color_for_area( 'content', 'borders' ),
),
);
// Add the background option.
$background_color = get_theme_mod( 'background_color' );
if ( ! $background_color ) {
$background_color_arr = get_theme_support( 'custom-background' );
$background_color = $background_color_arr[0]['default-color'];
}
$editor_color_palette[] = array(
'name' => __( 'Background Color', 'twentytwenty' ),
'slug' => 'background',
'color' => '#' . $background_color,
);
// If we have accent colors, add them to the block editor palette.
if ( $editor_color_palette ) {
add_theme_support( 'editor-color-palette', $editor_color_palette );
}
// Block Editor Font Sizes.
add_theme_support(
'editor-font-sizes',
array(
array(
'name' => _x( 'Small', 'Name of the small font size in the block editor', 'twentytwenty' ),
'shortName' => _x( 'S', 'Short name of the small font size in the block editor.', 'twentytwenty' ),
'size' => 18,
'slug' => 'small',
),
array(
'name' => _x( 'Regular', 'Name of the regular font size in the block editor', 'twentytwenty' ),
'shortName' => _x( 'M', 'Short name of the regular font size in the block editor.', 'twentytwenty' ),
'size' => 21,
'slug' => 'normal',
),
array(
'name' => _x( 'Large', 'Name of the large font size in the block editor', 'twentytwenty' ),
'shortName' => _x( 'L', 'Short name of the large font size in the block editor.', 'twentytwenty' ),
'size' => 26.25,
'slug' => 'large',
),
array(
'name' => _x( 'Larger', 'Name of the larger font size in the block editor', 'twentytwenty' ),
'shortName' => _x( 'XL', 'Short name of the larger font size in the block editor.', 'twentytwenty' ),
'size' => 32,
'slug' => 'larger',
),
)
);
add_theme_support( 'editor-styles' );
// If we have a dark background color then add support for dark editor style.
// We can determine if the background color is dark by checking if the text-color is white.
if ( '#ffffff' === strtolower( twentytwenty_get_color_for_area( 'content', 'text' ) ) ) {
add_theme_support( 'dark-editor-style' );
}
}
add_action( 'after_setup_theme', 'twentytwenty_block_editor_settings' );
/**
* Overwrite default more tag with styling and screen reader markup.
*
* @param string $html The default output HTML for the more tag.
* @return string
*/
function twentytwenty_read_more_tag( $html ) {
return preg_replace( '/<a(.*)>(.*)<\/a>/iU', sprintf( '<div class="read-more-button-wrap"><a$1><span class="faux-button">$2</span> <span class="screen-reader-text">"%1$s"</span></a></div>', get_the_title( get_the_ID() ) ), $html );
}
add_filter( 'the_content_more_link', 'twentytwenty_read_more_tag' );
/**
* Enqueues scripts for customizer controls & settings.
*
* @since Twenty Twenty 1.0
*
* @return void
*/
function twentytwenty_customize_controls_enqueue_scripts() {
$theme_version = wp_get_theme()->get( 'Version' );
// Add main customizer js file.
wp_enqueue_script( 'twentytwenty-customize', get_template_directory_uri() . '/assets/js/customize.js', array( 'jquery' ), $theme_version );
// Add script for color calculations.
wp_enqueue_script( 'twentytwenty-color-calculations', get_template_directory_uri() . '/assets/js/color-calculations.js', array( 'wp-color-picker' ), $theme_version );
// Add script for controls.
wp_enqueue_script( 'twentytwenty-customize-controls', get_template_directory_uri() . '/assets/js/customize-controls.js', array( 'twentytwenty-color-calculations', 'customize-controls', 'underscore', 'jquery' ), $theme_version );
wp_localize_script( 'twentytwenty-customize-controls', 'twentyTwentyBgColors', twentytwenty_get_customizer_color_vars() );
}
add_action( 'customize_controls_enqueue_scripts', 'twentytwenty_customize_controls_enqueue_scripts' );
/**
* Enqueue scripts for the customizer preview.
*
* @since Twenty Twenty 1.0
*
* @return void
*/
function twentytwenty_customize_preview_init() {
$theme_version = wp_get_theme()->get( 'Version' );
wp_enqueue_script( 'twentytwenty-customize-preview', get_theme_file_uri( '/assets/js/customize-preview.js' ), array( 'customize-preview', 'customize-selective-refresh', 'jquery' ), $theme_version, array( 'in_footer' => true ) );
wp_localize_script( 'twentytwenty-customize-preview', 'twentyTwentyBgColors', twentytwenty_get_customizer_color_vars() );
wp_localize_script( 'twentytwenty-customize-preview', 'twentyTwentyPreviewEls', twentytwenty_get_elements_array() );
wp_add_inline_script(
'twentytwenty-customize-preview',
sprintf(
'wp.customize.selectiveRefresh.partialConstructor[ %1$s ].prototype.attrs = %2$s;',
wp_json_encode( 'cover_opacity' ),
wp_json_encode( twentytwenty_customize_opacity_range() )
)
);
}
add_action( 'customize_preview_init', 'twentytwenty_customize_preview_init' );
/**
* Get accessible color for an area.
*
* @since Twenty Twenty 1.0
*
* @param string $area The area we want to get the colors for.
* @param string $context Can be 'text' or 'accent'.
* @return string Returns a HEX color.
*/
function twentytwenty_get_color_for_area( $area = 'content', $context = 'text' ) {
// Get the value from the theme-mod.
$settings = get_theme_mod(
'accent_accessible_colors',
array(
'content' => array(
'text' => '#000000',
'accent' => '#cd2653',
'secondary' => '#6d6d6d',
'borders' => '#dcd7ca',
),
'header-footer' => array(
'text' => '#000000',
'accent' => '#cd2653',
'secondary' => '#6d6d6d',
'borders' => '#dcd7ca',
),
)
);
// If we have a value return it.
if ( isset( $settings[ $area ] ) && isset( $settings[ $area ][ $context ] ) ) {
return $settings[ $area ][ $context ];
}
// Return false if the option doesn't exist.
return false;
}
/**
* Returns an array of variables for the customizer preview.
*
* @since Twenty Twenty 1.0
*
* @return array
*/
function twentytwenty_get_customizer_color_vars() {
$colors = array(
'content' => array(
'setting' => 'background_color',
),
'header-footer' => array(
'setting' => 'header_footer_background_color',
),
);
return $colors;
}
/**
* Get an array of elements.
*
* @since Twenty Twenty 1.0
*
* @return array
*/
function twentytwenty_get_elements_array() {
// The array is formatted like this:
// [key-in-saved-setting][sub-key-in-setting][css-property] = [elements].
$elements = array(
'content' => array(
'accent' => array(
'color' => array( '.color-accent', '.color-accent-hover:hover', '.color-accent-hover:focus', ':root .has-accent-color', '.has-drop-cap:not(:focus):first-letter', '.wp-block-button.is-style-outline', 'a' ),
'border-color' => array( 'blockquote', '.border-color-accent', '.border-color-accent-hover:hover', '.border-color-accent-hover:focus' ),
'background-color' => array( 'button', '.button', '.faux-button', '.wp-block-button__link', '.wp-block-file .wp-block-file__button', 'input[type="button"]', 'input[type="reset"]', 'input[type="submit"]', '.bg-accent', '.bg-accent-hover:hover', '.bg-accent-hover:focus', ':root .has-accent-background-color', '.comment-reply-link' ),
'fill' => array( '.fill-children-accent', '.fill-children-accent *' ),
),
'background' => array(
'color' => array( ':root .has-background-color', 'button', '.button', '.faux-button', '.wp-block-button__link', '.wp-block-file__button', 'input[type="button"]', 'input[type="reset"]', 'input[type="submit"]', '.wp-block-button', '.comment-reply-link', '.has-background.has-primary-background-color:not(.has-text-color)', '.has-background.has-primary-background-color *:not(.has-text-color)', '.has-background.has-accent-background-color:not(.has-text-color)', '.has-background.has-accent-background-color *:not(.has-text-color)' ),
'background-color' => array( ':root .has-background-background-color' ),
),
'text' => array(
'color' => array( 'body', '.entry-title a', ':root .has-primary-color' ),
'background-color' => array( ':root .has-primary-background-color' ),
),
'secondary' => array(
'color' => array( 'cite', 'figcaption', '.wp-caption-text', '.post-meta', '.entry-content .wp-block-archives li', '.entry-content .wp-block-categories li', '.entry-content .wp-block-latest-posts li', '.wp-block-latest-comments__comment-date', '.wp-block-latest-posts__post-date', '.wp-block-embed figcaption', '.wp-block-image figcaption', '.wp-block-pullquote cite', '.comment-metadata', '.comment-respond .comment-notes', '.comment-respond .logged-in-as', '.pagination .dots', '.entry-content hr:not(.has-background)', 'hr.styled-separator', ':root .has-secondary-color' ),
'background-color' => array( ':root .has-secondary-background-color' ),
),
'borders' => array(
'border-color' => array( 'pre', 'fieldset', 'input', 'textarea', 'table', 'table *', 'hr' ),
'background-color' => array( 'caption', 'code', 'code', 'kbd', 'samp', '.wp-block-table.is-style-stripes tbody tr:nth-child(odd)', ':root .has-subtle-background-background-color' ),
'border-bottom-color' => array( '.wp-block-table.is-style-stripes' ),
'border-top-color' => array( '.wp-block-latest-posts.is-grid li' ),
'color' => array( ':root .has-subtle-background-color' ),
),
),
'header-footer' => array(
'accent' => array(
'color' => array( 'body:not(.overlay-header) .primary-menu > li > a', 'body:not(.overlay-header) .primary-menu > li > .icon', '.modal-menu a', '.footer-menu a, .footer-widgets a:where(:not(.wp-block-button__link))', '#site-footer .wp-block-button.is-style-outline', '.wp-block-pullquote:before', '.singular:not(.overlay-header) .entry-header a', '.archive-header a', '.header-footer-group .color-accent', '.header-footer-group .color-accent-hover:hover' ),
'background-color' => array( '.social-icons a', '#site-footer button:not(.toggle)', '#site-footer .button', '#site-footer .faux-button', '#site-footer .wp-block-button__link', '#site-footer .wp-block-file__button', '#site-footer input[type="button"]', '#site-footer input[type="reset"]', '#site-footer input[type="submit"]' ),
),
'background' => array(
'color' => array( '.social-icons a', 'body:not(.overlay-header) .primary-menu ul', '.header-footer-group button', '.header-footer-group .button', '.header-footer-group .faux-button', '.header-footer-group .wp-block-button:not(.is-style-outline) .wp-block-button__link', '.header-footer-group .wp-block-file__button', '.header-footer-group input[type="button"]', '.header-footer-group input[type="reset"]', '.header-footer-group input[type="submit"]' ),
'background-color' => array( '#site-header', '.footer-nav-widgets-wrapper', '#site-footer', '.menu-modal', '.menu-modal-inner', '.search-modal-inner', '.archive-header', '.singular .entry-header', '.singular .featured-media:before', '.wp-block-pullquote:before' ),
),
'text' => array(
'color' => array( '.header-footer-group', 'body:not(.overlay-header) #site-header .toggle', '.menu-modal .toggle' ),
'background-color' => array( 'body:not(.overlay-header) .primary-menu ul' ),
'border-bottom-color' => array( 'body:not(.overlay-header) .primary-menu > li > ul:after' ),
'border-left-color' => array( 'body:not(.overlay-header) .primary-menu ul ul:after' ),
),
'secondary' => array(
'color' => array( '.site-description', 'body:not(.overlay-header) .toggle-inner .toggle-text', '.widget .post-date', '.widget .rss-date', '.widget_archive li', '.widget_categories li', '.widget cite', '.widget_pages li', '.widget_meta li', '.widget_nav_menu li', '.powered-by-wordpress', '.footer-credits .privacy-policy', '.to-the-top', '.singular .entry-header .post-meta', '.singular:not(.overlay-header) .entry-header .post-meta a' ),
),
'borders' => array(
'border-color' => array( '.header-footer-group pre', '.header-footer-group fieldset', '.header-footer-group input', '.header-footer-group textarea', '.header-footer-group table', '.header-footer-group table *', '.footer-nav-widgets-wrapper', '#site-footer', '.menu-modal nav *', '.footer-widgets-outer-wrapper', '.footer-top' ),
'background-color' => array( '.header-footer-group table caption', 'body:not(.overlay-header) .header-inner .toggle-wrapper::before' ),
),
),
);
/**
* Filters Twenty Twenty theme elements.
*
* @since Twenty Twenty 1.0
*
* @param array Array of elements.
*/
return apply_filters( 'twentytwenty_get_elements_array', $elements );
}
function forzar_login_en_paginas_especificas() {
// Lista de IDs de páginas que quieres proteger
$paginas_protegidas = array(16, 19, 9, 17, 24, 2, 3, 20, 14, 18, 21, 22, 131, 181, 192, 471); // Reemplaza con los IDs de tus páginas
if ( is_page($paginas_protegidas) && !is_user_logged_in() ) {
auth_redirect(); // Redirige al formulario de login
}
}
add_action('template_redirect', 'forzar_login_en_paginas_especificas');
add_action('user_register', 'crear_usuario_moodle_desde_wp', 10, 1);
function crear_usuario_moodle_desde_wp($user_id) {
$user = get_userdata($user_id);
// Solo aplicar a usuarios con rol 'subscriber'
if (!in_array('subscriber', $user->roles)) {
return;
}
// Preparar datos para Moodle
$moodle_user = array(
'username' => $user->user_login,
'password' => 'TempPass123!', // requerido por la API aunque uses OAuth2
'firstname' => $user->first_name ?: 'Nombre',
'lastname' => $user->last_name ?: 'Apellido',
'email' => $user->user_email,
'auth' => 'oauth2', // importante para que no use login interno
);
// Configuración del Web Service
$token = '0dcead7cde2e96bd46e4672baa13179b'; // Reemplazar
$domainname = 'https://audentes.sumar.com.py/cursos'; // Reemplazar con tu URL Moodle
$functionname = 'core_user_create_users';
$params = array('users' => array($moodle_user));
$serverurl = $domainname . '/webservice/rest/server.php'
. '?wstoken=' . $token
. '&wsfunction=' . $functionname
. '&moodlewsrestformat=json';
// Enviar la solicitud
$response = wp_remote_post($serverurl, array(
'body' => $params,
));
// Registro en el log para seguimiento (opcional)
if (is_wp_error($response)) {
error_log('Error creando usuario en Moodle: ' . $response->get_error_message());
} else {
$body = wp_remote_retrieve_body($response);
error_log('Respuesta de Moodle: ' . $body);
}
}
// =======================
// Guardar confirmación de lectura al enviar WPForms
// =======================
add_action( 'wpforms_process_complete', function( $fields, $entry, $form_data, $entry_id ) {
// Ajusta el ID de tu formulario
if ( absint( $form_data['id'] ) === 395 && is_user_logged_in() ) {
foreach ( $fields as $field ) {
// Ajusta el valor exacto de tu radio/checkbox
if ( $field['value'] === 'Sí, confirmo' ) {
update_user_meta( get_current_user_id(), 'documento_confirmado', 'true' );
}
}
}
}, 10, 4 );
// =======================
// Pasar flag al JS para saber si ya confirmó
// =======================
add_action( 'wp_enqueue_scripts', function() {
if ( is_user_logged_in() ) {
$user_id = get_current_user_id();
$confirmado = get_user_meta( $user_id, 'documento_confirmado', true ) === 'true' ? '1' : '0';
wp_add_inline_script(
'jquery-core',
'window.usuarioConfirmado = ' . $confirmado . ';',
'before'
);
}
});
add_action('init', function() {
if ( isset($_GET['sso_logout']) && $_GET['sso_logout'] === '1' ) {
// opcional: proteger con clave (ver más abajo)
wp_logout(); // borra cookies y dispara hooks
// redirigir donde quieras
wp_safe_redirect( 'https://audentes.sumar.com.py/' );
exit;
}
});
add_action('clear_auth_cookie', function () {
// Desloguea WP y luego manda a Moodle sin preguntar
wp_redirect('https://audentes.sumar.com.py/cursos/login/logout.php?wordpress=true');
exit;
});
function boton_organigrama_usuario() {
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
$user_id = $current_user->ID;
// 👇 Corrige la URL con el slug correcto de tu página
$organigrama_url = site_url('/index.php/organigrama-3/?node_id=' . $user_id);
return '<a href="' . esc_url($organigrama_url) . '" class="btn-organigrama" style="display:inline-block;padding:10px 20px;background:#8b0000;color:#fff;font-weight:bold;border-radius:6px;text-decoration:none;">Ver mi organigrama</a>';
} else {
return '<p>Debes iniciar sesión para ver tu organigrama.</p>';
}
}
add_shortcode('boton_organigrama', 'boton_organigrama_usuario');
// === Shortcode perfil de usuario ===
function perfil_usuario_shortcode() {
if (!is_user_logged_in()) {
return '<p>Debes iniciar sesión para ver tu perfil.</p>';
}
$current_user = wp_get_current_user();
$avatar = get_avatar($current_user->ID, 120);
// Intentamos traer los campos con y sin prefijo
$cargo = get_user_meta($current_user->ID, 'Cargo', true);
if (empty($cargo)) {
$cargo = get_user_meta($current_user->ID, 'ag_user_Cargo', true);
}
$whatsapp = get_user_meta($current_user->ID, 'WhatsApp', true);
if (empty($whatsapp)) {
$whatsapp = get_user_meta($current_user->ID, 'ag_user_WhatsApp', true);
}
// URL dinámica al organigrama (lleva al nodo del usuario)
$organigrama_url = site_url('/index.php/organigrama-3/?node_id=' . $current_user->ID);
ob_start(); ?>
<div class="user-profile-card">
<div class="user-avatar"><?php echo $avatar; ?></div>
<h2 class="user-name"><?php echo esc_html($current_user->display_name); ?></h2>
<p class="user-job"><?php echo esc_html($cargo); ?></p>
<div class="profile-actions">
<a href="<?php echo esc_url(site_url('/index.php/account/')); ?>" class="btn">✏️ Editar Perfil</a>
</div>
<div class="user-info">
<h3>Información Personal</h3>
<p><strong>Nombre:</strong> <?php echo esc_html($current_user->display_name); ?></p>
<p><strong>Email:</strong> <?php echo esc_html($current_user->user_email); ?></p>
<h3>Contacto</h3>
<p><strong>WhatsApp:</strong> <?php echo esc_html($whatsapp); ?></p>
<h3>Detalles del Trabajo</h3>
<p><strong>Cargo:</strong> <?php echo esc_html($cargo); ?></p>
</div>
</div>
<?php
return ob_get_clean();
}
add_shortcode('perfil_usuario', 'perfil_usuario_shortcode');
// === Script FUERTE para organigrama ===
function organigrama_focus_script() {
if (is_page('organigrama-3')) { ?>
<script>
document.addEventListener("DOMContentLoaded", function() {
const params = new URLSearchParams(window.location.search);
const nodeId = params.get("node_id");
if (!nodeId) return;
const container = document.querySelector("#inteorch-container");
if (!container) return;
setTimeout(() => {
// 1. Ocultar TODO
container.querySelectorAll(".children-container").forEach(ch => {
ch.style.setProperty("display", "none", "important");
});
// 2. Buscar el nodo del usuario
const userNode = container.querySelector(`.inteorch-node[data-employee-id="${nodeId}"]`);
if (userNode) {
const userContainer = userNode.closest(".inteorch-node-container");
if (userContainer) {
userContainer.style.display = "block";
userNode.classList.add("highlight-node");
// Buscar jefe inmediato (sube un nivel)
const parentChildrenWrapper = userContainer.closest(".children-nodes");
if (parentChildrenWrapper) {
const parentContainer = parentChildrenWrapper.closest(".inteorch-node-container");
if (parentContainer) {
parentContainer.style.display = "block";
parentContainer.querySelector(".inteorch-node").classList.add("highlight-boss");
// Mostrar pares
parentChildrenWrapper.querySelectorAll(":scope > .child-wrapper > .inteorch-node-container").forEach(sibling => {
sibling.style.display = "block";
// Mantener cerrados sus subordinados
const siblingChildren = sibling.querySelector(":scope > .children-container");
if (siblingChildren) {
siblingChildren.style.setProperty("display", "none", "important");
}
});
}
}
}
}
// 3. Hacer clic para expandir/cerrar subordinados
container.addEventListener("click", function(e) {
const clicked = e.target.closest(".inteorch-node");
if (!clicked) return;
const parentC = clicked.closest(".inteorch-node-container");
if (!parentC) return;
const directChildren = parentC.querySelector(":scope > .children-container");
if (directChildren) {
const isVisible = directChildren.style.display === "block";
directChildren.style.setProperty("display", isVisible ? "none" : "block", "important");
}
});
}, 1200); // ⏳ espera a que cargue el organigrama
});
</script>
<style>
.highlight-node {
outline: 3px solid #0073aa;
border-radius: 6px;
}
.highlight-boss {
outline: 2px dashed #ff6600;
border-radius: 6px;
}
</style>
<?php }
}
add_action('wp_footer', 'organigrama_focus_script');
// "Ver mi perfil" y "Página Principal" en el menú del admin bar
add_action( 'admin_bar_menu', function( $wp_admin_bar ) {
if ( ! is_user_logged_in() ) return;
// Eliminar "Editar perfil"
$wp_admin_bar->remove_node('edit-profile');
// Agregar "Ver mi perfil"
$wp_admin_bar->add_node( array(
'id' => 'ver-mi-perfil',
'parent' => 'user-actions',
'title' => '<span style="font-size:14px; font-weight:bold;">🔗 Ver mi perfil</span>',
'href' => 'https://audentes.sumar.com.py/index.php/perfil/',
'meta' => array( 'class' => 'ab-item ver-mi-perfil' )
) );
// Agregar "Página Principal"
$wp_admin_bar->add_node( array(
'id' => 'pagina-principal',
'parent' => 'user-actions',
'title' => '<span style="font-size:14px; font-weight:bold;">🏠 Página Principal</span>',
'href' => 'https://audentes.sumar.com.py',
'meta' => array( 'class' => 'ab-item pagina-principal' )
) );
}, 1 );
// Opcional: CSS para hacerlo aún más grande
add_action( 'wp_head', function(){ ?>
<style>
#wp-admin-bar-ver-mi-perfil > .ab-item {
font-size: 15px !important;
font-weight: bold !important;
color: #00b3ff !important;
}
#wp-admin-bar-ver-mi-perfil > .ab-item:hover {
color: #0073aa !important;
}
</style>
<?php });
// Shortcode que genera el organigrama y centra la rama del usuario logueado
function shortcode_organigrama_mi() {
if ( ! is_user_logged_in() ) {
return '<p>⚠️ Debes iniciar sesión para ver tu organigrama.</p>';
}
$user_id = get_current_user_id();
// Contenido del organigrama general (del plugin original)
$content = do_shortcode('[organigrama_general]');
// HTML del contenedor + botones de zoom
$output = '<div class="organigrama-wrapper" style="width:100vw; height:100vh; overflow:hidden; display:flex; flex-direction:column; align-items:center;">';
$output .= ' <div class="organigrama-controls" style="margin-bottom:10px;">';
$output .= ' <button id="zoomOut" style="background:#444;color:white;border:none;padding:6px 12px;margin:0 5px;border-radius:5px;cursor:pointer;font-size:16px;">➖</button>';
$output .= ' <button id="zoomIn" style="background:#444;color:white;border:none;padding:6px 12px;margin:0 5px;border-radius:5px;cursor:pointer;font-size:16px;">➕</button>';
$output .= ' </div>';
$output .= ' <div id="organigrama-container" style="width:100%; height:100%; overflow:auto; position:relative;">';
$output .= ' <div id="zoom-wrapper" style="transform-origin:center center;">';
$output .= $content;
$output .= ' </div>';
$output .= ' </div>';
$output .= '</div>';
// Script JS
$output .= <<<HTML
<script>
document.addEventListener("DOMContentLoaded", function () {
const myUserId = {$user_id};
const container = document.getElementById("organigrama-container");
const wrapper = document.getElementById("zoom-wrapper");
let escala = 1;
function aplicarEscala() {
wrapper.style.transform = `scale(\${escala})`;
wrapper.style.transformOrigin = "center center";
}
// --- Ajusta el organigrama completo ---
function autoFit() {
const bounds = wrapper.getBoundingClientRect();
const scaleX = container.clientWidth / bounds.width;
const scaleY = container.clientHeight / bounds.height;
escala = Math.min(scaleX, scaleY) * 0.9; // margen 10%
aplicarEscala();
}
// Botones zoom
document.getElementById("zoomIn").addEventListener("click", function () {
escala += 0.1;
aplicarEscala();
});
document.getElementById("zoomOut").addEventListener("click", function () {
escala = Math.max(0.2, escala - 0.1);
aplicarEscala();
});
// --- Centrar en el nodo del usuario logueado ---
function focusOnNode() {
if (!myUserId) return false;
let targetNode = wrapper.querySelector(`[data-user-id="\${myUserId}"]`);
if (!targetNode) {
targetNode = wrapper.querySelector(`[data-employee-id="\${myUserId}"]`);
}
if (targetNode) {
autoFit();
// Rectángulos después del ajuste
const rect = targetNode.getBoundingClientRect();
const wrapperRect = wrapper.getBoundingClientRect();
// Coordenadas relativas al wrapper
const nodeX = rect.left - wrapperRect.left + rect.width / 2;
const nodeY = rect.top - wrapperRect.top + rect.height / 2;
// Ajustar scroll para que el nodo quede al centro de la pantalla
const scrollX = nodeX * escala - window.innerWidth / 2;
const scrollY = nodeY * escala - window.innerHeight / 2;
container.scrollTo({
top: scrollY,
left: scrollX,
behavior: "smooth"
});
// Resaltar nodo
targetNode.classList.add("highlight-node");
setTimeout(() => targetNode.classList.remove("highlight-node"), 4000);
console.log("✅ Nodo centrado en pantalla:", myUserId);
return true;
}
return false;
}
// Intentar varias veces por si tarda en renderizar
let attempts = 0;
const interval = setInterval(function() {
if (focusOnNode() || attempts > 20) {
clearInterval(interval);
if (attempts > 20) {
console.warn("⚠️ No encontré el nodo con id =", myUserId);
}
}
attempts++;
}, 500);
});
</script>
<style>
.highlight-node {
transition: box-shadow 0.3s, border 0.3s, background 0.3s;
box-shadow: 0 0 15px rgba(200,0,0,0.6) !important;
border: 2px solid #c00 !important;
border-radius: 8px !important;
}
</style>
HTML;
return $output;
}
add_shortcode('organigrama_mi', 'shortcode_organigrama_mi');
// Ocultar "Audentes Conecta" y el logo de WordPress en la admin bar
add_action( 'admin_bar_menu', function( $wp_admin_bar ) {
if ( ! is_user_logged_in() ) return;
// Elimina el nombre del sitio
$wp_admin_bar->remove_node( 'site-name' );
// Elimina el logo de WordPress (menú con enlaces de WP.org, soporte, etc.)
$wp_admin_bar->remove_node( 'wp-logo' );
}, 999 );
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists