WordPress.org

Ready to get started?Download WordPress

Forums

BBCode for author description (3 posts)

  1. dilneiss88
    Member
    Posted 5 years ago #

    hi

    i'd like to make the bbcode to author descriptions works, like [img][url]

    i will make the description works like a signature (like forums)

    i searched alot and did'nt found anything...

  2. dilneiss88
    Member
    Posted 5 years ago #

    i found an way..
    but need to make this as a plugin.. anybody can help me to create a plugin for this?

    open: wp-includes/author-template.php
    Replace

    function the_author_description() {
    	echo get_the_author_description();
    }

    with

    function the_author_description() {
    	echo bbcode(get_the_author_description());
    }

    save send back to server

    open: ur themefolder/author.php

    replace: <?php echo $curauth->user_description; ?>
    with: <?php echo bbcode($curauth->user_description); ?>

    open: wp-includes/functions.php
    add in the last line before the ?>

    function bbcode($sText)
    {
       $sTagArray['B)'] = array('tag'=>'XX');
       $sTagArray['o}o'] = array('tag'=>'XX');
       $sTagArray['br'] = array('tag'=>'<br />');
       $sTagArray['hr'] = array('tag'=>'<hr>');
    
       $atagArray['img'] = array('open'=>'<img src="','close'=>'">');
       $atagArray['IMG'] = array('open'=>'<img src="','close'=>'">');
       $atagArray['b'] = array('open'=>'<b>', 'close'=>'</b>');
       $atagArray['B'] = array('open'=>'<b>', 'close'=>'</b>');
       $atagArray['i'] = array('open'=>'<i>', 'close'=>'</i>');
       $atagArray['u'] = array('open'=>'<u>', 'close'=>'</u>');
       $atagArray['url'] = array('open'=>'<a href="', 'close'=>'" target="_blank">\\1</a>');
       $atagArray['URL'] = array('open'=>'<a href="', 'close'=>'" target="_blank">\\1</a>');
       $atagArray['email'] = array('open'=>'<a href="mailto:', 'close'=>'">\\1</a>');
       $atagArray['url=(.*)'] = array('open'=>'<a href="', 'close'=>'" target="_blank">\\2</a>');
       $atagArray['URL=(.*)'] = array('open'=>'<a href="', 'close'=>'" target="_blank">\\2</a>');
       $atagArray['email=(.*)'] = array('open'=>'<a href="mailto:', 'close'=>'">\\2</a>');
       $atagArray['color=(.*)'] = array('open'=>'<font color="', 'close'=>'">\\2</font>');
       $atagArray['size=(.*)'] = array('open'=>'<font size="', 'close'=>'">\\2</font>');
       $atagArray['font=(.*)'] = array('open'=>'<font face="', 'close'=>'">\\2</font>');
    
       foreach ($atagArray as $stagName => $replace)
       {
           $tagEnd = preg_replace("/\W/sUi", "", $stagName);
    
           $sText = preg_replace(
               "|\[$stagName\](.*)\[/$tagEnd\]|sUi",
               "$replace[open]\\1$replace[close]",
               $sText
           );
       }
    
       foreach ($sTagArray as $stagName => $replace)
       {
           if (eregi("[)(#$]", $stagName))
           {
               $stagNameNew = preg_replace("#([\)\(\$\#])#", "\\ \\1", $stagName);
               $stagNameNew = preg_replace("#( +)#", "", $stagNameNew);
               $sTagArray[ $stagNameNew ] = array('tag' => $replace['tag']);
               unset($sTagArray[ $stagName ]);
           }
       }
    
       foreach ($sTagArray as $stagName => $replace)
       {
           $sText= preg_replace("|\[$stagName\]|sUi", "$replace[tag]", $sText);
       }
    
       return $sText;
    }

    done :D

    now, need to improve this as a plugin..

  3. NotAlame
    Member
    Posted 4 years ago #

    Hi!

    I want to know how to insert this function in the function file of a wordpress theme so that we can use it...

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic