Changeset 2487416
- Timestamp:
- 03/05/2021 02:17:22 AM (5 years ago)
- Location:
- layers/trunk
- Files:
-
- 2 edited
-
layers.php (modified) (1 diff)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
layers/trunk/layers.php
r2470618 r2487416 13 13 14 14 if ( !defined( 'ABSPATH' ) ) { 15 http_response_code( 404 );16 die();15 http_response_code( 404 ); 16 die(); 17 17 } 18 18 19 add_shortcode( 'layer', 'layers_shortcode' ); 19 20 function layers_shortcode( $atts, $content = null ) { 20 $atts = shortcode_atts(21 array(22 'id'=> '',23 'class'=> '',24 'color'=> '',25 'padding'=> '',26 'background-color' => '',27 'background-image' => '',28 ),29 $atts,30 'layer'31 );32 return '<div id="' . $atts['id'] . '" class="layer ' . $atts['class'] . '" style="color:' . $atts['color'] . ';padding:' . $atts['padding'] . ';background-color:' . $atts['background-color'] . ';background-image:url(' . $atts['background-image'] . ')">' . do_shortcode( $content ) . '</div>';21 $atts = shortcode_atts( 22 array( 23 'id' => '', 24 'class' => '', 25 'color' => '', 26 'padding' => '', 27 'background-color' => '', 28 'background-image' => '', 29 ), 30 $atts, 31 'layer' 32 ); 33 return '<div id="' . $atts['id'] . '" class="layer ' . $atts['class'] . '" style="color:' . $atts['color'] . ';padding:' . $atts['padding'] . ';background-color:' . $atts['background-color'] . ';background-image:url(' . $atts['background-image'] . ')">' . do_shortcode( $content ) . '</div>'; 33 34 } 34 add_shortcode( 'layer', 'layers_shortcode' ); 35 36 add_action( 'plugins_loaded', array( 'LayersPageTemplate', 'get_instance' ) ); 35 37 class LayersPageTemplate { 36 private static $instance; 37 protected $templates; 38 public static function get_instance() { 39 if ( null == self::$instance ) { 40 self::$instance = new LayersPageTemplate(); 41 } 42 return self::$instance; 43 } 44 private function __construct() { 45 $this->templates = array(); 46 if ( version_compare( floatval( get_bloginfo( 'version' ) ), '4.7', '<' ) ) { 47 add_filter( 48 'page_attributes_dropdown_pages_args', 49 array( $this, 'register_project_templates' ) 50 ); 51 } else { 52 add_filter( 53 'theme_page_templates', array( $this, 'add_new_template' ) 54 ); 38 private static $instance; 39 protected $templates; 40 public static function get_instance() { 41 if ( null == self::$instance ) { 42 self::$instance = new LayersPageTemplate(); 43 } 44 return self::$instance; 45 } 46 private function __construct() { 47 $this->templates = array(); 48 if ( version_compare( floatval( get_bloginfo( 'version' ) ), '4.7', '<' ) ) { 49 add_filter( 50 'page_attributes_dropdown_pages_args', 51 array( $this, 'register_project_templates' ) 52 ); 53 } else { 54 add_filter( 55 'theme_page_templates', array( $this, 'add_new_template' ) 56 ); 57 } 58 add_filter( 59 'wp_insert_post_data', 60 array( $this, 'register_project_templates' ) 61 ); 62 add_filter( 63 'template_include', 64 array( $this, 'view_project_template') 65 ); 66 $this->templates = array( 67 'layers-template.php' => 'Layers', 68 ); 69 } 70 public function add_new_template( $posts_templates ) { 71 $posts_templates = array_merge( $posts_templates, $this->templates ); 72 return $posts_templates; 73 } 74 public function register_project_templates( $atts ) { 75 $cache_key = 'page_templates-' . md5( get_theme_root() . '/' . get_stylesheet() ); 76 $templates = wp_get_theme()->get_page_templates(); 77 if ( empty( $templates ) ) { 78 $templates = array(); 79 } 80 wp_cache_delete( $cache_key , 'themes'); 81 $templates = array_merge( $templates, $this->templates ); 82 wp_cache_add( $cache_key, $templates, 'themes', 1800 ); 83 return $atts; 84 } 85 public function view_project_template( $template ) { 86 global $post; 87 if ( ! $post ) { 88 return $template; 89 } 90 if ( ! isset( $this->templates[get_post_meta( 91 $post->ID, '_wp_page_template', true 92 )] ) ) { 93 return $template; 94 } 95 $file = plugin_dir_path( __FILE__ ) . get_post_meta( 96 $post->ID, '_wp_page_template', true 97 ); 98 if ( file_exists( $file ) ) { 99 return $file; 100 } else { 101 echo $file; 102 } 103 return $template; 104 } 55 105 } 56 add_filter(57 'wp_insert_post_data',58 array( $this, 'register_project_templates' )59 );60 add_filter(61 'template_include',62 array( $this, 'view_project_template')63 );64 $this->templates = array(65 'layers-template.php' => 'Layers',66 );67 }68 public function add_new_template( $posts_templates ) {69 $posts_templates = array_merge( $posts_templates, $this->templates );70 return $posts_templates;71 }72 public function register_project_templates( $atts ) {73 $cache_key = 'page_templates-' . md5( get_theme_root() . '/' . get_stylesheet() );74 $templates = wp_get_theme()->get_page_templates();75 if ( empty( $templates ) ) {76 $templates = array();77 }78 wp_cache_delete( $cache_key , 'themes');79 $templates = array_merge( $templates, $this->templates );80 wp_cache_add( $cache_key, $templates, 'themes', 1800 );81 return $atts;82 }83 public function view_project_template( $template ) {84 global $post;85 if ( ! $post ) {86 return $template;87 }88 if ( ! isset( $this->templates[get_post_meta(89 $post->ID, '_wp_page_template', true90 )] ) ) {91 return $template;92 }93 $file = plugin_dir_path( __FILE__ ). get_post_meta(94 $post->ID, '_wp_page_template', true95 );96 if ( file_exists( $file ) ) {97 return $file;98 } else {99 echo $file;100 }101 return $template;102 }103 }104 add_action( 'plugins_loaded', array( 'LayersPageTemplate', 'get_instance' ) ); -
layers/trunk/readme.txt
r2470618 r2487416 6 6 Tags: layer, layers, section, sections, panel, panels, hero 7 7 Requires at least: 5.0 8 Tested up to: 5. 68 Tested up to: 5.7 9 9 License: GPL 10 10 License URI: https://www.gnu.org/licenses/gpl.html
Note: See TracChangeset
for help on using the changeset viewer.