<commit_before><?php

namespace Gnowland\JetFuel\Module;

use Gnowland\JetFuel\Instance;

/**
 * Module: force-excerpt-field
 *
 * Force visibility of excerpt on edit screen
 *
 * @example jetfuel('force-excerpt-field', $post_type(string|array));
 *
 * @link https://developer.wordpress.org/reference/hooks/hidden_meta_boxes
 *
 * @package WordPress
 * @subpackage WPJetFuel
 * @since 0.2.0
 */
class ForceExcerptField extends Instance {
    protected $options;

    public function run() {
        $this->setup()->hook();
    }

    protected function setup() {
        $this->options = ['post', 'page'];
        $this->setDefaultConfig(['all']);
        return $this;
    }

    protected function hook() {
        // Force display of excerpt field
        add_action('hidden_meta_boxes', [$this, 'forceExcerptField'], 10, 2);
        // Force enable excerpt for Page post type
        if (in_array('all', $this->config) || in_array('page', $this->config)) {
            if (is_admin() && current_user_can('edit_posts')) {
                add_action('init', [$this, 'enableExcerptForPages']);
            }
        }
    }

    function forceExcerptField( $hidden, $screen ) {
        if (in_array('all', $this->config)) {
            if (in_array($screen->id, $this->options)) {
                if(($key = array_search('postexcerpt', $hidden)) !== false) {
                    unset($hidden[$key]);
                }
            }
        } elseif (in_array($screen->id, $this->config)) {
            if(($key = array_search('postexcerpt', $hidden)) !== false) {
                unset($hidden[$key]);
            }
        }
        return $hidden;
    }

    function enableExcerptForPages() {<commit_msg>add_post_type_support should be fired outside admin too<commit_after><?php

namespace Gnowland\JetFuel\Module;

use Gnowland\JetFuel\Instance;

/**
 * Module: force-excerpt-field
 *
 * Force visibility of excerpt on edit screen
 *
 * @example jetfuel('force-excerpt-field', $post_type(string|array));
 *
 * @link https://developer.wordpress.org/reference/hooks/hidden_meta_boxes
 * @link https://developer.wordpress.org/reference/hooks/init
 *
 * @package WordPress
 * @subpackage WPJetFuel
 * @since 0.2.0
 */
class ForceExcerptField extends Instance {
    protected $options;

    public function run() {
        $this->setup()->hook();
    }

    protected function setup() {
        $this->options = ['post', 'page'];
        $this->setDefaultConfig(['all']);
        return $this;
    }

    protected function hook() {
        // Force display of excerpt field
        add_action('hidden_meta_boxes', [$this, 'forceExcerptField'], 10, 2);
        // Force enable excerpt for Page post type
        if (in_array('all', $this->config) || in_array('page', $this->config)) {
            add_action('init', [$this, 'enableExcerptForPages']);
        }
    }

    function forceExcerptField( $hidden, $screen ) {
        if (in_array('all', $this->config)) {
            if (in_array($screen->id, $this->options)) {
                if(($key = array_search('postexcerpt', $hidden)) !== false) {
                    unset($hidden[$key]);
                }
            }
        } elseif (in_array($screen->id, $this->config)) {
            if(($key = array_search('postexcerpt', $hidden)) !== false) {
                unset($hidden[$key]);
            }
        }
        return $hidden;
    }

    function enableExcerptForPages() {
{'fraction_non_alphanumeric': 0.15523255813953488, 'fraction_numerical': 0.0034883720930232558, 'mean_word_length': 2.4827935222672064, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 25, 'https://': 3, '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': '2865174', 'n_tokens_mistral': 1066, 'n_tokens_neox': 1003, 'n_words': 209}