debugMode = false;
//Increase check interval if update alert is already present
$uber_update_checker->throttleRedundantChecks = true;
$uber_update_checker->throttledCheckPeriod = 120;
$uber_update_checker->addQueryArgFilter( 'ubermenu_filter_update_checks' );
$uber_update_checker->addResultFilter( 'ubermenu_filter_update_results' );
//$uber_update_checker->checkForUpdates(); //Testing
}
}
ubermenu_update_checker();
add_action( 'all_admin_notices' , 'ubermenu_updater_check_download_notice' );
function ubermenu_updater_check_download_notice(){
global $pagenow;
if( $pagenow == 'update-core.php' ){
if( ubermenu_op( 'purchase_code' , 'updates' , '' ) ){
if( !UBERMENU_AUTO_UPDATES ){
//echo 'no ups';
$plugin_updates = get_plugin_updates();
//uberp( $plugin_updates , 3 );
if( isset( $plugin_updates[ 'ubermenu/ubermenu.php' ] ) ): ?>
UberMenu automatic updates are in beta. To test them out, please see
Automatic Updates. Make sure to run a backup first! ?>
UberMenu automatic updates have been disabled. To re-enable them, set UBERMENU_AUTO_UPDATES to 1 in wp-config.php
$val ){
$queryArgs[$key] = urlencode( $val );
}
$queryArgs['site_url'] = get_site_url( null , '' , 'http' );
$queryArgs['ubermenu_version'] = UBERMENU_VERSION;
$queryArgs['auto_updates'] = UBERMENU_AUTO_UPDATES;
return $queryArgs;
}
function ubermenu_filter_update_results( $pluginInfo, $result ){
$notices = array();
if( isset( $pluginInfo->error ) ){
//$notices = get_option( UBERMENU_UPDATE_NOTICES_KEY , array() );
if( !isset( $notices['errors'] ) ) $notices['errors'] = array();
$notices['errors'][] = $pluginInfo->error;
}
update_option( UBERMENU_UPDATE_NOTICES_KEY , $notices );
return $pluginInfo;
}
$file = basename( dirname( UBERMENU_FILE ) ) . '/' . basename( UBERMENU_FILE );
add_action( "after_plugin_row_$file" , 'ubermenu_plugin_display_notice' , 10 , 2 );
function ubermenu_plugin_display_notice( $file , $plguin_data ){
$notices = get_option( UBERMENU_UPDATE_NOTICES_KEY , array() );
if( isset( $notices['errors'] ) ){
echo '| ';
foreach ( $notices['errors'] as $e ){
if( is_string( $e ) ) echo " UberMenu update check error: $e ";
else uberp( $e,4);
}
echo ' |
';
}
}
function ubermenu_updates_get_account_settings(){
return get_option( UBERMENU_PREFIX.'updates' , array() );
}
//updates.sevenspark.com/ubermenu
//ubermenu_op( '')
add_filter( 'ubermenu_settings_panel_sections' , 'ubermenu_updates_section' , 100 );
add_filter( 'ubermenu_settings_panel_fields' , 'ubermenu_updates_fields' , 100 );
function ubermenu_updates_section( $sections ){
$prefix = UBERMENU_PREFIX;
$sections[] = array(
'id' => $prefix.'updates',
'title' => __( 'Updates', 'ubermenu' ),
'sub_sections' => array(
'backups' => array(
'title' => __( 'Backups' , 'ubermenu' ),
),
'updates' => array(
'title' => __( 'Account Info' , 'ubermenu' ),
),
),
);
return $sections;
}
function ubermenu_updates_fields( $fields = array() ){
$section = UBERMENU_PREFIX.'updates';
$f = array();
$f[] = array(
'name' => 'backups_header',
'label' => __( 'Custom Asset Backups' , 'ubermenu' ),
'desc' => __( 'UberMenu will attempt to automatically backup and restore your custom.css and custom.js files when you update', 'ubermenu' ),
'type' => 'header',
'group' => 'backups',
);
$f[] = array(
'name' => 'backup_custom_assets',
'label' => __( 'Backup custom assets' , 'ubermenu' ),
'desc' => __( 'Automatically backup custom.css and custom.js so that they can be restored after updating the plugin', 'ubermenu' ),
'type' => 'checkbox',
'default' => 'on',
'group' => 'backups',
);
$f[] = array(
'name' => 'backup_notice',
'label' => __( 'Automatic backups status' , 'ubermenu' ),
'desc' => 'ubermenu_field_backup_notice',
'type' => 'html',
'group' => 'backups',
);
$f[] = array(
'name' => 'update_settings',
'label' => __( 'Update Notifications' , 'ubermenu' ), //__( 'Automatic Updates' , 'ubermenu' ),
'desc' => __( 'Enter your Envato info to receive update notifications', 'ubermenu' ),
'type' => 'header',
'group' => 'updates',
);
$f[] = array(
'name' => 'envato_username',
'label' => __( 'CodeCanyon Username' , 'ubermenu' ),
'desc' => 'Enter your Envato Username. This must match the username on the account you used to purchase the UberMenu license.',
'type' => 'text',
'group' => 'updates',
);
$f[] = array(
'name' => 'api_key',
'label' => __( 'API Key' , 'ubermenu' ),
'desc' => __( 'Enter your Envato API Key. Create an API key at codecanyon.net by visiting your Settings Page and clicking "API Keys" in the left menu.', 'ubermenu' ),
'type' => 'text',
'group' => 'updates',
);
$f[] = array(
'name' => 'purchase_code',
'label' => __( 'Purchase Code' , 'ubermenu' ),
'desc' => __( 'Enter your Envato Purchase Code', 'ubermenu' ) . '. Find your purchase code',
'type' => 'text',
'group' => 'updates',
);
// $f[] = array(
// 'name' => 'video_tutorials',
// 'label' => __( 'Video Tutorials' , 'ubermenu' ),
// 'desc' => ubermenu_video_tutorials_help(),
// 'type' => 'html',
// 'group' => 'video_tutorials',
// );
$fields[$section] = $f;
return $fields;
}
function ubermenu_field_backup_notice(){
$note = $msg = '';
$custom_dir = trailingslashit( UBERMENU_DIR ).'custom/';
//Find the Backups directory
$uploads = wp_upload_dir();
$uploads_dir = trailingslashit( $uploads['basedir'] );
$backups_dir = $uploads_dir . 'ubermenu_backups/';
$uploads_url = trailingslashit( $uploads['baseurl'] );
$backups_url = $uploads_url . 'ubermenu_backups/';
if( !is_writable( $uploads_dir ) ){
//TODO - readd this: These files will be lost when updating if not backed up first
$note = 'The uploads directory is not writable by the server ( '.$uploads_dir.' ).
UberMenu will not automatically be able to back up your custom.css and custom.js if you create them. Please make this directory writable if you wish to automatically back up these files, otherwise you can back them up and restore manually after plugin update.
(If you are not using custom.css or custom.js, you can safely ignore this message)
';
$msg.= '';
}
else{
$backups_exist = false;
$custom_css = $backups_dir . 'custom.css';
$custom_css_url = $backups_url . 'custom.css';
if( file_exists( $custom_css ) ){
$backups_exist = true;
$msg.= '';
}
$custom_js = $backups_dir . 'custom.js';
$custom_js_url = $backups_url . 'custom.js';
if( file_exists( $custom_js ) ){
$backups_exist = true;
$msg.= '';
}
if( file_exists( $backups_dir ) ){
if( file_exists( $custom_dir . 'custom.css' ) && !is_writable( $backups_dir . 'css' ) ){
$msg.= '';
}
if( file_exists( $custom_dir . 'custom.js' ) && !is_writable( $backups_dir . 'js' ) ){
$msg.= '';
}
}
if( !$backups_exist ){
if( file_exists( $custom_dir.'custom.css' ) ||
file_exists( $custom_dir.'custom.js' )){
$msg.= '';
}
else{
$msg.= '';
}
}
}
if( UBERMENU_AUTO_UPDATES && ubermenu_op( 'purchase_code' , 'updates' , '' ) ){
$msg.= '
UberMenu Automatic Updates capability has been activated
';
}
return $msg;
}
function ubermenu_update_db_check() {
if( get_site_option( UBERMENU_VERSION_KEY ) != UBERMENU_VERSION ){
ubermenu_run_update();
}
}
add_action( 'plugins_loaded', 'ubermenu_update_db_check' );
function ubermenu_run_update(){
ubermenu_restore_custom_assets();
update_site_option( UBERMENU_VERSION_KEY , UBERMENU_VERSION );
}