Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
initial commit
  • Loading branch information
cmc12028 committed Mar 10, 2016
1 parent 482e447 commit 5dd1d1d
Show file tree
Hide file tree
Showing 8 changed files with 486 additions and 7 deletions.
64 changes: 64 additions & 0 deletions grandchild-functions.php
@@ -0,0 +1,64 @@
<?php
/*
Plugin Name: Stormwise
Description: Sample grandchild theme built as a plugin.
Author: Web Dev
Author URI: http://www.your-website.com
Version: 1.0
*/


require_once( plugin_dir_path( __FILE__ ) . 'template-class.php' );
add_action( 'plugins_loaded', array( 'Page_Template_Plugin', 'get_instance' ) );

// Adds our new file with styles
function grandchild_add_scripts_styles() {
wp_register_script( 'grandchild-script', plugins_url( 'grandchild-scripts.js', __FILE__ ), array( 'jquery' ), '1.0' );
wp_enqueue_script( 'grandchild-script' );

wp_register_style( 'grandchild-style', plugins_url( 'grandchild-styles.css', __FILE__ ), array(), '1.0' );
wp_enqueue_style( 'grandchild-style' );
}
add_action( 'wp_enqueue_scripts', 'grandchild_add_scripts_styles', 99999999 );

// Search for templates in plugin 'templates' dir, and load if exists
function grandchild_template_include( $template ) {
if ( file_exists( untrailingslashit( plugin_dir_path( __FILE__ ) ) . '/templates/' . basename( $template ) ) )
$template = untrailingslashit( plugin_dir_path( __FILE__ ) ) . '/templates/' . basename( $template );

return $template;
}
add_filter( 'template_include', 'grandchild_template_include', 11 );

if ( function_exists('register_sidebar') ) {
register_sidebar( array(
'name' => __( 'Header - Image' ),
'id' => 'header-image',
'description' => __( 'Widgets in this area will be shown in the header.' ),
'before_title' => '<h1>',
'after_title' => '</h1>',
) );

register_sidebar( array(
'name' => __( 'Footer - Social' ),
'id' => 'footer-social',
'description' => __( 'Widgets in this area will be shown on the right hand side of the footer.' ),
'before_title' => '<h1>',
'after_title' => '</h1>',
) );
}

// We are hooking to the 'load_custom_header' filter
// and return a value of 'true' meaning that we want to
// load a custom header
add_filter( 'load_custom_header', '__return_true', 99 );

add_filter( 'get_custom_header', function( $header ) {
return plugin_dir_path( __FILE__ ).'templates/header.php';
}, 99 );

add_filter( 'load_custom_footer', '__return_true', 99 );

add_filter( 'get_custom_footer', function( $footer ) {
return plugin_dir_path( __FILE__ ).'templates/footer.php';
}, 99 );
5 changes: 5 additions & 0 deletions grandchild-scripts.js
@@ -0,0 +1,5 @@
jQuery(document).ready(function() {

//alert('grandchild');

});
49 changes: 49 additions & 0 deletions grandchild-styles.css
@@ -0,0 +1,49 @@
#site-title .widget_sp_image {
list-style-type:none;
padding-top: 28px;
float:right;
}

@media (max-width: 991px) {
#site-title .searchform .form-group .form-control {
width: 118px;
}
}

@media (max-width: 767px) {
#footer li.simple-social-icons ul.alignright {
float:left;
margin-top: 6px;
}
}


.social-facebook:before {
display: none;
}

.social-twitter:before {
display: none;
}

.simple-social-icons ul li a, .simple-social-icons ul li a:hover {
padding: 9px !important;
}

#uc-site-header h1, #uc-site-header p, #uc-site-header a {
color: white;
}

.metaslider h1 {
color: white;
margin-top: 5px;
margin-bottom: 3px;
}

#footer li.simple-social-icons li {
margin-bottom: 0px !important;
}

#footer li.simple-social-icons ul {
margin-top: -10px;
}
221 changes: 221 additions & 0 deletions template-class.php
@@ -0,0 +1,221 @@
<?php

