Skip to content

Commit

Permalink
adds default compatibility to no plugin builder, ie Codeinwp/themeisl…
Browse files Browse the repository at this point in the history
  • Loading branch information
selul committed Apr 2, 2019
1 parent 5c98c9f commit ac15bbb
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 8 deletions.
93 changes: 93 additions & 0 deletions builders/class-none-full-width-templates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php
/**
* Class ThemeIsle\FullWidthTemplates\Elementor
*
* @package ThemeIsle\FullWidthTemplates\Elementor
* @copyright Copyright (c) 2017, Andrei Lupu
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
* @since 1.0.0
*/

namespace ThemeIsle\FullWidthTemplates;

class None {
/**
* @var Elementor
*/
public static $instance = null;

protected function init(){
// for the standard template
add_action( 'fwpt_std_content', array( $this, 'render_content' ) );
add_action( 'fwpt_std_before_content', array( $this, 'render_std_before_content' ) );
add_action( 'fwpt_std_after_content', array( $this, 'render_std_after_content' ) );

}

/**
* Display the WordPress loop
*/
public function render_content() {
while ( have_posts() ) : the_post();
the_content();
endwhile;
}


/**
* Display the header of the standard template
*/
public function render_std_before_content() {
get_header();
}

/**
* Display the footer of the standard template
*/
public function render_std_after_content() {
get_footer();
}


/**
* @static
* @since 1.0.0
* @access public
* @return Elementor
*/
public static function instance() {
if ( null === self::$instance ) {
self::$instance = new self();
self::$instance->init();
}

return self::$instance;
}

/**
* Throw error on object clone
*
* The whole idea of the singleton design pattern is that there is a single
* object therefore, we don't want the object to be cloned.
*
* @access public
* @since 1.0.0
* @return void
*/
public function __clone() {
// Cloning instances of the class is forbidden.
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'textdomain' ), '1.0.0' );
}

/**
* Disable unserializing of the class
*
* @access public
* @since 1.0.0
* @return void
*/
public function __wakeup() {
// Unserializing instances of the class is forbidden.
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'textdomain' ), '1.0.0' );
}
}
25 changes: 17 additions & 8 deletions class-full-width-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

namespace ThemeIsle;

use ThemeIsle\FullWidthTemplates\Elementor;
use ThemeIsle\FullWidthTemplates\None;

if ( ! class_exists( '\ThemeIsle\FullWidthTemplates' ) ) {

class FullWidthTemplates {
Expand All @@ -33,6 +36,7 @@ class FullWidthTemplates {
* Defines the library behaviour
*/
protected function init() {

// Add your templates to this array.
$this->templates = apply_filters( 'fwpt_templates_list', array(
'templates/builder-fullwidth.php' => html_entity_decode( '&harr; ' ) . __( 'Page Builder - Full Width - Blank', 'textdomain' ),
Expand Down Expand Up @@ -92,11 +96,6 @@ public function redirect_page_template( $template ) {
return $template;
}

protected function guess_builder(){
$builder = 'elementor';
return $builder;
}

/**
* Adds our template to the pages cache in order to trick WordPress
* into thinking the template file exists where it doesn't really exist.
Expand Down Expand Up @@ -145,17 +144,27 @@ public function load_theme_overwrites() {
include_once( $func_filename );
}
}

public function is_elementor(){
if ( defined( 'ELEMENTOR_PATH' ) && class_exists( 'Elementor\Widget_Base' ) ) {
return true;
}
return false;
}
/**
* Add support for Elementor and call the class
*/
public function add_support_for_elementor(){

// We check if the Elementor plugin has been installed / activated.
if ( defined( 'ELEMENTOR_PATH' ) && class_exists( 'Elementor\Widget_Base' ) ) {
if( $this->is_elementor()){
require_once( dirname( __FILE__ ) . '/builders/class-elementor-full-width-templates.php' );
FullWidthTemplates\Elementor::instance();
return;
}

require_once( dirname( __FILE__ ) . '/builders/class-none-full-width-templates.php' );
FullWidthTemplates\None::instance();
return;
}

/**
Expand All @@ -165,7 +174,7 @@ public function add_support_for_elementor(){
* @return FullWidthTemplates
*/
public static function instance() {
if ( is_null( self::$instance ) ) {
if ( null === self::$instance ) {
self::$instance = new self();
self::$instance->init();
}
Expand Down

0 comments on commit ac15bbb

Please sign in to comment.