$el['id'],
'search_type' => 'Wrapper ID',
'results' => $res,
);
}
}
//If
if( !$found && isset( $el['class'] ) ){
$res = ubermenu_search_files( array( $theme , $child_theme ) , array( '*.php' ), $el['class'] );
if( $res ){
$found = true;
$result_sets[] = array(
'search_string' => $el['class'],
'search_type' => 'Wrapper Class',
'results' => $res,
);
}
}
}
//TODO
// $result_sets = array(
// 'search_string'
// 'search_type' //class, ID
// 'results'
// );
//Next, search for wp_nav_menu(
$wp_nav_menu_results = ubermenu_search_files( array( $theme , $child_theme ) , array( '*.php' ), 'wp_nav_menu(' );
$result_sets[] = array(
'search_string' => 'wp_nav_menu(',
'search_type' => 'WordPress menu function (look in these results if the above don\'t help you locate the menu',
'results' => $wp_nav_menu_results,
);
$rstr = '';
foreach( $result_sets as $s ){
$rstr.= '
';
}
$reply['html'] = $rstr;
//echo $rstr;
$reply['results'] = $wp_nav_menu_results;
$reply['echo'] = 'echo echo';
//$reply['wrappers'] = $_POST['wrappers'];
}
else{
$reply['error'] = 'Nonce doesn\'t check out';
}
echo json_encode( $reply );
die();
}
add_action( 'wp_ajax_ubermenu_diagnostics_search' , 'ubermenu_diagnostics_search_theme_callback' );
/*
* Recursively glob into subdirectories to find matching patterns
*/
function ubermenu_glob_recursive( $pattern, $flags = 0 ){
$files = glob( $pattern, $flags );
foreach( glob( dirname( $pattern ).'/*', GLOB_ONLYDIR|GLOB_NOSORT ) as $dir ){
$files = array_merge( $files, ubermenu_glob_recursive( $dir.'/'.basename( $pattern ), $flags ) );
}
return $files;
}
/*
* Search the contents of a file ($path) for a string ($needle)
*/
function ubermenu_search_file( $path , $needle ){
$handle = fopen( $path , 'r' );
$found = false; // init as false
$line = 0;
$lines = array();
while( ($buffer = fgets( $handle ) ) !== false ) {
$line++;
if( strpos( $buffer, $needle ) !== false ) {
$found = true;
//echo 'FOUND['; echo $buffer; echo ']';
$lines[$line] = $buffer;
//break;
}
}
fclose( $handle );
//return $found;
return $found == true ? $lines : false;
}
/*
* For each path and file match, search the file for the string match
*/
function ubermenu_search_files( $paths = array() , $file_matches = array() , $string_match ){
$results = array();
foreach( $paths as $path ){
foreach( $file_matches as $file_match ){
//echo $path . $file_match;
$files = ubermenu_glob_recursive( $path.'/'.$file_match );
foreach( $files as $file ){
$lines = ubermenu_search_file( $file , $string_match );
if( false !== $lines ){
$short_file = substr( $file , strlen( dirname( $path ) ) );
//echo '
'.$short_file.'
';
$results[$short_file] = array();
foreach( $lines as $line_num => $content ){
$results[$short_file][$line_num] = $content;
//echo $line_num . ' :: '. esc_html( $content ).'';
}
}
}
}
}
return $results;
}
function ubermenu_find_theme_menu(){
$time_start = microtime(true);
$theme = get_template_directory();
$child_theme = get_stylesheet_directory();
//echo 'Search class="topmenu"
';
$results = ubermenu_search_files( array( $theme , $child_theme ) , array( '*.php' ), 'class="topmenu"' );
//echo 'Search wp_nav_menu(
';
$results = ubermenu_search_files( array( $theme , $child_theme ) , array( '*.php' ), 'wp_nav_menu(' );
$time_end = microtime(true);
//dividing with 60 will give the execution time in minutes other wise seconds
$execution_time = ($time_end - $time_start);
//execution time of the script
echo 'Total Execution Time: '.$execution_time.' Seconds';
}