Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated with latest phpcs ruleset #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 93 additions & 27 deletions class-fullwidth-page-templates.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,44 @@
<?php
// Exit if accessed directly
/**
* Fullwidth Page Templates
*
* @package Fullwidth Page Templates
* @since 1.0.0
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}



/**
* Fullwidth_Page_Templates
*
* @since 1.0.0
*/
class Fullwidth_Page_Templates {

/**
* Instance
*
* @since 1.0.0
*
* @access private
* @var object Class object.
*/
private $templates;

function __construct() {
/**
* Constructor
*
* @since 1.0.0
*/
public function __construct() {

$this->includes();

$this->templates = array(
'template-page-builder-no-sidebar.php' => esc_html__( 'FW No Sidebar', 'fullwidth-templates' ),
'template-page-builder.php' => esc_html__( 'FW Fullwidth', 'fullwidth-templates' ),
'template-page-builder-no-sidebar.php' => esc_html__( 'FW No Sidebar', 'fullwidth-templates' ),
'template-page-builder.php' => esc_html__( 'FW Fullwidth', 'fullwidth-templates' ),
'template-page-builder-no-header-footer.php' => esc_html__( 'FW Fullwidth No Header Footer', 'fullwidth-templates' ),
);

Expand All @@ -29,13 +48,13 @@ function __construct() {
add_filter(
'page_attributes_dropdown_pages_args',
array( $this, 'fpt_register_project_templates' )
);
);
} else {
// Add a filter to the wp 4.7 version attributes metabox
// Add a filter to the wp 4.7 version attributes metabox.
add_action( 'init', array( $this, 'post_type_template' ), 999 );
}

// Add a filter to the save post to inject out template into the page cache
// Add a filter to the save post to inject out template into the page cache.
add_filter( 'wp_insert_post_data', array( $this, 'fpt_register_project_templates' ) );
add_filter( 'template_include', array( $this, 'fpt_view_project_template' ) );

Expand All @@ -44,19 +63,32 @@ function __construct() {
add_filter( 'wp', array( $this, 'theme_support' ) );
}

public function body_class( $body_Class ) {
/**
* Define body class.
*
* @param Array $body_class body class.
*
* @return array
* @since 1.0.0
*/
public function body_class( $body_class ) {

$template = get_page_template_slug();

if ( false !== $template && $this->is_template_active() ) {
$body_Class[] = 'fpt-template';
$body_class[] = 'fpt-template';
}

$body_Class[] = 'fpt-template-' . get_template();
$body_class[] = 'fpt-template-' . get_template();

return $body_Class;
return $body_class;
}

/**
* Theme Support.
*
* @since 1.0.0
*/
public function theme_support() {

if ( $this->is_template_active() ) {
Expand All @@ -65,41 +97,62 @@ public function theme_support() {

}

/**
* Check Template is active or not.
*
* @since 1.0.0
* @return boolean
*/
public function is_template_active() {

$template = get_page_template_slug();

if ( false !== $template && array_key_exists( $template, $this->templates ) ) {
return true;
}

return false;
}

/**
* Enqueue script.
*
* @since 1.0.0
*/
public function enqueue() {
if ( is_page_template( 'template-page-builder.php' ) ) {
wp_register_style( 'fullwidth-template', plugins_url( 'assets/css/fullwidth-template.css', __FILE__ ) );
wp_register_style( 'fullwidth-template', plugins_url( 'assets/css/fullwidth-template.css', __FILE__ ), array(), 'FPT_VER' );
wp_enqueue_style( 'fullwidth-template' );
}

if ( is_page_template( 'template-page-builder-no-sidebar.php' ) ) {
wp_register_style( 'fullwidth-template-no-sidebar', plugins_url( 'assets/css/fullwidth-template-no-sidebar.css', __FILE__ ) );
wp_register_style( 'fullwidth-template-no-sidebar', plugins_url( 'assets/css/fullwidth-template-no-sidebar.css', __FILE__ ), array(), 'FPT_VER' );
wp_enqueue_style( 'fullwidth-template-no-sidebar' );
}

if( is_page_template( 'template-page-builder-no-header-footer.php' ) ) {
wp_register_style( 'fullwidth-template-no-header-footer', plugins_url( 'assets/css/fullwidth-template-no-header-footer.css', __FILE__ ) );
if ( is_page_template( 'template-page-builder-no-header-footer.php' ) ) {
wp_register_style( 'fullwidth-template-no-header-footer', plugins_url( 'assets/css/fullwidth-template-no-header-footer.css', __FILE__ ), array(), 'FPT_VER' );
wp_enqueue_style( 'fullwidth-template-no-header-footer' );
}
}

/**
* Include file.
*
* @since 1.0.0
*/
private function includes() {
require_once FPT_DIR . '/templates/default/template-helpers.php';
}

/**
* Post Type Template.
*
* @since 1.0.0
*/
public function post_type_template() {
$args = array(
'public' => true
'public' => true,
);

$post_types = get_post_types( $args, 'names', 'and' );
Expand All @@ -112,22 +165,30 @@ public function post_type_template() {
foreach ( $post_types as $post_type ) {
add_filter( 'theme_' . $post_type . '_templates', array( $this, 'add_new_template' ) );
}

}
}

/**
* Adds our template to the page dropdown for v4.7+
*
* @param array $posts_templates of Add New Template.
* @since 1.0.0
* @return array
*/
public function add_new_template( $posts_templates ) {
$posts_templates = array_merge( $posts_templates, $this->templates );
return $posts_templates;
}

function fpt_register_project_templates( $atts ) {

// Create the key used for the themes cache
/**
* Register Project Templates.
*
* @param string $atts to Register Project Templates.
* @since 1.0.0
* @return string
*/
public function fpt_register_project_templates( $atts ) {
// Create the key used for the themes cache.
$cache_key = 'page_templates-' . md5( get_theme_root() . '/' . get_stylesheet() );

$templates = wp_get_theme()->get_page_templates();
Expand All @@ -143,7 +204,12 @@ function fpt_register_project_templates( $atts ) {
return $atts;
}

function fpt_view_project_template( $template ) {
/**
* Define fpt view project template.
*
* @param string $template for fpt view project template.
*/
public function fpt_view_project_template( $template ) {

global $post;

Expand All @@ -159,14 +225,14 @@ function fpt_view_project_template( $template ) {

$file = FPT_DIR . '/templates/default/' . get_post_meta( $post->ID, '_wp_page_template', true );

// Just to be safe, we check if the file exist first
// Just to be safe, we check if the file exist first.
if ( file_exists( $file ) ) {
return $file;
} else {
echo $file;
echo esc_attr( $file );
}

return $template;
}

}
}
8 changes: 4 additions & 4 deletions fullwidth-page-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* @package Fullwidth_Page_Templates
*/

// Exit if accessed directly
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
Expand All @@ -29,12 +29,12 @@
*/
function init_fullwidth_template() {

// Load localization file
// Load localization file.
load_plugin_textdomain( 'fullwidth-templates' );

// Init dynamic header footer
// Init dynamic header footer.
new Fullwidth_Page_Templates();

}

add_action( 'plugins_loaded', 'init_fullwidth_template' );
add_action( 'plugins_loaded', 'init_fullwidth_template' );
6 changes: 5 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
<?php
// Silence is golden.
/**
* Silence is golden.
*
* @package Fullwidth_Page_Templates
*
24 changes: 24 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards for Plugins">
<description>Generally-applicable sniffs for WordPress plugins</description>
<rule ref="PHPCompatibility">
<exclude name="WordPress.PHP.StrictComparisons.LooseComparison" />
<exclude name="WordPress.PHP.StrictInArray.MissingTrueStrict" />
</rule>
<rule ref="PHPCompatibility"/>
<config name="testVersion" value="5.3-"/>

<rule ref="WordPress-Core" />
<rule ref="WordPress-Docs" />
<rule ref="WordPress-Extra" />

<!-- Check all PHP files in directory tree by default. -->
<arg name="extensions" value="php"/>
<file>.</file>

<!-- Show sniff codes in all reports -->
<arg value="s"/>

<exclude-pattern>*/node_modules/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>
</ruleset>
6 changes: 5 additions & 1 deletion templates/default/index.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
<?php
// Silence is golden.
/**
* Silence is golden.
*
* @package Fullwidth_Page_Templates
*
35 changes: 28 additions & 7 deletions templates/default/template-helpers.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
<?php
/**
* Template Helpers.
* Get header and Footer content.
*
* @package Fullwidth_Page_Templates
*/

/**
* No Content Get Header.
*
* @since 1.0.0
*/
function no_content_get_header() {

?>
?>
<!DOCTYPE html>
<html <?php language_attributes(); ?> class="no-js">
<head>
Expand All @@ -13,22 +24,32 @@ function no_content_get_header() {
</head>

<body <?php body_class(); ?>>
<?php
do_action( 'page_builder_content_body_before' );
<?php
do_action( 'page_builder_content_body_before' );

}

/**
* No Content Get Footer.
*
* @since 1.0.0
*/
function no_content_get_footer() {
do_action( 'page_builder_content_body_after' );
wp_footer();
?>
wp_footer();
?>
</body>
</html>
<?php
<?php
}

/**
* Page builder page elements.
*
* @since 1.0.0
*/
function page_builder_page_elements() {
the_content();
}

add_action( 'page_builder_page_elements', 'page_builder_page_elements' );
add_action( 'page_builder_page_elements', 'page_builder_page_elements' );
15 changes: 10 additions & 5 deletions templates/default/template-page-builder-no-header-footer.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<?php
/* Template Name: BSF Fullwidth No Header Footer */
<?php
/**
* Template Name: BSF Fullwidth No Header Footer.
*
* @package Fullwidth_Page_Templates
*/

no_content_get_header();

do_action( 'page_builder_before_content_wrapper' );

while ( have_posts() ) : the_post();
do_action( 'page_builder_page_elements' ); // Give your elements priorities so that they hook in the right place.
while ( have_posts() ) :
the_post();
do_action( 'page_builder_page_elements' ); // Give your elements priorities so that they hook in the right place.
endwhile;

do_action( 'page_builder_after_content_wrapper' );

no_content_get_footer();
no_content_get_footer();
Loading