-2

I want to check if a path contain a string,

like, if path contain plugins then return false, and if path contain themes then return true.

D:\wamp\www\wp-content/plugins/someplugin/index.phtml // return false

D:\wamp\www\wp-content/themes/index.php // return true
rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
user007
  • 3,203
  • 13
  • 46
  • 77

2 Answers2

1

I hope this suffices.

<?php

$pos1 = stripos('D:\wamp\www\wp-content/theme/someplugin/index.phtml', 'theme');
if ($pos1 === false) {
    echo "Not a theme";
}
else
{
    echo "It's a theme !";
}
?>

OUTPUT:

It's a theme !

Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
1

Just because @Dave Chen asked :

So what would wp-plugins or wp-themes trigger?

then, set an exact match :

$themes = "/themes/";
$file01 = "D:\wamp\www\wp-content/themes/index.php"; 
$file02 = "D:\wamp\www\wp-content/wp-themes/index.php";

$is_theme = stripos($file01, $themes ); // returns true
$is_theme = stripos($file02, $themes ); // returns false
Community
  • 1
  • 1
JFK
  • 40,963
  • 31
  • 133
  • 306