/* Plugin Name: Child Pages Shortcode Author: Takayuki Miyauchi Plugin URI: https://github.com/miya0001/child-pages-shortcode Description: You can use shortcode for display child pages from the page. Version: 1.9.3 Author URI: http://wpist.me/ Domain Path: /languages Text Domain: child-pages-shortcode */ $child_pages_shortcode = new Child_Pages_Shortcode(); $child_pages_shortcode->register(); class Child_Pages_Shortcode { private $ver = '1.1.4'; function register() { add_action('plugins_loaded', array($this, 'plugins_loaded')); } function plugins_loaded() { add_shortcode("child_pages", array($this, "shortcode")); add_action("init", array($this, "init")); add_action("wp_enqueue_scripts", array($this, "wp_enqueue_scripts")); } public function init() { add_post_type_support('page', 'excerpt'); } public function wp_enqueue_scripts() { /* * Filter the stylesheet URI * * @since none * @param string $stylesheet_uri URI to the stylesheet. */ $css = apply_filters( "child-pages-shortcode-stylesheet", plugins_url("css/child-pages-shortcode.min.css", __FILE__) ); wp_enqueue_style( 'child-pages-shortcode-css', $css, array(), $this->ver, 'all' ); /* * Filter the JavaScript URI * * @since none * @param string $javascript_uri URI to the JavaScript. */ $js = apply_filters( "child-pages-shortcode-js", plugins_url("js/child-pages-shortcode.min.js", __FILE__) ); wp_enqueue_script( 'child-pages-shortcode', $js, array('jquery'), $this->ver, false ); } public function shortcode($p, $template = null) { if( !isset($p['id']) || !intval($p['id']) ){ $p['id'] = get_the_ID(); } if (!isset($p['size']) || !$p['size']) { $p['size'] = 'thumbnail'; } if (!isset($p['width']) || !intval($p['width'])) { $p['width'] = "50%"; } if (!isset($p['disable_shortcode']) || !$p['disable_shortcode']) { add_filter("child-pages-shortcode-output", "do_shortcode"); } return $this->display($p, $template); } private function display($p, $block_template) { global $post; $html = ''; if ($block_template) { $template = $block_template; $template = str_replace('
', '', $template); $template = str_replace('
', '', $template); /* * Filter the temaplate * * @since none * @param string $template Template HTML. */ $template = apply_filters( 'child-pages-shortcode-template', $template, $p ); } else { /* * Filter the temaplate * * @since none * @param string $template Template HTML. */ $template = apply_filters( 'child-pages-shortcode-template', $this->get_template(), $p ); $html = sprintf( '