Apparently I don’t know enough about BBCode definition
  • I’m trying to implement the Subroutines feature from my old engine. It’s very useful when an entry contains repeating text or formatting. But obviously I don’t know enough yet. After spending two days with it, let me ask you what’s the problem.

    What do I want?
    I want a tag pair called [sub name]contents[/sub], which creates a [name parameters] tag for BBCode. This puts contents in the text, replacing placeholders with parameters. For example,
    [sub keyboard](table)(tr)(td)%1(/td)………[/sub]
    [keyboard Q W E R T ………]
    This creates a template to display a keyboard with a table and put letters on it.

    What did I do?
    As for the parameter handling, I didn’t reach there yet. The problem is in an earlier stage. I „wrote” a function to create the [sub] tag:
    add_filter('init', 'plugin_sub_def');

    function plugin_sub_def() {
    $bbcode =& plugin_bbcode_init();

    $bbcode->addCode (
     'sub',
     'callback_replace',
     'plugin_sub_add',
     array('usecontent_param' => array ('default')),
     'inline',
     array ('listitem', 'block', 'inline', 'link'),
     array ());
    $bbcode->setCodeFlag ('sub', 'closetag', BBCODE_CLOSETAG_MUSTEXIST);
    }
    In fact, I copied it from other plugins. And I „wrote” another function to be called by the tag:
    function plugin_sub_add($action, $attributes, $content, $params, &$node_object) {
    if ($action == 'validate') {
    return true;
    }

      $name=key($attributes);
    echo '{'.$name.'}<br>';
      echo '{{'.$content.'}}<br>';

    $bbcode =& plugin_bbcode_init();

    $bbcode->addCode (
     $name,
     'callback_replace_single',
     'plugin_sub_execute',
     array('usecontent_param' => array ('default'),
     'content'=>$content),
     'inline',
     array ('listitem', 'block', 'inline', 'link'),
     array ());
    $bbcode->setCodeFlag ($name, 'closetag', BBCODE_CLOSETAG_FORBIDDEN);

    // echo'<pre>';print_r($bbcode->_codes);echo'</pre>';
    return $content;
    }
    The echo statements are just for debugging, of course. The line with // lists the BBCode tags database, and proves the new tag is registered.
    Now we’re supposed to have a new tag (in the example, [keyboard]) in the database, and it has to call the third function, plugin_sub_execute, which is yet unwritten, there are only some debugging code there to notify the control is passing by. But it doesn’t.

    What am I doing wrong? Sorry if it’s deadly obvious for the expert, but I’m just popped out from the egg.