ClassSetup.php 7.45 KB
Newer Older
alchemyunited's avatar
alchemyunited committed
1 2
<?php

3
namespace WPezThemeChildBasic\App\Setup;
alchemyunited's avatar
alchemyunited committed
4

alchemyunited's avatar
alchemyunited committed
5 6
use WPezThemeChildBasic\App\Core\HooksRegister\ClassHooksRegister;
use WPezThemeChildBasic\App\Core\SetupImages\ClassSetupImages;
7
use WPezThemeChildBasic\App\Setup\Styles\ClassStyles;
alchemyunited's avatar
alchemyunited committed
8 9 10

class ClassSetup {

11 12 13 14 15 16 17
    protected $_new_reg_hooks;

    protected $_arr_actions;

    protected $_arr_filters;


alchemyunited's avatar
alchemyunited committed
18 19
    public function __construct() {

20 21
        $this->setPropertyDefaults();

alchemyunited's avatar
alchemyunited committed
22 23 24
        $this->images( true );

        $this->styles();
25 26 27 28 29 30 31

        // this should be last
        $this->registerHooks();
    }

    protected function setPropertyDefaults() {

alchemyunited's avatar
alchemyunited committed
32
        $this->_new_reg_hooks = new ClassHooksRegister();
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
        $this->_arr_actions   = [];
        $this->_arr_filters   = [];
    }

    /**
     * After gathering (below) the arr_actions and arr_filter, it's time to
     * make some RegisterHook magic
     */
    protected function registerHooks() {

        $this->_new_reg_hooks->loadActions( $this->_arr_actions );

        $this->_new_reg_hooks->loadFilters( $this->_arr_filters );

        $this->_new_reg_hooks->doRegister();

alchemyunited's avatar
alchemyunited committed
49 50 51 52 53 54 55
    }


