initial commit
This commit is contained in:
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/**
|
||||
* Initialize the Redux Template Library.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @package Redux Framework
|
||||
*/
|
||||
|
||||
namespace ReduxTemplates;
|
||||
|
||||
use ReduxTemplates;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Redux Templates Init Class
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class Init {
|
||||
|
||||
/**
|
||||
* Init constructor.
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function __construct() {
|
||||
global $pagenow;
|
||||
|
||||
if ( 'widgets.php' === $pagenow ) {
|
||||
return;
|
||||
}
|
||||
|
||||
require_once REDUXTEMPLATES_DIR_PATH . 'classes/class-templates.php';
|
||||
|
||||
add_action( 'init', array( $this, 'load' ) );
|
||||
|
||||
if ( did_action( 'init' ) ) { // In case the devs load it at the wrong place.
|
||||
$this->load();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load everything up after init.
|
||||
*
|
||||
* @access public
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public static function load() {
|
||||
new ReduxTemplates\Templates();
|
||||
}
|
||||
}
|
||||
|
||||
new Init();
|
@ -0,0 +1,153 @@
|
||||
<?php // phpcs:ignore WordPress.Files.FileName
|
||||
|
||||
/**
|
||||
* CSS overrides for block plugins.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @package Redux Framework
|
||||
*/
|
||||
|
||||
namespace ReduxTemplates;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Redux Templates Templates Class
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class Template_Overrides {
|
||||
|
||||
/**
|
||||
* ReduxTemplates Template_Overrides.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects if the current page has blocks or not.
|
||||
*
|
||||
* @return bool
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public static function is_gutenberg(): bool {
|
||||
global $post;
|
||||
if ( function_exists( 'has_blocks' ) && has_blocks( $post->ID ) ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects the current theme and provides overrides.
|
||||
*
|
||||
* @return string
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public static function get_overrides(): string {
|
||||
|
||||
if ( ! self::is_gutenberg() ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$template = mb_strtolower( get_template() );
|
||||
|
||||
$css = '';
|
||||
if ( method_exists( __CLASS__, $template ) ) {
|
||||
$css = call_user_func( array( __CLASS__, $template ) );
|
||||
$css = preg_replace( '/\s+/S', ' ', $css );
|
||||
}
|
||||
|
||||
$css .= <<<'EOD'
|
||||
#main {
|
||||
padding: unset !important;
|
||||
}
|
||||
#content {
|
||||
padding: unset !important;
|
||||
}
|
||||
#wrapper {
|
||||
min-height: unset !important;
|
||||
}
|
||||
.alignfull, .alignwide {
|
||||
margin: unset !important;
|
||||
max-width: unset !important;
|
||||
width: unset !important;
|
||||
}
|
||||
}
|
||||
EOD;
|
||||
// Remove comments.
|
||||
$css = preg_replace( '!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $css );
|
||||
// Remove space after colons.
|
||||
$css = str_replace( ': ', ':', $css );
|
||||
// Remove space after commas.
|
||||
$css = str_replace( ', ', ',', $css );
|
||||
// Remove space after opening bracket.
|
||||
$css = str_replace( ' {', '{', $css );
|
||||
// Remove whitespace.
|
||||
return str_replace( array( "\r\n", "\r", "\n", "\t", ' ', ' ', ' ' ), '', $css );
|
||||
}
|
||||
|
||||
/**
|
||||
* Consulting theme overrides.
|
||||
*
|
||||
* @return string
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public static function consulting(): string {
|
||||
return <<<'EOD'
|
||||
#content-core {
|
||||
max-width: 100%;
|
||||
}
|
||||
EOD;
|
||||
}
|
||||
|
||||
/**
|
||||
* Avada theme overrides.
|
||||
*
|
||||
* @return string
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public static function avada(): string {
|
||||
return <<<'EOD'
|
||||
#main .fusion-row {
|
||||
max-width: unset;
|
||||
}
|
||||
EOD;
|
||||
}
|
||||
|
||||
/**
|
||||
* GeneratePress theme overrides.
|
||||
*
|
||||
* @return string
|
||||
* @since 4.1.24
|
||||
*/
|
||||
public static function generatepress(): string {
|
||||
return <<<'EOD'
|
||||
.site-content {
|
||||
display: block!important;
|
||||
}
|
||||
EOD;
|
||||
}
|
||||
|
||||
/**
|
||||
* TwentyTwenty theme overrides.
|
||||
*
|
||||
* @return string
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public static function twentytwenty(): string {
|
||||
return <<<'EOD'
|
||||
[class*="__inner-container"] > *:not(.alignwide):not(.alignfull):not(.alignleft):not(.alignright):not(.is-style-wide) {
|
||||
max-width: unset !important;
|
||||
}
|
||||
.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) {
|
||||
margin-top: unset;
|
||||
margin-bottom: unset;
|
||||
}
|
||||
EOD;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,171 @@
|
||||
<?php // phpcs:ignore WordPress.Files.FileName
|
||||
/**
|
||||
* Templates overrides for pages.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @package Redux Framework
|
||||
*/
|
||||
|
||||
namespace ReduxTemplates;
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
/**
|
||||
* Redux Templates Templates Class
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
class Templates {
|
||||
|
||||
/**
|
||||
* Default container width.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public static $content_width = 1200;
|
||||
|
||||
/**
|
||||
* ReduxTemplates Template.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function __construct() {
|
||||
global $pagenow;
|
||||
|
||||
if ( 'widgets.php' === $pagenow ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) && ( class_exists( 'Classic_Editor' ) || defined( 'DISABLE_GUTENBERG_FILE' ) || class_exists( 'CodePopular_disable_gutenberg' ) ) ) {
|
||||
|
||||
// We don't want to add templates unless it's a gutenberg page.
|
||||
return;
|
||||
}
|
||||
|
||||
// Include ReduxTemplates default template without wrapper.
|
||||
add_filter( 'template_include', array( $this, 'template_include' ) );
|
||||
|
||||
// Override the default content-width when using Redux templates so the template doesn't look like shit.
|
||||
add_action( 'wp', array( $this, 'modify_template_content_width' ) );
|
||||
|
||||
// Add ReduxTemplates supported Post types in page template.
|
||||
$post_types = get_post_types( array(), 'object' );
|
||||
|
||||
if ( ! empty( $post_types ) ) {
|
||||
foreach ( $post_types as $post_type ) {
|
||||
if ( isset( $post_type->name ) && isset( $post_type->show_in_rest ) && true === $post_type->show_in_rest ) {
|
||||
add_filter( "theme_{$post_type->name}_templates", array( $this, 'add_templates' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
add_filter( 'admin_body_class', array( $this, 'add_body_class' ), 999 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the redux-template class to the admin body if a redux-templates page type is selected.
|
||||
*
|
||||
* @param string|null $classes Classes string for the admin panel.
|
||||
*
|
||||
* @return string|null
|
||||
* @since 4.1.19
|
||||
*/
|
||||
public function add_body_class( ?string $classes ): ?string {
|
||||
global $post;
|
||||
|
||||
$screen = get_current_screen();
|
||||
|
||||
if ( 'post' === $screen->base && get_current_screen()->is_block_editor() ) {
|
||||
$check = get_post_meta( $post->ID, '_wp_page_template', true );
|
||||
|
||||
if ( strpos( $check, 'redux-templates_' ) !== false ) {
|
||||
$classes .= ' redux-template';
|
||||
}
|
||||
}
|
||||
|
||||
return $classes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the $content_width variable for themes, so our templates work properly and don't look squished.
|
||||
*
|
||||
* @param array $to_find Template keys to check against.
|
||||
*
|
||||
* @return bool
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function check_template( array $to_find = array() ): bool {
|
||||
global $post;
|
||||
|
||||
if ( ! empty( $post ) ) {
|
||||
$template = get_page_template_slug( $post->ID );
|
||||
|
||||
if ( false !== strpos( $template, 'redux' ) ) {
|
||||
$test = mb_strtolower( preg_replace( '/[^A-Za-z0-9 ]/', '', $template ) );
|
||||
|
||||
foreach ( $to_find as $key ) {
|
||||
if ( false !== strpos( $test, $key ) ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the $content_width variable for themes, so our templates work properly and don't look squished.
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function modify_template_content_width() {
|
||||
$to_find = array( 'cover', 'canvas', 'fullwidth' );
|
||||
if ( $this->check_template( $to_find ) ) {
|
||||
global $content_width;
|
||||
if ( $content_width < 1000 ) {
|
||||
$content_width = get_option( '_redux_content_width', self::$content_width );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Include the template
|
||||
*
|
||||
* @param string|null $template Template type.
|
||||
*
|
||||
* @return string|null
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function template_include( ?string $template ): ?string {
|
||||
if ( is_singular() ) {
|
||||
$page_template = get_post_meta( get_the_ID(), '_wp_page_template', true );
|
||||
|
||||
if ( 'redux-templates_full_width' === $page_template ) {
|
||||
$template = REDUXTEMPLATES_DIR_PATH . 'classes/templates/template-full-width.php';
|
||||
} elseif ( 'redux-templates_contained' === $page_template ) {
|
||||
$template = REDUXTEMPLATES_DIR_PATH . 'classes/templates/template-contained.php';
|
||||
} elseif ( 'redux-templates_canvas' === $page_template ) {
|
||||
$template = REDUXTEMPLATES_DIR_PATH . 'classes/templates/template-canvas.php';
|
||||
}
|
||||
}
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to add the templates to the dropdown
|
||||
*
|
||||
* @param array $post_templates Default post template array.
|
||||
*
|
||||
* @return array
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function add_templates( array $post_templates ): array {
|
||||
$post_templates['redux-templates_contained'] = __( 'Redux Contained', 'redux-framework' );
|
||||
$post_templates['redux-templates_full_width'] = __( 'Redux Full Width', 'redux-framework' );
|
||||
$post_templates['redux-templates_canvas'] = __( 'Redux Canvas', 'redux-framework' );
|
||||
|
||||
return $post_templates;
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Silence is golden.
|
||||
*
|
||||
* @package Redux Framework
|
||||
*/
|
||||
|
||||
echo null;
|
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
/**
|
||||
* Silence is golden.
|
||||
*
|
||||
* @package Redux Framework
|
||||
*/
|
||||
|
||||
echo null;
|
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* ReduxTemplates - Canvas / Theme Override
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @package redux-framework
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html <?php language_attributes(); ?>>
|
||||
<head>
|
||||
<meta charset="<?php bloginfo( 'charset' ); ?>">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||||
<link rel="profile" href="https://gmpg.org/xfn/11"/>
|
||||
<?php if ( ! current_theme_supports( 'title-tag' ) ) : ?>
|
||||
<title><?php echo esc_html( wp_get_document_title() ); ?></title>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
wp_head();
|
||||
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo '<style id="redux-template-overrides">' . ReduxTemplates\Template_Overrides::get_overrides() . '</style>';
|
||||
?>
|
||||
</head>
|
||||
<body <?php body_class(); ?>>
|
||||
<?php wp_body_open(); ?>
|
||||
<?php
|
||||
while ( have_posts() ) :
|
||||
the_post();
|
||||
the_content();
|
||||
|
||||
// If comments are open, or we have at least one comment, load up the comment template.
|
||||
if ( comments_open() || get_comments_number() ) :
|
||||
comments_template();
|
||||
endif;
|
||||
?>
|
||||
<?php endwhile; ?>
|
||||
<?php wp_footer(); ?>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* ReduxTemplates - Full Width / Contained
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @package redux-framework
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
get_header();
|
||||
|
||||
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo '<style id="redux-template-overrides">' . ReduxTemplates\Template_Overrides::get_overrides() . '</style>';
|
||||
|
||||
while ( have_posts() ) :
|
||||
the_post();
|
||||
the_content();
|
||||
|
||||
// If comments are open, or we have at least one comment, load up the comment template.
|
||||
if ( comments_open() || get_comments_number() ) :
|
||||
comments_template();
|
||||
endif;
|
||||
endwhile; // End of the loop.
|
||||
|
||||
get_footer();
|
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* ReduxTemplates - Full Width / Stretched
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @package redux-framework
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
get_header();
|
||||
|
||||
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
||||
echo '<style id="redux-template-overrides">' . ReduxTemplates\Template_Overrides::get_overrides() . '</style>';
|
||||
|
||||
while ( have_posts() ) :
|
||||
the_post();
|
||||
the_content();
|
||||
|
||||
// If comments are open, or we have at least one comment, load up the comment template.
|
||||
if ( comments_open() || get_comments_number() ) :
|
||||
comments_template();
|
||||
endif;
|
||||
endwhile; // End of the loop.
|
||||
|
||||
get_footer();
|
@ -0,0 +1,19 @@
|
||||
<?php // phpcs:ignore WordPress.Files.FileName
|
||||
/**
|
||||
* Redux page templates.
|
||||
*
|
||||
* @package Redux_Templates
|
||||
* @subpackage Core
|
||||
* @subpackage Core
|
||||
* @author Redux.io + Dovy Paukstys
|
||||
*/
|
||||
|
||||
defined( 'ABSPATH' ) || exit;
|
||||
|
||||
// Define Physical Path.
|
||||
define( 'REDUXTEMPLATES_DIR_PATH', trailingslashit( plugin_dir_path( __FILE__ ) ) );
|
||||
|
||||
require_once REDUXTEMPLATES_DIR_PATH . 'classes/class-init.php';
|
||||
require_once REDUXTEMPLATES_DIR_PATH . 'classes/class-template-overrides.php';
|
||||
|
||||
new ReduxTemplates\Init();
|
Reference in New Issue
Block a user