<commit_before><?php

namespace GetOlympus\Zeus\Helpers\Controller;

use GetOlympus\Zeus\Helpers\Controller\Helpers;
use GetOlympus\Zeus\Helpers\Controller\HelpersClean;

/**
 * Clean Features helper
 *
 * @package    OlympusZeusCore
 * @subpackage Helpers\Controller
 * @author     <NAME> <<EMAIL>>
 * @since      0.0.49
 *
 */

class HelpersCleanFeatures extends HelpersClean
{
    /**
     * @var array
     */
    protected $available = [
        'admin_bar',          // Remove admin bar on frontend pages
        'body_class',         // Remove unecessary details in `body_class()` method
        'capital_p_dangit',   // Remove the filter that converts "Wordpress" to "WordPress"
        'comment_autolinks',  // Remove auto-converted URLs in comments to avoid spammers
        'comments_reply',     // Loads the comment-reply JS file only when needed
        'dashicons',          // Remove Dashicons from admin bar for non-logged users
        'embeds',             // Remove embeds integration
        'embeds_script',      // Remove embeds script integration
        'emojicons',          // Remove emojicons integration
        'gravatar_queries',   // Remove Gravatar query strings
        'medium_large_size',  // Prevents WordPress from generating the medium_large 768px thumbnail size of image uploads
        'pdf_thumbnails',     // Remove PDF thumbnails generator
        'self_pingback',      // Remove self pingbacks
        'slow_heartbeat',     // Changes Heartbeat post calls from 15 to 60 seconds for less CPU usage
        'version',            // Remove WP Version (?ver=) from scripts and styles
    ];

    /**
     * Add all usefull WP filters and hooks.
     *
     * @param  array   $args
     */
    public function init($args)
    {
        if (empty($args)) {
            return;
        }

        // Special case
        if (is_bool($args) && $args) {
            $args = $this->available;
        }

        // Iterate on all
        foreach ($args as $key) {
            $key = strtolower($key);

            if (!in_array($key, $this->available)) {
                continue;
            }

            $key = str_replace('_', '-', $key);

            $function = Helpers::toFunctionFormat($key);
            $function = 'feature'.ucfirst($function);
            $this->$function();
        }
    }

    /**
     * Remove admin bar on frontend pages
     */
    public function featureAdminBar()
    {
        add_filter('show_admin_bar', '__return_false');
        remove_action('init', 'wp_admin_bar_init');
    }

    /**
     * Remove unecessary details in `body_class()` method
     */
    public function featureBodyClass()
    {
        add_filter('body_class', function ($classes, $class) {
            // Author pages
            if (isset($classes['author'])) {
                // Get author
                if (!$name = get_query_var('author_name')) {
                    $author = get_userdata(get_query_var('author'));
                } else {
                    $author = get_user_by('slug', $name);
                }

                // Get data to remove
                $removed[] = 'author-'.$author->ID;
                $removed[] = 'author-'.$author->user_nicename;

                // Remove classes
                $classes = array_diff($classes, $removed);
            }

            // Single pages
            if (isset($classes['single'])) {
                // Get post details
                $post = get_queried_object();
                $pid = get_queried_object_id();

                // Check post type
                if (isset($post->post_type)) {
                    $removed[] = 'single-'.sanitize_html_class($post->post_type, $pid);
                    $removed[] = 'postid-'.$pid;

                    // Remove classes
                    $classes = array_diff($classes, $removed);
                }
            }

            // Archive pages
            if (isset($classes['category']) || isset($classes['tag']) || isset($classes['tax'])) {
                // Get object details
                $obj = get_queried_object();

                // Check object ID
                if (isset($obj->term_id)) {
                    // Get class
                    $obj_class = sanitize_html_class($obj->slug, $obj->term_id);
                    $obj_class = is_numeric($obj_class) || !trim($obj_class, '-') ? 
                        $obj->term_id : 
                        $obj_class;

                    // Remove details
                    if (isset($classes['category'])) {
                        $removed[] = 'category-'.$obj_class;
                        $removed[] = 'category-'.$obj->term_id;
                    }
                    else if (isset($classes['tag'])) {
                        $removed[] = 'tag-'.$obj_class;
                        $removed[] = 'tag-'.$obj->term_id;
                    }
                    else if (isset($classes['tax'])) {
                        $removed[] = 'tax-'.sanitize_html_class($obj->taxonomy);
                        $removed[] = 'term-'.$obj_class;
                        $removed[] = 'term-'.$obj->term_id;
                    }

                    // Remove classes
                    $classes = array_diff($classes, $removed);
                }
            }

            // Return all classes
            return array_merge($classes, (array)$class);
        }, 10, 2);
    }