    protected function images( $bool = true ) {

        if ( $bool !== true ) {
            return;
56
        };
alchemyunited's avatar
alchemyunited committed
57
        // what
alchemyunited's avatar
alchemyunited committed
58
        $new_images = new ClassSetupImages();
alchemyunited's avatar
alchemyunited committed
59 60 61 62 63 64

        $arr_ais = [];

        /**
         * Note: These sizes are based on Bootstrap 4 breakpoints
         */
alchemyunited's avatar
alchemyunited committed
65
        $arr_ais[] = [
alchemyunited's avatar
alchemyunited committed
66
            'active'       => 'true',
alchemyunited's avatar
alchemyunited committed
67
            'name'         => 'wpez_xs',
alchemyunited's avatar
alchemyunited committed
68 69 70
            'width'        => 576,
            'height'       => 576,
            'crop'         => false,
alchemyunited's avatar
alchemyunited committed
71
            'names_choose' => [
alchemyunited's avatar
alchemyunited committed
72 73 74 75 76
                'active' => true,
                'option' => 'XS',
            ]
        ];

alchemyunited's avatar
alchemyunited committed
77
        $arr_ais[] = [
alchemyunited's avatar
alchemyunited committed
78
            'active'       => true,
alchemyunited's avatar
alchemyunited committed
79
            'name'         => 'wpez_sm',
alchemyunited's avatar
alchemyunited committed
80 81 82
            'width'        => 768,
            'height'       => 768,
            'crop'         => false,
alchemyunited's avatar
alchemyunited committed
83
            'names_choose' => [
alchemyunited's avatar
alchemyunited committed
84 85 86 87 88
                'active' => true,
                'option' => 'SM ',
            ]
        ];

alchemyunited's avatar
alchemyunited committed
89
        $arr_ais[] = [
alchemyunited's avatar
alchemyunited committed
90
            'active'       => true,
alchemyunited's avatar
alchemyunited committed
91
            'name'         => 'wpez_md',
alchemyunited's avatar
alchemyunited committed
92 93 94
            'width'        => 992,
            'height'       => 992,
            'crop'         => false,
alchemyunited's avatar
alchemyunited committed
95
            'names_choose' => [
alchemyunited's avatar
alchemyunited committed
96 97 98 99 100
                'active' => true,
                'option' => 'MD',
            ]
        ];

alchemyunited's avatar
alchemyunited committed
101
        $arr_ais[] = [
alchemyunited's avatar
alchemyunited committed
102
            'active'       => true,
alchemyunited's avatar
alchemyunited committed
103
            'name'         => 'wpez_lg',
alchemyunited's avatar
alchemyunited committed
104 105 106
            'width'        => 1200,
            'height'       => 1200,
            'crop'         => false,
alchemyunited's avatar
alchemyunited committed
107
            'names_choose' => [
alchemyunited's avatar
alchemyunited committed
108 109 110 111 112
                'active' => true,
                'option' => 'LG',
            ]
        ];

alchemyunited's avatar
alchemyunited committed
113
        $arr_ais[] = [
alchemyunited's avatar
alchemyunited committed
114
            'active'       => true,
alchemyunited's avatar
alchemyunited committed
115
            'name'         => 'wpez_xl',
alchemyunited's avatar
alchemyunited committed
116 117 118
            'width'        => 1500,
            'height'       => 1500,
            'crop'         => false,
alchemyunited's avatar
alchemyunited committed
119 120
            'names_choose' => [
                'active' => true,
alchemyunited's avatar
alchemyunited committed
121 122 123 124 125 126 127 128 129
                'option' => 'XL',
            ]
        ];

        // - jpgQualityFilter
        // - https://developer.wordpress.org/reference/hooks/jpeg_quality-2/
        // - https://developer.wordpress.org/reference/hooks/wp_editor_set_quality/
        /*
        $int_jpg_quality = 82;
130
        $new_images->setJpgQuality($int_jpg_quality);
alchemyunited's avatar
alchemyunited committed
131 132
        */

133 134

        // add_filter( 'jpg_quality', [ $new_images, 'jpgQualityFilter' ] );
alchemyunited's avatar
alchemyunited committed
135 136
        /*
        $this->_arr_filters[] = [
137

alchemyunited's avatar
alchemyunited committed
138
            'active'    => true,
139 140 141 142 143 144
            'hook'      => 'jpg_quality',
            'component' => $new_images,
            'callback'  => 'jpgQualityFilter'
        ];

        // add_filter( 'wp_editor_set_quality', [ $new_images, ' jpgQualityFilter' ] );
alchemyunited's avatar
alchemyunited committed
145
        $this->_arr_filters[] = [
146

alchemyunited's avatar
alchemyunited committed
147
            'active'    => true,
148 149 150 151
            'hook'      => 'wp_editor_set_quality',
            'component' => $new_images,
            'callback'  => 'jpgQualityFilter'
        ];
alchemyunited's avatar
alchemyunited committed
152
        */
153 154

        $new_images->setImageSizes( $arr_ais );
alchemyunited's avatar
alchemyunited committed
155

alchemyunited's avatar
alchemyunited committed
156

alchemyunited's avatar
alchemyunited committed
157 158 159
        // - imageSizeNamesChooseFilter
        // - Perhaps you want to unset() and/or rename the $sizes? This is your chance :)
        // - note: if you don't return and array[] your changes will be ignored. $sizes has to be an []
160

alchemyunited's avatar
alchemyunited committed
161 162 163 164 165 166
        // add_filter('imageSizeNamesChooseFilterCustomizeSizes', function($sizes){ return $sizes; });

        // - imageSizeNamesChooseFilter
        // - *temporarily set the content_width for the names_choose  filter
        // - 0 (zero) tells WP "ignore your content_width check for the names_choose"
        // ref: https://codex.wordpress.org/Content_Width
alchemyunited's avatar
alchemyunited committed
167 168 169

        // $new_images->setContentWidth();

alchemyunited's avatar
alchemyunited committed
170 171 172

        // - imageSizeNamesChooseFilter
        // - true will compare the image width to the content_width and stop names_choose for images with widths wider than the content_width
alchemyunited's avatar
alchemyunited committed
173 174 175 176

         //$bool_width_compare = true;
         // $new_images->setContentWidthCompare($bool_width_compare);

alchemyunited's avatar
alchemyunited committed
177 178 179 180 181

        // - within the imageSizeNamesChooseFilter
        // - when adding these new image sizes to the names_choose $sizes array: 'before', 'after' or 'replace'
        /*
        $str_add_how = 'after';
182
        $new_images->setImageSizeNamesChooseAddWhere($str_add_how);
alchemyunited's avatar
alchemyunited committed
183 184 185 186 187 188 189 190
        */

        // - setPostThumbnailSize
        // - use set_post_thumbnail_size() by using the name of one of your custom image sizes
        // - note: the name needs to be one of the custom image sizes (above), and not one of the native WP image sizes
        // - ref: https://developer.wordpress.org/reference/functions/set_post_thumbnail_size/
        /*
        $str_img_size_name = 'TODO';
191
        $new_images->setPostThumbnailSizeName($str_img_size_name);
alchemyunited's avatar
alchemyunited committed
192 193

        // $mix_crop = false; // bool or array
194
        // $new_images->setPostThumbnailSizeCrop($mix_crop);
alchemyunited's avatar
alchemyunited committed
195 196 197

        */

198
        // add_action( 'init', [ $new_images, 'setPostThumbnailSize' ] );
alchemyunited's avatar
alchemyunited committed
199
        $this->_arr_actions[] = [
200 201 202 203 204 205 206

            'active'    => false, //   <<<
            'hook'      => 'init',
            'component' => $new_images,
            'callback'  => 'setPostThumbnailSize'
        ];

alchemyunited's avatar
alchemyunited committed
207
        // when
208
        // add_action( 'after_setup_theme', [ $new_images, 'addImageSize' ] );
alchemyunited's avatar
alchemyunited committed
209
        $this->_arr_actions[] = [
210 211 212 213 214 215

            'active'    => true, //   <<<
            'hook'      => 'after_setup_theme',
            'component' => $new_images,
            'callback'  => 'addImageSize'
        ];
alchemyunited's avatar
alchemyunited committed
216

217
        // add_filter( 'image_size_names_choose', [ $new_images, 'imageSizeNamesChooseFilter' ], 100, 1 );
alchemyunited's avatar
alchemyunited committed
218
        $this->_arr_filters[] = [
219 220 221 222 223 224 225

            'active'    => true, //   <<<
            'hook'      => 'image_size_names_choose',
            'component' => $new_images,
            'callback'  => 'imageSizeNamesChooseFilter',
            'priority'  => 100
        ];
alchemyunited's avatar
alchemyunited committed
226 227 228 229 230 231 232 233 234 235 236

    }


    protected function styles( $bool = true ) {

        if ( $bool !== true ) {
            return;
        }

        // what
237
        $new_styles = new ClassStyles();
alchemyunited's avatar
alchemyunited committed
238

239
        // add_action( 'wp_enqueue_scripts', [ $new_styles, 'wpEnqueueStyleParent' ] );
alchemyunited's avatar
alchemyunited committed
240
        $this->_arr_actions[] = [
241

alchemyunited's avatar
alchemyunited committed
242
            'active'    => false, //   <<<
243 244 245 246 247 248
            'hook'      => 'wp_enqueue_scripts',
            'component' => $new_styles,
            'callback'  => 'wpEnqueueStyleParent'
        ];

        // add_action( 'wp_enqueue_scripts', [ $new_styles, 'wpEnqueueStyleChild' ], 10 );
alchemyunited's avatar
alchemyunited committed
249
        $this->_arr_actions[] = [
250 251 252 253 254 255

            'active'    => true, //   <<<
            'hook'      => 'wp_enqueue_scripts',
            'component' => $new_styles,
            'callback'  => 'wpEnqueueStyleChild'
        ];
alchemyunited's avatar
alchemyunited committed
256 257 258 259 260

    }


}