]> _ Git - nec-initiative-wordpress.git/commitdiff
Localise configuration and add simple plugin to enable theme-independent page templates.
authorStephen Cameron <stephen@cubedesigners.com>
Thu, 22 Jul 2021 09:49:00 +0000 (11:49 +0200)
committerStephen Cameron <stephen@cubedesigners.com>
Thu, 22 Jul 2021 09:49:00 +0000 (11:49 +0200)
.gitignore
wp-config.php
wp-content/plugins/cube-templater/cube-templater.php [new file with mode: 0644]
wp-content/plugins/cube-templater/templates/gutenberg-full-width.php [new file with mode: 0644]

index 567e5c69d64497ebf5cc914bf0c81920ba446489..8a2d890a8d4533623a671540742b896e9f5fa441 100644 (file)
@@ -6,6 +6,9 @@ local-config.php
 node_modules
 *.log
 /wp-content/*
+!/wp-content/plugins/
+/wp-content/plugins/*
+!/wp-content/plugins/cube-templater/
 # /wp-content/themes/index.php
 # !/wp-content/themes/
 # !/wp-content/mu-plugins/
index 9d3b4cf816710f91a702d3c862c6d50d101b1686..073a5835c39bd9d6bfe3c694bb07adea8d641d04 100644 (file)
@@ -1,41 +1,32 @@
 <?php
-/**
- * The base configuration for WordPress
- *
- * The wp-config.php creation script uses this file during the
- * installation. You don't have to use the web site, you can
- * copy this file to "wp-config.php" and fill in the values.
- *
- * This file contains the following configurations:
- *
- * * MySQL settings
- * * Secret keys
- * * Database table prefix
- * * ABSPATH
- *
- * @link https://codex.wordpress.org/Editing_wp-config.php
- *
- * @package WordPress
- */
-
-// ** MySQL settings - You can get this info from your web host ** //
-/** The name of the database for WordPress */
-define('DB_NAME', 'necinitiysnec');
-
-/** MySQL database username */
-define('DB_USER', 'necinitiysnec');
-
-/** MySQL database password */
-define('DB_PASSWORD', 'HARper123');
+// Include local configuration if it exists
+if (file_exists(dirname(__FILE__) . '/local-config.php')) {
+    include(dirname(__FILE__) . '/local-config.php');
+}
 
-/** MySQL hostname */
-define('DB_HOST', 'necinitiysnec.mysql.db');
+// Global DB config
+if (!defined('DB_NAME')) {
+    define('DB_NAME', 'necinitiysnec');
+}
+if (!defined('DB_USER')) {
+    define('DB_USER', 'necinitiysnec');
+}
+if (!defined('DB_PASSWORD')) {
+    define('DB_PASSWORD', 'HARper123');
+}
+if (!defined('DB_HOST')) {
+    define('DB_HOST', 'necinitiysnec.mysql.db');
+}
 
 /** Database Charset to use in creating database tables. */
-define('DB_CHARSET', 'utf8mb4');
+if (!defined('DB_CHARSET')) {
+    define('DB_CHARSET', 'utf8mb4');
+}
 
 /** The Database Collate type. Don't change this if in doubt. */
-define('DB_COLLATE', '');
+if (!defined('DB_COLLATE')) {
+    define('DB_COLLATE', '');
+}
 
 /**#@+
  * Authentication Unique Keys and Salts.
@@ -77,7 +68,9 @@ $table_prefix  = 'wp_';
  *
  * @link https://codex.wordpress.org/Debugging_in_WordPress
  */
-define('WP_DEBUG', false);
+if (!defined('WP_DEBUG')) {
+    define('WP_DEBUG', false);
+}
 
 /* That's all, stop editing! Happy blogging. */
 
