Last active
July 29, 2016 15:35
-
-
Save quimo/a5125a59e55498df526600e83e89958c to your computer and use it in GitHub Desktop.
WordPress | Plugin Skinner
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Plugin Name: Skinner | |
| * Plugin URI: | |
| * Description: Simple sub-template manager | |
| * Version: 1.0 | |
| * Author: Simone Alati | |
| * Author URI: http://www.simonealati.it | |
| */ | |
| class Skinner { | |
| /** | |
| * render | |
| * mostra un chunk HTML eseguendo le sostituzioni dei placeholder | |
| * Skinner::render(array( | |
| * 'template' => 'test', | |
| * 'fields' => 'campo1,campo2,campo3' | |
| * ); | |
| * i template si trovano in "plugins/skinner/templates/" | |
| */ | |
| public static function render($atts) { | |
| // analisi parametri | |
| $template = $atts['template']; | |
| $fields = $atts['fields']; | |
| $data = explode(',',$fields); | |
| $plugin_url = plugins_url(); | |
| $subtemplate_url = plugins_url().'/skinner/templates'; | |
| // recupero template | |
| $template_content = @file_get_contents($subtemplate_url.'/'.$template.'.html'); | |
| if ($template_content === false) $template_content = @file_get_contents($subtemplate_url.'/'.$template.'.htm'); | |
| // sostituzione dei [+placeholder+] | |
| if ($template_content && $data) { | |
| foreach ($data as $value) { | |
| // sostituzione dei campi ACF | |
| if (get_field($value)) $template_content = str_replace("[+".$value."+]",get_field($value),$template_content); | |
| } | |
| } | |
| return $template_content; | |
| } | |
| } | |
| add_shortcode('skinner','Skinner::render'); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment