3439 posts Ruben Bristian
  • Most Wanted Bounty Winner
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 6-7 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Won a Competition
  • Bought between 100 and 499 items
  • Exclusive Author
  • Referred between 500 and 999 users
+5 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?

557 posts Fuel Your Web
  • Elite Author
  • Won a Competition
  • Sold between 250 000 and 1 000 000 dollars
  • Exclusive Author
  • Has been a member for 7-8 years
  • Bought between 50 and 99 items
  • Referred between 200 and 499 users
  • Europe
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…

631 posts
  • Football Contest Participant/Runner-up
  • United Kingdom
  • Sold between 10 000 and 50 000 dollars
  • Most Wanted Bounty Winner
  • Interviewed on the Envato Notes blog
  • Referred between 50 and 99 users
  • Bought between 100 and 499 items
  • Envato Studio (Microlancer) Beta Tester
  • Exclusive Author
+1 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 :)

3439 posts Ruben Bristian
  • Most Wanted Bounty Winner
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 6-7 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Won a Competition
  • Bought between 100 and 499 items
  • Exclusive Author
  • Referred between 500 and 999 users
+5 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!

1184 posts How's the surf doing?
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • United Kingdom
  • Referred between 200 and 499 users
  • Exclusive Author
  • Has been a member for 3-4 years
  • Envato Studio (Microlancer) Beta Tester
+1 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 :)

3439 posts Ruben Bristian
  • Most Wanted Bounty Winner
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 6-7 years
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Won a Competition
  • Bought between 100 and 499 items
  • Exclusive Author
  • Referred between 500 and 999 users
+5 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