_constants(); $this->_includes(); $this->_hooks(); } /** * Defines the constants for use within the plugin. * * @access private * @since 1.0 * @updated 1.6 * * @return void */ protected function _constants() { /** * Plugin Version */ define( 'EWPT_PLUGIN_VER', '1.8.0' ); /** * Plugin Name */ define( 'EWPT_PLUGIN_NAME', __( 'Envato WordPress Toolkit', 'envato-wordpress-toolkit' ) ); /** * Plugin Slug */ define( 'EWPT_PLUGIN_SLUG', 'envato-wordpress-toolkit' ); /** * Maximum request time */ define( 'EWPT_PLUGIN_MAX_EXECUTION_TIME' , 60 * 5 ); /** * Plugin Directory Path */ define( 'EWPT_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); /** * Plugin Directory URL */ define( 'EWPT_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); /** * Theme Backup Directory Path */ define( 'EWPT_BACKUP_DIR', WP_CONTENT_DIR . '/envato-backups/' ); /** * Theme Backup Directory URL */ define( 'EWPT_BACKUP_URL', WP_CONTENT_URL . '/envato-backups/' ); /** * Create a key for the .htaccess secure download link. * * @uses NONCE_KEY Defined in the WP root config.php */ define( 'EWPT_SECURE_KEY', md5( NONCE_KEY ) ); } /** * Include required files * * @since 1.0 * @access private * * @return void */ protected function _includes() { /* load required files */ if ( ! class_exists( 'Envato_Theme_Upgrader' ) ) { require_once( EWPT_PLUGIN_DIR . 'includes/class-wp-upgrader.php' ); } if ( ! class_exists( 'Envato_Backup' ) ) { require_once( EWPT_PLUGIN_DIR . 'includes/class-envato-backup.php' ); } if ( ! class_exists( 'Envato_Protected_API' ) ) { require_once( EWPT_PLUGIN_DIR . 'includes/class-envato-api.php' ); } $options = get_option( EWPT_PLUGIN_SLUG ); if ( ! class_exists( 'WP_GitHub_Updater' ) && ! isset( $options['deactivate_github_updater'] ) ) { require_once( EWPT_PLUGIN_DIR . 'includes/class-github-updater.php' ); } } /** * Setup the default filters and actions * * @uses add_action() To add various actions * * @access private * @since 1.0 * * @return void */ protected function _hooks() { /** * add envato menu item, change menu filter for multisite */ if ( is_multisite() ) { add_action( 'network_admin_menu', array( $this, '_envato_menu' ), 101 ); } else { add_action( 'admin_menu', array( $this, '_envato_menu' ), 101 ); } /** * Menu Icon CSS */ add_action( 'admin_head', array( $this, '_menu_icon' ) ); /** * Load text domain */ add_action( 'plugins_loaded', array( $this, '_load_textdomain' ) ); /** * Create AJAX nonce */ add_action( 'init', array( $this, '_ajax_notification_nonce' ) ); /** * loaded during admin init */ add_action( 'admin_init', array( $this, '_admin_init' ) ); /** * change link URL & text after install & upgrade */ add_filter( 'install_theme_complete_actions', array( $this, '_complete_actions' ), 10, 1 ); add_filter( 'update_theme_complete_actions', array( $this, '_complete_actions' ), 10, 1 ); add_filter( 'http_request_args', array( $this , '_http_request_args' ), 10, 1 ); add_action( 'wp_ajax_hide_admin_notification', array( $this, '_hide_admin_notification' ) ); add_action( 'admin_notices', array( $this, '_deprecation_notice' ) ); } /** * Adds the deprecation admin notice. * * @since 1.8.0 */ public function _deprecation_notice(){ $class = 'notice notice-error'; $message = __( 'Warning: The Envato Toolkit plugin is no longer supported and will stop functioning very shortly. Please delete the Envato Toolkit plugin and install the Envato Market plugin.', 'sample-text-domain' ); printf( '
', esc_attr( $class ), esc_html( $message ) ); } /** * Loads the text domain. * * @return void * * @access private * @since 1.7.1 */ public function _load_textdomain() { load_plugin_textdomain( 'envato-wordpress-toolkit', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); } /** * Create a nonce for AJAX notifications * * @uses wp_create_nonce() Generates and returns a nonce. * * @access private * @since 1.7.0 * * @return void */ public function _ajax_notification_nonce() { /* only if in the admin area */ if ( is_admin() ) $this->ajax_notification_nonce = wp_create_nonce( 'ajax-notification-nonce' ); } /** * Adds the Envato menu item * * @access private * @since 1.0 * * @return void */ public function _envato_menu() { /** * Stop Mojo Marketplace from tracking your movements! */ remove_action( 'admin_footer', 'mm_ux_log', 9 ); $menu_page = add_menu_page( EWPT_PLUGIN_NAME, __( 'Envato Toolkit', 'envato-wordpress-toolkit' ) .' !', 'manage_options', EWPT_PLUGIN_SLUG, array( $this, '_envato_menu_page' ), null, 58 ); add_action('admin_print_scripts-' . $menu_page, array( $this, '_envato_load_scripts' ) ); add_action('admin_print_styles-' . $menu_page, array( $this, '_envato_load_styles' ) ); } /** * Menu Font Icon CSS * * Changes the menu image icon to a font based version. * * @access private * @since 1.7.1 * * @return string Return icon CSS. */ public function _menu_icon() { global $wp_version; $wp_38plus = version_compare( $wp_version, '3.8', '>=' ) ? true : false; $fontsize = $wp_38plus ? '20px' : '16px'; $wp_38minus = ''; if ( ! $wp_38plus ) { $wp_38minus = ' #adminmenu .toplevel_page_envato-wordpress-toolkit .menu-icon-generic div.wp-menu-image { background: none; } #adminmenu .toplevel_page_envato-wordpress-toolkit .menu-icon-generic div.wp-menu-image:before { padding-left: 6px; }'; } echo ' '; } /** * Loads the scripts for the plugin * * @access private * @since 1.0 * * @return void */ public function _envato_load_scripts() { wp_enqueue_script( 'theme-preview' ); wp_enqueue_script( 'ajax-notification', EWPT_PLUGIN_URL . 'assets/js/ajax-notification.js', false, EWPT_PLUGIN_VER ); } /** * Loads the styles for the plugin * * @access private * @since 1.0 * * @return void */ public function _envato_load_styles() { wp_enqueue_style( 'envato-wp-updater', EWPT_PLUGIN_URL . 'assets/css/style.css', false, EWPT_PLUGIN_VER, 'all' ); } /** * Envato Updater HTML * * Creates the page used to verify themes for auto install/update * * @access private * @since 1.0 * @updated 1.4 * * @return string Returns the verification form & themes list */ public function _envato_menu_page() { if ( ! current_user_can( 'manage_options' ) ) wp_die( __( 'You do not have sufficient permissions to access this page.', 'envato-wordpress-toolkit' ) ); /* read in existing API value from database */ $options = get_option( EWPT_PLUGIN_SLUG ); /* display environment errors */ if ( ! empty( $options['env_errors'] ) ) { foreach ( $options['env_errors'] as $k => $v ) { if ( empty( $options['dismissed_errors'][$k] ) ) { echo '' . $v . '
' . __( 'User Settings Updated.', 'envato-wordpress-toolkit' ) . '
' . __( 'Theme Activated.', 'envato-wordpress-toolkit' ) . '
' . __( 'Theme Deleted.', 'envato-wordpress-toolkit' ) . '
' . $description . '
'; } /* Theme Backup URI */ $theme_backup_uri = $this->_get_theme_backup_uri( $template ); /* Links list */ if ( $stylesheet && $template && $current_stylesheet !== $stylesheet ) { $links[] = '' . __( 'Activate', 'envato-wordpress-toolkit' ) . ' |'; $links[] = '' . __( 'Preview', 'envato-wordpress-toolkit' ) . ' '; $links[] = '' . __( 'Preview', 'envato-wordpress-toolkit' ) . ' '; $links[] = '' . __( 'Delete' ) . ' |'; $links[] = '' . esc_attr( sprintf( __( 'View version %1$s details', 'envato-wordpress-toolkit' ), $latest_version ) ) . ' |'; if ( ! empty( $theme_backup_uri ) ) { $links[] = '' . esc_attr( __( 'Download Backup', 'envato-wordpress-toolkit' ) ) . ' |'; } $content.= '' . sprintf( __( 'The template files are located in %2$s. The stylesheet files are located in %3$s. %4$s uses templates from %5$s. Changes made to the templates will affect both themes.', 'envato-wordpress-toolkit' ), $title, str_replace( WP_CONTENT_DIR, '', $template_dir ), str_replace( WP_CONTENT_DIR, '', $stylesheet_dir ), $title, $parent_theme ) . '
' . sprintf( __( 'All of this theme’s files are located in %2$s.', 'envato-wordpress-toolkit' ), $title, str_replace( WP_CONTENT_DIR, '', $template_dir ), str_replace( WP_CONTENT_DIR, '', $stylesheet_dir ) ) . '
' . __( 'Tags: ' ). join( ', ', $tags ) . '
'; } /* Upgrade/Install message */ if ( $has_update ) { if ( ! current_user_can( 'update_themes' ) ) { $content.= sprintf( '' . __( 'There is a new version of %1$s available. View version %3$s details.', 'envato-wordpress-toolkit' ) . '
' . __( 'There is a new version of %1$s available. View version %3$s details or update automatically.', 'envato-wordpress-toolkit' ) . '
' . __( '%1$s has not been installed. View version %3$s details.', 'envato-wordpress-toolkit' ) . '
' . __( '%1$s has not been installed. View version %3$s details or install automatically.', 'envato-wordpress-toolkit' ) . '
wp-content/envato-backups. However, if you\'re experiencing problems while attempting to upgrade, it\'s likely to be a permissions issue and you may want to manually backup your theme before upgrading. Alternatively, if you don\'t want to backup your theme you can check the box below.', 'envato-wordpress-toolkit' );
}
/**
* No theme backup
*
* @access private
* @since 1.0
*
* @return string
*/
public function _field_skip_theme_backup() {
$options = get_option( EWPT_PLUGIN_SLUG );
$field_value = isset( $options['skip_theme_backup'] ) ? true : false;
echo '';
}
/**
* Github Updater
*
* @access private
* @since 1.7.1
*
* @return string
*/
public function _section_github_updater() {
printf( __( 'This option lets you deactivate the %s class, so it does not load. If you want to update the plugin in the future, just uncheck this option and the plugin will look for a new version on Github; check it and it stops looking.', 'envato-wordpress-toolkit' ), 'WP_GitHub_Updater' );
}
/**
* Deactivate Github Updater
*
* @access private
* @since 1.7.1
*
* @return string
*/
public function _field_deactivate_github_updater() {
$options = get_option( EWPT_PLUGIN_SLUG );
$field_value = isset( $options['deactivate_github_updater'] ) ? true : false;
echo '';
}
/**
* SSL Verify description
*
* @access private
* @since 1.7.3
*
* @return string
*/
public function _section_sslverify() {
printf( __( 'Checking this option will set %s to %s for all HTTP requests to the Envato API.', 'envato-wordpress-toolkit' ), 'sslverify', 'false' );
}
/**
* Set SSL Verify to false
*
* @access private
* @since 1.7.3
*
* @return string
*/
public function _field_deactivate_sslverify() {
$options = get_option( EWPT_PLUGIN_SLUG );
$field_value = isset( $options['deactivate_sslverify'] ) ? true : false;
echo '';
}
/**
* Change the text on the install or upgrade screen
*
* @access private
* @since 1.0
*
* @return array
*/
public function _complete_actions( $actions ) {
if ( isset( $_GET['page'] ) && isset( $_GET['action'] ) ) {
$page = $_GET['page'];
$action = $_GET['action'];
if ( $page == EWPT_PLUGIN_SLUG ) {
if ( 'install-theme' == $action || 'upgrade-theme' == $action ) {
$actions['themes_page'] = '' . sprintf( __( 'Return to %s', 'envato-wordpress-toolkit' ), EWPT_PLUGIN_NAME ) . '';
}
}
}
return $actions;
}
/**
* Manually installs a theme from the Envato API.
*
* @access private
* @since 1.0
* @updated 1.1
*
* @param string Theme item_id from ThemeForests
* @param array List of all purchased themes
* @return void
*/
protected function _install_theme( $theme, $themes ) {
global $current_screen;
check_admin_referer( 'install-theme_' . $theme );
if ( ! current_user_can( 'install_themes' ) )
wp_die( __( 'You do not have sufficient permissions to install themes for this site.', 'envato-wordpress-toolkit' ) );
/* setup theme info in $api array */
$api = (object) array();
foreach( $themes as $t ) {
if ( $theme == $t->item_id ) {
$api->name = $t->item_name;
$api->version = $t->version;
continue;
}
}
$title = sprintf( __( 'Installing Theme: %s', 'envato-wordpress-toolkit' ), $api->name . ' ' . $api->version );
$nonce = 'install-theme_' . $theme;
$url = network_admin_url( 'admin.php?page=' . EWPT_PLUGIN_SLUG . '&action=install-theme&theme=' . $theme );
$type = 'web';
/* trick WP into thinking it's the themes page for the icon32 */
$current_screen->parent_base = 'themes';
/* new Envato_Theme_Upgrader */
$upgrader = new Envato_Theme_Upgrader( new Theme_Installer_Skin( compact( 'title', 'url', 'api', 'nonce' ) ) );
/* install the theme */
$upgrader->install( $this->protected_api->wp_download( $theme ) );
}
/**
* Activate an Envato theme
*
* @access private
* @since 1.0
*
* @param string Template name
* @param array Stylesheet name
* @return void
*/
protected function _activate_theme( $template, $stylesheet ) {
check_admin_referer( 'switch-theme_' . $template );
if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) )
wp_die( __( 'You do not have sufficient permissions to update themes for this site.', 'envato-wordpress-toolkit' ) );
if ( ! function_exists( 'switch_theme' ) )
include_once( ABSPATH . 'wp-admin/includes/theme.php' );
switch_theme( $template, $stylesheet );
wp_redirect( network_admin_url( 'admin.php?page=' . EWPT_PLUGIN_SLUG . '&activated=true&tab=themes' ) );
exit;
}
/**
* Manually upgrades a theme from the Envato API.
*
* @access private
* @since 1.0
* @updated 1.1
*
* @param string Theme slug
* @param string Theme item_id from ThemeForests
* @return void
*/
protected function _upgrade_theme( $theme, $item_id ) {
global $current_screen;
check_admin_referer( 'upgrade-theme_' . $theme );
if ( ! current_user_can( 'update_themes' ) )
wp_die( __( 'You do not have sufficient permissions to update themes for this site.', 'envato-wordpress-toolkit' ) );
$title = __( 'Update Theme', 'envato-wordpress-toolkit' );
$nonce = 'upgrade-theme_' . $theme;
$url = network_admin_url( 'admin.php?page=' . EWPT_PLUGIN_SLUG . '&action=upgrade-theme&tab=themes&theme=' . $theme . '&item_id=' . $item_id );
/* trick WP into thinking it's the themes page for the icon32 */
$current_screen->parent_base = 'themes';
/* Upgrade Theme if a backup is created first */
$options = get_option( EWPT_PLUGIN_SLUG );
if ( isset( $options['skip_theme_backup'] ) || $this->_backup_theme( $theme ) === true ) {
/* new Envato_Theme_Upgrader */
$upgrader = new Envato_Theme_Upgrader( new Theme_Upgrader_Skin( compact( 'title', 'nonce', 'url', 'theme' ) ) );
/* upgrade the theme */
$upgrader->upgrade( $theme, $this->protected_api->wp_download( $item_id ) );
}
}
/**
* Delete an Envato theme
*
* @access private
* @since 1.0
*
* @param string Template name
* @return void
*/
protected function _delete_theme( $template ) {
check_admin_referer( 'delete-theme_' . $template );
if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) )
wp_die( __( 'You do not have sufficient permissions to update themes for this site.', 'envato-wordpress-toolkit' ) );
if ( ! current_user_can( 'delete_themes' ) )
wp_die( __( 'You do not have sufficient permissions to delete themes for this site.', 'envato-wordpress-toolkit' ) );
if ( ! function_exists( 'delete_theme' ) )
include_once( ABSPATH . 'wp-admin/includes/theme.php' );
delete_theme( $template, wp_nonce_url( network_admin_url( 'admin.php?page=' . EWPT_PLUGIN_SLUG . '&action=delete&template=' . $template ), 'delete-theme_' . $template ) );
wp_redirect( network_admin_url( 'admin.php?page=' . EWPT_PLUGIN_SLUG . '&deleted=true&tab=themes' ) );
exit;
}
/**
* Backup an Envato theme.
*
* This function requires the template/theme slug
* to locate and backup that theme.
*
* @access private
* @since 1.4
*
* @param string Template slug
* @return void
*/
protected function _backup_theme( $theme ) {
$backup_errors = array();
$theme_backup = Envato_Backup::get_instance();
$theme_backup->path = EWPT_BACKUP_DIR;
$theme_backup->root = get_theme_root() . '/' . $theme . '/';
$theme_backup->archive_filename = strtolower( sanitize_file_name( $theme . '.backup.' . date( 'Y-m-d-H-i-s', time() + ( current_time( 'timestamp' ) - time() ) ) . '.zip' ) );
if ( ( ! is_dir( $theme_backup->path() ) && ( ! is_writable( dirname( $theme_backup->path() ) ) || ! mkdir( $theme_backup->path() ) ) ) || ! is_writable( $theme_backup->path() ) ) {
array_push( $backup_errors, 'Invalid backup path' );
return false;
}
if ( ! is_dir( $theme_backup->root() ) || ! is_readable( $theme_backup->root() ) ) {
array_push( $backup_errors, 'Invalid root path' );
return false;
}
$theme_backup->backup();
if ( file_exists( Envato_Backup::get_instance()->archive_filepath() ) ) {
return true;
} else {
return $backup_errors;
}
}
/**
* Prepare the envato backup directory and .htaccess
*
* @access private
* @since 1.4
*
* @return void
*/
function _prepare_envato_backup() {
$path = EWPT_BACKUP_DIR;
/* Create the backups directory if it doesn't exist */
if ( is_writable( dirname( $path ) ) && ! is_dir( $path ) )
mkdir( $path, 0755 );
/* Secure the directory with a .htaccess file */
$htaccess = $path . '.htaccess';
$contents[] = '# ' . __( 'This .htaccess file ensures that other people cannot download your backup files.', 'envato-wordpress-toolkit' );
$contents[] = '';
$contents[] = 'Environment error: %s Dismiss this.', $e->getMessage() ); $env_error .= '' . $this->ajax_notification_nonce . '
'; $options['env_errors']['max_execution_time'] = $env_error; update_option( EWPT_PLUGIN_SLUG, $options ); } $r['timeout'] = EWPT_PLUGIN_MAX_EXECUTION_TIME; } return $r; } /** * Attempt to force increase to max_execution_time, throw exception with user-friendly message otherwise * * @author Japheth Thomson * * @access private * @since 1.6.1 */ public function _set_max_execution_time() { if ( ! @set_time_limit( EWPT_PLUGIN_MAX_EXECUTION_TIME ) ) { throw new Exception( 'Unable to increase maximum execution time. Due to settings on your server, large themes may be unable to update automatically. Please consult your server administrator if this causes issues for you.' ); } } /** * Ajax method for hiding dismissable admin notices. * Forked from original code by Tom McFarlin. * * @author Japheth Thomson * * @access private * @since 1.6.1 */ public function _hide_admin_notification() { if( wp_verify_nonce( $_REQUEST['nonce'], 'ajax-notification-nonce' ) && ! empty( $_REQUEST['notice_id'] ) ) { $options = get_option( EWPT_PLUGIN_SLUG ); // If the update to the option is successful, send 1 back to the browser; // Otherwise, send 0. $options['dismissed_errors'][$_REQUEST['notice_id']] = 1; if ( update_option( EWPT_PLUGIN_SLUG, $options ) ) { die( '1' ); } else { die( '0' ); } // end if/else } // end if } } /** * Instantiates the Class * * @since 1.0 * @global object */ $envato_wp_toolkit = new Envato_WP_Toolkit(); } /* End of file index.php */ /* Location: ./index.php */