Forum Moderators: coopster
So here's the thing. There's a bit of code in WP core files - it's a class that's set. Within this class is a function that has a switch (case/break).
What I need to know is, is it possible to write a function *outside* this file that will insert an extra line of code into the switch?
For example, say the code is this:
class Something extends Another_Class{
function start($args) {
switch($args['style']) {
case: "div":
echo "<div>\n";
break;
case: "ol":
echo <ol>\n";
break;
} So I'm wanting to know if it's possib;e to write a piece of external code that will change the "div" case to this:
case: "div":
echo "<div id='someID'>\n";
echo "<div>\n";
break; So does anyone know if anything like this is possible? If so, can someone provide me a nudge on how? (like what am I looking for to pull this off?)
Thanks :)
yes, someone else mentioned the "extend" for the class - and I'm working to put that in place - but this part of PHP is a little beyond me. I get the idea (that it extends the original class), but I'm not really clear on the specifics. Right now, the class I'm trying to "overwrite" is a little complicated. Well, for me anyway! LOL
I'm trying to take the existing class, which is this (I'm cleaning it up a bit - getting rid of extraneous stuff):
class Walker_Comment extends Walker {
var $tree_type = 'comment';
var $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID'); function start_lvl(&$output, $depth, $args) {
$GLOBALS['comment_depth'] = $depth + 1;
switch ( $args['style'] ) {
case 'div':
break;
case 'ol':
echo "<ol class='children'>\n";
break;
default:
case 'ul':
echo "<ul class='children'>\n";
break;
}
} function end_lvl(&$output, $depth, $args) {
$GLOBALS['comment_depth'] = $depth + 1;
switch ( $args['style'] ) {
case 'div':
break;
case 'ol':
echo "</ol>\n";
break;
default:
case 'ul':
echo "</ul>\n";
break;
}
} function start_el(&$output, $comment, $depth, $args) {
$depth++;
$GLOBALS['comment_depth'] = $depth; if ( !empty($args['callback']) ) {call_user_func($args['callback'], $comment, $args, $depth);
return;
} $GLOBALS['comment'] = $comment;
extract($args, EXTR_SKIP); if ( 'div' == $args['style'] ) {
$tag = 'div';
$add_below = 'comment';
} else {
$tag = 'li';
$add_below = 'div-comment';
}
?> /* this part is actually the layout
} function end_el(&$output, $comment, $depth, $args) {
if ( !empty($args['end-callback']) ) {
call_user_func($args['end-callback'], $comment, $args, $depth);
return;
}
if ( 'div' == $args['style'] )
echo "</div>\n";
else
echo "</li>\n";
} } Now the bolded stuff above is what I want to change - I basically just want to add lines to the "switch" function (that's all I'm trying to do). So I wrote an "overwrite", and it takes - but only partially. When I actually get it to take without any errors, then the entire page is blank (however the source code is all there - which is REALLY bizarre to me - usually if the whole page is blank, the source code is blank too - but in this case, the background color shows up, but nothing else visually, but the source code is ALL there. Even my error logs are clean!). if I edit it to fix it so stuff is visible, I get error messages (and quite frankly, nothing shows up still LOL - just the errors)
So *something* is taking, but I haven't been able to muddle through *what* exactly is going on.
If you want to see what I did:
class my_Walker_Comment extends Walker {
var $tree_type = 'comment';
var $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID'); function start_lvl(&$output, $depth, $args) {
$GLOBALS['comment_depth'] = $depth + 1; switch ( $args['style'] ) {
case 'div': echo "<div class='replylink'>Show/Hide Replies</div>\n";
echo "<div class='children'>\n"; break;
case 'ol':
echo "<ol class='children'>\n";
break;
default:
case 'ul':
echo "<ul class='children'>\n";
break;
}
} function end_lvl(&$output, $depth, $args) {
$GLOBALS['comment_depth'] = $depth + 1; switch ( $args['style'] ) {
case 'div': echo "<!--/end children-->\n";
echo "</div>\n\n"; break;
case 'ol':
echo "</ol>\n";
break;
default:
case 'ul':
echo "</ul>\n";
break;
}
}
} $walker = new my_Walker_Comment();
$walker->start_lvl(&$output, $depth, $args);
$walker->end_lvl(&$output, $depth, $args); When I keep the "&$output, $depth, $args" part in the "$walker->" above, then the entire page is blank (save the source code and the background color), if I leave that part out, I get errors about missing arguments (which is to be expected I guess).
The bolded stuff is what I'm trying to add to the original class.
You know, it's suddenly dawned on me that maybe it *is* working, but the reason everything is blank is because I'm not redoing the entire class - just part of it. Hmm...