• Resolved Marco

    (@jrmarco)


    Morning everyone,
    I’m have some issue with shortcode defined by a plugin that I’m working on. Shortcode are define by users, saved into a table (wpdb) and called by relative shortcode:
    ex. user define: [text] -> here-my-recall
    What I have since now is :

    	function callback($att,$content,$tag){
            global $wpdb;
    
    	/* Row result from SQL query */
    	$data = $wpdb->get_results($sql);
    		foreach($data as $row) {
    			$shortcode = $row->shortcode;
    			$code = $row->code;
    			if(strcmp($tag,$shortcode)) { return $code; break; }
    		}
    	}
    	
    	function shortcode_add() {
    		global $wpdb;
    
    	/* Row result from SQL query */
    		$data = $wpdb->get_results($sql);
    		foreach($data as $row) {
    			$shortcode = $row->shortcode;
    			add_shortcode($shortcode,'callback');
    		}
    	}

    Now how can I let WP learn them and use everywhere?
    Thanks for help

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    You cannot pass a new shortcode tag as an existing shortcode tag, WP will not recognize it as a shortcode. It’s not just the square brackets that make up a shortcode. The tag needs to be recognized as well. Try a different definition structure. For example:
    [define tag="example"]Text to replace every occurrence of the "example" shortcode[/define]

    You would add your shortcode tag “define” where the callback adds user shortcodes based on the “tag” attribute and content within the [define] shortcode tags.

    Ya know, there’s all sorts of text expanders already available, which is what you are creating here. Users could simply install one of these existing expanders to get the same functionality. The true power of shortcodes is logic can be programmed into the callbacks to handle complex situations. If you want to “reinvent the wheel”, that’s fine, I just wanted to point out that very similar solutions exist. There is something elegant about using shortcodes to define shortcodes!

Viewing 1 replies (of 1 total)

The topic ‘Shortcode and plugin’ is closed to new replies.