templates
3 years ago
class-init.php
2 years ago
class-template-overrides.php
3 years ago
class-templates.php
2 years ago
index.php
4 years ago
class-template-overrides.php
154 lines
| 1 | <?php // phpcs:ignore WordPress.Files.FileName |
| 2 | |
| 3 | /** |
| 4 | * CSS overrides for block plugins. |
| 5 | * |
| 6 | * @since 4.0.0 |
| 7 | * @package Redux Framework |
| 8 | */ |
| 9 | |
| 10 | namespace ReduxTemplates; |
| 11 | |
| 12 | defined( 'ABSPATH' ) || exit; |
| 13 | |
| 14 | /** |
| 15 | * Redux Templates Templates Class |
| 16 | * |
| 17 | * @since 4.0.0 |
| 18 | */ |
| 19 | class Template_Overrides { |
| 20 | |
| 21 | /** |
| 22 | * ReduxTemplates Template_Overrides. |
| 23 | * |
| 24 | * @since 4.0.0 |
| 25 | */ |
| 26 | public function __construct() { |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Detects if the current page has blocks or not. |
| 31 | * |
| 32 | * @return bool |
| 33 | * @since 4.0.0 |
| 34 | */ |
| 35 | public static function is_gutenberg(): bool { |
| 36 | global $post; |
| 37 | if ( function_exists( 'has_blocks' ) && has_blocks( $post->ID ) ) { |
| 38 | return true; |
| 39 | } |
| 40 | |
| 41 | return false; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Detects the current theme and provides overrides. |
| 46 | * |
| 47 | * @return string |
| 48 | * @since 4.0.0 |
| 49 | */ |
| 50 | public static function get_overrides(): string { |
| 51 | |
| 52 | if ( ! self::is_gutenberg() ) { |
| 53 | return ''; |
| 54 | } |
| 55 | |
| 56 | $template = mb_strtolower( get_template() ); |
| 57 | |
| 58 | $css = ''; |
| 59 | if ( method_exists( __CLASS__, $template ) ) { |
| 60 | $css = call_user_func( array( __CLASS__, $template ) ); |
| 61 | $css = preg_replace( '/\s+/S', ' ', $css ); |
| 62 | } |
| 63 | |
| 64 | $css .= <<<'EOD' |
| 65 | #main { |
| 66 | padding: unset !important; |
| 67 | } |
| 68 | #content { |
| 69 | padding: unset !important; |
| 70 | } |
| 71 | #wrapper { |
| 72 | min-height: unset !important; |
| 73 | } |
| 74 | .alignfull, .alignwide { |
| 75 | margin: unset !important; |
| 76 | max-width: unset !important; |
| 77 | width: unset !important; |
| 78 | } |
| 79 | } |
| 80 | EOD; |
| 81 | // Remove comments. |
| 82 | $css = preg_replace( '!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $css ); |
| 83 | // Remove space after colons. |
| 84 | $css = str_replace( ': ', ':', $css ); |
| 85 | // Remove space after commas. |
| 86 | $css = str_replace( ', ', ',', $css ); |
| 87 | // Remove space after opening bracket. |
| 88 | $css = str_replace( ' {', '{', $css ); |
| 89 | // Remove whitespace. |
| 90 | return str_replace( array( "\r\n", "\r", "\n", "\t", ' ', ' ', ' ' ), '', $css ); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Consulting theme overrides. |
| 95 | * |
| 96 | * @return string |
| 97 | * @since 4.0.0 |
| 98 | */ |
| 99 | public static function consulting(): string { |
| 100 | return <<<'EOD' |
| 101 | #content-core { |
| 102 | max-width: 100%; |
| 103 | } |
| 104 | EOD; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Avada theme overrides. |
| 109 | * |
| 110 | * @return string |
| 111 | * @since 4.0.0 |
| 112 | */ |
| 113 | public static function avada(): string { |
| 114 | return <<<'EOD' |
| 115 | #main .fusion-row { |
| 116 | max-width: unset; |
| 117 | } |
| 118 | EOD; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * GeneratePress theme overrides. |
| 123 | * |
| 124 | * @return string |
| 125 | * @since 4.1.24 |
| 126 | */ |
| 127 | public static function generatepress(): string { |
| 128 | return <<<'EOD' |
| 129 | .site-content { |
| 130 | display: block!important; |
| 131 | } |
| 132 | EOD; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * TwentyTwenty theme overrides. |
| 137 | * |
| 138 | * @return string |
| 139 | * @since 4.0.0 |
| 140 | */ |
| 141 | public static function twentytwenty(): string { |
| 142 | return <<<'EOD' |
| 143 | [class*="__inner-container"] > *:not(.alignwide):not(.alignfull):not(.alignleft):not(.alignright):not(.is-style-wide) { |
| 144 | max-width: unset !important; |
| 145 | } |
| 146 | .wp-block-archives:not(.alignwide):not(.alignfull), .wp-block-categories:not(.alignwide):not(.alignfull), .wp-block-code, .wp-block-columns:not(.alignwide):not(.alignfull), .wp-block-cover:not(.alignwide):not(.alignfull):not(.alignleft):not(.alignright):not(.aligncenter), .wp-block-embed:not(.alignwide):not(.alignfull):not(.alignleft):not(.alignright):not(.aligncenter), .wp-block-gallery:not(.alignwide):not(.alignfull):not(.alignleft):not(.alignright):not(.aligncenter), .wp-block-group:not(.has-background):not(.alignwide):not(.alignfull), .wp-block-image:not(.alignwide):not(.alignfull):not(.alignleft):not(.alignright):not(.aligncenter), .wp-block-latest-comments:not(.aligncenter):not(.alignleft):not(.alignright), .wp-block-latest-posts:not(.aligncenter):not(.alignleft):not(.alignright), .wp-block-media-text:not(.alignwide):not(.alignfull), .wp-block-preformatted, .wp-block-pullquote:not(.alignwide):not(.alignfull):not(.alignleft):not(.alignright), .wp-block-quote, .wp-block-quote.is-large, .wp-block-quote.is-style-large, .wp-block-verse, .wp-block-video:not(.alignwide):not(.alignfull) { |
| 147 | margin-top: unset; |
| 148 | margin-bottom: unset; |
| 149 | } |
| 150 | EOD; |
| 151 | } |
| 152 | |
| 153 | } |
| 154 |