diff --git a/wp-content/plugins/cube-templater/cube-templater.php b/wp-content/plugins/cube-templater/cube-templater.php
new file mode 100644 (file)
index 0000000..27dd0be
--- /dev/null
@@ -0,0 +1,168 @@
+<?php
+/*
+Plugin Name: Theme Independent Page Templates
+Plugin URI: http://www.wpexplorer.com/wordpress-page-templates-plugin/
+Description: Allows page templates to be added independent of a theme. Necessary in order to add a page template to Mesmerize PRO theme.
+Version: 1.1.0
+Author: WPExplorer + Cubedesigners
+Author URI: http://www.wpexplorer.com/
+*/
+
+class PageTemplater {
+
+    /**
+     * A reference to an instance of this class.
+     */
+    private static $instance;
+
+    /**
+     * The array of templates that this plugin tracks.
+     */
+    protected $templates;
+
+    /**
+     * Returns an instance of this class.
+     */
+    public static function get_instance() {
+
+        if ( null == self::$instance ) {
+            self::$instance = new PageTemplater();
+        }
+
+        return self::$instance;
+
+    }
+
+    /**
+     * Initializes the plugin by setting filters and administration functions.
+     */
+    private function __construct() {
+
+        $this->templates = array();
+
+
+        // Add a filter to the attributes metabox to inject template into the cache.
+        if ( version_compare( floatval( get_bloginfo( 'version' ) ), '4.7', '<' ) ) {
+
+            // 4.6 and older
+            add_filter(
+                'page_attributes_dropdown_pages_args',
+                array( $this, 'register_project_templates' )
+            );
+
+        } else {
+
+            // Add a filter to the wp 4.7 version attributes metabox
+            add_filter(
+                'theme_page_templates', array( $this, 'add_new_template' )
+            );
+
+        }
+
+        // Add a filter to the save post 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 to determine if the page has our
+        // template assigned and return it's path
+        add_filter(
+            'template_include',
+            array( $this, 'view_project_template')
+        );
+
+
+        // Add your templates to this array.
+        $this->templates = array(
+            'gutenberg-full-width.php' => 'Gutenberg Full Width Page',
+        );
+
+    }
+
+    /**
+     * Adds our template to the page dropdown for v4.7+
+     *
+     */
+    public function add_new_template( $posts_templates ) {
+        $posts_templates = array_merge( $posts_templates, $this->templates );
+        return $posts_templates;
+    }
+
+    /**
+     * Adds our template to the pages cache in order to trick WordPress
+     * into thinking the template file exists where it doens't really exist.
+     */
+    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_get_theme()->get_page_templates();
+        if ( empty( $templates ) ) {
+            $templates = array();
+        }
+
+        // New cache, therefore remove the old one
+        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;
+
+    }
+
+    /**
+     * Checks if the template is assigned to the page
+     */
+    public function view_project_template( $template ) {
+        // Return the search template if we're searching (instead of the template for the first result)
+        if ( is_search() ) {
+            return $template;
+        }
+
+        // Get global post
+        global $post;
+
+        // Return template if post is empty
+        if ( ! $post ) {
+            return $template;
+        }
+
+        // Return default template if we don't have a custom one defined
+        if ( ! isset( $this->templates[get_post_meta(
+                $post->ID, '_wp_page_template', true
+            )] ) ) {
+            return $template;
+        }
+
+        // Allows filtering of file path (default: ./templates subfolder of theme)
+        $filepath = apply_filters( 'page_templater_plugin_dir_path', plugin_dir_path( __FILE__ ) . 'templates/' );
+
+        $file =  $filepath . 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;
+        } else {
+            echo $file;
+        }
+
+        // Return template
+        return $template;
+
+    }
+
+}
+add_action( 'plugins_loaded', array( 'PageTemplater', 'get_instance' ) );
diff --git a/wp-content/plugins/cube-templater/templates/gutenberg-full-width.php b/wp-content/plugins/cube-templater/templates/gutenberg-full-width.php
new file mode 100644 (file)
index 0000000..ee7518b
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+/*
+ * Template Name: Gutenberg Full Width Page
+ * This template is needed so we can use the normal Gutenberg editor instead of the stupid Mesmerize Customizer
+ * interface for long text pages. At least with Gutenberg we can control formatting and heading levels.
+ * This template is based on the Full Width Page template from Mesmerize PRO.
+ */
+
+### NOTE: This template needs to be manually added to the plugin's constructor (cube-templater.php)
+
+//add_filter('mesmerize_full_width_page', '__return_true');
+
+mesmerize_get_header();
+?>
+    <div class="<?php mesmerize_page_content_class(); ?>">
+        <div class="<?php mesmerize_page_content_wrapper_class(); ?>">
+
+            <div class="content-section content-section-spacing">
+                <div class="gridContainer">
+                    <div class="row">
+                        <div data-type="column">
+                            <?php
+                            while (have_posts()) : the_post();
+                                the_content();
+                            endwhile;
+                            ?>
+                        </div>
+                    </div>
+                </div>
+            </div>
+
+        </div>
+    </div>
+
+<?php get_footer(); ?>