onOffice-Web-Org / oo-wp-plugin

onOffice for WP-Websites
https://wp-plugin.onoffice.com
GNU General Public License v3.0
9 stars 9 forks source link

Automated selection of renamed custom templates #749

Open fredericalpers opened 8 months ago

fredericalpers commented 8 months ago

Initiative

Enhance the usability of the onOffice for WP-Websites plugin

Epic

Implement automated custom template selection

User Story

As a real estate agent utilizing the onOffice for WP-Websites plugin, I encounter inefficiencies when creating e.g. new property lists. Currently, if I have customized the template for displaying property lists and renamed it from the default name, subsequent property lists do not automatically select the custom template. Instead, the plugin defaults to the provided default template, leading to manual selection and potential errors.

The current workflow for selecting templates for property lists lacks automation and introduces unncessary manual steps. This results in inconsistency and potential errors, especially when managing multiple property lists with custom templates. To address this issue and streamline the template selection process, I propose enhancing the plugin to automatically choose the correct custom template wheneber a new property list is created.

https://developer.wordpress.org/themes/template-files-section/page-template-files/

Tasks

By implementing automatic selection of custom templates for property lists, the onOffice for WP-Websites plugin can significantly enhance user experience and streamline workflow for web agencies and real estate agents managing property listings on a website.

yeneastgate commented 8 months ago

As a real estate agent utilizing the onOffice for WP-Websites plugin, I encounter inefficiencies when creating e.g. new property lists. Currently, if I have customized the template for displaying property lists and renamed it from the default name, subsequent property lists do not automatically select the custom template. Instead, the plugin defaults to the provided default template, leading to manual selection and potential errors.

@fredericalpers Your desired state means: When creating e.g. a new property list, property details, or new forms, and in the template selection of the "Layout & Design" box, "select renamed custom templates" will be the priority, right? e.g. I customized a template and renamed it "custom_template" from the "default" template in the "estate" folder of "template.dist". => Your desired state is that: When creating e.g. new property lists, "custom_template" will be prioritized selection of renamed custom templates

Screenshot 2024-03-18 154905 Screenshot 2024-03-18 155106

yeneastgate commented 8 months ago
  • Investigate the current mechanism for template selection in the onOffice for WP-Websites plugin

@fredericalpers Here are the results of my investigation of "current mechanism for template selection in the onOffice":

1.1.Prioritize: Template selection will be prioritized in folder order as follows: onoffice-theme in the WordPress "themes" folder => Plugin "onoffice-personalized" => "templates.dist" of wp onoffice plugin 1.2.Mechanism of operation(Mechanism of Saving template selection to Database) Step 1: Selected template(default.php) information will be saved in the config as a URL For example: onoffice-theme/templates/estate/default.php. Step 2: When Changing Template Name, Only the name of the template file is changed. URLs saved in the config are not updated accordingly. ex: When user has behavior to add a listview estate and select template "defautl.php". Selected template information(onoffice-theme/templates/estate/default.php) will be saved in the config of => Because when the user renames the template in the custom template folder(default.php => renameDefault.php) => The database cannot save the renamed template into the database

fredericalpers commented 7 months ago

Your desired state is that: When creating e.g. new property lists, "custom_template" will be prioritized selection of renamed custom templates

Screenshot 2024-03-18 154905 Screenshot 2024-03-18 155106

that's correct :)

yeneastgate commented 7 months ago

@fredericalpers Currently, we have found a solution based on using the "Creating Custom Page Templates for Global Use" mechanism. To create a global template, we need to write an opening PHP comment at the top of the file that states the template’s name. Screenshot 2024-03-19 162133 However, the considerations of utilizing WordPress's page templates file functionality to automatic selection of custom templates must ensure the following conditions: the directories must have permission to write data(put contents) to the file: 1.onoffice-theme/templates 2.onoffice-personalized/templates Screenshot 2024-03-19 162333 Because we use "file_put_contents" method to automatically write an opening PHP comment at the top of the file. This is a demo video: https://files.fm/u/8pu5n3fysk#/view/3uud7nhban You can review the code and test it in this branch: https://github.com/onOffice-Web-Org/oo-wp-plugin/tree/45378-automated-selection-of-renamed-custom-templates

fredericalpers commented 7 months ago

@yeneastgate this seems to be working as we intended, thank you :)

yeneastgate commented 7 months ago

@fredericalpers

the directories must have permission to write data(put contents) to the file: 1.onoffice-theme/templates 2.onoffice-personalized/templates

This is drawback of this solution. => I will continue to research to find a better solution can overcome this drawback and respond to you as soon as I find it.

yeneastgate commented 7 months ago

@fredericalpers

  1. According to the recommendation of WordPress Developer Resources (https://developer.wordpress.org/advanced-administration/server/file-permissions/#shared-hosting-with-suexec), the correct permissions is all directories should be 755 or 750.

  2. For our solution, permissions are required for more "user:group" is "www-data" in addition to directory permissions is 755 with 2 directories : +"onoffice-theme" directory (wp-content/themes/{your theme}/onoffice-theme/templates) +"onoffice-personalized" directory (/wp-content/plugins/onoffice-personalized/templates)

  3. As my knowledge: If the "/wp-content/themes" and "/wp-content/plugins" directories are owned by root or any other users other than "www-data", you may not be able to install plugins, add themes, or even upload files to your website from the dashboard backend WordPress.

An issue you may face is automatically installing plugins, and themes in the WordPress admin will require you to log in via FTP/SFTP if the files aren't owned by www-data.

=> So this solution "feasibility of utilizing WordPress's page templates file functionality" can be implemented with condition "/wp-content/themes" and "/wp-content /plugins" directories which have "user:group" is "www-data".

  1. For cases "/wp-content/themes" and "/wp-content /plugins" directories which do not have "user:group" is "www-data" permission. We tried manually adding template files by editing the file locally and using FTP to upload the file to the server in this branch( 45378-automated-selection-of-renamed-custom-templates-v2) This is the demo video, please watch and give me your opinion: https://files.fm/u/w65kq3aaxw#/view/w9jyr5kk8x => However, with this solution, we can not handle the behavior rename file of users to "automated selection of renamed custom template". We only can display the Template Name of "WordPress's page templates file" when selecting the template in the backend.

There is my analysis of the feasibility of this feature. So that you have a clear overview and hope to help you decide the plan for this issue.

fredericalpers commented 2 months ago

Due to the priority and relevance of other issues and projects, this issue will be postponed to v5.3