[wp-trac] [WordPress Trac] #54525: URL Object

WordPress Trac noreply at wordpress.org
Sat Nov 27 02:58:47 UTC 2021


#54525: URL Object
-------------------------+-----------------------------
 Reporter:  grosfaignan  |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 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)
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/54525>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list