Update from Git Manager GUI
This commit is contained in:
88
includes/class-wmw-shortcodes.php
Normal file
88
includes/class-wmw-shortcodes.php
Normal file
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) exit;
|
||||
|
||||
class WMW_Shortcodes {
|
||||
|
||||
public function register() {
|
||||
add_shortcode( 'wmw_wiki', array( $this, 'wiki_index' ) );
|
||||
add_shortcode( 'wmw_article', array( $this, 'single_article' ) );
|
||||
add_shortcode( 'wmw_search', array( $this, 'search_box' ) );
|
||||
add_shortcode( 'wmw_wiki_list', array( $this, 'wiki_list' ) );
|
||||
add_shortcode( 'wmw_breadcrumb', array( $this, 'breadcrumb' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* [wmw_wiki id="1"] or [wmw_wiki slug="my-plugin"]
|
||||
*/
|
||||
public function wiki_index( $atts ) {
|
||||
$atts = shortcode_atts( array(
|
||||
'id' => 0,
|
||||
'slug' => '',
|
||||
'layout' => 'grid', // grid | list
|
||||
), $atts, 'wmw_wiki' );
|
||||
|
||||
$wiki = null;
|
||||
if ( $atts['id'] ) {
|
||||
$wiki = get_post( absint( $atts['id'] ) );
|
||||
} elseif ( $atts['slug'] ) {
|
||||
$wiki = get_page_by_path( $atts['slug'], OBJECT, 'wmw_wiki' );
|
||||
}
|
||||
|
||||
if ( ! $wiki || $wiki->post_type !== 'wmw_wiki' ) return '';
|
||||
|
||||
ob_start();
|
||||
WMW_Frontend::render_wiki_index( $wiki, $atts['layout'] );
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* [wmw_article id="5"]
|
||||
*/
|
||||
public function single_article( $atts ) {
|
||||
$atts = shortcode_atts( array( 'id' => 0 ), $atts, 'wmw_article' );
|
||||
$article = get_post( absint( $atts['id'] ) );
|
||||
if ( ! $article || $article->post_type !== 'wmw_article' ) return '';
|
||||
|
||||
ob_start();
|
||||
WMW_Frontend::render_article( $article );
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* [wmw_search wiki_id="1" placeholder="Suche..."]
|
||||
*/
|
||||
public function search_box( $atts ) {
|
||||
$atts = shortcode_atts( array(
|
||||
'wiki_id' => 0,
|
||||
'placeholder' => 'Wiki durchsuchen…',
|
||||
), $atts, 'wmw_search' );
|
||||
|
||||
ob_start();
|
||||
WMW_Frontend::render_search_box( absint( $atts['wiki_id'] ), $atts['placeholder'] );
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* [wmw_wiki_list columns="3"]
|
||||
*/
|
||||
public function wiki_list( $atts ) {
|
||||
$atts = shortcode_atts( array( 'columns' => 3 ), $atts, 'wmw_wiki_list' );
|
||||
$wikis = wmw_get_wikis();
|
||||
if ( empty( $wikis ) ) return '';
|
||||
|
||||
ob_start();
|
||||
WMW_Frontend::render_wiki_list( $wikis, absint( $atts['columns'] ) );
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* [wmw_breadcrumb]
|
||||
*/
|
||||
public function breadcrumb( $atts ) {
|
||||
global $post;
|
||||
if ( ! $post ) return '';
|
||||
ob_start();
|
||||
WMW_Frontend::render_breadcrumb( $post );
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user