/** * instantiates the shortcode object * * @param array $shortcode_atts the raw parameters passed in from the shortcode * @param array $subclass_shortcode_defaults additional shortcode attributes to use as defined * in the instantiating subclass * */ public function __construct($shortcode_atts, $subclass_shortcode_defaults = array()) { // set the global shortcode flag Participants_Db::$shortcode_present = true; $this->prefix = Participants_Db::$prefix; // increment the index each time this class is instantiated Participants_Db::$instance_index++; $this->shortcode_defaults = array('title' => '', 'class' => '', 'template' => 'default', 'fields' => '', 'groups' => '', 'action' => '', 'target_instance' => Participants_Db::$instance_index, 'target_page' => '', 'record_id' => false, 'filtering' => 0); // error_log(__METHOD__.' incoming shorcode atts:'.print_r($shortcode_atts,1)); // set up the shortcode_atts property $this->_setup_shortcode_atts($shortcode_atts, $subclass_shortcode_defaults); $this->module = $this->shortcode_atts['module']; /* * save the shortcode attributes to the session array * * skip this if doing AJAX because it would just store the default values, not * the actual values from the shortcode */ if ($this->shortcode_atts['filtering'] != 1) { Participants_Db::$session->update($this->prefix . 'shortcode_atts', array($this->module => array(Participants_Db::$instance_index => $this->shortcode_atts))); } $this->wrap_class = $this->prefix . $this->module . ' ' . $this->prefix . 'instance-' . Participants_Db::$instance_index; //$this->module = $subclass->module; $this->options = Participants_Db::$plugin_options; $this->display_groups = $this->_get_display_groups(); $this->_set_display_columns(); $this->wrap_class = trim($this->wrap_class) . ' ' . trim($this->shortcode_atts['class']); // set the template to use $this->set_template($this->shortcode_atts['template']); }
/** * triggers the shortcode present action the first time a plugin shortcode is instantiated * */ public function plugin_shortcode_action() { if (!Participants_Db::$shortcode_present) { Participants_Db::$shortcode_present = true; do_action(Participants_Db::$prefix . 'shortcode_active'); } }
/** * checks a template for an embedded shortcode * * runs on the 'template_include' filter * * @param type $template name of the template file in use * @param string $tag the shortcode string to search for * @return bool true if a shortcode matching the tag is present in the template */ public static function template_check_shortcode($template, $tag = '[pdb_') { if (file_exists($template)) { $contents = file_get_contents($template); if (self::has_shortcode($contents, $tag)) { self::$shortcode_present = true; } } return $template; }