WPThemeReview icon indicating copy to clipboard operation
WPThemeReview copied to clipboard

Adding more functions in the discouraged functions list

Open ernilambar opened this issue 8 years ago • 12 comments

function name -> recommended usage

  • site_url() -> home_url()
  • get_home_url() -> home_url()
  • paginate_links() -> the_posts_pagination()
  • single_cat_title() -> the_archive_title()
  • single_tag_title() -> the_archive_title()
  • category_description() -> the_archive_description()
  • tag_description() -> the_archive_description()

ernilambar avatar Jan 23 '17 07:01 ernilambar

Related Theme Check issue https://github.com/WordPress/theme-check/issues/119

I think these would make sense. Just to clarify that these will be warning and not errors.

A PR can be made once we have merged the latest WPCS to this fork which should happen either this week or the next.

grappler avatar Jan 23 '17 08:01 grappler

@grappler Why wait for the back-merge ? A new WordPress.Theme.AlternativeFunctions or WordPress.Theme.DiscouragedFunctions sniff can be added any time. As these are quite Theme specific function, that seems most appropriate to me.

jrfnl avatar Jan 23 '17 14:01 jrfnl

WordPress.Theme.DiscouragedFunctions sounds good. I am not fully sure what I was thinking. Maybe to prevent merge conflicts or that I was high on the parameter abstract sniff.

grappler avatar Jan 23 '17 14:01 grappler

Isnt using home_url() instead of site_url() required? Similarly get_home_url() and paginate_links(). May be we should separate which should be ERROR and which are WARNING.

ernilambar avatar Jan 24 '17 03:01 ernilambar

Isnt using home_url() instead of site_url() required?

No, but we can always run the sniff on existing themes once is made to see if we can find any use cases.

May be we should separate which should be ERROR and which are WARNING.

The error would be part of restricted functions were as the warnings would be discouraged.

grappler avatar Jan 24 '17 16:01 grappler

I wouldn't report an error on any of those. There are legit use cases for them in themes. However, more often than not, the functions on the right are more appropriate. So, a warning/info notice might be appropriate.

justintadlock avatar Jan 24 '17 18:01 justintadlock

How about update_option()? I have had themes change my thumbnail size, my front page choice, created a menu (I know that's another function), and I don't actually know what else. I know they can store their own options, but is there some way to check they are not changing other things?

joyously avatar Apr 09 '17 19:04 joyously

@joyously Yes, by checking the parameter/option name that is being modified.

grappler avatar Apr 09 '17 20:04 grappler

Options need to be handled in the customizer, why would we allow this? "I know they can store their own options" What would this be?

carolinan avatar Apr 10 '17 05:04 carolinan

Examples found in themes for site_url() at https://wpdirectory.net/search/01CWPQE2HWN1VCW14NTJZVR73W

$atts['href'] = site_url() . esc_attr( $item->url );

wp_redirect(site_url());

$source = get_site_url();

if (strpos($item->src,get_site_url())!==false):

'domain' => esc_url(site_url()),

$items .= '<li class="menu-item nx-mega-menu"><a href="'. site_url('wp-login.php') .'">

$form = preg_replace( '/<\/form>/i', '<meta itemprop="target" content="' . site_url( '/?s={search} ' ) . '"/></form>', $form );

<a href=\'http://pixelthemestudio.ca/product/pixel-linear/\' target=\'_blank\'><img src='.site_url().'/wp-content/themes/pts-pixel-linear/admin/assets/images/new-ad.jpg /></a> '

echo '<a class="tag" alt="' . $tag->name . '" href="'.site_url("/").'?tag='.$tag->slug.'">'.$tag->name.'</a>';

$siteURL = str_replace( "www.", "", site_url( '/' ) );

joyously avatar Nov 19 '18 19:11 joyously

I'm thinking wp_redirect should be on this list.

joyously avatar May 17 '19 20:05 joyously

I don't think we have a PR on this, so I'll remove that tag. This sniff can go in a next release (after 0.2.0)

dingo-d avatar May 18 '19 12:05 dingo-d