From 5dd1d1d4803e12d8b4b1030bd969a698ea8fe2c5 Mon Sep 17 00:00:00 2001 From: Christopher M Cerrigione Date: Thu, 10 Mar 2016 12:23:03 -0500 Subject: [PATCH] initial commit --- grandchild-functions.php | 64 +++++++++++ grandchild-scripts.js | 5 + grandchild-styles.css | 49 ++++++++ template-class.php | 221 ++++++++++++++++++++++++++++++++++++ templates/_notes/dwsync.xml | 5 + templates/footer.php | 54 +++++++++ templates/header.php | 88 ++++++++++++++ test.rtf | 7 -- 8 files changed, 486 insertions(+), 7 deletions(-) create mode 100644 grandchild-functions.php create mode 100644 grandchild-scripts.js create mode 100644 grandchild-styles.css create mode 100644 template-class.php create mode 100644 templates/_notes/dwsync.xml create mode 100644 templates/footer.php create mode 100644 templates/header.php delete mode 100644 test.rtf diff --git a/grandchild-functions.php b/grandchild-functions.php new file mode 100644 index 0000000..41c5640 --- /dev/null +++ b/grandchild-functions.php @@ -0,0 +1,64 @@ + __( 'Header - Image' ), + 'id' => 'header-image', + 'description' => __( 'Widgets in this area will be shown in the header.' ), + 'before_title' => '

', + 'after_title' => '

', + ) ); + + 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' => '

', + 'after_title' => '

', + ) ); +} + +// 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 ); \ No newline at end of file diff --git a/grandchild-scripts.js b/grandchild-scripts.js new file mode 100644 index 0000000..fa28f0b --- /dev/null +++ b/grandchild-scripts.js @@ -0,0 +1,5 @@ +jQuery(document).ready(function() { + + //alert('grandchild'); + +}); diff --git a/grandchild-styles.css b/grandchild-styles.css new file mode 100644 index 0000000..b2cdd79 --- /dev/null +++ b/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; +} \ No newline at end of file diff --git a/template-class.php b/template-class.php new file mode 100644 index 0000000..f64c1ce --- /dev/null +++ b/template-class.php @@ -0,0 +1,221 @@ +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 diff --git a/templates/_notes/dwsync.xml b/templates/_notes/dwsync.xml new file mode 100644 index 0000000..fcd89cc --- /dev/null +++ b/templates/_notes/dwsync.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/templates/footer.php b/templates/footer.php new file mode 100644 index 0000000..1a280a3 --- /dev/null +++ b/templates/footer.php @@ -0,0 +1,54 @@ + + + + +
+ + +
+ + + + + diff --git a/templates/header.php b/templates/header.php new file mode 100644 index 0000000..8db659b --- /dev/null +++ b/templates/header.php @@ -0,0 +1,88 @@ + section and everything up till
+ * + */ + +include get_template_directory().'/inc/vars.php'; + +?> + +> + + + + + +<?php wp_title( '|', true, 'right' ); ?> + + + + + +> + + + + + + +
+ + +
+
\ No newline at end of file diff --git a/test.rtf b/test.rtf deleted file mode 100644 index ab98d9a..0000000 --- a/test.rtf +++ /dev/null @@ -1,7 +0,0 @@ -{\rtf1\ansi\ansicpg1252\cocoartf1404\cocoasubrtf340 -{\fonttbl\f0\fswiss\fcharset0 Helvetica;} -{\colortbl;\red255\green255\blue255;} -\margl1440\margr1440\vieww10800\viewh8400\viewkind0 -\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0 - -\f0\fs24 \cf0 Hello World } \ No newline at end of file