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

Checkbox checked on activation #220

Merged
merged 4 commits into from
Jan 2, 2023

Conversation

pbrocks
Copy link
Collaborator

@pbrocks pbrocks commented Dec 30, 2022

Also placed in its own section on initial settings page

image


if ( Event::POST_TYPE !== $post->post_type || 1 !== intval( $gp_settings['pages']['post_or_event_date'] ) ) {
if ( Event::POST_TYPE !== $post->post_type || 1 !== intval( $event_date_format ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make $post->post_type get_post_type( $post )

includes/core/classes/class-setup.php Outdated Show resolved Hide resolved
@@ -78,6 +78,8 @@ protected function setup_hooks() {
* @return void
*/
public function activate_gatherpress_plugin() {
$gp_settings['general']['post_or_event_date'] = true;
add_option( 'gp_general', $gp_settings );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're gonna have to do better than that. Does it matter if it works? It's only going to run once on initial activation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$gp_settings doesn't appear to be defined here is what I mean.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is defined. How would you do it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

you are setting $gp_settings['general']['post_or_event_date'] = true; and you did not define $gp_settings in the method. You need to set something like $gp_settings = get_option( 'gp_general' ); first and also check that it's an array and such so you don't throw any notices.

@@ -78,6 +78,8 @@ protected function setup_hooks() {
* @return void
*/
public function activate_gatherpress_plugin() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public function activate_gatherpress_plugin() {
public function activate_gatherpress_plugin() {
$gp_settings = [];

To @mauteri 's point, the variable should be defined(Or I think you'll see a bunch of undefined offset warnings in the logs) and in this case, I think it just needs a default value. I'm pretty sure get_option( 'gp_general' ) won't work at this point because this happens on plugin activation. So I think just setting the default to an empty array is the best solution here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok got it... I don't think this should be on activation hook as new options will then require the same sort of treatment and won't be backwards compatible. This should use the default if not saved to the database. I can take a look at this later and make a recommendation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmarx @mauteri The variable is set on activation. No errors/warnings/notices are thrown. Don't need to declare en empty array. Just set what you can. The other settings can't be set until the pages exist and will require that the settings page is visited and options updated. The checkbox, however, will be checked and then saved again when the other settings are saved.

@pbrocks
Copy link
Collaborator Author

pbrocks commented Jan 2, 2023

@mauteri This looks great. I appreciate the cleanup work to check for settings or set variable to empty. Can you merge?

@mauteri
Copy link
Contributor

mauteri commented Jan 2, 2023

@mauteri This looks great. I appreciate the cleanup work to check for settings or set variable to empty. Can you merge?

Sure, it is a different PR, so going to close this one. When I checked out the branch it created a new PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants