Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

i want to submit a theme to the wordpress.org. when i put the define('WP_DEBUG', true); in my wp-config.php. my theme showed some errors.but i don't know how to correct theme.

Q1:Warning: Missing argument 2 for cutstr() in ....htdocs\wordpress\wp-content\themes\warm-home\functions.php on line 156. the following is my function.

function cutstr($string, $length) {
         $string =strip_tags($string);
        preg_match_all("/[x01-x7f]|[xc2-xdf][x80-xbf]|xe0[xa0-xbf][x80-xbf]|
[xe1-xef][x80-xbf][x80-xbf]|xf0[x90-xbf][x80-xbf][x80-xbf]|[xf1-xf7][x80-xbf][x80-xbf][x80-xbf]/", $string, $info);  
         for($i=0; $i<count($info[0]); $i++) {
                $wordscut= '';
                $wordscut .= $info[0][$i];
                $j='';
                $j = ord($info[0][$i]) > 127 ? $j + 2 : $j + 1;
                 if ($j > $length - 3) {
                         return $wordscut." ...";
                 }
         }
         return join('', $info[0]);
}
add_action('after_setup_theme','cutstr');

invoked the function line is: <p><?php echo cutstr($post->post_content,150) ?></p>.there is no Missing argument 2 . why shows the above error? how correct it?

share|improve this question
add comment

1 Answer

do_action( 'after_setup_theme' ); doesn’t pass any parameter. You are cutting something of the length 0 after theme setup. Why?

Plus, your registration with add_action doesn’t tell WordPress that you want two parameters. The default is one parameter.

You don’t need this call at all. If you define the function in your functions.php it will be available in the loop.

Learn the Plugin API, it isn’t so hard. :)

Always prefix you functions. Otherwise your users may get fatal errors when someone else has written a function with the same name.

If your function does what I think it does, you may have a look at my function utf8_truncate(). No regex needed.

share|improve this answer
    
there is no do_action() in my function? how to write the add_action function. i am sorry. i am new to programme.add_action('after_setup_theme','cutstr()');. is this right? –  enjoylife May 29 '11 at 9:04
    
once there was an error told me.the theme registers some custom functionality in the function warmHome_setup() however this function in not hooked so the functionality is not available. Recommend hooking the theme to the after_setup_theme hook. –  enjoylife May 29 '11 at 9:08
    
so i think if i custom a function ,i should add this line after the function"add_action('after_setup_theme','cutstr()'). so could you tell me,when i should add the add_action. thank you –  enjoylife May 29 '11 at 9:09
    
@enjoylife I added a note about the add_action() call. Read the Codex page about filters and actions. I cannot say it better. –  toscho May 29 '11 at 9:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.