3567 posts Ruben Bristian
  • Sells items exclusively on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Has been part of the Envato Community for over 6 years
+10 more
KrownThemes says

Hi

Is there a way how i can check if a user is updating the theme vs a new installation? I want to show a basic information message to users who update, but not to users who install the theme. This is the code i’m currently using:

add_action( 'admin_notices', 'krown_update_notice' );
function krown_update_notice() {
    if ( get_option( 'krown_updated_20' ) != 'yes' ) {
            echo 'MESSAGE HERE';
            printf(__('<a class="button button-primary" href="%1$s">Update Content'), '?krown_update_done_do=0');
    }
}

add_action( 'admin_init', 'krown_update_done_do' );
function krown_update_done_do() {
   global $current_user;
    $user_id = $current_user->ID;
    if ( isset( $_GET['krown_update_done_do'] ) && '0' == $_GET['krown_update_done_do'] ) {
        add_option( 'krown_updated_20', 'yes' );
        krown_update_setup();
    }
}

The code above shows a message with a button, and after the user clicks the button, a function runs and the message will no longer appear. However, this message also shows for users who install the theme from scratch. Is there any easy method to prevent this?

624 posts Fuel Your Web
  • Elite Author: Sold more than $75,000 on Envato Market
  • Won a competition
  • Had an item featured on Envato Market
  • Has been part of the Envato Community for over 7 years
+5 more
Pirenko says

Hi,
Why don’t you use an extra variable? Something like ‘krown_new_install’? Then you check for both before showing your message…

633 posts
  • Has referred 50+ members
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 100+ items on Envato Market
+5 more
UBLThemes says

Hi Ruben, as far as I can see there is no wordpress function that can do this or any global fields that may help.

I’ve checked the database to check if there is a updated or theme installation date but there is not.

The only way I can see you can do this is by creating a theme option which will insert into the database the date or the version of install when the theme is first activated, but never give that option to the user.

Then you can call the date when you are needing to check these things.

But this looks irrelevant to your situation as it sounds like you need it now, but you can implement this from now on so you are able to do this in the future.

Or do it now and then do a quick update in a day or 2, then you have this option in your theme now, the only thing is, people who have activated in the 2 days will be classed as updated, but after a couple of days if they have not clicked the button to run the function then what can you do?

The solution above is what I have always used because I could not find a solution a year or 2 ago so I started installing the theme version and date in the theme options and then calling it after.

I hope this helps in future though :)

3567 posts Ruben Bristian
  • Sells items exclusively on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Has been part of the Envato Community for over 6 years
+10 more
KrownThemes says

^ Yeah, i know.. I never needed to do this until now, so i never though to register the theme version as an option in the db. I think that i’ll settle with adding a message like “if this is a new install, dismiss this message” :)

Thanks for your input!

1357 posts How's the surf doing?
  • Has referred 200+ members
  • Has sold $500,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+6 more
tommusrhodus says

I think that i’ll settle with adding a message like “if this is a new install, dismiss this message” :)

Sometimes the most simple option is also the most effective :)

3567 posts Ruben Bristian
  • Sells items exclusively on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $500,000+ on Envato Market
  • Has been part of the Envato Community for over 6 years
+10 more
KrownThemes says


I think that i’ll settle with adding a message like “if this is a new install, dismiss this message” :)
Sometimes the most simple option is also the most effective :)

:D

by
by
by
by
by
by