    /**
     * Remove the filter that converts "Wordpress" to "WordPress"
     */
    public function featureCapitalPDangit()
    {
        foreach (['comment_text', 'the_content', 'the_title', 'wp_title'] as $filter) {
            $priority = has_filter($filter, 'capital_P_dangit');

            if (false !== $priority) {
                remove_filter($filter, 'capital_P_dangit', $priority);
            }
        }<commit_msg>CodeFactir check<commit_after><?php

namespace GetOlympus\Zeus\Helpers\Controller;

use GetOlympus\Zeus\Helpers\Controller\Helpers;
use GetOlympus\Zeus\Helpers\Controller\HelpersClean;

/**
 * Clean Features helper
 *
 * @package    OlympusZeusCore
 * @subpackage Helpers\Controller
 * @author     <NAME> <<EMAIL>>
 * @since      0.0.49
 *
 */

class HelpersCleanFeatures extends HelpersClean
{
    /**
     * @var array
     */
    protected $available = [
        'admin_bar',          // Remove admin bar on frontend pages
        'body_class',         // Remove unecessary details in `body_class()` method
        'capital_p_dangit',   // Remove the filter that converts "Wordpress" to "WordPress"
        'comment_autolinks',  // Remove auto-converted URLs in comments to avoid spammers
        'comments_reply',     // Loads the comment-reply JS file only when needed
        'dashicons',          // Remove Dashicons from admin bar for non-logged users
        'embeds',             // Remove embeds integration
        'embeds_script',      // Remove embeds script integration
        'emojicons',          // Remove emojicons integration
        'gravatar_queries',   // Remove Gravatar query strings
        'medium_large_size',  // Prevents WordPress from generating the medium_large 768px thumbnail size of image uploads
        'pdf_thumbnails',     // Remove PDF thumbnails generator
        'self_pingback',      // Remove self pingbacks
        'slow_heartbeat',     // Changes Heartbeat post calls from 15 to 60 seconds for less CPU usage
        'version',            // Remove WP Version (?ver=) from scripts and styles
    ];

    /**
     * Add all usefull WP filters and hooks.
     *
     * @param  array   $args
     */
    public function init($args)
    {
        if (empty($args)) {
            return;
        }

        // Special case
        if (is_bool($args) && $args) {
            $args = $this->available;
        }

        // Iterate on all
        foreach ($args as $key) {
            $key = strtolower($key);

            if (!in_array($key, $this->available)) {
                continue;
            }

            $key = str_replace('_', '-', $key);

            $function = Helpers::toFunctionFormat($key);
            $function = 'feature'.ucfirst($function);
            $this->$function();
        }
    }

    /**
     * Remove admin bar on frontend pages
     */
    public function featureAdminBar()
    {
        add_filter('show_admin_bar', '__return_false');
        remove_action('init', 'wp_admin_bar_init');
    }

    /**
     * Remove unecessary details in `body_class()` method
     */
    public function featureBodyClass()
    {
        add_filter('body_class', function ($classes, $class) {
            // Author pages
            if (isset($classes['author'])) {
                // Get author
                if (!$name = get_query_var('author_name')) {
                    $author = get_userdata(get_query_var('author'));
                } else {
                    $author = get_user_by('slug', $name);
                }

                // Get data to remove
                $removed[] = 'author-'.$author->ID;
                $removed[] = 'author-'.$author->user_nicename;

                // Remove classes
                $classes = array_diff($classes, $removed);
            }

            // Single pages
            if (isset($classes['single'])) {
                // Get post details
                $post = get_queried_object();
                $pid = get_queried_object_id();

                // Check post type
                if (isset($post->post_type)) {
                    $removed[] = 'single-'.sanitize_html_class($post->post_type, $pid);
                    $removed[] = 'postid-'.$pid;

                    // Remove classes
                    $classes = array_diff($classes, $removed);
                }
            }

            // Archive pages
            if (isset($classes['category']) || isset($classes['tag']) || isset($classes['tax'])) {
                // Get object details
                $obj = get_queried_object();

                // Check object ID
                if (isset($obj->term_id)) {
                    // Get class
                    $obj_class = sanitize_html_class($obj->slug, $obj->term_id);
                    $obj_class = is_numeric($obj_class) || !trim($obj_class, '-') ? $obj->term_id : $obj_class;

                    // Remove details
                    if (isset($classes['category'])) {
                        $removed[] = 'category-'.$obj_class;
                        $removed[] = 'category-'.$obj->term_id;
                    } else if (isset($classes['tag'])) {
                        $removed[] = 'tag-'.$obj_class;
                        $removed[] = 'tag-'.$obj->term_id;
                    } else if (isset($classes['tax'])) {
                        $removed[] = 'tax-'.sanitize_html_class($obj->taxonomy);
                        $removed[] = 'term-'.$obj_class;
                        $removed[] = 'term-'.$obj->term_id;
                    }

                    // Remove classes
                    $classes = array_diff($classes, $removed);
                }
            }

            // Return all classes
            return array_merge($classes, (array)$class);
        }, 10, 2);
    }

    /**
     * Remove the filter that converts "Wordpress" to "WordPress"
     */
    public function featureCapitalPDangit()
    {
        foreach (['comment_text', 'the_content', 'the_title', 'wp_title'] as $filter) {
            $priority = has_filter($filter, 'capital_P_dangit');

            if (false !== $priority) {
                remove_filter($filter, 'capital_P_dangit', $priority);
            }
        }
{'fraction_non_alphanumeric': 0.1272492466637968, 'fraction_numerical': 0.002410675850193715, 'mean_word_length': 1.5406824146981628, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4934807', 'n_tokens_mistral': 3186, 'n_tokens_neox': 3060, 'n_words': 709}