Ok, that's all!

parent 8f86e7d8
Pipeline #18 skipped
......@@ -39,7 +39,7 @@ class autoshortcoder_Settings {
public function __construct ( $parent ) {
$this->parent = $parent;
$this->base = 'wpt_';
$this->base = 'autoshortcode_';
// Initialise settings
add_action( 'init', array( $this, 'init_settings' ), 11 );
......
......@@ -76,6 +76,8 @@ class autoshortcoder {
*/
public $script_suffix;
private $done;
/**
* Constructor function.
* @access public
......@@ -85,6 +87,8 @@ class autoshortcoder {
public function __construct ( $file = '', $version = '1.0.0' ) {
$this->_version = $version;
$this->_token = 'autoshortcoder';
$this->done = false;
// Load plugin environment variables
$this->file = $file;
......@@ -106,9 +110,57 @@ class autoshortcoder {
}
//add_action( 'init', array( $this, 'load_localisation' ), 0 );
add_filter( 'the_content', array( $this, 'add_shortcodes'));
} // End __construct ()
public function get_tagarray () {
$options = get_option('autoshortcode_autoshortcode_settings');
$options = explode("\n", str_replace("\r", "", $options));
$opt=array();
foreach($options as $optline) {
$optarray = explode("|", $optline);
$tag = trim($optarray[0]);
if(count($optarray) > 2) {
$title=$optarray[1];
$shortcode=$optarray[2];
} else {
$title=false;
$shortcode=$optarray[1];
}
if(!in_array($tag, $opt))
$opt[$tag] = array();
$opt[$tag][] = array('title' => $title, 'shortcode' => $shortcode);
}
//print_r($opt);
return $opt;
}
public function add_shortcodes ( $content ) {
if(!$this->done) {
$tags = wp_get_post_tags($GLOBALS['post']->ID, array('fields' => 'names'));
$opts = $this->get_tagarray();
foreach($opts as $tagname => $tagcontent)
{
if (in_array($tagname, $tags)) {
foreach($tagcontent as $addcode) {
$content.="<hr>";
if($addcode['title']) {
$content.='<h4>'.$addcode['title'].'</h4>';
}
$content.=do_shortcode($addcode['shortcode']);
$content.="<hr>";
}
}
}
}
$this->done=true;
return $content;
}
/**
* Load admin CSS.
* @access public
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment