0

I'm asking if it's possible to call a php page or to define a link without having to define the folder "detectmobile" where it is located ?

require (get_template_directory() . '/detectmobile/header_settings_page.php') ;

Is there a search function in the template that will query the presence of a specific php page in each folder?

Does exist a function that do that ?

require (get_template_directory() . '/*/header_settings_page.php') ;
6
  • 2
    I don't think such function exists in WordPress core. After all, wouldn't it be easier to just explicitly specify the subfolder name/path? What makes you ask the question?
    – Sally CJ
    Jul 18, 2022 at 14:26
  • 2
    is detectmobile a folder you're using or an example? Can you provide more context for the problem this is trying to solve? What are you trying to achieve that requires this? Note that searches are expensive/slow, and a wildcard in a require statement is not possible, and would have negative security consequences if it was. The more specific you can make your question that better the answers you will get, and the more people will participate. Use the Edit link under the tag list to improve the question
    – Tom J Nowell
    Jul 18, 2022 at 15:00
  • Thank you, Sally and Tom. I ask this question because I want to save time and reuse the functions in child models or for a franchise of the website: these php pages should not be in the same folders for some reason.My website template is defined as an application, I have a lot of php pages due to different style, functions and scripts for each page. A restructuring of the files must be possible quickly for a better organization and because the website will evolve continuously. I found this php code, but I don't know if it will work in wordpress - Security is important
    – imagIne
    Jul 18, 2022 at 15:53
  • 1
    I agree with Tom in that a file search would result in a lot of overhead. Performing a search across a hard-coded data structure would be better - I suppose you could programmatically generate it beforehand as well. The best solution is likely one which wouldn't require any variety of search or scan, but it's still not clear to me what your end-goal is here, so it's hard to recommend any approach. For class files you can use an autoloader if your file structure follows any variety of convention - but it doesn't sound as though yours does?
    – bosco
    Jul 18, 2022 at 16:41
  • @imagIne, "because I want to save time" - I still do not understand why would something like locate_template( 'foo/header_settings_page.php', true ) be troublesome to you? And even if there was such function in question, what if header_settings_page.php existed in both foo/ and foo2/, or foo/a/ and foo/b/? How would you determine which one should be loaded? Have you considered storing the relative path to the database instead, e.g. via a post meta?
    – Sally CJ
    Jul 19, 2022 at 9:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.