Opened 3 years ago
Last modified 3 years ago
#54525 new enhancement
URL Object
Reported by: | grosfaignan | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
hi
i would to suggest to wordpress to build a wordpress URL_Object who implement url distribution logic like theses.
example : this url : " http://localhost/author/admin/ ”
{ base_url : http://localhost/author/admin/ protocol : http root : localhost full_path:author/admin/ template : author.php /**...some stuff*/ {child path:author path_type:users_list {child path:admin path_type:user_name {user_object:WP_user /*...data from WP_user*/ } } } }
another example with this url : “ http://localhost/2021/10/20/my_comment/ "(a comment url)
{ base_url : http://localhost/2021/10/20/my_comment/ protocol : http root : localhost full_path:2021/10/20/my_comment/ template : comments.php /**...some stuff*/ {child path:2021 path_type:date(year) {child path:10 path_type:date(month) {child path:20 path_type:date(day) {comment_object:WP_Comment /*...data from WP_Comment like*/ comment_ID:"" comment_post_ID :"" comment_author :"" comment_author_email :"" /***...and more */ } } } } }
another example with this url : http://localhost/vehicle/car/
{ base_url : http://localhost/vehicle/car/ protocol : http root : localhost full_path:vehicle/car/ template : category.php /**...some stuff*/ {child path:vehicle path_type:category parent_category:none {child path:car path_type:category parent_category:vehicle {object_array /*...listed object for this category*/ {object_1:car_with_4_wheels /*object fields and data */ color:"" wheels:"" type:"" motor:"" gear_ratio:"" /**...and more*/ } {object_2:car_with_3_wheels} {object_3:car_with_5_wheels} /***...and more */ } } } }
the underlying idea is to give us the possibility to know where url part come from, to make more flexible and logic routing.
to explain a little bit my purpose , we will move to : http://localhost/vehicle/car/my_black_car_with_four_wheels
we can get this object :
{ base_url : http://localhost/vehicle/car/ protocol : http root : localhost full_path:vehicle/car/ template : category.php /**...some stuff*/ {child path:vehicle path_type:category parent_category:none {child path:car path_type:category parent_category:vehicle {object:car_object /*object fields and data */ color:black wheels:4 type:sportive motor:950ch gear_ratio:6 /**...and more*/ } } } }
in addition, the possibilites to create wordpress routing from this object will be a good idea. i'll try to give you an example : we want to create a user car space with this url format :
http://localhost/user/vehicle/cars
/**first we will create this object*/ $my_url_object = new url_object(/${root}/${users}/${category:vehicle}/${category:cars});
this action will instantiate the url object and the routing logic at the same time, so we will get this url_object
{ base_url : http://localhost/user/vehicle/car protocol : http (will depends form the server config) root : localhost template : "" /**...some stuff*/ {child path:user {user_object:WP_user /**data from WP_user */ data:"" ID:"" caps:"" roles:"" /**... and more */ } {child path:vehicle {category_object : vehicle /**data from vehicle object */ } {child path:car {category_object:car /**data from car object */ /**for example:*/ color:"" wheels:"" type:"" wheels_size:"" motor:"" gear_ratio:"" /**...and more*/ } } } } }
the only last thing we have to do is to decide which template will be used:
$my_url_object->set_template(user_car.php)
Change History (2)
#2
@
3 years ago
the actual problem in wordpress is when we catch any url, we can't know how it was build by wordpress-core.
by the way, if we catch an url like " http://localhost/supersonic " we can use this url to make a real routing, because we don't know how wordpress have build it,so we can't know if " /supersonic" refer to a user_name, tu a user_product, to a category, or to any other item.
so if we could have an object ready to explain url building process by wordpress. we could catch referent data more efficiently
convertly if in the url object we could get something like:
/**...*/ path: "supersonic" => refer_to: WP_user //for example
we could make routing more efficiently
Hi there, welcome back to WordPress Trac! Thanks for the ticket.
Just linking to some potentially related tickets here: #12935, #18276, #36292, #41145.