Import legacy nurinda.co.id website
This commit is contained in:
1 parent
3f59bb9038
commit
6e21646ac4
13389 files changed
+3246690
No files matched your search
@@ -0,0 +1,130 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* About admin page
|
||||
*/
|
||||
|
||||
add_action( 'admin_menu', 'us_add_info_home_page', 50 );
|
||||
function us_add_info_home_page() {
|
||||
add_submenu_page( 'us-theme-options', US_THEMENAME . ': Home', us_translate_x( 'About', 'personal data group label' ), 'manage_options', 'us-home', 'us_welcome_page', 11 );
|
||||
}
|
||||
|
||||
function us_welcome_page() {
|
||||
|
||||
// Predefined URLs
|
||||
$help_portal = 'https://help.us-themes.com';
|
||||
$help_portal_api_url = 'https://help.us-themes.com/envato_auth';
|
||||
|
||||
$urlparts = parse_url( site_url() );
|
||||
$domain = $urlparts['host'];
|
||||
$return_url = admin_url( 'admin.php?page=us-home' );
|
||||
|
||||
|
||||
?>
|
||||
<div class="wrap about-wrap us-home">
|
||||
|
||||
<div class="us-header">
|
||||
<h1><?php echo sprintf( __( 'Welcome to <strong>%s</strong>', 'us' ), US_THEMENAME . ' ' . US_THEMEVERSION ) ?></h1>
|
||||
|
||||
<div class="us-header-links">
|
||||
<div class="us-header-link">
|
||||
<a href="<?php echo $help_portal ?>/<?php echo ( defined( 'US_ACTIVATION_THEMENAME' ) ) ? strtolower( US_ACTIVATION_THEMENAME ) : strtolower( US_THEMENAME ); ?>/" target="_blank"><?php _e( 'Online Documentation', 'us' ) ?></a>
|
||||
</div>
|
||||
<div class="us-header-link">
|
||||
<a href="<?php echo $help_portal ?>/<?php echo ( defined( 'US_ACTIVATION_THEMENAME' ) ) ? strtolower( US_ACTIVATION_THEMENAME ) : strtolower( US_THEMENAME ); ?>/tickets/" target="_blank"><?php _e( 'Support Portal', 'us' ) ?></a>
|
||||
</div>
|
||||
<div class="us-header-link">
|
||||
<a href="<?php echo $help_portal ?>/<?php echo ( defined( 'US_ACTIVATION_THEMENAME' ) ) ? strtolower( US_ACTIVATION_THEMENAME ) : strtolower( US_THEMENAME ); ?>/changelog/" target="_blank"><?php _e( 'Theme Changelog', 'us' ) ?></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if ( get_option( 'us_license_activated', 0 ) == 1 ) { ?>
|
||||
<div class="us-activation">
|
||||
<div class="us-activation-status yes"><?php echo sprintf( __( '%s is activated', 'us' ), US_THEMENAME ); ?></div>
|
||||
<p><?php echo sprintf( __( 'You can deactivate it on your %sLicenses%s page.', 'us' ), '<a href="' . $help_portal . '/user/licenses/" target="_blank">', '</a>' ); ?></p>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
} elseif ( ! defined( 'US_THEME_BETA' ) ) {
|
||||
$host_is_dev = FALSE;
|
||||
|
||||
$host = $_SERVER['HTTP_HOST'];
|
||||
|
||||
$chunks = explode( '.', $host );
|
||||
|
||||
if ( ( 1 === count( $chunks ) ) OR ( in_array(
|
||||
end( $chunks ), array(
|
||||
'local',
|
||||
'dev',
|
||||
'wp',
|
||||
'test',
|
||||
'example',
|
||||
'localhost',
|
||||
'invalid',
|
||||
)
|
||||
) ) OR preg_match( '/^[0-9\.]+$/', $host )
|
||||
) {
|
||||
$host_is_dev = TRUE;
|
||||
}
|
||||
|
||||
if ( $host_is_dev ) {
|
||||
?>
|
||||
<div class="updated hidden"><p>You are working on localhost development environment</p></div>
|
||||
<?php
|
||||
}
|
||||
|
||||
$config = us_config( 'envato', array( 'purchase_url' => '#' ) );
|
||||
$purchase_url = $config['purchase_url'];
|
||||
|
||||
?>
|
||||
|
||||
<form class="us-activation" id="activation" method="post" action="<?php echo $help_portal_api_url; ?>">
|
||||
<input type="hidden" name="domain" value="<?php echo $domain; ?>">
|
||||
<input type="hidden" name="return_url" value="<?php echo $return_url; ?>">
|
||||
<input type="hidden" name="theme" value="<?php echo ( defined( 'US_ACTIVATION_THEMENAME' ) ) ? US_ACTIVATION_THEMENAME : US_THEMENAME; ?>">
|
||||
|
||||
<div class="us-activation-status no">
|
||||
<span><?php echo sprintf( __( '%s is not activated', 'us' ), US_THEMENAME ); ?></span>
|
||||
<div class="us-activation-desc">
|
||||
<div class="us-activation-desc-sign"></div>
|
||||
<div class="us-activation-desc-text">
|
||||
<p><?php _e( 'By activating theme license you will unlock premium options:', 'us' ) ?></p>
|
||||
<ul>
|
||||
<li><?php _e( 'Theme update notifications and ability to update the theme via one click', 'us' ) ?></li>
|
||||
<li><?php _e( 'Ability to install and update premium addons via one click', 'us' ) ?></li>
|
||||
<li><?php _e( 'Ability to import any of theme demos', 'us' ) ?></li>
|
||||
</ul>
|
||||
<p><?php _e( 'Don\'t have valid license yet?', 'us' ) ?><br><a target="_blank" href="<?php echo $purchase_url; ?>"><?php echo sprintf( __( 'Purchase %s license', 'us' ), US_THEMENAME ); ?></a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<input class="button button-primary" type="submit" value="<?php echo us_translate( 'Activate' ) ?>" name="activate">
|
||||
</form>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
<div class="us-features">
|
||||
<div class="one-third">
|
||||
<h4><i class="dashicons dashicons-screenoptions"></i><?php _e( 'Install Addons', 'us' ) ?></h4>
|
||||
|
||||
<p><?php echo sprintf( __( '%s comes with popular plugins which increase theme abilities, install them via one click.', 'us' ), US_THEMENAME ); ?></p>
|
||||
<a class="button us-button" href="<?php echo admin_url( 'admin.php?page=us-addons' ); ?>"><?php _e( 'Go to Addons page', 'us' ) ?></a>
|
||||
</div>
|
||||
<div class="one-third">
|
||||
<h4><i class="dashicons dashicons-download"></i><?php _e( 'Import Demo Content', 'us' ) ?></h4>
|
||||
|
||||
<p><?php _e( 'Installed this theme for the first time? Import demo content to build your site not from scratch.', 'us' ) ?></p>
|
||||
<a class="button us-button" href="<?php echo admin_url( 'admin.php?page=us-demo-import' ); ?>">
|
||||
<?php _e( 'Go to Demo Import', 'us' ) ?></a>
|
||||
</div>
|
||||
<div class="one-third">
|
||||
<h4><i class="dashicons dashicons-admin-appearance"></i><?php _e( 'Customize Appearance', 'us' ) ?></h4>
|
||||
|
||||
<p><?php _e( 'To customize the look of your site (colors, layouts, fonts) go to the Theme Options panel.', 'us' ) ?></p>
|
||||
<a class="button us-button" href="<?php echo admin_url( 'admin.php?page=us-theme-options' ); ?>"><?php _e( 'Go to Theme Options', 'us' ) ?></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
@@ -0,0 +1,421 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Addons admin page
|
||||
*/
|
||||
|
||||
if ( ! function_exists( 'get_plugins' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
}
|
||||
|
||||
if ( ! current_user_can( 'install_plugins' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$js_composer_path = 'js_composer';
|
||||
$installed_plugins = get_plugins();
|
||||
$keys = array_keys( $installed_plugins );
|
||||
|
||||
foreach ( $keys as $key ) {
|
||||
if ( preg_match( '|^' . $js_composer_path . '/|', $key ) ) {
|
||||
$js_composer_path = $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Display admin notice when WPBakery Page Builder is not active
|
||||
if ( ( ! get_option( 'us_dismiss_addons_install_notice' ) ) AND ( ! isset( $installed_plugins[ $js_composer_path ] ) ) ) {
|
||||
add_action( 'admin_notices', 'us_js_composer_install_admin_notice' );
|
||||
}
|
||||
if ( ( ! get_option( 'us_dismiss_addons_activate_notice' ) ) AND ( isset( $installed_plugins[ $js_composer_path ] ) ) AND is_plugin_inactive( $js_composer_path ) ) {
|
||||
add_action( 'admin_notices', 'us_js_composer_activate_admin_notice' );
|
||||
}
|
||||
function us_js_composer_install_admin_notice() {
|
||||
?>
|
||||
<div class="notice notice-warning us-addons-notice for-installing is-dismissible">
|
||||
<p><?php echo sprintf( __( 'This theme recommends to use %s plugin.', 'us' ), '<strong><a href="' . admin_url( 'admin.php?page=us-addons' ) . '">WPBakery Page Builder</a></strong>' ); ?></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
function us_js_composer_activate_admin_notice() {
|
||||
?>
|
||||
<div class="notice notice-warning us-addons-notice for-activating is-dismissible">
|
||||
<p><?php echo sprintf( __( 'This theme recommends to use %s plugin.', 'us' ), '<strong><a href="' . admin_url( 'admin.php?page=us-addons' ) . '">WPBakery Page Builder</a></strong>' ); ?></p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
add_action( 'admin_print_scripts', 'us_admin_addons_assets', 99 );
|
||||
function us_admin_addons_assets() {
|
||||
?>
|
||||
<script>
|
||||
jQuery(document).on('click', '.us-addons-notice .notice-dismiss', function(){
|
||||
var $notice = jQuery(this).closest('.us-addons-notice'),
|
||||
pluginAction = ($notice.hasClass('for-activating')) ? 'activate' : 'install';
|
||||
jQuery.ajax({
|
||||
url: '<?php echo admin_url( 'admin-ajax.php' ); ?>',
|
||||
data: {
|
||||
action: 'us_dismiss_addons_notice',
|
||||
pluginAction: pluginAction
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_us_dismiss_addons_notice', 'us_dismiss_addons_notice' );
|
||||
function us_dismiss_addons_notice() {
|
||||
if ( $_GET['pluginAction'] == 'activate' ) {
|
||||
update_option( 'us_dismiss_addons_activate_notice', 1 );
|
||||
} elseif ( $_GET['pluginAction'] == 'install' ) {
|
||||
update_option( 'us_dismiss_addons_install_notice', 1 );
|
||||
}
|
||||
}
|
||||
|
||||
add_action( 'admin_menu', 'us_add_addons_page', 20 );
|
||||
function us_add_addons_page() {
|
||||
add_submenu_page( 'us-theme-options', US_THEMENAME . ': ' . __( 'Addons', 'us' ), __( 'Addons', 'us' ), 'manage_options', 'us-addons', 'us_addons_page', 11 );
|
||||
}
|
||||
|
||||
function us_addons_page() {
|
||||
$plugins = us_config( 'addons', array() );
|
||||
|
||||
foreach ( $plugins as $i => $plugin ) {
|
||||
if ( isset( $plugins[ $i ]['premium'] ) AND ! isset( $plugins[ $i ]['source'] ) ) {
|
||||
$plugins = us_api_addons( $plugins, TRUE );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$installed_plugins = get_plugins();
|
||||
global $us_template_directory_uri;
|
||||
$plugins_html = '';
|
||||
|
||||
foreach ( $plugins as $plugin ) {
|
||||
|
||||
$keys = array_keys( get_plugins() );
|
||||
|
||||
$plugin['file_path'] = $plugin['slug'];
|
||||
foreach ( $keys as $key ) {
|
||||
if ( preg_match( '|^' . $plugin['slug'] . '/|', $key ) ) {
|
||||
$plugin['file_path'] = $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$classes = ' ' . $plugin['slug'];
|
||||
if ( ! isset( $plugin['premium'] ) ) {
|
||||
$classes .= ' is_free';
|
||||
} else {
|
||||
$classes .= ' is_premium';
|
||||
}
|
||||
$btn_classes = $btn_atts = $btn_text = $btn_url = '';
|
||||
|
||||
// Separate params for FREE and PREMIUM plugins
|
||||
if ( ! isset( $plugin['premium'] ) ) {
|
||||
$icon_file = isset( $plugin['icon_file'] ) ? $plugin['icon_file'] : 'png';
|
||||
$icon_url = 'https://ps.w.org/' . $plugin['slug'] . '/assets/icon-256x256.' . $icon_file;
|
||||
$plugin['url'] = 'https://wordpress.org/plugins/' . $plugin['slug'] . '/';
|
||||
} else {
|
||||
$icon_url = $us_template_directory_uri . '/framework/admin/img/' . $plugin['slug'] . '.png';
|
||||
}
|
||||
|
||||
if ( is_plugin_active( $plugin['file_path'] ) ) {
|
||||
$classes .= ' status_active';
|
||||
|
||||
} elseif ( ! isset( $installed_plugins[ $plugin['file_path'] ] ) ) {
|
||||
|
||||
if ( isset( $plugin['premium'] ) AND ! get_option( 'us_license_activated', 0 ) ) {
|
||||
$classes .= ' status_locked';
|
||||
} else {
|
||||
$classes .= ' status_notinstalled';
|
||||
$btn_text = us_translate( 'Install Now' );
|
||||
$btn_url = 'javascript:void(0);';
|
||||
$btn_classes .= ' color_primary action-button';
|
||||
$btn_atts = ' data-plugin="' . $plugin['slug'] . '" data-action="install"';
|
||||
}
|
||||
|
||||
} elseif ( is_plugin_inactive( $plugin['file_path'] ) ) {
|
||||
$classes .= ' status_notactive';
|
||||
$btn_text = us_translate( 'Activate Plugin' );
|
||||
$btn_url = 'javascript:void(0);';
|
||||
$btn_classes .= ' color_primary action-button';
|
||||
$btn_atts = ' data-plugin="' . $plugin['slug'] . '" data-action="activate"';
|
||||
}
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
<div class="us-addon<?php echo $classes; ?>">
|
||||
<div class="us-addon-content">
|
||||
<a href="<?php echo $plugin['url'] ?>" target="_blank">
|
||||
<img class="us-addon-icon" src="<?php echo $icon_url; ?>" alt="icon">
|
||||
<h2 class="us-addon-title"><?php echo $plugin['name'] ?></h2>
|
||||
</a>
|
||||
<p class="us-addon-desc"><?php echo $plugin['description']; ?></p>
|
||||
</div>
|
||||
<div class="us-addon-control">
|
||||
<div class="us-addon-status"><?php echo us_translate_x( 'Active', 'plugin' ); ?></div>
|
||||
<?php
|
||||
// Screenlock for premium plugins
|
||||
if ( isset( $plugin['premium'] ) AND ! get_option( 'us_license_activated', 0 ) ) {
|
||||
?>
|
||||
<div class="us-addon-lock">
|
||||
<div><?php echo sprintf( __( '<a href="%s">Activate the theme</a> to install premium addons', 'us' ), admin_url( 'admin.php?page=us-home#activation' ) ) ?></div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
if ( $btn_text != '' AND $btn_url != '' ) {
|
||||
?>
|
||||
<a class="usof-button<?php echo $btn_classes; ?>" href="<?php echo $btn_url; ?>" <?php echo $btn_atts; ?>><span><?php echo $btn_text; ?></span></a>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
$plugins_html .= ob_get_clean();
|
||||
}
|
||||
|
||||
?>
|
||||
<div class="us-addons">
|
||||
<h1 class="us-admin-title"><?php echo __( 'Recommended Plugins', 'us' ); ?></h1>
|
||||
<p class="us-admin-subtitle"><?php echo sprintf( __( 'Premium and free plugins, compatible with %s', 'us' ), US_THEMENAME ) ?></p>
|
||||
<div class="us-addons-list"><?php echo $plugins_html ?></div>
|
||||
</div>
|
||||
<script>
|
||||
jQuery(function($){
|
||||
var isRunning = false;
|
||||
$('.action-button').click(function(){
|
||||
if (isRunning) return;
|
||||
isRunning = true;
|
||||
$('.us-addons-list').addClass('disable-buttons');
|
||||
var plugin = $(this).attr('data-plugin'),
|
||||
action = $(this).attr('data-action'),
|
||||
$tile = $(this).closest('.us-addon'),
|
||||
$status = $tile.find('.us-addon-status'),
|
||||
$button = $(this);
|
||||
|
||||
$tile.removeClass(function(index, css){
|
||||
return (css.match(/(^|\s)status_\S+/g) || []).join(' ');
|
||||
});
|
||||
if (action == 'install') {
|
||||
$tile.addClass('status_installing');
|
||||
$button.html('<i class="g-preloader type_1"></i><?php echo esc_js( us_translate( 'Installing...' ) ); ?>');
|
||||
} else {
|
||||
$tile.addClass('status_activating');
|
||||
$button.html('<i class="g-preloader type_1"></i><?php esc_js( _e( 'Activating...', 'us' ) ); ?>');
|
||||
}
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '<?php echo admin_url( 'admin-ajax.php' ); ?>',
|
||||
data: {
|
||||
action: 'us_ajax_addons_' + action,
|
||||
plugin: plugin,
|
||||
security: '<?php echo wp_create_nonce( 'us-addons-actions' ); ?>'
|
||||
},
|
||||
success: function(data){
|
||||
isRunning = false;
|
||||
$('.us-addons-list').removeClass('disable-buttons');
|
||||
$button.hide();
|
||||
$tile.removeClass(function(index, css){
|
||||
return (css.match(/(^|\s)status_\S+/g) || []).join(' ');
|
||||
});
|
||||
if (data != undefined && data.success) {
|
||||
$tile.addClass('status_active');
|
||||
$status.html('<?php echo esc_js( us_translate_x( 'Active', 'plugin' ) ); ?>');
|
||||
} else {
|
||||
$tile.addClass('status_error');
|
||||
if (data != undefined && data.data != undefined && data.data.message != undefined) {
|
||||
$status.html(data.data.message);
|
||||
} else {
|
||||
$status.html('<?php echo esc_js( us_translate( 'An error has occurred. Please reload the page and try again.' ) ); ?>');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
add_action( 'wp_ajax_us_ajax_addons_install', 'us_ajax_addons_install' );
|
||||
add_action( 'wp_ajax_us_ajax_addons_activate', 'us_ajax_addons_activate' );
|
||||
|
||||
function us_ajax_addons_activate() {
|
||||
|
||||
if ( ! check_ajax_referer( 'us-addons-actions', 'security', FALSE ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! isset( $_POST['plugin'] ) OR ! $_POST['plugin'] ) {
|
||||
wp_send_json_error( array( 'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ) ) );
|
||||
}
|
||||
|
||||
$result = us_activate_plugin();
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
wp_send_json_error( array( 'message' => $result->get_error_message() ) );
|
||||
}
|
||||
|
||||
wp_send_json_success( array( 'plugin' => $_POST['plugin'] ) );
|
||||
|
||||
}
|
||||
|
||||
function us_activate_plugin() {
|
||||
if ( empty( $_POST['plugin'] ) ) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$plugins = us_config( 'addons', array() );
|
||||
|
||||
if ( empty( $plugins ) ) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$_plugins = array();
|
||||
foreach ( $plugins as $i => $plugin ) {
|
||||
$_plugins[ $plugin['slug'] ] = $plugin;
|
||||
}
|
||||
|
||||
$plugins = $_plugins;
|
||||
|
||||
$slug = urldecode( $_POST['plugin'] );
|
||||
|
||||
if ( ! isset( $plugins[ $slug ] ) ) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$plugin = $plugins[ $slug ];
|
||||
|
||||
$plugin_data = get_plugins( '/' . $plugin['slug'] ); // Retrieve all plugins.
|
||||
$plugin_file = array_keys( $plugin_data ); // Retrieve all plugin files from installed plugins.
|
||||
|
||||
$plugin_to_activate = trailingslashit( $plugin['slug'] ) . $plugin_file[0]; // Match plugin slug with appropriate plugin file.
|
||||
ob_start();
|
||||
$activate = activate_plugin( $plugin_to_activate ); // Activate the plugin.
|
||||
ob_get_clean();
|
||||
|
||||
if ( is_wp_error( $activate ) ) {
|
||||
return $activate;
|
||||
} else {
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
function us_ajax_addons_install() {
|
||||
set_time_limit( 300 );
|
||||
|
||||
if ( ! check_ajax_referer( 'us-addons-actions', 'security', FALSE ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( ! isset( $_POST['plugin'] ) OR ! $_POST['plugin'] ) {
|
||||
wp_send_json_error( array( 'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ) ) );
|
||||
}
|
||||
|
||||
$result = us_install_plugin();
|
||||
|
||||
if ( is_wp_error( $result ) ) {
|
||||
wp_send_json_error( array( 'message' => $result->get_error_message() ) );
|
||||
}
|
||||
|
||||
wp_send_json_success( array( 'plugin' => $_POST['plugin'] ) );
|
||||
}
|
||||
|
||||
function us_install_plugin() {
|
||||
if ( empty( $_POST['plugin'] ) ) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$plugins = us_config( 'addons', array() );
|
||||
|
||||
foreach ( $plugins as $i => $plugin ) {
|
||||
if ( ! isset( $plugins[ $i ]['premium'] ) ) {
|
||||
// Define WordPress repository plugin URL based on slug
|
||||
$plugins[ $i ]['source'] = 'https://downloads.wordpress.org/plugin/' . $plugin['slug'] . '.latest-stable.zip';
|
||||
} elseif ( empty( $plugins[ $i ]['source'] ) ) {
|
||||
unset( $plugins[ $i ] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $plugins ) ) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$_plugins = array();
|
||||
foreach ( $plugins as $i => $plugin ) {
|
||||
$_plugins[ $plugin['slug'] ] = $plugin;
|
||||
}
|
||||
|
||||
$plugins = $_plugins;
|
||||
|
||||
$slug = urldecode( $_POST['plugin'] );
|
||||
|
||||
if ( ! isset( $plugins[ $slug ] ) ) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$plugin = $plugins[ $slug ];
|
||||
|
||||
if ( file_exists( trailingslashit( WP_PLUGIN_DIR ) . $slug ) ) {
|
||||
return us_activate_plugin();
|
||||
}
|
||||
|
||||
if ( ! filesystem_permission_check() ) {
|
||||
return new WP_Error( 'us-addons', __( 'Please adjust file permissions to allow plugins installation', 'us' ) );
|
||||
}
|
||||
|
||||
$us_template_directory = get_template_directory();
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin-install.php';
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
||||
|
||||
$skin = new WP_Ajax_Upgrader_Skin();
|
||||
$upgrader = new Plugin_Upgrader( $skin );
|
||||
|
||||
$install_result = $upgrader->install( $plugin['source'] );
|
||||
|
||||
if ( is_wp_error( $install_result ) ) {
|
||||
return $install_result;
|
||||
}
|
||||
|
||||
if ( ! $install_result ) {
|
||||
return new WP_Error( 'plugin_error', us_translate( 'An error has occurred. Please reload the page and try again.' ) );
|
||||
}
|
||||
|
||||
ob_start();
|
||||
$activate = activate_plugin( $upgrader->plugin_info() );
|
||||
ob_get_clean();
|
||||
if ( is_wp_error( $activate ) ) {
|
||||
return $activate;
|
||||
}
|
||||
|
||||
return $skin->result;
|
||||
}
|
||||
|
||||
function filesystem_permission_check() {
|
||||
ob_start();
|
||||
$creds = request_filesystem_credentials( '', '', FALSE, FALSE, NULL );
|
||||
ob_get_clean();
|
||||
|
||||
// Abort if permissions were not available.
|
||||
if ( ! WP_Filesystem( $creds ) ) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,84 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
// Actions after theme activation
|
||||
add_action( 'admin_init', 'us_theme_activation', 99 );
|
||||
function us_theme_activation() {
|
||||
global $pagenow;
|
||||
if ( is_admin() AND $pagenow == 'themes.php' AND isset( $_GET['activated'] ) ) {
|
||||
// Set menu
|
||||
$user = wp_get_current_user();
|
||||
update_user_option( $user->ID, US_THEMENAME . '_cpt_in_menu_set', FALSE, TRUE );
|
||||
|
||||
// Add Default Footer post type if needed
|
||||
us_add_default_footer();
|
||||
|
||||
// Redirect to About the Theme page
|
||||
header( 'Location: ' . admin_url( 'admin.php?page=us-home' ) );
|
||||
}
|
||||
}
|
||||
|
||||
// Show indication for beta versions
|
||||
if ( is_user_logged_in() AND defined( 'US_THEME_BETA' ) ) {
|
||||
add_action( 'admin_bar_menu', 'us_beta_admin_bar_menu', 1000 );
|
||||
}
|
||||
function us_beta_admin_bar_menu( $wp_admin_bar ) {
|
||||
$wp_admin_bar->add_node(
|
||||
array(
|
||||
'id' => 'us-beta',
|
||||
'title' => US_THEMENAME . ' BETA',
|
||||
'meta' => array(
|
||||
'html' => '<style>#wp-admin-bar-us-beta>*{background:#e95095!important;color:#fff!important;}</style>',
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Hide some our metaboxes on Menus admin page
|
||||
add_action( 'admin_head', 'us_include_cpt_to_menu', 99 );
|
||||
function us_include_cpt_to_menu() {
|
||||
global $pagenow;
|
||||
if ( is_admin() AND $pagenow == 'nav-menus.php' ) {
|
||||
$already_set = get_user_option( US_THEMENAME . '_cpt_in_menu_set' );
|
||||
|
||||
if ( ! $already_set ) {
|
||||
$hidden_meta_boxes = get_user_option( 'metaboxhidden_nav-menus' );
|
||||
|
||||
if ( ! is_array( $hidden_meta_boxes ) ) {
|
||||
$hidden_meta_boxes = array();
|
||||
}
|
||||
|
||||
if ( $hidden_meta_boxes !== FALSE ) {
|
||||
if ( ( $key = array_search( 'add-post-type-us_portfolio', $hidden_meta_boxes ) ) !== FALSE AND isset( $hidden_meta_boxes[$key] ) ) {
|
||||
unset( $hidden_meta_boxes[$key] );
|
||||
}
|
||||
if ( ( $key = array_search( 'add-us_portfolio_category', $hidden_meta_boxes ) ) === FALSE ) {
|
||||
$hidden_meta_boxes[] = 'add-us_portfolio_category';
|
||||
}
|
||||
if ( ( $key = array_search( 'add-us_portfolio_tag', $hidden_meta_boxes ) ) === FALSE ) {
|
||||
$hidden_meta_boxes[] = 'add-us_portfolio_tag';
|
||||
}
|
||||
if ( ( $key = array_search( 'add-post-type-us_widget_area', $hidden_meta_boxes ) ) !== FALSE AND isset( $hidden_meta_boxes[$key] ) ) {
|
||||
unset( $hidden_meta_boxes[$key] );
|
||||
}
|
||||
|
||||
$user = wp_get_current_user();
|
||||
update_user_option( $user->ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes, TRUE );
|
||||
update_user_option( $user->ID, US_THEMENAME . '_cpt_in_menu_set', TRUE, TRUE );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Custom CSS for all admin pages
|
||||
add_action( 'admin_print_scripts', 'us_enqueue_admin_css', 12 );
|
||||
function us_enqueue_admin_css() {
|
||||
global $us_template_directory_uri;
|
||||
wp_enqueue_style( 'us-theme-admin', $us_template_directory_uri . '/framework/admin/css/theme-admin.css', array(), US_THEMEVERSION );
|
||||
wp_enqueue_style( 'us-font-awesome', $us_template_directory_uri . '/css/base/fontawesome.css', array(), US_THEMEVERSION );
|
||||
}
|
||||
|
||||
// Custom CSS for visual editor
|
||||
add_action( 'admin_init', 'us_theme_add_editor_styles' );
|
||||
function us_theme_add_editor_styles() {
|
||||
add_editor_style( 'framework/admin/css/editor-style.css' );
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
add_filter( 'usof_container_classes', 'usgb_usof_container_classes' );
|
||||
function usgb_usof_container_classes( $classes ) {
|
||||
return $classes . ' with_gb';
|
||||
}
|
||||
|
||||
add_action( 'init', 'usgb_create_post_types', 7 );
|
||||
function usgb_create_post_types() {
|
||||
|
||||
// Grid Layout post type
|
||||
register_post_type(
|
||||
'us_grid_layout', array(
|
||||
'labels' => array(
|
||||
'name' => __( 'Grid Layouts', 'us' ),
|
||||
'singular_name' => __( 'Grid Layout', 'us' ),
|
||||
'add_new' => __( 'Add Grid Layout', 'us' ),
|
||||
'add_new_item' => __( 'Add Grid Layout', 'us' ),
|
||||
),
|
||||
'public' => TRUE,
|
||||
'show_in_menu' => 'us-theme-options',
|
||||
'exclude_from_search' => TRUE,
|
||||
'show_in_admin_bar' => FALSE,
|
||||
'publicly_queryable' => FALSE,
|
||||
'show_in_nav_menus' => FALSE,
|
||||
'capability_type' => array( 'us_page_block', 'us_page_blocks' ),
|
||||
'map_meta_cap' => TRUE,
|
||||
'supports' => FALSE,
|
||||
'rewrite' => FALSE,
|
||||
'register_meta_box_cb' => 'usgb_us_grid_type_pages',
|
||||
)
|
||||
);
|
||||
|
||||
// Add "Used in" column into Grid Layouts admin page
|
||||
add_filter( 'manage_us_grid_layout_posts_columns', 'ushb_us_grid_layout_columns_head' );
|
||||
add_action( 'manage_us_grid_layout_posts_custom_column', 'ushb_us_grid_layout_columns_content', 10, 2 );
|
||||
function ushb_us_grid_layout_columns_head( $defaults ) {
|
||||
$result = array();
|
||||
foreach ( $defaults as $key => $title ) {
|
||||
if ( $key == 'date' ) {
|
||||
$result['used_in'] = __( 'Used in', 'us' );
|
||||
}
|
||||
$result[$key] = $title;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
function ushb_us_grid_layout_columns_content( $column_name, $post_ID ) {
|
||||
if ( $column_name == 'used_in' ) {
|
||||
echo us_get_used_in_locations( $post_ID );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function usgb_us_grid_type_pages() {
|
||||
global $post;
|
||||
// Dev note: This check is not necessary, but still wanted to make sure this function won't be bound somewhere else
|
||||
if ( ! ( $post instanceof WP_Post ) OR $post->post_type !== 'us_grid_layout' ) {
|
||||
return;
|
||||
}
|
||||
if ( $post->post_status === 'auto-draft' ) {
|
||||
// Page for creating new grid: creating it instantly and proceeding to editing
|
||||
$post_data = array( 'ID' => $post->ID );
|
||||
// Retrieving occupied names to generate new post title properly
|
||||
$existing_grids = usgb_get_existing_grids();
|
||||
if ( isset( $_GET['duplicate_from'] ) AND ( $original_post = get_post( (int) $_GET['duplicate_from'] ) ) !== NULL ) {
|
||||
// Handling post duplication
|
||||
$post_data['post_content'] = $original_post->post_content;
|
||||
$title_pattern = $original_post->post_title . ' (%d)';
|
||||
$cur_index = 2;
|
||||
} else {
|
||||
// Handling creation from scratch
|
||||
$title_pattern = __( 'Layout', 'us' ) . ' %d';
|
||||
$cur_index = count( $existing_grids ) + 1;
|
||||
}
|
||||
// Generating new post title
|
||||
while ( in_array( $post_data['post_title'] = sprintf( $title_pattern, $cur_index ), $existing_grids ) ) {
|
||||
$cur_index ++;
|
||||
}
|
||||
wp_update_post( $post_data );
|
||||
wp_publish_post( $post->ID );
|
||||
// Redirect
|
||||
if ( isset( $_GET['duplicate_from'] ) ) {
|
||||
// When duplicating post, showing posts list next
|
||||
wp_redirect( admin_url( 'edit.php?post_type=us_grid_layout' ) );
|
||||
} else {
|
||||
// When creating from scratch proceeding to post editing next
|
||||
wp_redirect( admin_url( 'post.php?post=' . $post->ID . '&action=edit' ) );
|
||||
}
|
||||
} else {
|
||||
// Page for editing a grid
|
||||
add_action( 'admin_enqueue_scripts', 'usgb_enqueue_scripts' );
|
||||
add_action( 'edit_form_top', 'usgb_edit_form_top' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get available grids
|
||||
* @return array
|
||||
*/
|
||||
function usgb_get_existing_grids() {
|
||||
$result = array();
|
||||
$grids = get_posts(
|
||||
array(
|
||||
'post_type' => 'us_grid_layout',
|
||||
'posts_per_page' => - 1,
|
||||
'post_status' => 'any',
|
||||
'suppress_filters' => 0,
|
||||
)
|
||||
);
|
||||
foreach ( $grids as $grid ) {
|
||||
$result[$grid->ID] = $grid->post_title;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function usgb_enqueue_scripts() {
|
||||
// Appending dependencies
|
||||
usof_print_styles();
|
||||
usof_print_scripts();
|
||||
|
||||
// Appending required assets
|
||||
global $us_template_directory_uri;
|
||||
wp_enqueue_script( 'us-grid-builder', $us_template_directory_uri . '/framework/admin/js/grid-builder.js', array( 'usof-scripts' ), TRUE );
|
||||
|
||||
// Disabling WP auto-save
|
||||
wp_dequeue_script( 'autosave' );
|
||||
}
|
||||
|
||||
function usgb_edit_form_top( $post ) {
|
||||
echo '<div class="usof-container type_builder" data-ajaxurl="' . esc_attr( admin_url( 'admin-ajax.php' ) ) . '" data-id="' . esc_attr( $post->ID ) . '">';
|
||||
echo '<form class="usof-form" method="post" action="#" autocomplete="off">';
|
||||
// Output _nonce and _wp_http_referer hidden fields for ajax secuirity checks
|
||||
wp_nonce_field( 'usgb-update' );
|
||||
echo '<div class="usof-header">';
|
||||
echo '<div class="usof-header-title">' . __( 'Grid Layout', 'us' ) . '</div>';
|
||||
|
||||
us_load_template(
|
||||
'vendor/usof/templates/field', array(
|
||||
'name' => 'post_title',
|
||||
'id' => 'usof_header_title',
|
||||
'field' => array(
|
||||
'type' => 'text',
|
||||
'placeholder' => __( 'Grid Layout Name', 'us' ),
|
||||
'classes' => 'desc_0', // Reset desc position of global GB field
|
||||
),
|
||||
'values' => array(
|
||||
'post_title' => $post->post_title,
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
echo '<div class="usof-control for_help"><a href="https://help.us-themes.com/' . strtolower( US_THEMENAME ) . '/grid/" target="_blank" title="' . us_translate( 'Help' ) . '"></a></div>';
|
||||
echo '<div class="usof-control for_import"><a href="#" title="' . __( 'Export / Import', 'us' ) . '"></a></div>';
|
||||
echo '<div class="usof-control for_templates">';
|
||||
echo '<a href="#" title="' . __( 'Grid Layout Templates', 'us' ) . '"></a>';
|
||||
echo '<div class="usof-control-desc"><span>' . __( 'Choose Grid Layout Template to start with', 'us' ) . '</span></div>';
|
||||
echo '</div>';
|
||||
echo '<div class="usof-control for_save status_clear">';
|
||||
echo '<button class="usof-button type_save" type="button"><span>' . us_translate( 'Save Changes' ) . '</span>';
|
||||
echo '<span class="usof-preloader"></span></button>';
|
||||
echo '<div class="usof-control-message"></div></div></div>';
|
||||
|
||||
us_load_template(
|
||||
'vendor/usof/templates/field', array(
|
||||
'name' => 'post_content',
|
||||
'id' => 'usof_header',
|
||||
'field' => array(
|
||||
'type' => 'grid_builder',
|
||||
'classes' => 'desc_0', // Reset desc position of global GB field
|
||||
),
|
||||
'values' => array(
|
||||
'post_content' => $post->post_content,
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
echo '</form>';
|
||||
echo '</div>';
|
||||
}
|
||||
|
||||
// Add "Duplicate" link for Grid Layouts admin page
|
||||
add_filter( 'post_row_actions', 'usgb_post_row_actions', 10, 2 );
|
||||
function usgb_post_row_actions( $actions, $post ) {
|
||||
if ( $post->post_type === 'us_grid_layout' ) {
|
||||
// Removing duplicate post plugin affection
|
||||
unset( $actions['duplicate'], $actions['edit_as_new_draft'] );
|
||||
$actions = us_array_merge_insert(
|
||||
$actions, array(
|
||||
'duplicate' => '<a href="' . admin_url( 'post-new.php?post_type=us_grid_layout&duplicate_from=' . $post->ID ) . '" aria-label="' . esc_attr__( 'Duplicate', 'us' ) . '">' . esc_html__( 'Duplicate', 'us' ) . '</a>',
|
||||
), 'before', isset( $actions['trash'] ) ? 'trash' : 'untrash'
|
||||
);
|
||||
}
|
||||
|
||||
return $actions;
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Theme updater for activated licenses
|
||||
*/
|
||||
|
||||
$license_activated = get_option( 'us_license_activated', 0 );
|
||||
$license_secret = get_option( 'us_license_secret' );
|
||||
|
||||
if ( $license_activated AND $license_secret != '' ) {
|
||||
function us_api_themes_update( $updates ) {
|
||||
|
||||
$updates = us_check_theme_updates( $updates );
|
||||
|
||||
return $updates;
|
||||
}
|
||||
|
||||
add_filter( "pre_set_site_transient_update_themes", "us_api_themes_update" );
|
||||
} else {
|
||||
function us_api_themes_update_deactivated( $updates ) {
|
||||
|
||||
$updates = us_check_theme_updates_deactivated( $updates );
|
||||
|
||||
return $updates;
|
||||
}
|
||||
|
||||
add_filter( "pre_set_site_transient_update_themes", "us_api_themes_update_deactivated" );
|
||||
}
|
||||
|
||||
function us_check_theme_updates_deactivated( $updates ) {
|
||||
$result = us_api_get_themes_deactivated();
|
||||
|
||||
if ( ! empty( $result->data->new_version ) ) {
|
||||
|
||||
$installed = wp_get_themes();
|
||||
$filtered = array();
|
||||
foreach ( $installed as $theme ) {
|
||||
$filtered[$theme->Name] = $theme;
|
||||
}
|
||||
|
||||
if ( isset( $filtered[US_THEMENAME] ) ) {
|
||||
$current = $filtered[US_THEMENAME];
|
||||
|
||||
if ( version_compare( $current->Version, $result->data->new_version, '<' ) ) {
|
||||
$update = array(
|
||||
"url" => $result->data->url,
|
||||
"new_version" => $result->data->new_version,
|
||||
"package" => NULL,
|
||||
);
|
||||
|
||||
$updates->response[US_THEMENAME] = $update;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $updates;
|
||||
}
|
||||
|
||||
function us_api_get_themes_deactivated( $timeout = 1800 ) {
|
||||
|
||||
$urlparts = parse_url( site_url() );
|
||||
|
||||
$url = "https://help.us-themes.com/us.api/check_update/" . strtolower( US_THEMENAME ) . "?current_version=" . urlencode( US_THEMEVERSION );
|
||||
$transient = 'us_update_theme_data_deactivated_' . US_THEMENAME;
|
||||
|
||||
/* create the cache and allow filtering before it's saved */
|
||||
if ( $results = us_api_remote_request( $url ) ) {
|
||||
set_transient( $transient, $results, $timeout );
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
|
||||
function us_check_theme_updates( $updates ) {
|
||||
$license_secret = get_option( 'us_license_secret' );
|
||||
|
||||
$result = us_api_get_themes( $license_secret );
|
||||
|
||||
if ( ! empty( $result->data->new_version ) ) {
|
||||
|
||||
$installed = wp_get_themes();
|
||||
$filtered = array();
|
||||
foreach ( $installed as $theme ) {
|
||||
$filtered[$theme->Name] = $theme;
|
||||
}
|
||||
|
||||
if ( isset( $filtered[US_THEMENAME] ) ) {
|
||||
$current = $filtered[US_THEMENAME];
|
||||
|
||||
if ( version_compare( $current->Version, $result->data->new_version, '<' ) ) {
|
||||
$update = array(
|
||||
"url" => $result->data->url,
|
||||
"new_version" => $result->data->new_version,
|
||||
"package" => $result->data->package,
|
||||
);
|
||||
|
||||
$updates->response[US_THEMENAME] = $update;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $updates;
|
||||
}
|
||||
|
||||
function us_api_get_themes( $license_secret, $timeout = 1800 ) {
|
||||
|
||||
$urlparts = parse_url( site_url() );
|
||||
$domain = $urlparts['host'];
|
||||
|
||||
$url = "https://help.us-themes.com/us.api/check_update/" . strtolower( US_THEMENAME ) . "?secret=" . urlencode( $license_secret ) . "&domain=" . urlencode( $domain ) . "¤t_version=" . urlencode( US_THEMEVERSION );
|
||||
$transient = 'us_update_theme_data_' . US_THEMENAME;
|
||||
|
||||
if ( FALSE !== $results = get_transient( $transient ) ) {
|
||||
return $results;
|
||||
}
|
||||
|
||||
/* create the cache and allow filtering before it's saved */
|
||||
if ( $results = us_api_remote_request( $url ) ) {
|
||||
set_transient( $transient, $results, $timeout );
|
||||
|
||||
return $results;
|
||||
}
|
||||
}
|
||||
|
||||
add_filter( 'sanitize_key', 'us_sanitize_key_themename', 10, 2 );
|
||||
function us_sanitize_key_themename( $key, $raw_key ) {
|
||||
if ( in_array( $raw_key, array( 'Impreza', 'Zephyr' ) ) ) {
|
||||
$key = $raw_key;
|
||||
}
|
||||
|
||||
return $key;
|
||||
}
|
||||
|
||||
add_action( '_network_admin_menu', 'us_add_theme_update_notice_to_menu' );
|
||||
add_action( '_user_admin_menu', 'us_add_theme_update_notice_to_menu' );
|
||||
add_action( '_admin_menu', 'us_add_theme_update_notice_to_menu' );
|
||||
function us_add_theme_update_notice_to_menu(){
|
||||
global $menu;
|
||||
|
||||
if ( isset($menu[60]) AND isset($menu[60][2]) AND $menu[60][2] == 'themes.php' ) {
|
||||
$update_notification = '';
|
||||
$update_themes = get_site_transient( 'update_themes' );
|
||||
if ( ! empty( $update_themes->response ) AND isset( $update_themes->response[US_THEMENAME] ) ) {
|
||||
$update_notification = ' <span class="update-plugins count-1"><span class="plugin-count">1</span></span>';
|
||||
}
|
||||
$menu[60][0] = us_translate( 'Appearance' ) . $update_notification;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
add_filter( 'wp_prepare_themes_for_js', 'us_wp_prepare_themes_for_js' );
|
||||
function us_wp_prepare_themes_for_js( $themes ) {
|
||||
if ( ! empty( $themes ) ) {
|
||||
foreach ( $themes as $slug => $theme_args ) {
|
||||
if ( $slug == US_THEMENAME AND $theme_args['hasUpdate'] AND ( ! $theme_args['hasPackage'] ) ) {
|
||||
$themes[$slug]['update'] = $theme_args['update'] .
|
||||
'<p><strong>' . sprintf( __( '%sActivate the theme%s to update it', 'us' ), '<a href="' . admin_url( 'admin.php?page=us-home#activation' ) . '">', '</a>' ) . '.</strong></p>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $themes;
|
||||
}
|
||||
|
||||
add_filter( 'site_transient_update_themes', 'us_site_transient_update_themes' );
|
||||
function us_site_transient_update_themes( $current ) {
|
||||
global $pagenow;
|
||||
if ( ! empty( $pagenow ) AND $pagenow == 'update-core.php' ) {
|
||||
if ( ! empty( $current->response ) ) {
|
||||
foreach ( $current->response as $stylesheet => $data ) {
|
||||
if ( $stylesheet == US_THEMENAME AND empty( $data['package'] ) ) {
|
||||
$current->response[$stylesheet]['new_version'] .= '.<br>' . sprintf( __( '%sActivate the theme%s to update it', 'us' ), '<a href="' . admin_url( 'admin.php?page=us-home#activation' ) . '">', '</a>' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return $current;
|
||||
}
|
||||
|
||||
add_action( 'upgrader_process_complete', 'us_upgrader_process_complete', 10, 2 );
|
||||
function us_upgrader_process_complete( $upgrader, $atts ) {
|
||||
if ( $atts['action'] == 'update' AND $atts['type'] == 'theme' AND $atts['bulk'] == 1) {
|
||||
if ( ! empty( $atts['themes'] ) ) {
|
||||
foreach ( $atts['themes'] as $theme ) {
|
||||
if ( $theme == US_THEMENAME AND get_option( 'us_license_activated', 0 ) != 1 ) {
|
||||
echo '<div class="error"><p>' . sprintf( __( '%sActivate the theme%s to update it', 'us' ), '<a target="_top" href="' . admin_url( 'admin.php?page=us-home#activation' ) . '">', '</a>' ) . '</p></div>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php defined( 'ABSPATH' ) OR die( 'This script cannot be accessed directly.' );
|
||||
|
||||
/**
|
||||
* Updater of the plugins from UpSolution Help Portal
|
||||
*/
|
||||
|
||||
add_filter( 'us_config_addons', 'us_api_addons' );
|
||||
|
||||
function us_api_addons( $plugins, $force_request = FALSE ) {
|
||||
|
||||
$license_activated = get_option( 'us_license_activated', 0 );
|
||||
$license_secret = get_option( 'us_license_secret' );
|
||||
$addons_version = get_option( 'us_addons_version' );
|
||||
|
||||
if ( $license_activated AND $license_secret != '' ) {
|
||||
|
||||
$urlparts = parse_url( site_url() );
|
||||
$domain = $urlparts['host'];
|
||||
|
||||
$url = "https://help.us-themes.com/us.api/check_addons_update/" . strtolower( US_THEMENAME ) . "?secret=" . urlencode( $license_secret ) . "&domain=" . urlencode( $domain ) . "¤t_version=" . urlencode( US_THEMEVERSION );
|
||||
$transient = 'us_update_addons_data_' . US_THEMENAME;
|
||||
|
||||
if ( ( ! empty( $addons_version ) AND $addons_version == US_THEMEVERSION ) AND FALSE !== $results = get_transient( $transient ) ) {
|
||||
$update_addons_data = $results;
|
||||
}
|
||||
|
||||
if ( ( empty( $update_addons_data ) OR $force_request ) AND $results = us_api_remote_request( $url ) ) {
|
||||
set_transient( $transient, $results, 1800 );
|
||||
$update_addons_data = $results;
|
||||
update_option( 'us_addons_version', US_THEMEVERSION );
|
||||
}
|
||||
|
||||
if ( ! empty( $update_addons_data->data ) ) {
|
||||
foreach ( $plugins as $i => $plugin ) {
|
||||
$slug = $plugin['slug'];
|
||||
if ( isset( $update_addons_data->data->$slug ) ) {
|
||||
$plugins[$i]['version'] = $update_addons_data->data->$slug->new_version;
|
||||
$plugins[$i]['source'] = $update_addons_data->data->$slug->package;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
$addons = us_config( 'addons', array() );
|
||||
|
||||
foreach ( $addons as $i => $addon ) {
|
||||
if ( empty( $addons[$i]['version'] ) OR empty( $addons[$i]['source'] ) ) {
|
||||
unset( $addons[$i] );
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $addons ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Transient hook for automatical updates of bundled plugins
|
||||
add_action( 'site_transient_update_plugins', 'us_addons_transient_update' );
|
||||
function us_addons_transient_update( $trans ) {
|
||||
|
||||
$installed_plugins = get_plugins();
|
||||
|
||||
$addons = us_config( 'addons', array() );
|
||||
|
||||
foreach ( $addons as $i => $addon ) {
|
||||
if ( empty( $addons[$i]['version'] ) OR empty( $addons[$i]['source'] ) ) {
|
||||
unset( $addons[$i] );
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $addons as $addon ) {
|
||||
$plugin_basename = sprintf( '%s/%s.php', $addon['slug'], $addon['slug'] );
|
||||
|
||||
if ( ! isset( $installed_plugins[$plugin_basename] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( version_compare( $installed_plugins[$plugin_basename]['Version'], $addon['version'], '<' ) ) {
|
||||
$trans->response[$plugin_basename] = new StdClass();
|
||||
$trans->response[$plugin_basename]->plugin = $plugin_basename;
|
||||
$trans->response[$plugin_basename]->url = $addon['changelog_url'];
|
||||
$trans->response[$plugin_basename]->slug = $addon['slug'];
|
||||
$trans->response[$plugin_basename]->package = $addon['source'];
|
||||
$trans->response[$plugin_basename]->new_version = $addon['version'];
|
||||
$trans->response[$plugin_basename]->id = '0';
|
||||
}
|
||||
}
|
||||
|
||||
return $trans;
|
||||
}
|
||||
|
||||
// Seen when user clicks "view details" on the plugin listing page
|
||||
add_action( 'install_plugins_pre_plugin-information', 'us_addons_update_popup' );
|
||||
function us_addons_update_popup() {
|
||||
|
||||
if ( ! isset( $_GET['plugin'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$plugin_slug = sanitize_file_name( $_GET['plugin'] );
|
||||
|
||||
$addons = us_config( 'addons', array() );
|
||||
|
||||
foreach ( $addons as $i => $addon ) {
|
||||
if ( empty( $addons[$i]['version'] ) OR empty( $addons[$i]['source'] ) ) {
|
||||
unset( $addons[$i] );
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $addons as $addon ) {
|
||||
if ( $addon['slug'] == $plugin_slug ) {
|
||||
$changelog_url = $addon['changelog_url'];
|
||||
|
||||
echo '<html><body style="height: 90%; background: #fcfcfc"><p>See the <a href="' . $changelog_url . '" ' . 'target="_blank">' . $changelog_url . '</a> for the detailed changelog</p></body></html>';
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
add_action( 'admin_head', 'us_remove_bsf_update_counter' );
|
||||
function us_remove_bsf_update_counter() {
|
||||
remove_action( 'admin_head', 'bsf_update_counter', 999 );
|
||||
}
|
||||
Reference in new issue
Block a user