Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it easier to extend templates #969

Closed
swissspidy opened this issue Nov 2, 2018 · 2 comments · Fixed by #1522
Closed

Make it easier to extend templates #969

swissspidy opened this issue Nov 2, 2018 · 2 comments · Fixed by #1522
Labels
[Type] Enhancement A suggestion for improvement.
Milestone

Comments

@swissspidy
Copy link
Member

Right now there's no easy way to edit templates like the project edit form (https://github.com/GlotPress/GlotPress-WP/blob/99d0799ab378d16eb0c5cb63be0fead7f06c201d/gp-templates/project-form.php) without completely overriding the templates on your site.

An action hook in project-form.php to allow plugins to print additional settings fields would already be of great help.

@toolstack
Copy link
Contributor

You'd also need a hook on the route to be able to do something with the added fields, as otherwise they would just be dropped when the project was saved to the database.

@toolstack toolstack added this to the Future milestone Nov 2, 2018
@2ndkauboy
Copy link
Contributor

2ndkauboy commented Oct 27, 2022

As @swissspidy indicated, I had to overwrite the whole template. Saving the new fields, I have used two available actions like this:

function gp_project_save_custom_field( $project, $projectBefore ) {
    $projectPostData = gp_post( 'project' );
    if ( isset( $projectPostData['custom_field'] ) ) {
        gp_update_meta( project->id, '_custom_field', $projectPostData['custom_field'], 'project' );
    }
}

add_filter( 'gp_project_saved', 'gp_project_save_custom_field', 10, 2 );
add_filter( 'gp_project_created', 'gp_project_save_custom_field', 10, 1 );

The action to add some additional fields would have helped a lot to avoid overwriting the whole template. At least with the gp_tmpl_load_locations it was fortunately possible to add such a template, but only using array_unshift to move the custom directory to the front of the list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Enhancement A suggestion for improvement.
Projects
None yet
3 participants