/**
* This plugin allows you to include templates with your plugin so that they can
* be added with any theme.
*
* @package Page Template Example
* @version 1.0.0
* @since 0.1.0
*/
class Page_Template_Plugin {

/**
* Plugin version, used for cache-busting of style and script file references.
*
* @since 1.0.0
*
* @var string
*/
const VERSION = '1.0.0';

/**
* Unique identifier for the plugin.
*
* The variable name is used as the text domain when internationalizing strings
* of text.
*
* @since 1.0.0
*
* @var string
*/
protected $plugin_slug;

/**
* A reference to an instance of this class.
*
* @since 0.1.0
*
* @var Page_Template_Plugin
*/
private static $instance;

/**
* The array of templates that this plugin tracks.
*
* @var array
*/
protected $templates;


/**
* Returns an instance of this class. An implementation of the singleton design pattern.
*
* @return Page_Templae_Example A reference to an instance of this class.
* @since 1.0.0
*/
public static function get_instance() {

if( null == self::$instance ) {
self::$instance = new Page_Template_Plugin();
} // end if

return self::$instance;

} // end getInstance

/**
* Initializes the plugin by setting localization, filters, and administration functions.
*
* @version 1.0.0
* @since 1.0.0
*/
private function __construct() {

$this->templates = array();
$this->plugin_locale = 'pte';

// Grab the translations for the plugin
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );

// Add a filter to the page attributes metabox to inject our template into the page template cache.
add_filter('page_attributes_dropdown_pages_args', array( $this, 'register_project_templates' ) );

// Add a filter to the save post in order to inject out template into the page cache
add_filter('wp_insert_post_data', array( $this, 'register_project_templates' ) );

// Add a filter to the template include in order to determine if the page has our template assigned and return it's path
add_filter('template_include', array( $this, 'view_project_template') );

// Register hooks that are fired when the plugin is activated, deactivated, and uninstalled, respectively.
register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );

// Add your templates to this array.
$this->templates = array(
'page-sample.php' => __( 'Sample', $this->plugin_slug ),
//'page-sample2.php' => __( 'Sample2', $this->plugin_slug ),
//'page-sample3.php' => __( 'Sample3', $this->plugin_slug ),
);

// adding support for theme templates to be merged and shown in dropdown
$templates = wp_get_theme()->get_page_templates();
$templates = array_merge( $templates, $this->templates );

} // end constructor

/**
* Load the plugin text domain for translation.
*
* @since 1.0.0
*/
public function load_plugin_textdomain() {

$domain = $this->plugin_slug;
$locale = apply_filters( 'plugin_locale', get_locale(), $domain );

load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '/' . $domain . '-' . $locale . '.mo' );
load_plugin_textdomain( $domain, FALSE, basename( dirname( __FILE__ ) ) . '/languages/' );

} // end load_plugin_textdomain

/**
* Adds our template to the pages cache in order to trick WordPress
* into thinking the template file exists where it doens't really exist.
*
* @param array $atts The attributes for the page attributes dropdown
* @return array $atts The attributes for the page attributes dropdown
* @verison 1.0.0
* @since 1.0.0
*/
public function register_project_templates( $atts ) {

// Create the key used for the themes cache
$cache_key = 'page_templates-' . md5( get_theme_root() . '/' . get_stylesheet() );

// Retrieve the cache list. If it doesn't exist, or it's empty prepare an array
$templates = wp_cache_get( $cache_key, 'themes' );
if ( empty( $templates ) ) {
$templates = array();
} // end if

// Since we've updated the cache, we need to delete the old cache
wp_cache_delete( $cache_key , 'themes');

// Now add our template to the list of templates by merging our templates
// with the existing templates array from the cache.
$templates = array_merge( $templates, $this->templates );

// Add the modified cache to allow WordPress to pick it up for listing
// available templates
wp_cache_add( $cache_key, $templates, 'themes', 1800 );

return $atts;

} // end register_project_templates

/**
* Checks if the template is assigned to the page
*
* @version 1.0.0
* @since 1.0.0
*/
public function view_project_template( $template ) {

global $post;

// If no posts found, return to
// avoid "Trying to get property of non-object" error
if ( !isset( $post ) ) return $template;

if ( ! isset( $this->templates[ get_post_meta( $post->ID, '_wp_page_template', true ) ] ) ) {
return $template;
} // end if

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

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

return $template;

} // end view_project_template

/*--------------------------------------------*
* deactivate the plugin
*---------------------------------------------*/
static function deactivate( $network_wide ) {
foreach($this as $value) {
page-template-example::delete_template( $value );
}

} // end deactivate

/*--------------------------------------------*
* Delete Templates from Theme
*---------------------------------------------*/
public function delete_template( $filename ){
$theme_path = get_template_directory();
$template_path = $theme_path . '/' . $filename;
if( file_exists( $template_path ) ) {
unlink( $template_path );
}

// we should probably delete the old cache
wp_cache_delete( $cache_key , 'themes');
}

/**
* Retrieves and returns the slug of this plugin. This function should be called on an instance
* of the plugin outside of this class.
*
* @return string The plugin's slug used in the locale.
* @version 1.0.0
* @since 1.0.0
*/
public function get_locale() {
return $this->plugin_slug;
} // end get_locale

} // end class
5 changes: 5 additions & 0 deletions templates/_notes/dwsync.xml
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8" ?>
<dwsync>
<file name="footer.php" server="development.wordpress.uconn.edu/edu.uconn.wordpress.development/public_html/wp-content/" local="131020296231496563" remote="131020296230000000" Dst="1" />
<file name="header.php" server="development.wordpress.uconn.edu/edu.uconn.wordpress.development/public_html/wp-content/" local="131020220764679034" remote="131020220760000000" Dst="1" />
</dwsync>

0 comments on commit 5dd1d1d

Please sign in to comment.