2021-09-24 18:39:19 +02:00
< ? php
if ( ! defined ( 'ABSPATH' ) ) {
exit ; // Exit if accessed directly
}
if ( ! class_exists ( 'acf_pro_updates' ) ) :
class acf_pro_updates {
/*
* __construct
*
* Initialize filters , action , variables and includes
*
* @ type function
* @ date 23 / 06 / 12
* @ since 5.0 . 0
*
* @ param n / a
* @ return n / a
*/
function __construct () {
// actions
add_action ( 'init' , array ( $this , 'init' ), 20 );
2021-09-21 15:01:08 +02:00
}
2021-09-24 18:39:19 +02:00
/*
* init
*
* description
*
* @ type function
* @ date 10 / 4 / 17
* @ since 5.5 . 10
*
* @ param $post_id ( int )
* @ return $post_id ( int )
*/
function init () {
// bail early if no show_updates
if ( ! acf_get_setting ( 'show_updates' ) ) {
return ;
}
// bail early if not a plugin (included in theme)
if ( ! acf_is_plugin_active () ) {
return ;
}
// register update
acf_register_plugin_update (
array (
'id' => 'pro' ,
'key' => acf_pro_get_license_key (),
'slug' => acf_get_setting ( 'slug' ),
'basename' => acf_get_setting ( 'basename' ),
'version' => acf_get_setting ( 'version' ),
)
);
// admin
if ( is_admin () ) {
add_action ( 'in_plugin_update_message-' . acf_get_setting ( 'basename' ), array ( $this , 'modify_plugin_update_message' ), 10 , 2 );
}
}
/*
* modify_plugin_update_message
*
* Displays an update message for plugin list screens .
*
* @ type function
* @ date 14 / 06 / 2016
* @ since 5.3 . 8
*
* @ param $message ( string )
* @ param $plugin_data ( array )
* @ param $r ( object )
* @ return $message
*/
function modify_plugin_update_message ( $plugin_data , $response ) {
// bail ealry if has key
if ( acf_pro_get_license_key () ) {
return ;
}
// display message
echo '<br />' . sprintf ( __ ( 'To enable updates, please enter your license key on the <a href="%1$s">Updates</a> page. If you don\'t have a licence key, please see <a href="%2$s" target="_blank">details & pricing</a>.' , 'acf' ), admin_url ( 'edit.php?post_type=acf-field-group&page=acf-settings-updates' ), 'https://www.advancedcustomfields.com/pro/?utm_source=ACF%2Bpro%2Bplugin&utm_medium=insideplugin&utm_campaign=ACF%2Bupgrade&utm_content=updates' );
}
2021-09-21 15:01:08 +02:00
}
2021-09-24 18:39:19 +02:00
// initialize
new acf_pro_updates ();
2021-09-21 15:01:08 +02:00
endif ; // class_exists check
/*
* acf_pro_get_license
*
* This function will return the license
*
2021-09-24 18:39:19 +02:00
* @ type function
* @ date 20 / 09 / 2016
* @ since 5.4 . 0
2021-09-21 15:01:08 +02:00
*
2021-09-24 18:39:19 +02:00
* @ param n / a
* @ return n / a
2021-09-21 15:01:08 +02:00
*/
function acf_pro_get_license () {
2021-09-24 18:39:19 +02:00
2021-09-21 15:01:08 +02:00
// get option
2021-09-24 18:39:19 +02:00
$license = get_option ( 'acf_pro_license' );
2021-09-21 15:01:08 +02:00
// bail early if no value
2021-09-24 18:39:19 +02:00
if ( ! $license ) {
return false ;
}
2021-09-21 15:01:08 +02:00
// decode
2021-09-24 18:39:19 +02:00
$license = maybe_unserialize ( base64_decode ( $license ) );
2021-09-21 15:01:08 +02:00
// bail early if corrupt
2021-09-24 18:39:19 +02:00
if ( ! is_array ( $license ) ) {
return false ;
}
2021-09-21 15:01:08 +02:00
// return
return $license ;
2021-09-24 18:39:19 +02:00
2021-09-21 15:01:08 +02:00
}
/*
* acf_pro_get_license_key
*
* This function will return the license key
*
2021-09-24 18:39:19 +02:00
* @ type function
* @ date 20 / 09 / 2016
* @ since 5.4 . 0
2021-09-21 15:01:08 +02:00
*
2021-09-24 18:39:19 +02:00
* @ param n / a
* @ return n / a
2021-09-21 15:01:08 +02:00
*/
function acf_pro_get_license_key () {
2021-09-24 18:39:19 +02:00
2021-09-21 15:01:08 +02:00
// vars
2021-09-24 18:39:19 +02:00
$license = acf_pro_get_license ();
2021-09-21 15:01:08 +02:00
$home_url = home_url ();
2021-09-24 18:39:19 +02:00
2021-09-21 15:01:08 +02:00
// bail early if empty
2021-09-24 18:39:19 +02:00
if ( ! $license || ! $license [ 'key' ] ) {
return false ;
}
2021-09-21 15:01:08 +02:00
// bail early if url has changed
2021-09-24 18:39:19 +02:00
if ( acf_strip_protocol ( $license [ 'url' ] ) !== acf_strip_protocol ( $home_url ) ) {
return false ;
}
2021-09-21 15:01:08 +02:00
// return
return $license [ 'key' ];
2021-09-24 18:39:19 +02:00
2021-09-21 15:01:08 +02:00
}
/*
* acf_pro_update_license
*
* This function will update the DB license
*
2021-09-24 18:39:19 +02:00
* @ type function
* @ date 20 / 09 / 2016
* @ since 5.4 . 0
2021-09-21 15:01:08 +02:00
*
2021-09-24 18:39:19 +02:00
* @ param $key ( string )
* @ return n / a
2021-09-21 15:01:08 +02:00
*/
function acf_pro_update_license ( $key = '' ) {
2021-09-24 18:39:19 +02:00
2021-09-21 15:01:08 +02:00
// vars
$value = '' ;
2021-09-24 18:39:19 +02:00
2021-09-21 15:01:08 +02:00
// key
2021-09-24 18:39:19 +02:00
if ( $key ) {
2021-09-21 15:01:08 +02:00
// vars
$data = array (
2021-09-24 18:39:19 +02:00
'key' => $key ,
'url' => home_url (),
2021-09-21 15:01:08 +02:00
);
2021-09-24 18:39:19 +02:00
2021-09-21 15:01:08 +02:00
// encode
2021-09-24 18:39:19 +02:00
$value = base64_encode ( maybe_serialize ( $data ) );
2021-09-21 15:01:08 +02:00
}
2021-09-24 18:39:19 +02:00
2021-09-21 15:01:08 +02:00
// re-register update (key has changed)
2021-09-24 18:39:19 +02:00
acf_register_plugin_update (
array (
'id' => 'pro' ,
'key' => $key ,
'slug' => acf_get_setting ( 'slug' ),
'basename' => acf_get_setting ( 'basename' ),
'version' => acf_get_setting ( 'version' ),
)
);
2021-09-21 15:01:08 +02:00
// update
2021-09-24 18:39:19 +02:00
return update_option ( 'acf_pro_license' , $value );
2021-09-21 15:01:08 +02:00
}
2021-09-24 18:39:19 +02:00