-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
  • 40,889
  • 58
  • 100
  • 149
user007
  • 3,025
  • 13
  • 44
  • 76

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
  • 66,874
  • 43
  • 94
  • 124
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,653
  • 31
  • 130
  • 299