Hotel Raxa - Advanced Booking System Implementation
🏨 Hotel Booking Enhancements: - Implemented Eagle Booking Advanced Pricing add-on - Added Booking.com-style rate management system - Created professional calendar interface for pricing - Integrated deals and discounts functionality 💰 Advanced Pricing Features: - Dynamic pricing models (per room, per person, per adult) - Base rates, adult rates, and child rates management - Length of stay discounts and early bird deals - Mobile rates and secret deals implementation - Seasonal promotions and flash sales 📅 Availability Management: - Real-time availability tracking - Stop sell and restriction controls - Closed to arrival/departure functionality - Minimum/maximum stay requirements - Automatic sold-out management 💳 Payment Integration: - Maintained Redsys payment gateway integration - Seamless integration with existing Eagle Booking - No modifications to core Eagle Booking plugin 🛠️ Technical Implementation: - Custom database tables for advanced pricing - WordPress hooks and filters integration - AJAX-powered admin interface - Data migration from existing Eagle Booking - Professional calendar view for revenue management 📊 Admin Interface: - Booking.com-style management dashboard - Visual rate and availability calendar - Bulk operations for date ranges - Statistics and analytics dashboard - Modal dialogs for quick editing 🔧 Code Quality: - WordPress coding standards compliance - Secure database operations with prepared statements - Proper input validation and sanitization - Error handling and logging - Responsive admin interface 🤖 Generated with Claude Code (https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
File diff suppressed because one or more lines are too long
1
wp-content/plugins/envato-market/css/envato-market.css
Normal file
1
wp-content/plugins/envato-market/css/envato-market.css
Normal file
File diff suppressed because one or more lines are too long
123
wp-content/plugins/envato-market/envato-market.php
Normal file
123
wp-content/plugins/envato-market/envato-market.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Name: Envato Market
|
||||
* Plugin URI: https://envato.com/market-plugin/
|
||||
* Description: WordPress Theme & Plugin management for the Envato Market.
|
||||
* Version: 2.0.12
|
||||
* Author: Envato
|
||||
* Author URI: https://envato.com
|
||||
* Requires at least: 5.1
|
||||
* Tested up to: 6.1
|
||||
* Requires PHP: 7.0
|
||||
* Text Domain: envato-market
|
||||
* Domain Path: /languages/
|
||||
*
|
||||
* @package Envato_Market
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
|
||||
/* Set plugin version constant. */
|
||||
define( 'ENVATO_MARKET_VERSION', '2.0.12' );
|
||||
|
||||
/* Debug output control. */
|
||||
define( 'ENVATO_MARKET_DEBUG_OUTPUT', 0 );
|
||||
|
||||
/* Set constant path to the plugin directory. */
|
||||
define( 'ENVATO_MARKET_SLUG', basename( plugin_dir_path( __FILE__ ) ) );
|
||||
|
||||
/* Set constant path to the main file for activation call */
|
||||
define( 'ENVATO_MARKET_CORE_FILE', __FILE__ );
|
||||
|
||||
/* Set constant path to the plugin directory. */
|
||||
define( 'ENVATO_MARKET_PATH', trailingslashit( plugin_dir_path( __FILE__ ) ) );
|
||||
|
||||
/* Set the constant path to the plugin directory URI. */
|
||||
define( 'ENVATO_MARKET_URI', trailingslashit( plugin_dir_url( __FILE__ ) ) );
|
||||
|
||||
|
||||
if ( ! version_compare( PHP_VERSION, '5.4', '>=' ) ) {
|
||||
add_action( 'admin_notices', 'envato_market_fail_php_version' );
|
||||
} elseif ( ENVATO_MARKET_SLUG !== 'envato-market' ) {
|
||||
add_action( 'admin_notices', 'envato_market_fail_installation_method' );
|
||||
} else {
|
||||
|
||||
if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
|
||||
// Makes sure the plugin functions are defined before trying to use them.
|
||||
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
|
||||
}
|
||||
define( 'ENVATO_MARKET_NETWORK_ACTIVATED', is_plugin_active_for_network( ENVATO_MARKET_SLUG . '/envato-market.php' ) );
|
||||
|
||||
/* Envato_Market Class */
|
||||
require_once ENVATO_MARKET_PATH . 'inc/class-envato-market.php';
|
||||
|
||||
if ( ! function_exists( 'envato_market' ) ) :
|
||||
/**
|
||||
* The main function responsible for returning the one true
|
||||
* Envato_Market Instance to functions everywhere.
|
||||
*
|
||||
* Use this function like you would a global variable, except
|
||||
* without needing to declare the global.
|
||||
*
|
||||
* Example: <?php $envato_market = envato_market(); ?>
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return Envato_Market The one true Envato_Market Instance
|
||||
*/
|
||||
function envato_market() {
|
||||
return Envato_Market::instance();
|
||||
}
|
||||
endif;
|
||||
|
||||
|
||||
/**
|
||||
* Loads the main instance of Envato_Market to prevent
|
||||
* the need to use globals.
|
||||
*
|
||||
* This doesn't fire the activation hook correctly if done in 'after_setup_theme' hook.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return object Envato_Market
|
||||
*/
|
||||
envato_market();
|
||||
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'envato_market_fail_php_version' ) ) {
|
||||
|
||||
/**
|
||||
* Show in WP Dashboard notice about the plugin is not activated.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function envato_market_fail_php_version() {
|
||||
$message = esc_html__( 'The Envato Market plugin requires PHP version 5.4+, plugin is currently NOT ACTIVE. Please contact the hosting provider to upgrade the version of PHP.', 'envato-market' );
|
||||
$html_message = sprintf( '<div class="notice notice-error">%s</div>', wpautop( $message ) );
|
||||
echo wp_kses_post( $html_message );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ( ! function_exists( 'envato_market_fail_installation_method' ) ) {
|
||||
|
||||
/**
|
||||
* The plugin needs to be installed into the `envato-market/` folder otherwise it will not work correctly.
|
||||
* This alert will display if someone has installed it into the incorrect folder (i.e. github download zip).
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function envato_market_fail_installation_method() {
|
||||
$message = sprintf( esc_html__( 'Envato Market plugin is not installed correctly. Please delete this plugin and get the correct zip file from %s.', 'envato-market' ), '<a href="https://envato.com/market-plugin/" target="_blank">https://envato.com/market-plugin/</a>' );
|
||||
$html_message = sprintf( '<div class="notice notice-error">%s</div>', wpautop( $message ) );
|
||||
echo wp_kses_post( $html_message );
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 5.9 KiB |
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
/**
|
||||
* Upgrader skin classes.
|
||||
*
|
||||
* @package Envato_Market
|
||||
*/
|
||||
|
||||
// Include the WP_Upgrader_Skin class.
|
||||
if ( ! class_exists( 'WP_Upgrader_Skin', false ) ) :
|
||||
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader-skins.php';
|
||||
endif;
|
||||
|
||||
if ( ! class_exists( 'Envato_Market_Theme_Installer_Skin' ) ) :
|
||||
|
||||
/**
|
||||
* Theme Installer Skin.
|
||||
*
|
||||
* @class Envato_Market_Theme_Installer_Skin
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Envato_Market_Theme_Installer_Skin extends Theme_Installer_Skin {
|
||||
|
||||
/**
|
||||
* Modify the install actions.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function after() {
|
||||
if ( empty( $this->upgrader->result['destination_name'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$theme_info = $this->upgrader->theme_info();
|
||||
if ( empty( $theme_info ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$name = $theme_info->display( 'Name' );
|
||||
$stylesheet = $this->upgrader->result['destination_name'];
|
||||
$template = $theme_info->get_template();
|
||||
|
||||
$activate_link = add_query_arg(
|
||||
array(
|
||||
'action' => 'activate',
|
||||
'template' => urlencode( $template ),
|
||||
'stylesheet' => urlencode( $stylesheet ),
|
||||
),
|
||||
admin_url( 'themes.php' )
|
||||
);
|
||||
$activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $stylesheet );
|
||||
|
||||
$install_actions = array();
|
||||
|
||||
if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
|
||||
$install_actions['preview'] = '<a href="' . wp_customize_url( $stylesheet ) . '" class="hide-if-no-customize load-customize"><span aria-hidden="true">' . __( 'Live Preview', 'envato-market' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Live Preview “%s”', 'envato-market' ), $name ) . '</span></a>';
|
||||
}
|
||||
|
||||
if ( is_multisite() ) {
|
||||
if ( current_user_can( 'manage_network_themes' ) ) {
|
||||
$install_actions['network_enable'] = '<a href="' . esc_url( network_admin_url( wp_nonce_url( 'themes.php?action=enable&theme=' . urlencode( $stylesheet ) . '&paged=1&s', 'enable-theme_' . $stylesheet ) ) ) . '" target="_parent">' . __( 'Network Enable', 'envato-market' ) . '</a>';
|
||||
}
|
||||
}
|
||||
|
||||
$install_actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="activatelink"><span aria-hidden="true">' . __( 'Activate', 'envato-market' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Activate “%s”', 'envato-market' ), $name ) . '</span></a>';
|
||||
|
||||
$install_actions['themes_page'] = '<a href="' . esc_url( admin_url( 'admin.php?page=' . envato_market()->get_slug() . '&tab=themes' ) ) . '" target="_parent">' . __( 'Return to Theme Installer', 'envato-market' ) . '</a>';
|
||||
|
||||
if ( ! $this->result || is_wp_error( $this->result ) || is_multisite() || ! current_user_can( 'switch_themes' ) ) {
|
||||
unset( $install_actions['activate'], $install_actions['preview'] );
|
||||
}
|
||||
|
||||
if ( ! empty( $install_actions ) ) {
|
||||
$this->feedback( implode( ' | ', $install_actions ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
if ( ! class_exists( 'Envato_Market_Plugin_Installer_Skin' ) ) :
|
||||
|
||||
/**
|
||||
* Plugin Installer Skin.
|
||||
*
|
||||
* @class Envato_Market_Plugin_Installer_Skin
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Envato_Market_Plugin_Installer_Skin extends Plugin_Installer_Skin {
|
||||
|
||||
/**
|
||||
* Modify the install actions.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function after() {
|
||||
$plugin_file = $this->upgrader->plugin_info();
|
||||
$install_actions = array();
|
||||
|
||||
if ( current_user_can( 'activate_plugins' ) ) {
|
||||
$install_actions['activate_plugin'] = '<a href="' . esc_url( wp_nonce_url( 'plugins.php?action=activate&plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ) ) . '" target="_parent">' . __( 'Activate Plugin', 'envato-market' ) . '</a>';
|
||||
}
|
||||
|
||||
if ( is_multisite() ) {
|
||||
unset( $install_actions['activate_plugin'] );
|
||||
|
||||
if ( current_user_can( 'manage_network_plugins' ) ) {
|
||||
$install_actions['network_activate'] = '<a href="' . esc_url( network_admin_url( wp_nonce_url( 'plugins.php?action=activate&plugin=' . urlencode( $plugin_file ), 'activate-plugin_' . $plugin_file ) ) ) . '" target="_parent">' . __( 'Network Activate', 'envato-market' ) . '</a>';
|
||||
}
|
||||
}
|
||||
|
||||
$install_actions['plugins_page'] = '<a href="' . esc_url( admin_url( 'admin.php?page=' . envato_market()->get_slug() . '&tab=plugins' ) ) . '" target="_parent">' . __( 'Return to Plugin Installer', 'envato-market' ) . '</a>';
|
||||
|
||||
if ( ! $this->result || is_wp_error( $this->result ) ) {
|
||||
unset( $install_actions['activate_plugin'], $install_actions['site_activate'], $install_actions['network_activate'] );
|
||||
}
|
||||
|
||||
if ( ! empty( $install_actions ) ) {
|
||||
$this->feedback( implode( ' | ', $install_actions ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
/**
|
||||
* Theme Upgrader class.
|
||||
*
|
||||
* @package Envato_Market
|
||||
*/
|
||||
|
||||
// Include the WP_Upgrader class.
|
||||
if ( ! class_exists( 'WP_Upgrader', false ) ) :
|
||||
include_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
||||
endif;
|
||||
|
||||
if ( ! class_exists( 'Envato_Market_Theme_Upgrader' ) ) :
|
||||
|
||||
/**
|
||||
* Extends the WordPress Theme_Upgrader class.
|
||||
*
|
||||
* This class makes modifications to the strings during install & upgrade.
|
||||
*
|
||||
* @class Envato_Market_Plugin_Upgrader
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Envato_Market_Theme_Upgrader extends Theme_Upgrader {
|
||||
|
||||
/**
|
||||
* Initialize the upgrade strings.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function upgrade_strings() {
|
||||
parent::upgrade_strings();
|
||||
|
||||
$this->strings['downloading_package'] = __( 'Downloading the Envato Market upgrade package…', 'envato-market' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the install strings.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function install_strings() {
|
||||
parent::install_strings();
|
||||
|
||||
$this->strings['downloading_package'] = __( 'Downloading the Envato Market install package…', 'envato-market' );
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
|
||||
if ( ! class_exists( 'Envato_Market_Plugin_Upgrader' ) ) :
|
||||
|
||||
/**
|
||||
* Extends the WordPress Plugin_Upgrader class.
|
||||
*
|
||||
* This class makes modifications to the strings during install & upgrade.
|
||||
*
|
||||
* @class Envato_Market_Plugin_Upgrader
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Envato_Market_Plugin_Upgrader extends Plugin_Upgrader {
|
||||
|
||||
/**
|
||||
* Initialize the upgrade strings.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function upgrade_strings() {
|
||||
parent::upgrade_strings();
|
||||
|
||||
$this->strings['downloading_package'] = __( 'Downloading the Envato Market upgrade package…', 'envato-market' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the install strings.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function install_strings() {
|
||||
parent::install_strings();
|
||||
|
||||
$this->strings['downloading_package'] = __( 'Downloading the Envato Market install package…', 'envato-market' );
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
478
wp-content/plugins/envato-market/inc/admin/functions.php
Normal file
478
wp-content/plugins/envato-market/inc/admin/functions.php
Normal file
@@ -0,0 +1,478 @@
|
||||
<?php
|
||||
/**
|
||||
* Functions
|
||||
*
|
||||
* @package Envato_Market
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interate over the themes array and displays each theme.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $group The theme group. Options are 'purchased', 'active', 'installed', or 'install'.
|
||||
*/
|
||||
function envato_market_themes_column( $group = 'install' ) {
|
||||
$premium = envato_market()->items()->themes( $group );
|
||||
if ( empty( $premium ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $premium as $slug => $theme ) :
|
||||
$name = $theme['name'];
|
||||
$author = $theme['author'];
|
||||
$version = $theme['version'];
|
||||
$description = $theme['description'];
|
||||
$url = $theme['url'];
|
||||
$author_url = $theme['author_url'];
|
||||
$theme['hasUpdate'] = false;
|
||||
|
||||
if ( 'active' === $group || 'installed' === $group ) {
|
||||
$get_theme = wp_get_theme( $slug );
|
||||
if ( $get_theme->exists() ) {
|
||||
$name = $get_theme->get( 'Name' );
|
||||
$author = $get_theme->get( 'Author' );
|
||||
$version = $get_theme->get( 'Version' );
|
||||
$description = $get_theme->get( 'Description' );
|
||||
$author_url = $get_theme->get( 'AuthorURI' );
|
||||
if ( version_compare( $version, $theme['version'], '<' ) ) {
|
||||
$theme['hasUpdate'] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Setup the column CSS classes.
|
||||
$classes = array( 'envato-card', 'theme' );
|
||||
|
||||
if ( 'active' === $group ) {
|
||||
$classes[] = 'active';
|
||||
}
|
||||
|
||||
// Setup the update action links.
|
||||
$update_actions = array();
|
||||
|
||||
if ( true === $theme['hasUpdate'] ) {
|
||||
$classes[] = 'update';
|
||||
$classes[] = 'envato-card-' . esc_attr( $slug );
|
||||
|
||||
if ( current_user_can( 'update_themes' ) ) {
|
||||
// Upgrade link.
|
||||
$upgrade_link = add_query_arg(
|
||||
array(
|
||||
'action' => 'upgrade-theme',
|
||||
'theme' => esc_attr( $slug ),
|
||||
),
|
||||
self_admin_url( 'update.php' )
|
||||
);
|
||||
|
||||
$update_actions['update'] = sprintf(
|
||||
'<a class="update-now" href="%1$s" aria-label="%2$s" data-name="%3$s %5$s" data-slug="%4$s" data-version="%5$s">%6$s</a>',
|
||||
wp_nonce_url( $upgrade_link, 'upgrade-theme_' . $slug ),
|
||||
esc_attr__( 'Update %s now', 'envato-market' ),
|
||||
esc_attr( $name ),
|
||||
esc_attr( $slug ),
|
||||
esc_attr( $theme['version'] ),
|
||||
esc_html__( 'Update Available', 'envato-market' )
|
||||
);
|
||||
|
||||
$update_actions['details'] = sprintf(
|
||||
'<a href="%1$s" class="details" title="%2$s" target="_blank">%3$s</a>',
|
||||
esc_url( $url ),
|
||||
esc_attr( $name ),
|
||||
sprintf(
|
||||
__( 'View version %1$s details.', 'envato-market' ),
|
||||
$theme['version']
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Setup the action links.
|
||||
$actions = array();
|
||||
|
||||
if ( 'active' === $group && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
|
||||
// Customize theme.
|
||||
$customize_url = admin_url( 'customize.php' );
|
||||
$customize_url .= '?theme=' . urlencode( $slug );
|
||||
$customize_url .= '&return=' . urlencode( envato_market()->get_page_url() . '#themes' );
|
||||
$actions['customize'] = '<a href="' . esc_url( $customize_url ) . '" class="button button-primary load-customize hide-if-no-customize"><span aria-hidden="true">' . __( 'Customize', 'envato-market' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Customize “%s”', 'envato-market' ), $name ) . '</span></a>';
|
||||
} elseif ( 'installed' === $group ) {
|
||||
$can_activate = true;
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
// Multisite needs special attention.
|
||||
if ( is_multisite() && ! $get_theme->is_allowed( 'both' ) && current_user_can( 'manage_sites' ) ) {
|
||||
$can_activate = false;
|
||||
if ( current_user_can( 'manage_network_themes' ) ) {
|
||||
$actions['network_enable'] = '<a href="' . esc_url( network_admin_url( wp_nonce_url( 'themes.php?action=enable&theme=' . urlencode( $slug ) . '&paged=1&s', 'enable-theme_' . $slug ) ) ) . '" class="button"><span aria-hidden="true">' . __( 'Network Enable', 'envato-market' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Network Enable “%s”', 'envato-market' ), $name ) . '</span></a>';
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
// Can activate theme.
|
||||
if ( $can_activate && current_user_can( 'switch_themes' ) ) {
|
||||
$activate_link = add_query_arg(
|
||||
array(
|
||||
'action' => 'activate',
|
||||
'stylesheet' => urlencode( $slug ),
|
||||
),
|
||||
admin_url( 'themes.php' )
|
||||
);
|
||||
$activate_link = wp_nonce_url( $activate_link, 'switch-theme_' . $slug );
|
||||
|
||||
// Activate link.
|
||||
$actions['activate'] = '<a href="' . esc_url( $activate_link ) . '" class="button"><span aria-hidden="true">' . __( 'Activate', 'envato-market' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Activate “%s”', 'envato-market' ), $name ) . '</span></a>';
|
||||
|
||||
// Preview theme.
|
||||
if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
|
||||
$preview_url = admin_url( 'customize.php' );
|
||||
$preview_url .= '?theme=' . urlencode( $slug );
|
||||
$preview_url .= '&return=' . urlencode( envato_market()->get_page_url() . '#themes' );
|
||||
$actions['customize_preview'] = '<a href="' . esc_url( $preview_url ) . '" class="button button-primary load-customize hide-if-no-customize"><span aria-hidden="true">' . __( 'Live Preview', 'envato-market' ) . '</span><span class="screen-reader-text">' . sprintf( __( 'Live Preview “%s”', 'envato-market' ), $name ) . '</span></a>';
|
||||
}
|
||||
}
|
||||
} elseif ( 'install' === $group && current_user_can( 'install_themes' ) ) {
|
||||
// Install link.
|
||||
$install_link = add_query_arg(
|
||||
array(
|
||||
'page' => envato_market()->get_slug(),
|
||||
'action' => 'install-theme',
|
||||
'id' => $theme['id'],
|
||||
),
|
||||
self_admin_url( 'admin.php' )
|
||||
);
|
||||
|
||||
$actions['install'] = '
|
||||
<a href="' . wp_nonce_url( $install_link, 'install-theme_' . $theme['id'] ) . '" class="button button-primary">
|
||||
<span aria-hidden="true">' . __( 'Install', 'envato-market' ) . '</span>
|
||||
<span class="screen-reader-text">' . sprintf( __( 'Install %s', 'envato-market' ), $name ) . '</span>
|
||||
</a>';
|
||||
}
|
||||
if ( 0 === strrpos( html_entity_decode( $author ), '<a ' ) ) {
|
||||
$author_link = $author;
|
||||
} else {
|
||||
$author_link = '<a href="' . esc_url( $author_url ) . '">' . esc_html( $author ) . '</a>';
|
||||
}
|
||||
?>
|
||||
<div class="envato-market-block" data-id="<?php echo esc_attr( $theme['id'] ); ?>">
|
||||
<div class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>">
|
||||
<div class="envato-card-top">
|
||||
<a href="<?php echo esc_url( $url ); ?>" class="column-icon">
|
||||
<img src="<?php echo esc_url( $theme['thumbnail_url'] ); ?>"/>
|
||||
</a>
|
||||
<div class="column-name">
|
||||
<h4>
|
||||
<a href="<?php echo esc_url( $url ); ?>"><?php echo esc_html( $name ); ?></a>
|
||||
<span class="version" aria-label="<?php esc_attr_e( 'Version %s', 'envato-market' ); ?>">
|
||||
<?php echo esc_html( sprintf( __( 'Version %s', 'envato-market' ), $version ) ); ?>
|
||||
</span>
|
||||
</h4>
|
||||
</div>
|
||||
<div class="column-description">
|
||||
<div class="description">
|
||||
<?php echo wp_kses_post( wpautop( strip_tags( $description ) ) ); ?>
|
||||
</div>
|
||||
<p class="author">
|
||||
<cite>
|
||||
<?php esc_html_e( 'By', 'envato-market' ); ?>
|
||||
<?php echo wp_kses_post( $author_link ); ?>
|
||||
</cite>
|
||||
</p>
|
||||
</div>
|
||||
<?php if ( ! empty( $update_actions ) ) { ?>
|
||||
<div class="column-update">
|
||||
<?php echo implode( "\n", $update_actions ); ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="envato-card-bottom">
|
||||
<div class="column-rating">
|
||||
<?php
|
||||
if ( ! empty( $theme['rating'] ) ) {
|
||||
if ( is_array( $theme['rating'] ) ) {
|
||||
$count = ! empty( $theme['rating']['count'] ) ? $theme['rating']['count'] : 0;
|
||||
$rating = ! empty( $theme['rating']['rating'] ) ? (int) $theme['rating']['rating'] : 0;
|
||||
wp_star_rating(
|
||||
array(
|
||||
'rating' => $count > 0 ? ( $rating / 5 * 100 ) : 0,
|
||||
'type' => 'percent',
|
||||
'number' => $count,
|
||||
)
|
||||
);
|
||||
} else {
|
||||
wp_star_rating(
|
||||
array(
|
||||
'rating' => $theme['rating'] > 0 ? ( $theme['rating'] / 5 * 100 ) : 0,
|
||||
'type' => 'percent',
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<div class="column-actions">
|
||||
<?php echo implode( "\n", $actions ); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
endforeach;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interate over the plugins array and displays each plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $group The plugin group. Options are 'purchased', 'active', 'installed', or 'install'.
|
||||
*/
|
||||
function envato_market_plugins_column( $group = 'install' ) {
|
||||
$premium = envato_market()->items()->plugins( $group );
|
||||
if ( empty( $premium ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$plugins = envato_market()->items()->wp_plugins();
|
||||
|
||||
foreach ( $premium as $slug => $plugin ) :
|
||||
$name = $plugin['name'];
|
||||
$author = $plugin['author'];
|
||||
$version = $plugin['version'];
|
||||
$description = $plugin['description'];
|
||||
$url = $plugin['url'];
|
||||
$author_url = $plugin['author_url'];
|
||||
$plugin['hasUpdate'] = false;
|
||||
|
||||
// Setup the column CSS classes.
|
||||
$classes = array( 'envato-card', 'plugin' );
|
||||
|
||||
if ( 'active' === $group ) {
|
||||
$classes[] = 'active';
|
||||
}
|
||||
|
||||
// Setup the update action links.
|
||||
$update_actions = array();
|
||||
|
||||
// Check for an update.
|
||||
if ( isset( $plugins[ $slug ] ) && version_compare( $plugins[ $slug ]['Version'], $plugin['version'], '<' ) ) {
|
||||
$plugin['hasUpdate'] = true;
|
||||
|
||||
$classes[] = 'update';
|
||||
$classes[] = 'envato-card-' . sanitize_key( dirname( $slug ) );
|
||||
|
||||
if ( current_user_can( 'update_plugins' ) ) {
|
||||
// Upgrade link.
|
||||
$upgrade_link = add_query_arg(
|
||||
array(
|
||||
'action' => 'upgrade-plugin',
|
||||
'plugin' => $slug,
|
||||
),
|
||||
self_admin_url( 'update.php' )
|
||||
);
|
||||
|
||||
// Details link.
|
||||
$details_link = add_query_arg(
|
||||
array(
|
||||
'action' => 'upgrade-plugin',
|
||||
'tab' => 'plugin-information',
|
||||
'plugin' => dirname( $slug ),
|
||||
'section' => 'changelog',
|
||||
'TB_iframe' => 'true',
|
||||
'width' => 640,
|
||||
'height' => 662,
|
||||
),
|
||||
self_admin_url( 'plugin-install.php' )
|
||||
);
|
||||
|
||||
$update_actions['update'] = sprintf(
|
||||
'<a class="update-now" href="%1$s" aria-label="%2$s" data-name="%3$s %6$s" data-plugin="%4$s" data-slug="%5$s" data-version="%6$s">%7$s</a>',
|
||||
wp_nonce_url( $upgrade_link, 'upgrade-plugin_' . $slug ),
|
||||
esc_attr__( 'Update %s now', 'envato-market' ),
|
||||
esc_attr( $name ),
|
||||
esc_attr( $slug ),
|
||||
sanitize_key( dirname( $slug ) ),
|
||||
esc_attr( $version ),
|
||||
esc_html__( 'Update Available', 'envato-market' )
|
||||
);
|
||||
|
||||
$update_actions['details'] = sprintf(
|
||||
'<a href="%1$s" class="thickbox details" title="%2$s">%3$s</a>',
|
||||
esc_url( $details_link ),
|
||||
esc_attr( $name ),
|
||||
sprintf(
|
||||
__( 'View version %1$s details.', 'envato-market' ),
|
||||
$version
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Setup the action links.
|
||||
$actions = array();
|
||||
|
||||
if ( 'active' === $group ) {
|
||||
// Deactivate link.
|
||||
$deactivate_link = add_query_arg(
|
||||
array(
|
||||
'action' => 'deactivate',
|
||||
'plugin' => $slug,
|
||||
),
|
||||
self_admin_url( 'plugins.php' )
|
||||
);
|
||||
|
||||
$actions['deactivate'] = '
|
||||
<a href="' . wp_nonce_url( $deactivate_link, 'deactivate-plugin_' . $slug ) . '" class="button">
|
||||
<span aria-hidden="true">' . __( 'Deactivate', 'envato-market' ) . '</span>
|
||||
<span class="screen-reader-text">' . sprintf( __( 'Deactivate %s', 'envato-market' ), $name ) . '</span>
|
||||
</a>';
|
||||
} elseif ( 'installed' === $group ) {
|
||||
if ( ! is_multisite() && current_user_can( 'delete_plugins' ) ) {
|
||||
// Delete link.
|
||||
$delete_link = add_query_arg(
|
||||
array(
|
||||
'action' => 'delete-selected',
|
||||
'checked[]' => $slug,
|
||||
),
|
||||
self_admin_url( 'plugins.php' )
|
||||
);
|
||||
|
||||
$actions['delete'] = '
|
||||
<a href="' . wp_nonce_url( $delete_link, 'bulk-plugins' ) . '" class="button-delete">
|
||||
<span aria-hidden="true">' . __( 'Delete', 'envato-market' ) . '</span>
|
||||
<span class="screen-reader-text">' . sprintf( __( 'Delete %s', 'envato-market' ), $name ) . '</span>
|
||||
</a>';
|
||||
}
|
||||
|
||||
if ( ! is_multisite() && current_user_can( 'activate_plugins' ) ) {
|
||||
// Activate link.
|
||||
$activate_link = add_query_arg(
|
||||
array(
|
||||
'action' => 'activate',
|
||||
'plugin' => $slug,
|
||||
),
|
||||
self_admin_url( 'plugins.php' )
|
||||
);
|
||||
|
||||
$actions['activate'] = '
|
||||
<a href="' . wp_nonce_url( $activate_link, 'activate-plugin_' . $slug ) . '" class="button">
|
||||
<span aria-hidden="true">' . __( 'Activate', 'envato-market' ) . '</span>
|
||||
<span class="screen-reader-text">' . sprintf( __( 'Activate %s', 'envato-market' ), $name ) . '</span>
|
||||
</a>';
|
||||
}
|
||||
|
||||
// @codeCoverageIgnoreStart
|
||||
// Multisite needs special attention.
|
||||
if ( is_multisite() ) {
|
||||
if ( current_user_can( 'manage_network_plugins' ) ) {
|
||||
$actions['network_activate'] = '
|
||||
<a href="' . esc_url( network_admin_url( wp_nonce_url( 'plugins.php?action=activate&plugin=' . urlencode( $slug ), 'activate-plugin_' . $slug ) ) ) . '" class="button">
|
||||
<span aria-hidden="true">' . __( 'Network Activate', 'envato-market' ) . '</span>
|
||||
<span class="screen-reader-text">' . sprintf( __( 'Network Activate %s', 'envato-market' ), $name ) . '</span>
|
||||
</a>';
|
||||
}
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
} elseif ( 'install' === $group && current_user_can( 'install_plugins' ) ) {
|
||||
// Install link.
|
||||
$install_link = add_query_arg(
|
||||
array(
|
||||
'page' => envato_market()->get_slug(),
|
||||
'action' => 'install-plugin',
|
||||
'id' => $plugin['id'],
|
||||
),
|
||||
self_admin_url( 'admin.php' )
|
||||
);
|
||||
|
||||
$actions['install'] = '
|
||||
<a href="' . wp_nonce_url( $install_link, 'install-plugin_' . $plugin['id'] ) . '" class="button button-primary">
|
||||
<span aria-hidden="true">' . __( 'Install', 'envato-market' ) . '</span>
|
||||
<span class="screen-reader-text">' . sprintf( __( 'Install %s', 'envato-market' ), $name ) . '</span>
|
||||
</a>';
|
||||
}
|
||||
if ( 0 === strrpos( html_entity_decode( $author ), '<a ' ) ) {
|
||||
$author_link = $author;
|
||||
} else {
|
||||
$author_link = '<a href="' . esc_url( $author_url ) . '">' . esc_html( $author ) . '</a>';
|
||||
}
|
||||
?>
|
||||
<div class="envato-market-block" data-id="<?php echo esc_attr( $plugin['id'] ); ?>">
|
||||
<div class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>">
|
||||
<div class="envato-card-top">
|
||||
<a href="<?php echo esc_url( $url ); ?>" class="column-icon">
|
||||
<img src="<?php echo esc_url( $plugin['thumbnail_url'] ); ?>"/>
|
||||
</a>
|
||||
<div class="column-name">
|
||||
<h4>
|
||||
<a href="<?php echo esc_url( $url ); ?>"><?php echo esc_html( $name ); ?></a>
|
||||
<span class="version" aria-label="<?php esc_attr_e( 'Version %s', 'envato-market' ); ?>">
|
||||
<?php echo esc_html( sprintf( __( 'Version %s', 'envato-market' ), ( isset( $plugins[ $slug ] ) ? $plugins[ $slug ]['Version'] : $version ) ) ); ?>
|
||||
</span>
|
||||
</h4>
|
||||
</div>
|
||||
<div class="column-description">
|
||||
<div class="description">
|
||||
<?php echo wp_kses_post( wpautop( strip_tags( $description ) ) ); ?>
|
||||
</div>
|
||||
<p class="author">
|
||||
<cite>
|
||||
<?php esc_html_e( 'By', 'envato-market' ); ?>
|
||||
<?php echo wp_kses_post( $author_link ); ?>
|
||||
</cite>
|
||||
</p>
|
||||
</div>
|
||||
<?php if ( ! empty( $update_actions ) ) { ?>
|
||||
<div class="column-update">
|
||||
<?php echo implode( "\n", $update_actions ); ?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="envato-card-bottom">
|
||||
<div class="column-rating">
|
||||
<?php
|
||||
if ( ! empty( $plugin['rating'] ) ) {
|
||||
if ( is_array( $plugin['rating'] ) && ! empty( $plugin['rating']['count'] ) ) {
|
||||
wp_star_rating(
|
||||
array(
|
||||
'rating' => $plugin['rating']['rating'] > 0 ? ( $plugin['rating']['rating'] / 5 * 100 ) : 0,
|
||||
'type' => 'percent',
|
||||
'number' => $plugin['rating']['count'],
|
||||
)
|
||||
);
|
||||
} else {
|
||||
wp_star_rating(
|
||||
array(
|
||||
'rating' => $plugin['rating'] > 0 ? ( $plugin['rating'] / 5 * 100 ) : 0,
|
||||
'type' => 'percent',
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
<div class="column-actions">
|
||||
<?php echo implode( "\n", $actions ); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
endforeach;
|
||||
}
|
||||
|
||||
/**
|
||||
* A handy method for logging to the st_out / and or debug_log
|
||||
* Use: write_log("My variable is {$variable}")
|
||||
*/
|
||||
if (!function_exists('write_log') && defined('ENVATO_LOCAL_DEVELOPMENT')) {
|
||||
|
||||
function write_log($log) {
|
||||
|
||||
if (is_array($log) || is_object($log)) {
|
||||
error_log(print_r($log, true));
|
||||
} else {
|
||||
error_log($log);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* Admin UI
|
||||
*
|
||||
* @package Envato_Market
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
if ( isset( $_GET['action'] ) ) {
|
||||
$id = ! empty( $_GET['id'] ) ? absint( trim( $_GET['id'] ) ) : '';
|
||||
|
||||
if ( 'install-plugin' === $_GET['action'] ) {
|
||||
Envato_Market_Admin::install_plugin( $id );
|
||||
} elseif ( 'install-theme' === $_GET['action'] ) {
|
||||
Envato_Market_Admin::install_theme( $id );
|
||||
}
|
||||
} else {
|
||||
add_thickbox();
|
||||
?>
|
||||
<div class="wrap about-wrap full-width-layout">
|
||||
<?php Envato_Market_Admin::render_intro_partial(); ?>
|
||||
<?php Envato_Market_Admin::render_tabs_partial(); ?>
|
||||
<form method="POST" action="<?php echo esc_url( ENVATO_MARKET_NETWORK_ACTIVATED ? network_admin_url( 'edit.php?action=envato_market_network_settings' ) : admin_url( 'options.php' ) ); ?>">
|
||||
<?php Envato_Market_Admin::render_themes_panel_partial(); ?>
|
||||
<?php Envato_Market_Admin::render_plugins_panel_partial(); ?>
|
||||
<?php Envato_Market_Admin::render_settings_panel_partial(); ?>
|
||||
<?php Envato_Market_Admin::render_help_panel_partial(); ?>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Items section
|
||||
*
|
||||
* @package Envato_Market
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
?>
|
||||
<p><?php esc_html_e( 'Add Envato Market themes & plugins using multiple OAuth tokens. This is especially useful when an item has been purchased on behalf of a third-party. This works similarly to the global OAuth Personal Token, but for individual items and additionally requires the Envato Market item ID.', 'envato-market' ); ?></p>
|
||||
|
||||
<p><?php esc_html_e( 'Warning: These tokens can be revoked by the account holder at any time.', 'envato-market' ); ?></p>
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* OAuth section
|
||||
*
|
||||
* @package Envato_Market
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
?>
|
||||
|
||||
<p>
|
||||
<?php printf( esc_html__( 'This area enables WordPress Theme & Plugin updates from Envato Market. Read more about how this process works at %s.', 'envato-market' ), '<a href="https://envato.com/market-plugin/" target="_blank">' . esc_html__( 'envato.com', 'envato-market' ) . '</a>' ); ?>
|
||||
</p>
|
||||
<p>
|
||||
<?php esc_html_e( 'Please follow the steps below:', 'envato-market' ); ?>
|
||||
</p>
|
||||
<ol>
|
||||
<li><?php printf( esc_html__( 'Generate an Envato API Personal Token by %s.', 'envato-market' ), '<a href="' . envato_market()->admin()->get_generate_token_url() . '" target="_blank">' . esc_html__( 'clicking this link', 'envato-market' ) . '</a>' ); ?></li>
|
||||
<li><?php esc_html_e( 'Name the token eg “My WordPress site”.', 'envato-market' ); ?></li>
|
||||
<li><?php esc_html_e( 'Ensure the following permissions are enabled:', 'envato-market' ); ?>
|
||||
<ul>
|
||||
<li><?php esc_html_e( 'View and search Envato sites', 'envato-market' ); ?></li>
|
||||
<li><?php esc_html_e( 'Download your purchased items', 'envato-market' ); ?></li>
|
||||
<li><?php esc_html_e( 'List purchases you\'ve made', 'envato-market' ); ?></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li><?php esc_html_e( 'Copy the token into the box below.', 'envato-market' ); ?></li>
|
||||
<li><?php esc_html_e( 'Click the "Save Changes" button.', 'envato-market' ); ?></li>
|
||||
<li><?php esc_html_e( 'A list of purchased Themes & Plugins from Envato Market will appear.', 'envato-market' ); ?></li>
|
||||
</ol>
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/**
|
||||
* Items setting
|
||||
*
|
||||
* @package Envato_Market
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
$items = envato_market()->get_option( 'items', array() );
|
||||
|
||||
?>
|
||||
<ul id="envato-market-items">
|
||||
<?php
|
||||
if ( ! empty( $items ) ) {
|
||||
foreach ( $items as $key => $item ) {
|
||||
if ( empty( $item['name'] ) || empty( $item['token'] ) || empty( $item['id'] ) || empty( $item['type'] ) || empty( $item['authorized'] ) ) {
|
||||
continue;
|
||||
}
|
||||
$class = 'success' === $item['authorized'] ? 'is-authorized' : 'not-authorized';
|
||||
echo '
|
||||
<li data-id="' . esc_attr( $item['id'] ) . '" class="' . esc_attr( $class ) . '">
|
||||
<span class="item-name">' . esc_html__( 'ID', 'envato-market' ) . ': ' . esc_html( $item['id'] ) . ' - ' . esc_html( $item['name'] ) . '</span>
|
||||
<button class="item-delete dashicons dashicons-dismiss">
|
||||
<span class="screen-reader-text">' . esc_html__( 'Delete', 'envato-market' ) . '</span>
|
||||
</button>
|
||||
<input type="hidden" name="' . esc_attr( envato_market()->get_option_name() ) . '[items][' . esc_attr( $key ) . '][name]" value="' . esc_html( $item['name'] ) . '" />
|
||||
<input type="hidden" name="' . esc_attr( envato_market()->get_option_name() ) . '[items][' . esc_attr( $key ) . '][token]" value="' . esc_html( $item['token'] ) . '" />
|
||||
<input type="hidden" name="' . esc_attr( envato_market()->get_option_name() ) . '[items][' . esc_attr( $key ) . '][id]" value="' . esc_html( $item['id'] ) . '" />
|
||||
<input type="hidden" name="' . esc_attr( envato_market()->get_option_name() ) . '[items][' . esc_attr( $key ) . '][type]" value="' . esc_html( $item['type'] ) . '" />
|
||||
<input type="hidden" name="' . esc_attr( envato_market()->get_option_name() ) . '[items][' . esc_attr( $key ) . '][authorized]" value="' . esc_html( $item['authorized'] ) . '" />
|
||||
</li>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
|
||||
<button class="button add-envato-market-item"><?php esc_html_e( 'Add Item', 'envato-market' ); ?></button>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Token setting
|
||||
*
|
||||
* @package Envato_Market
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
?>
|
||||
<input type="text" name="<?php echo esc_attr( envato_market()->get_option_name() ); ?>[token]" class="widefat" value="<?php echo esc_html( envato_market()->get_option( 'token' ) ); ?>" autocomplete="off">
|
||||
|
||||
<p class="description"><?php esc_html_e( 'Enter your Envato API Personal Token.', 'envato-market' ); ?></p>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Error details
|
||||
*
|
||||
* @package Envato_Market
|
||||
* @since 2.0.2
|
||||
*/
|
||||
|
||||
?>
|
||||
<div class="notice notice-error is-dismissible">
|
||||
<p><?php printf( '<strong>Additional Error Details:</strong><br/>%s.<br/> %s <br/> %s', esc_html( $title ), esc_html( $message ), esc_html( json_encode( $data ) ) ); ?></p>
|
||||
</div>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Error notice
|
||||
*
|
||||
* @package Envato_Market
|
||||
* @since 2.0.1
|
||||
*/
|
||||
|
||||
?>
|
||||
<div class="notice notice-error is-dismissible">
|
||||
<p><?php esc_html_e( 'Failed to connect to the Envato API. Please contact the hosting providier with this message: "The Envato Market WordPress plugin requires TLS version 1.2 or above, please confirm if this hosting account supports TLS version 1.2 and allows connections from WordPress to the host api.envato.com".', 'envato-market' ); ?></p>
|
||||
</div>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Error notice
|
||||
*
|
||||
* @package Envato_Market
|
||||
* @since 2.0.1
|
||||
*/
|
||||
|
||||
?>
|
||||
<div class="notice notice-error is-dismissible">
|
||||
<p><?php printf( esc_html__( 'Failed to locate the package file for this item. Please contact the item author for support, or install/upgrade the item manually from the %s.', 'envato-market' ), '<a href="https://themeforest.net/downloads" target="_blank">downloads page</a>' ); ?></p>
|
||||
</div>
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* Error notice
|
||||
*
|
||||
* @package Envato_Market
|
||||
* @since 2.0.1
|
||||
*/
|
||||
|
||||
?>
|
||||
<div class="notice notice-error is-dismissible">
|
||||
<p><?php printf( esc_html__( 'Incorrect token permissions, please generate another token or fix the permissions on the existing token.' ) ); ?></p>
|
||||
<p><?php printf( esc_html__( 'Please ensure only the following permissions are enabled: ', 'envato-market' ) ); ?></p>
|
||||
<ol>
|
||||
<?php foreach ( $this->get_required_permissions() as $permission ) { ?>
|
||||
<li><?php echo esc_html( $permission ); ?></li>
|
||||
<?php } ?>
|
||||
</ol>
|
||||
</div>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Error notice
|
||||
*
|
||||
* @package Envato_Market
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
?>
|
||||
<div class="notice notice-error is-dismissible">
|
||||
<p><?php esc_html_e( 'One or more Single Use OAuth Personal Tokens could not be verified and should be removed.', 'envato-market' ); ?></p>
|
||||
</div>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Error notice
|
||||
*
|
||||
* @package Envato_Market
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
?>
|
||||
<div class="notice notice-error is-dismissible">
|
||||
<p><?php esc_html_e( 'The OAuth Personal Token could not be verified. Please check that the Token has been entered correctly and has the minimum required permissions.', 'envato-market' ); ?></p>
|
||||
</div>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Success notice
|
||||
*
|
||||
* @package Envato_Market
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
?>
|
||||
<div class="notice notice-success is-dismissible">
|
||||
<p><?php esc_html_e( 'Your OAuth Personal Token has been verified. However, there are no WordPress downloadable items in your account.', 'envato-market' ); ?></p>
|
||||
</div>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Success notice
|
||||
*
|
||||
* @package Envato_Market
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
?>
|
||||
<div class="notice notice-success is-dismissible">
|
||||
<p><?php esc_html_e( 'All Single Use OAuth Personal Tokens have been verified.', 'envato-market' ); ?></p>
|
||||
</div>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
/**
|
||||
* Success notice
|
||||
*
|
||||
* @package Envato_Market
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
?>
|
||||
<div class="notice notice-success is-dismissible">
|
||||
<p><?php esc_html_e( 'Your OAuth Personal Token has been verified.', 'envato-market' ); ?></p>
|
||||
</div>
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* Help panel partial
|
||||
*
|
||||
* @package Envato_Market
|
||||
* @since 2.0.1
|
||||
*/
|
||||
|
||||
|
||||
?>
|
||||
<div id="help" class="panel">
|
||||
<div class="envato-market-blocks">
|
||||
<div class="envato-market-block">
|
||||
<h3>Troubleshooting:</h3>
|
||||
<p>If you’re having trouble with the plugin, please</p>
|
||||
<ol>
|
||||
<li>Confirm the old <code>Envato Toolkit</code> plugin is not installed.</li>
|
||||
<li>Confirm the latest version of WordPress is installed.</li>
|
||||
<li>Confirm the latest version of the <a href="https://envato.com/market-plugin/" target="_blank">Envato Market</a> plugin is installed.</li>
|
||||
<li>Try creating a new API token has from the <a href="<?php echo envato_market()->admin()->get_generate_token_url(); ?>" target="_blank">build.envato.com</a> website - ensure only the following permissions have been granted
|
||||
<ul>
|
||||
<li>View and search Envato sites</li>
|
||||
<li>Download your purchased items</li>
|
||||
<li>List purchases you've made</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li>Check with the hosting provider to ensure the API connection to <code>api.envato.com</code> is not blocked.</li>
|
||||
<li>Check with the hosting provider that the minimum TLS version is 1.2 or above on the server.</li>
|
||||
<li>If you can’t see your items - check with the item author to confirm the Theme or Plugin is compatible with the Envato Market plugin.</li>
|
||||
<li>Confirm your Envato account is still active and the items are still visible from <a href="https://themeforest.net/downloads" target="_blank">your downloads page</a>.</li>
|
||||
<li>Note - if an item has been recently updated, it may take up to 24 hours for the latest version to appear in the Envato Market plugin.</li>
|
||||
</ol>
|
||||
</div>
|
||||
<div class="envato-market-block">
|
||||
<h3>Health Check:</h3>
|
||||
<div class="envato-market-healthcheck">
|
||||
Problem starting healthcheck. Please check javascript console for errors.
|
||||
</div>
|
||||
<h3>Support:</h3>
|
||||
<p>The Envato Market plugin is maintained - we ensure it works best on the latest version of WordPress and on a modern hosting platform, however we can’t guarantee it’ll work on all WordPress sites or hosting environments.</p>
|
||||
<p>If you’ve tried all the troubleshooting steps and you’re still unable to get the Envato Market plugin to work on your site/hosting, at this time, our advice is to remove the Envato Market plugin and instead visit the Downloads section of ThemeForest/CodeCanyon to download the latest version of your items.</p>
|
||||
<p>If you’re having trouble with a specific item from ThemeForest or CodeCanyon, it’s best you browse to the Theme or Plugin item page, visit the ‘support’ tab and follow the next steps.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Intro partial
|
||||
*
|
||||
* @package Envato_Market
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
?>
|
||||
<div class="col">
|
||||
|
||||
<h1 class="about-title"><img class="about-logo" src="<?php echo envato_market()->get_plugin_url(); ?>images/envato-market-logo.svg" alt="Envato Market"><sup><?php echo esc_html( envato_market()->get_version() ); ?></sup></h1>
|
||||
<p><?php esc_html_e( 'Welcome!', 'envato-market' ); ?></p>
|
||||
<p><?php esc_html_e( 'This plugin can install WordPress themes and plugins purchased from ThemeForest & CodeCanyon by connecting with the Envato Market API using a secure OAuth personal token. Once your themes & plugins are installed WordPress will periodically check for updates, so keeping your items up to date is as simple as a few clicks.', 'envato-market' ); ?></p>
|
||||
<p><strong><?php printf( esc_html__( 'Find out more at %1$senvato.com%2$s.', 'envato-market' ), '<a href="https://envato.com/market-plugin/" target="_blank">', '</a>' ); ?></strong></p>
|
||||
</div>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugins panel partial
|
||||
*
|
||||
* @package Envato_Market
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
$plugins = envato_market()->items()->plugins( 'purchased' );
|
||||
|
||||
?>
|
||||
<div id="plugins" class="panel <?php echo empty( $plugins ) ? 'hidden' : ''; ?>">
|
||||
<div class="envato-market-blocks">
|
||||
<?php
|
||||
if ( ! empty( $plugins ) ) {
|
||||
envato_market_plugins_column( 'active' );
|
||||
envato_market_plugins_column( 'installed' );
|
||||
envato_market_plugins_column( 'install' );
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* Settings panel partial
|
||||
*
|
||||
* @package Envato_Market
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
$token = envato_market()->get_option( 'token' );
|
||||
$items = envato_market()->get_option( 'items', array() );
|
||||
|
||||
?>
|
||||
<div id="settings" class="panel">
|
||||
<div class="envato-market-blocks">
|
||||
<?php settings_fields( envato_market()->get_slug() ); ?>
|
||||
<?php Envato_Market_Admin::do_settings_sections( envato_market()->get_slug(), 2 ); ?>
|
||||
</div>
|
||||
<p class="submit">
|
||||
<input type="submit" name="submit" id="submit" class="button button-primary" value="<?php esc_html_e( 'Save Changes', 'envato-market' ); ?>" />
|
||||
<?php if ( ( '' !== $token || ! empty( $items ) ) && 10 !== has_action( 'admin_notices', array( $this, 'error_notice' ) ) ) { ?>
|
||||
<a href="<?php echo esc_url( add_query_arg( array( 'authorization' => 'check' ), envato_market()->get_page_url() ) ); ?>" class="button button-secondary auth-check-button" style="margin:0 5px"><?php esc_html_e( 'Test API Connection', 'envato-market' ); ?></a>
|
||||
<?php } ?>
|
||||
</p>
|
||||
</div>
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* Tabs partial
|
||||
*
|
||||
* @package Envato_Market
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
$tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : '';
|
||||
$themes = envato_market()->items()->themes( 'purchased' );
|
||||
$plugins = envato_market()->items()->plugins( 'purchased' );
|
||||
|
||||
?>
|
||||
<h2 class="nav-tab-wrapper">
|
||||
<?php
|
||||
// Themes tab.
|
||||
$theme_class = array();
|
||||
if ( ! empty( $themes ) ) {
|
||||
if ( empty( $tab ) ) {
|
||||
$tab = 'themes';
|
||||
}
|
||||
if ( 'themes' === $tab ) {
|
||||
$theme_class[] = 'nav-tab-active';
|
||||
}
|
||||
} else {
|
||||
$theme_class[] = 'hidden';
|
||||
}
|
||||
echo '<a href="#themes" data-id="theme" class="nav-tab ' . esc_attr( implode( ' ', $theme_class ) ) . '">' . esc_html__( 'Themes', 'envato-market' ) . '</a>';
|
||||
|
||||
// Plugins tab.
|
||||
$plugin_class = array();
|
||||
if ( ! empty( $plugins ) ) {
|
||||
if ( empty( $tab ) ) {
|
||||
$tab = 'plugins';
|
||||
}
|
||||
if ( 'plugins' === $tab ) {
|
||||
$plugin_class[] = 'nav-tab-active';
|
||||
}
|
||||
} else {
|
||||
$plugin_class[] = 'hidden';
|
||||
}
|
||||
echo '<a href="#plugins" data-id="plugin" class="nav-tab ' . esc_attr( implode( ' ', $plugin_class ) ) . '">' . esc_html__( 'Plugins', 'envato-market' ) . '</a>';
|
||||
|
||||
// Settings tab.
|
||||
echo '<a href="#settings" class="nav-tab ' . esc_attr( 'settings' === $tab || empty( $tab ) ? 'nav-tab-active' : '' ) . '">' . esc_html__( 'Settings', 'envato-market' ) . '</a>';
|
||||
|
||||
// Help tab.
|
||||
echo '<a href="#help" class="nav-tab ' . esc_attr( 'help' === $tab ? 'nav-tab-active' : '' ) . '">' . esc_html__( 'Help', 'envato-market' ) . '</a>';
|
||||
?>
|
||||
</h2>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* Themes panel partial
|
||||
*
|
||||
* @package Envato_Market
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
$themes = envato_market()->items()->themes( 'purchased' );
|
||||
|
||||
?>
|
||||
<div id="themes" class="panel <?php echo empty( $themes ) ? 'hidden' : ''; ?>">
|
||||
<div class="envato-market-blocks">
|
||||
<?php
|
||||
if ( ! empty( $themes ) ) {
|
||||
envato_market_themes_column( 'active' );
|
||||
envato_market_themes_column( 'installed' );
|
||||
envato_market_themes_column( 'install' );
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
458
wp-content/plugins/envato-market/inc/class-envato-market-api.php
Normal file
458
wp-content/plugins/envato-market/inc/class-envato-market-api.php
Normal file
@@ -0,0 +1,458 @@
|
||||
<?php
|
||||
/**
|
||||
* Envato API class.
|
||||
*
|
||||
* @package Envato_Market
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'Envato_Market_API' ) && class_exists( 'Envato_Market' ) ) :
|
||||
|
||||
/**
|
||||
* Creates the Envato API connection.
|
||||
*
|
||||
* @class Envato_Market_API
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Envato_Market_API {
|
||||
|
||||
/**
|
||||
* The single class instance.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* The Envato API personal token.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $token;
|
||||
|
||||
/**
|
||||
* Main Envato_Market_API Instance
|
||||
*
|
||||
* Ensures only one instance of this class exists in memory at any one time.
|
||||
*
|
||||
* @see Envato_Market_API()
|
||||
* @uses Envato_Market_API::init_globals() Setup class globals.
|
||||
* @uses Envato_Market_API::init_actions() Setup hooks and actions.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @static
|
||||
* @return object The one true Envato_Market_API.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function instance() {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self();
|
||||
self::$_instance->init_globals();
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* A dummy constructor to prevent this class from being loaded more than once.
|
||||
*
|
||||
* @see Envato_Market_API::instance()
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct() {
|
||||
/* We do nothing here! */
|
||||
}
|
||||
|
||||
/**
|
||||
* You cannot clone this class.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __clone() {
|
||||
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'envato-market' ), '1.0.0' );
|
||||
}
|
||||
|
||||
/**
|
||||
* You cannot unserialize instances of this class.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __wakeup() {
|
||||
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'envato-market' ), '1.0.0' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the class globals.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function init_globals() {
|
||||
// Envato API token.
|
||||
$this->token = envato_market()->get_option( 'token' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the Envato API.
|
||||
*
|
||||
* @uses wp_remote_get() To perform an HTTP request.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $url API request URL, including the request method, parameters, & file type.
|
||||
* @param array $args The arguments passed to `wp_remote_get`.
|
||||
* @return array|WP_Error The HTTP response.
|
||||
*/
|
||||
public function request( $url, $args = array() ) {
|
||||
$defaults = array(
|
||||
'sslverify' => !defined('ENVATO_LOCAL_DEVELOPMENT'),
|
||||
'headers' => $this->request_headers(),
|
||||
'timeout' => 14,
|
||||
);
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
|
||||
if ( !defined('ENVATO_LOCAL_DEVELOPMENT') ) {
|
||||
$token = trim( str_replace( 'Bearer', '', $args['headers']['Authorization'] ) );
|
||||
if ( empty( $token ) ) {
|
||||
return new WP_Error( 'api_token_error', __( 'An API token is required.', 'envato-market' ) );
|
||||
}
|
||||
}
|
||||
|
||||
$debugging_information = [
|
||||
'request_url' => $url,
|
||||
];
|
||||
|
||||
// Make an API request.
|
||||
$response = wp_remote_get( esc_url_raw( $url ), $args );
|
||||
|
||||
// Check the response code.
|
||||
$response_code = wp_remote_retrieve_response_code( $response );
|
||||
$response_message = wp_remote_retrieve_response_message( $response );
|
||||
|
||||
$debugging_information['response_code'] = $response_code;
|
||||
$debugging_information['response_cf_ray'] = wp_remote_retrieve_header( $response, 'cf-ray' );
|
||||
$debugging_information['response_server'] = wp_remote_retrieve_header( $response, 'server' );
|
||||
|
||||
if ( ! empty( $response->errors ) && isset( $response->errors['http_request_failed'] ) ) {
|
||||
// API connectivity issue, inject notice into transient with more details.
|
||||
$option = envato_market()->get_options();
|
||||
if ( empty( $option['notices'] ) ) {
|
||||
$option['notices'] = [];
|
||||
}
|
||||
$option['notices']['http_error'] = current( $response->errors['http_request_failed'] );
|
||||
envato_market()->set_options( $option );
|
||||
return new WP_Error( 'http_error', esc_html( current( $response->errors['http_request_failed'] ) ), $debugging_information );
|
||||
}
|
||||
|
||||
if ( 200 !== $response_code && ! empty( $response_message ) ) {
|
||||
return new WP_Error( $response_code, $response_message, $debugging_information );
|
||||
} elseif ( 200 !== $response_code ) {
|
||||
return new WP_Error( $response_code, __( 'An unknown API error occurred.', 'envato-market' ), $debugging_information );
|
||||
} else {
|
||||
$return = json_decode( wp_remote_retrieve_body( $response ), true );
|
||||
if ( null === $return ) {
|
||||
return new WP_Error( 'api_error', __( 'An unknown API error occurred.', 'envato-market' ), $debugging_information );
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deferred item download URL.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param int $id The item ID.
|
||||
* @return string.
|
||||
*/
|
||||
public function deferred_download( $id ) {
|
||||
if ( empty( $id ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$args = array(
|
||||
'deferred_download' => true,
|
||||
'item_id' => $id,
|
||||
);
|
||||
return add_query_arg( $args, esc_url( envato_market()->get_page_url() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the item download.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param int $id The item ID.
|
||||
* @param array $args The arguments passed to `wp_remote_get`.
|
||||
* @return bool|array The HTTP response.
|
||||
*/
|
||||
public function download( $id, $args = array() ) {
|
||||
if ( empty( $id ) ) {
|
||||
return false;
|
||||
}
|
||||
$domain = envato_market()->get_envato_api_domain();
|
||||
$path = $this->api_path_for('download');
|
||||
$url = $domain . $path . '?item_id=' . $id . '&shorten_url=true';
|
||||
$response = $this->request( $url, $args );
|
||||
|
||||
// @todo Find out which errors could be returned & handle them in the UI.
|
||||
if ( is_wp_error( $response ) || empty( $response ) || ! empty( $response['error'] ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! empty( $response['wordpress_theme'] ) ) {
|
||||
return $response['wordpress_theme'];
|
||||
}
|
||||
|
||||
if ( ! empty( $response['wordpress_plugin'] ) ) {
|
||||
return $response['wordpress_plugin'];
|
||||
}
|
||||
|
||||
// Missing a WordPress theme and plugin, report an error.
|
||||
$option = envato_market()->get_options();
|
||||
if ( ! isset( $option['notices'] ) ) {
|
||||
$option['notices'] = [];
|
||||
}
|
||||
$option['notices']['missing-package-zip'] = true;
|
||||
envato_market()->set_options( $option );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item by ID and type.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param int $id The item ID.
|
||||
* @param array $args The arguments passed to `wp_remote_get`.
|
||||
* @return array The HTTP response.
|
||||
*/
|
||||
public function item( $id, $args = array() ) {
|
||||
$domain = envato_market()->get_envato_api_domain();
|
||||
$path = $this->api_path_for('catalog-item');
|
||||
$url = $domain . $path . '?id=' . $id;
|
||||
$response = $this->request( $url, $args );
|
||||
|
||||
if ( is_wp_error( $response ) || empty( $response ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! empty( $response['wordpress_theme_metadata'] ) ) {
|
||||
return $this->normalize_theme( $response );
|
||||
}
|
||||
|
||||
if ( ! empty( $response['wordpress_plugin_metadata'] ) ) {
|
||||
return $this->normalize_plugin( $response );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of available themes.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $args The arguments passed to `wp_remote_get`.
|
||||
* @return array The HTTP response.
|
||||
*/
|
||||
public function themes( $args = array() ) {
|
||||
$themes = array();
|
||||
|
||||
$domain = envato_market()->get_envato_api_domain();
|
||||
$path = $this->api_path_for('list-purchases');
|
||||
$url = $domain . $path . '?filter_by=wordpress-themes';
|
||||
$response = $this->request( $url, $args );
|
||||
|
||||
if ( is_wp_error( $response ) || empty( $response ) || empty( $response['results'] ) ) {
|
||||
return $themes;
|
||||
}
|
||||
|
||||
foreach ( $response['results'] as $theme ) {
|
||||
$themes[] = $this->normalize_theme( $theme['item'] );
|
||||
}
|
||||
|
||||
return $themes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a theme.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $theme An array of API request values.
|
||||
* @return array A normalized array of values.
|
||||
*/
|
||||
public function normalize_theme( $theme ) {
|
||||
$normalized_theme = array(
|
||||
'id' => $theme['id'],
|
||||
'name' => ( ! empty( $theme['wordpress_theme_metadata']['theme_name'] ) ? $theme['wordpress_theme_metadata']['theme_name'] : '' ),
|
||||
'author' => ( ! empty( $theme['wordpress_theme_metadata']['author_name'] ) ? $theme['wordpress_theme_metadata']['author_name'] : '' ),
|
||||
'version' => ( ! empty( $theme['wordpress_theme_metadata']['version'] ) ? $theme['wordpress_theme_metadata']['version'] : '' ),
|
||||
'description' => self::remove_non_unicode( strip_tags( $theme['wordpress_theme_metadata']['description'] ) ),
|
||||
'url' => ( ! empty( $theme['url'] ) ? $theme['url'] : '' ),
|
||||
'author_url' => ( ! empty( $theme['author_url'] ) ? $theme['author_url'] : '' ),
|
||||
'thumbnail_url' => ( ! empty( $theme['thumbnail_url'] ) ? $theme['thumbnail_url'] : '' ),
|
||||
'rating' => ( ! empty( $theme['rating'] ) ? $theme['rating'] : '' ),
|
||||
'landscape_url' => '',
|
||||
);
|
||||
|
||||
// No main thumbnail in API response, so we grab it from the preview array.
|
||||
if ( empty( $normalized_theme['thumbnail_url'] ) && ! empty( $theme['previews'] ) && is_array( $theme['previews'] ) ) {
|
||||
foreach ( $theme['previews'] as $possible_preview ) {
|
||||
if ( ! empty( $possible_preview['landscape_url'] ) ) {
|
||||
$normalized_theme['landscape_url'] = $possible_preview['landscape_url'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( empty( $normalized_theme['thumbnail_url'] ) && ! empty( $theme['previews'] ) && is_array( $theme['previews'] ) ) {
|
||||
foreach ( $theme['previews'] as $possible_preview ) {
|
||||
if ( ! empty( $possible_preview['icon_url'] ) ) {
|
||||
$normalized_theme['thumbnail_url'] = $possible_preview['icon_url'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $normalized_theme;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of available plugins.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $args The arguments passed to `wp_remote_get`.
|
||||
* @return array The HTTP response.
|
||||
*/
|
||||
public function plugins( $args = array() ) {
|
||||
$plugins = array();
|
||||
|
||||
$domain = envato_market()->get_envato_api_domain();
|
||||
$path = $this->api_path_for('list-purchases');
|
||||
$url = $domain . $path . '?filter_by=wordpress-plugins';
|
||||
$response = $this->request( $url, $args );
|
||||
|
||||
if ( is_wp_error( $response ) || empty( $response ) || empty( $response['results'] ) ) {
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
foreach ( $response['results'] as $plugin ) {
|
||||
$plugins[] = $this->normalize_plugin( $plugin['item'] );
|
||||
}
|
||||
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $plugin An array of API request values.
|
||||
* @return array A normalized array of values.
|
||||
*/
|
||||
public function normalize_plugin( $plugin ) {
|
||||
$requires = null;
|
||||
$tested = null;
|
||||
$versions = array();
|
||||
|
||||
// Set the required and tested WordPress version numbers.
|
||||
foreach ( $plugin['attributes'] as $k => $v ) {
|
||||
if ( ! empty( $v['name'] ) && 'compatible-software' === $v['name'] && ! empty( $v['value'] ) && is_array( $v['value'] ) ) {
|
||||
foreach ( $v['value'] as $version ) {
|
||||
$versions[] = str_replace( 'WordPress ', '', trim( $version ) );
|
||||
}
|
||||
if ( ! empty( $versions ) ) {
|
||||
$requires = $versions[ count( $versions ) - 1 ];
|
||||
$tested = $versions[0];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$plugin_normalized = array(
|
||||
'id' => $plugin['id'],
|
||||
'name' => ( ! empty( $plugin['wordpress_plugin_metadata']['plugin_name'] ) ? $plugin['wordpress_plugin_metadata']['plugin_name'] : '' ),
|
||||
'author' => ( ! empty( $plugin['wordpress_plugin_metadata']['author'] ) ? $plugin['wordpress_plugin_metadata']['author'] : '' ),
|
||||
'version' => ( ! empty( $plugin['wordpress_plugin_metadata']['version'] ) ? $plugin['wordpress_plugin_metadata']['version'] : '' ),
|
||||
'description' => self::remove_non_unicode( strip_tags( $plugin['wordpress_plugin_metadata']['description'] ) ),
|
||||
'url' => ( ! empty( $plugin['url'] ) ? $plugin['url'] : '' ),
|
||||
'author_url' => ( ! empty( $plugin['author_url'] ) ? $plugin['author_url'] : '' ),
|
||||
'thumbnail_url' => ( ! empty( $plugin['thumbnail_url'] ) ? $plugin['thumbnail_url'] : '' ),
|
||||
'landscape_url' => ( ! empty( $plugin['previews']['landscape_preview']['landscape_url'] ) ? $plugin['previews']['landscape_preview']['landscape_url'] : '' ),
|
||||
'requires' => $requires,
|
||||
'tested' => $tested,
|
||||
'number_of_sales' => ( ! empty( $plugin['number_of_sales'] ) ? $plugin['number_of_sales'] : '' ),
|
||||
'updated_at' => ( ! empty( $plugin['updated_at'] ) ? $plugin['updated_at'] : '' ),
|
||||
'rating' => ( ! empty( $plugin['rating'] ) ? $plugin['rating'] : '' ),
|
||||
);
|
||||
|
||||
// No main thumbnail in API response, so we grab it from the preview array.
|
||||
if ( empty( $plugin_normalized['landscape_url'] ) && ! empty( $plugin['previews'] ) && is_array( $plugin['previews'] ) ) {
|
||||
foreach ( $plugin['previews'] as $possible_preview ) {
|
||||
if ( ! empty( $possible_preview['landscape_url'] ) ) {
|
||||
$plugin_normalized['landscape_url'] = $possible_preview['landscape_url'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( empty( $plugin_normalized['thumbnail_url'] ) && ! empty( $plugin['previews'] ) && is_array( $plugin['previews'] ) ) {
|
||||
foreach ( $plugin['previews'] as $possible_preview ) {
|
||||
if ( ! empty( $possible_preview['icon_url'] ) ) {
|
||||
$plugin_normalized['thumbnail_url'] = $possible_preview['icon_url'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $plugin_normalized;
|
||||
}
|
||||
|
||||
public function api_path_for( $path ) {
|
||||
if ( defined('ENVATO_LOCAL_DEVELOPMENT') ) {
|
||||
$paths = MONOLITH_API_PATHS;
|
||||
} else {
|
||||
$paths = array(
|
||||
'download' => '/v2/market/buyer/download',
|
||||
'catalog-item' => '/v2/market/catalog/item',
|
||||
'list-purchases' => '/v2/market/buyer/list-purchases',
|
||||
'total-items' => '/v1/market/total-items.json'
|
||||
);
|
||||
}
|
||||
|
||||
return $paths[$path];
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all non unicode characters in a string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $retval The string to fix.
|
||||
* @return string
|
||||
*/
|
||||
static private function remove_non_unicode( $retval ) {
|
||||
return preg_replace( '/[\x00-\x1F\x80-\xFF]/', '', $retval );
|
||||
}
|
||||
|
||||
private function request_headers() {
|
||||
$user_agent = array('User-Agent' => 'WordPress - Envato Market ' . envato_market()->get_version());
|
||||
$headers = array_merge($user_agent, envato_market()->get_envato_api_headers());
|
||||
return $headers;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
@@ -0,0 +1,386 @@
|
||||
<?php
|
||||
/**
|
||||
* Envato Market Github class.
|
||||
*
|
||||
* @package Envato_Market
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'Envato_Market_Github' ) ) :
|
||||
|
||||
/**
|
||||
* Creates the connection between Github to install & update the Envato Market plugin.
|
||||
*
|
||||
* @class Envato_Market_Github
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Envato_Market_Github {
|
||||
|
||||
/**
|
||||
* Action nonce.
|
||||
*
|
||||
* @type string
|
||||
*/
|
||||
const AJAX_ACTION = 'envato_market_dismiss_notice';
|
||||
|
||||
/**
|
||||
* The single class instance.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* The API URL.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $api_url = 'https://envato.github.io/wp-envato-market/dist/update-check.json';
|
||||
|
||||
/**
|
||||
* The Envato_Market_Items Instance
|
||||
*
|
||||
* Ensures only one instance of this class exists in memory at any one time.
|
||||
*
|
||||
* @see Envato_Market_Github()
|
||||
* @uses Envato_Market_Github::init_actions() Setup hooks and actions.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @static
|
||||
* @return object The one true Envato_Market_Github.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function instance() {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self();
|
||||
self::$_instance->init_actions();
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* A dummy constructor to prevent this class from being loaded more than once.
|
||||
*
|
||||
* @see Envato_Market_Github::instance()
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct() {
|
||||
/* We do nothing here! */
|
||||
}
|
||||
|
||||
/**
|
||||
* You cannot clone this class.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __clone() {
|
||||
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'envato-market' ), '1.0.0' );
|
||||
}
|
||||
|
||||
/**
|
||||
* You cannot unserialize instances of this class.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __wakeup() {
|
||||
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'envato-market' ), '1.0.0' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the actions and filters.
|
||||
*
|
||||
* @uses add_action() To add actions.
|
||||
* @uses add_filter() To add filters.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function init_actions() {
|
||||
|
||||
// Bail outside of the WP Admin panel.
|
||||
if ( ! is_admin() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
add_filter( 'http_request_args', array( $this, 'update_check' ), 5, 2 );
|
||||
add_filter( 'plugins_api', array( $this, 'plugins_api' ), 10, 3 );
|
||||
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'update_plugins' ) );
|
||||
add_filter( 'pre_set_transient_update_plugins', array( $this, 'update_plugins' ) );
|
||||
add_filter( 'site_transient_update_plugins', array( $this, 'update_state' ) );
|
||||
add_filter( 'transient_update_plugins', array( $this, 'update_state' ) );
|
||||
add_action( 'admin_notices', array( $this, 'notice' ) );
|
||||
add_action( 'wp_ajax_' . self::AJAX_ACTION, array( $this, 'dismiss_notice' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check Github for an update.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return false|object
|
||||
*/
|
||||
public function api_check() {
|
||||
$raw_response = wp_remote_get( self::$api_url );
|
||||
if ( is_wp_error( $raw_response ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( ! empty( $raw_response['body'] ) ) {
|
||||
$raw_body = json_decode( $raw_response['body'], true );
|
||||
if ( $raw_body ) {
|
||||
return (object) $raw_body;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables requests to the wp.org repository for Envato Market.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $request An array of HTTP request arguments.
|
||||
* @param string $url The request URL.
|
||||
* @return array
|
||||
*/
|
||||
public function update_check( $request, $url ) {
|
||||
|
||||
// Plugin update request.
|
||||
if ( false !== strpos( $url, '//api.wordpress.org/plugins/update-check/1.1/' ) ) {
|
||||
|
||||
// Decode JSON so we can manipulate the array.
|
||||
$data = json_decode( $request['body']['plugins'] );
|
||||
|
||||
// Remove the Envato Market.
|
||||
unset( $data->plugins->{'envato-market/envato-market.php'} );
|
||||
|
||||
// Encode back into JSON and update the response.
|
||||
$request['body']['plugins'] = wp_json_encode( $data );
|
||||
}
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* API check.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param bool $api Always false.
|
||||
* @param string $action The API action being performed.
|
||||
* @param object $args Plugin arguments.
|
||||
* @return mixed $api The plugin info or false.
|
||||
*/
|
||||
public function plugins_api( $api, $action, $args ) {
|
||||
if ( isset( $args->slug ) && 'envato-market' === $args->slug ) {
|
||||
$api_check = $this->api_check();
|
||||
if ( is_object( $api_check ) ) {
|
||||
$api = $api_check;
|
||||
}
|
||||
}
|
||||
return $api;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update check.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param object $transient The pre-saved value of the `update_plugins` site transient.
|
||||
* @return object
|
||||
*/
|
||||
public function update_plugins( $transient ) {
|
||||
$state = $this->state();
|
||||
if ( 'activated' === $state ) {
|
||||
$api_check = $this->api_check();
|
||||
if ( is_object( $api_check ) && version_compare( envato_market()->get_version(), $api_check->version, '<' ) ) {
|
||||
$transient->response['envato-market/envato-market.php'] = (object) array(
|
||||
'slug' => 'envato-market',
|
||||
'plugin' => 'envato-market/envato-market.php',
|
||||
'new_version' => $api_check->version,
|
||||
'url' => 'https://github.com/envato/wp-envato-market',
|
||||
'package' => $api_check->download_link,
|
||||
);
|
||||
}
|
||||
}
|
||||
return $transient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the plugin state.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function state() {
|
||||
$option = 'envato_market_state';
|
||||
$active_plugins = apply_filters( 'active_plugins', get_option( 'active_plugins' ) );
|
||||
// We also have to check network activated plugins. Otherwise this plugin won't update on multisite.
|
||||
$active_sitewide_plugins = get_site_option( 'active_sitewide_plugins' );
|
||||
if ( ! is_array( $active_plugins ) ) {
|
||||
$active_plugins = array();
|
||||
}
|
||||
if ( ! is_array( $active_sitewide_plugins ) ) {
|
||||
$active_sitewide_plugins = array();
|
||||
}
|
||||
$active_plugins = array_merge( $active_plugins, array_keys( $active_sitewide_plugins ) );
|
||||
if ( in_array( 'envato-market/envato-market.php', $active_plugins ) ) {
|
||||
$state = 'activated';
|
||||
update_option( $option, $state );
|
||||
} else {
|
||||
$state = 'install';
|
||||
update_option( $option, $state );
|
||||
foreach ( array_keys( get_plugins() ) as $plugin ) {
|
||||
if ( strpos( $plugin, 'envato-market.php' ) !== false ) {
|
||||
$state = 'deactivated';
|
||||
update_option( $option, $state );
|
||||
}
|
||||
}
|
||||
}
|
||||
return $state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Force the plugin state to be updated.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param object $transient The saved value of the `update_plugins` site transient.
|
||||
* @return object
|
||||
*/
|
||||
public function update_state( $transient ) {
|
||||
$state = $this->state();
|
||||
return $transient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin notices.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function notice() {
|
||||
$screen = get_current_screen();
|
||||
$slug = 'envato-market';
|
||||
$state = get_option( 'envato_market_state' );
|
||||
$notice = get_option( self::AJAX_ACTION );
|
||||
|
||||
if ( empty( $state ) ) {
|
||||
$state = $this->state();
|
||||
}
|
||||
|
||||
if (
|
||||
'activated' === $state ||
|
||||
'update-core' === $screen->id ||
|
||||
'update' === $screen->id ||
|
||||
'plugins' === $screen->id && isset( $_GET['action'] ) && 'delete-selected' === $_GET['action'] ||
|
||||
'dismissed' === $notice
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'deactivated' === $state ) {
|
||||
$activate_url = add_query_arg(
|
||||
array(
|
||||
'action' => 'activate',
|
||||
'plugin' => urlencode( "$slug/$slug.php" ),
|
||||
'_wpnonce' => urlencode( wp_create_nonce( "activate-plugin_$slug/$slug.php" ) ),
|
||||
),
|
||||
self_admin_url( 'plugins.php' )
|
||||
);
|
||||
|
||||
$message = sprintf(
|
||||
esc_html__( '%1$sActivate the Envato Market plugin%2$s to get updates for your ThemeForest and CodeCanyon items.', 'envato-market' ),
|
||||
'<a href="' . esc_url( $activate_url ) . '">',
|
||||
'</a>'
|
||||
);
|
||||
} elseif ( 'install' === $state ) {
|
||||
$install_url = add_query_arg(
|
||||
array(
|
||||
'action' => 'install-plugin',
|
||||
'plugin' => $slug,
|
||||
),
|
||||
self_admin_url( 'update.php' )
|
||||
);
|
||||
|
||||
$message = sprintf(
|
||||
esc_html__( '%1$sInstall the Envato Market plugin%2$s to get updates for your ThemeForest and CodeCanyon items.', 'envato-market' ),
|
||||
'<a href="' . esc_url( wp_nonce_url( $install_url, 'install-plugin_' . $slug ) ) . '">',
|
||||
'</a>'
|
||||
);
|
||||
}
|
||||
|
||||
if ( isset( $message ) ) {
|
||||
?>
|
||||
<div class="updated envato-market-notice notice is-dismissible">
|
||||
<p><?php echo wp_kses_post( $message ); ?></p>
|
||||
</div>
|
||||
<script>
|
||||
jQuery( document ).ready( function( $ ) {
|
||||
$( document ).on( 'click', '.envato-market-notice .notice-dismiss', function() {
|
||||
$.ajax( {
|
||||
url: ajaxurl,
|
||||
data: {
|
||||
action: '<?php echo self::AJAX_ACTION; ?>',
|
||||
nonce: '<?php echo wp_create_nonce( self::AJAX_ACTION ); ?>'
|
||||
}
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Dismiss admin notice.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function dismiss_notice() {
|
||||
if ( ! check_ajax_referer( self::AJAX_ACTION, 'nonce', false ) ) {
|
||||
status_header( 400 );
|
||||
wp_send_json_error( 'bad_nonce' );
|
||||
} elseif ( ! current_user_can( 'update_plugins' ) ) {
|
||||
wp_send_json_error( array( 'message' => __( 'User not allowed to update items.', 'envato-market' ) ) );
|
||||
}
|
||||
|
||||
update_option( self::AJAX_ACTION, 'dismissed' );
|
||||
wp_send_json_success();
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! function_exists( 'envato_market_github' ) ) :
|
||||
/**
|
||||
* Envato_Market_Github Instance
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return Envato_Market_Github
|
||||
*/
|
||||
function envato_market_github() {
|
||||
return Envato_Market_Github::instance();
|
||||
}
|
||||
endif;
|
||||
|
||||
/**
|
||||
* Loads the main instance of Envato_Market_Github
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
add_action( 'after_setup_theme', 'envato_market_github', 99 );
|
||||
|
||||
endif;
|
||||
@@ -0,0 +1,590 @@
|
||||
<?php
|
||||
/**
|
||||
* Items class.
|
||||
*
|
||||
* @package Envato_Market
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'Envato_Market_Items' ) ) :
|
||||
|
||||
/**
|
||||
* Creates the theme & plugin arrays & injects API results.
|
||||
*
|
||||
* @class Envato_Market_Items
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class Envato_Market_Items {
|
||||
|
||||
/**
|
||||
* The single class instance.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* Premium themes.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $themes = array();
|
||||
|
||||
/**
|
||||
* Premium plugins.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $plugins = array();
|
||||
|
||||
/**
|
||||
* WordPress plugins.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $wp_plugins = array();
|
||||
|
||||
/**
|
||||
* The Envato_Market_Items Instance
|
||||
*
|
||||
* Ensures only one instance of this class exists in memory at any one time.
|
||||
*
|
||||
* @see Envato_Market_Items()
|
||||
* @uses Envato_Market_Items::init_actions() Setup hooks and actions.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @static
|
||||
* @return object The one true Envato_Market_Items.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function instance() {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self();
|
||||
self::$_instance->init_actions();
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* A dummy constructor to prevent this class from being loaded more than once.
|
||||
*
|
||||
* @see Envato_Market_Items::instance()
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct() {
|
||||
/* We do nothing here! */
|
||||
}
|
||||
|
||||
/**
|
||||
* You cannot clone this class.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __clone() {
|
||||
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'envato-market' ), '1.0.0' );
|
||||
}
|
||||
|
||||
/**
|
||||
* You cannot unserialize instances of this class.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __wakeup() {
|
||||
_doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ huh?', 'envato-market' ), '1.0.0' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the hooks, actions and filters.
|
||||
*
|
||||
* @uses add_action() To add actions.
|
||||
* @uses add_filter() To add filters.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function init_actions() {
|
||||
// Check for theme & plugin updates.
|
||||
add_filter( 'http_request_args', array( $this, 'update_check' ), 5, 2 );
|
||||
|
||||
// Inject plugin updates into the response array.
|
||||
add_filter( 'pre_set_site_transient_update_plugins', array( $this, 'update_plugins' ), 5, 1 );
|
||||
add_filter( 'pre_set_transient_update_plugins', array( $this, 'update_plugins' ), 5, 1 );
|
||||
|
||||
// Inject theme updates into the response array.
|
||||
add_filter( 'pre_set_site_transient_update_themes', array( $this, 'update_themes' ), 1, 99999 );
|
||||
add_filter( 'pre_set_transient_update_themes', array( $this, 'update_themes' ), 1, 99999 );
|
||||
|
||||
// Inject plugin information into the API calls.
|
||||
add_filter( 'plugins_api', array( $this, 'plugins_api' ), 10, 3 );
|
||||
|
||||
// Rebuild the saved theme data.
|
||||
add_action( 'after_switch_theme', array( $this, 'rebuild_themes' ) );
|
||||
|
||||
// Rebuild the saved plugin data.
|
||||
add_action( 'activated_plugin', array( $this, 'rebuild_plugins' ) );
|
||||
add_action( 'deactivated_plugin', array( $this, 'rebuild_plugins' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the premium plugins list.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $group The plugin group. Options are 'purchased', 'active', 'installed', or 'install'.
|
||||
* @return array
|
||||
*/
|
||||
public function plugins( $group = '' ) {
|
||||
if ( ! empty( $group ) ) {
|
||||
if ( isset( self::$plugins[ $group ] ) ) {
|
||||
return self::$plugins[ $group ];
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
return self::$plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the premium themes list.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $group The theme group. Options are 'purchased', 'active', 'installed', or 'install'.
|
||||
* @return array
|
||||
*/
|
||||
public function themes( $group = '' ) {
|
||||
if ( ! empty( $group ) ) {
|
||||
if ( isset( self::$themes[ $group ] ) ) {
|
||||
return self::$themes[ $group ];
|
||||
} else {
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
return self::$themes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of WordPress plugins
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param bool $flush Forces a cache flush. Default is 'false'.
|
||||
* @return array
|
||||
*/
|
||||
public function wp_plugins( $flush = false ) {
|
||||
if ( empty( self::$wp_plugins ) || true === $flush ) {
|
||||
wp_cache_set( 'plugins', false, 'plugins' );
|
||||
self::$wp_plugins = get_plugins();
|
||||
}
|
||||
|
||||
return self::$wp_plugins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables requests to the wp.org repository for premium themes.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $request An array of HTTP request arguments.
|
||||
* @param string $url The request URL.
|
||||
* @return array
|
||||
*/
|
||||
public function update_check( $request, $url ) {
|
||||
|
||||
// Theme update request.
|
||||
if ( false !== strpos( $url, '//api.wordpress.org/themes/update-check/1.1/' ) ) {
|
||||
|
||||
/**
|
||||
* Excluded theme slugs that should never ping the WordPress API.
|
||||
* We don't need the extra http requests for themes we know are premium.
|
||||
*/
|
||||
self::set_themes();
|
||||
$installed = self::$themes['installed'];
|
||||
|
||||
// Decode JSON so we can manipulate the array.
|
||||
$data = json_decode( $request['body']['themes'] );
|
||||
|
||||
// Remove the excluded themes.
|
||||
foreach ( $installed as $slug => $id ) {
|
||||
unset( $data->themes->$slug );
|
||||
}
|
||||
|
||||
// Encode back into JSON and update the response.
|
||||
$request['body']['themes'] = wp_json_encode( $data );
|
||||
}
|
||||
|
||||
// Plugin update request.
|
||||
if ( false !== strpos( $url, '//api.wordpress.org/plugins/update-check/1.1/' ) ) {
|
||||
|
||||
/**
|
||||
* Excluded theme slugs that should never ping the WordPress API.
|
||||
* We don't need the extra http requests for themes we know are premium.
|
||||
*/
|
||||
self::set_plugins();
|
||||
$installed = self::$plugins['installed'];
|
||||
|
||||
// Decode JSON so we can manipulate the array.
|
||||
$data = json_decode( $request['body']['plugins'] );
|
||||
|
||||
// Remove the excluded themes.
|
||||
foreach ( $installed as $slug => $id ) {
|
||||
unset( $data->plugins->$slug );
|
||||
}
|
||||
|
||||
// Encode back into JSON and update the response.
|
||||
$request['body']['plugins'] = wp_json_encode( $data );
|
||||
}
|
||||
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject update data for premium themes.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param object $transient The pre-saved value of the `update_themes` site transient.
|
||||
* @return object
|
||||
*/
|
||||
public function update_themes( $transient ) {
|
||||
// Process premium theme updates.
|
||||
if ( isset( $transient->checked ) ) {
|
||||
self::set_themes( true );
|
||||
$installed = array_merge( self::$themes['active'], self::$themes['installed'] );
|
||||
|
||||
foreach ( $installed as $slug => $premium ) {
|
||||
$theme = wp_get_theme( $slug );
|
||||
if ( $theme->exists() && version_compare( $theme->get( 'Version' ), $premium['version'], '<' ) ) {
|
||||
$transient->response[ $slug ] = array(
|
||||
'theme' => $slug,
|
||||
'new_version' => $premium['version'],
|
||||
'url' => $premium['url'],
|
||||
'package' => envato_market()->api()->deferred_download( $premium['id'] ),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $transient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject update data for premium plugins.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param object $transient The pre-saved value of the `update_plugins` site transient.
|
||||
* @return object
|
||||
*/
|
||||
public function update_plugins( $transient ) {
|
||||
self::set_plugins( true );
|
||||
|
||||
// Process premium plugin updates.
|
||||
$installed = array_merge( self::$plugins['active'], self::$plugins['installed'] );
|
||||
$plugins = self::wp_plugins();
|
||||
|
||||
foreach ( $installed as $plugin => $premium ) {
|
||||
if ( isset( $plugins[ $plugin ] ) && version_compare( $plugins[ $plugin ]['Version'], $premium['version'], '<' ) ) {
|
||||
$_plugin = array(
|
||||
'slug' => dirname( $plugin ),
|
||||
'plugin' => $plugin,
|
||||
'new_version' => $premium['version'],
|
||||
'url' => $premium['url'],
|
||||
'package' => envato_market()->api()->deferred_download( $premium['id'] ),
|
||||
);
|
||||
$transient->response[ $plugin ] = (object) $_plugin;
|
||||
}
|
||||
}
|
||||
|
||||
return $transient;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inject API data for premium plugins.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param bool $response Always false.
|
||||
* @param string $action The API action being performed.
|
||||
* @param object $args Plugin arguments.
|
||||
* @return bool|object $response The plugin info or false.
|
||||
*/
|
||||
public function plugins_api( $response, $action, $args ) {
|
||||
self::set_plugins( true );
|
||||
|
||||
// Process premium theme updates.
|
||||
if ( 'plugin_information' === $action && isset( $args->slug ) ) {
|
||||
$installed = array_merge( self::$plugins['active'], self::$plugins['installed'] );
|
||||
foreach ( $installed as $slug => $plugin ) {
|
||||
if ( dirname( $slug ) === $args->slug ) {
|
||||
$response = new stdClass();
|
||||
$response->slug = $args->slug;
|
||||
$response->plugin = $slug;
|
||||
$response->plugin_name = $plugin['name'];
|
||||
$response->name = $plugin['name'];
|
||||
$response->version = $plugin['version'];
|
||||
$response->author = $plugin['author'];
|
||||
$response->homepage = $plugin['url'];
|
||||
$response->requires = $plugin['requires'];
|
||||
$response->tested = $plugin['tested'];
|
||||
$response->downloaded = $plugin['number_of_sales'];
|
||||
$response->last_updated = $plugin['updated_at'];
|
||||
$response->sections = array( 'description' => $plugin['description'] );
|
||||
$response->banners['low'] = $plugin['landscape_url'];
|
||||
$response->rating = ! empty( $plugin['rating'] ) && ! empty( $plugin['rating']['rating'] ) && $plugin['rating']['rating'] > 0 ? $plugin['rating']['rating'] / 5 * 100 : 0;
|
||||
$response->num_ratings = ! empty( $plugin['rating'] ) && ! empty( $plugin['rating']['count'] ) ? $plugin['rating']['count'] : 0;
|
||||
$response->download_link = envato_market()->api()->deferred_download( $plugin['id'] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the list of themes
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param bool $forced Forces an API request. Default is 'false'.
|
||||
* @param bool $use_cache Attempts to rebuild from the cache before making an API request.
|
||||
*/
|
||||
public function set_themes( $forced = false, $use_cache = false ) {
|
||||
$themes_transient = get_site_transient( envato_market()->get_option_name() . '_themes' );
|
||||
self::$themes = is_array($themes_transient) ? $themes_transient : array();
|
||||
|
||||
if ( empty(self::$themes) || true === $forced ) {
|
||||
$themes = envato_market()->api()->themes();
|
||||
foreach ( envato_market()->get_option( 'items', array() ) as $item ) {
|
||||
if ( empty( $item ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( 'theme' === $item['type'] ) {
|
||||
$request_args = array(
|
||||
'headers' => array(
|
||||
'Authorization' => 'Bearer ' . $item['token'],
|
||||
),
|
||||
);
|
||||
$request = envato_market()->api()->item( $item['id'], $request_args );
|
||||
if ( false !== $request ) {
|
||||
$themes[] = $request;
|
||||
}
|
||||
}
|
||||
}
|
||||
self::process_themes( $themes );
|
||||
} elseif ( true === $use_cache ) {
|
||||
self::process_themes( self::$themes['purchased'] );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the list of plugins
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param bool $forced Forces an API request. Default is 'false'.
|
||||
* @param bool $use_cache Attempts to rebuild from the cache before making an API request.
|
||||
* @param array $args Used to remove or add a plugin during activate and deactivate routines.
|
||||
*/
|
||||
public function set_plugins( $forced = false, $use_cache = false, $args = array() ) {
|
||||
$plugins_transient = get_site_transient( envato_market()->get_option_name() . '_plugins' );
|
||||
self::$plugins = is_array($plugins_transient) ? $plugins_transient : array();
|
||||
|
||||
if ( empty(self::$plugins) || true === $forced ) {
|
||||
$plugins = envato_market()->api()->plugins();
|
||||
foreach ( envato_market()->get_option( 'items', array() ) as $item ) {
|
||||
if ( empty( $item ) ) {
|
||||
continue;
|
||||
}
|
||||
if ( 'plugin' === $item['type'] ) {
|
||||
$request_args = array(
|
||||
'headers' => array(
|
||||
'Authorization' => 'Bearer ' . $item['token'],
|
||||
),
|
||||
);
|
||||
$request = envato_market()->api()->item( $item['id'], $request_args );
|
||||
if ( false !== $request ) {
|
||||
$plugins[] = $request;
|
||||
}
|
||||
}
|
||||
}
|
||||
self::process_plugins( $plugins, $args );
|
||||
} elseif ( true === $use_cache ) {
|
||||
self::process_plugins( self::$plugins['purchased'], $args );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild the themes array using the cache value if possible.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param mixed $filter Any data being filtered.
|
||||
* @return mixed
|
||||
*/
|
||||
public function rebuild_themes( $filter ) {
|
||||
self::set_themes( false, true );
|
||||
|
||||
return $filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild the plugins array using the cache value if possible.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $plugin The plugin to add or remove.
|
||||
*/
|
||||
public function rebuild_plugins( $plugin ) {
|
||||
$remove = ( 'deactivated_plugin' === current_filter() ) ? true : false;
|
||||
self::set_plugins(
|
||||
false,
|
||||
true,
|
||||
array(
|
||||
'plugin' => $plugin,
|
||||
'remove' => $remove,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes a string to do a value check against.
|
||||
*
|
||||
* Strip all HTML tags including script and style & then decode the
|
||||
* HTML entities so `&` will equal `&` in the value check and
|
||||
* finally lower case the entire string. This is required becuase some
|
||||
* themes & plugins add a link to the Author field or ambersands to the
|
||||
* names, or change the case of their files or names, which will not match
|
||||
* the saved value in the database causing a false negative.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $string The string to normalize.
|
||||
* @return string
|
||||
*/
|
||||
public function normalize( $string ) {
|
||||
return strtolower( html_entity_decode( wp_strip_all_tags( $string ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the themes and save the transient.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $purchased The purchased themes array.
|
||||
*/
|
||||
private function process_themes( $purchased ) {
|
||||
if ( is_wp_error( $purchased ) ) {
|
||||
$purchased = array();
|
||||
}
|
||||
|
||||
$current = wp_get_theme()->get_template();
|
||||
$active = array();
|
||||
$installed = array();
|
||||
$install = $purchased;
|
||||
|
||||
if ( ! empty( $purchased ) ) {
|
||||
foreach ( wp_get_themes() as $theme ) {
|
||||
|
||||
/**
|
||||
* WP_Theme object.
|
||||
*
|
||||
* @var WP_Theme $theme
|
||||
*/
|
||||
$template = $theme->get_template();
|
||||
$title = $theme->get( 'Name' );
|
||||
$author = $theme->get( 'Author' );
|
||||
|
||||
foreach ( $install as $key => $value ) {
|
||||
if ( $this->normalize( $value['name'] ) === $this->normalize( $title ) && $this->normalize( $value['author'] ) === $this->normalize( $author ) ) {
|
||||
$installed[ $template ] = $value;
|
||||
unset( $install[ $key ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $installed[ $current ] ) ) {
|
||||
$active[ $current ] = $installed[ $current ];
|
||||
unset( $installed[ $current ] );
|
||||
}
|
||||
|
||||
self::$themes['purchased'] = array_unique( $purchased, SORT_REGULAR );
|
||||
self::$themes['active'] = array_unique( $active, SORT_REGULAR );
|
||||
self::$themes['installed'] = array_unique( $installed, SORT_REGULAR );
|
||||
self::$themes['install'] = array_unique( array_values( $install ), SORT_REGULAR );
|
||||
|
||||
set_site_transient( envato_market()->get_option_name() . '_themes', self::$themes, HOUR_IN_SECONDS );
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the plugins and save the transient.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param array $purchased The purchased plugins array.
|
||||
* @param array $args Used to remove or add a plugin during activate and deactivate routines.
|
||||
*/
|
||||
private function process_plugins( $purchased, $args = array() ) {
|
||||
if ( is_wp_error( $purchased ) ) {
|
||||
$purchased = array();
|
||||
}
|
||||
|
||||
$active = array();
|
||||
$installed = array();
|
||||
$install = $purchased;
|
||||
|
||||
if ( ! empty( $purchased ) ) {
|
||||
foreach ( self::wp_plugins( true ) as $slug => $plugin ) {
|
||||
foreach ( $install as $key => $value ) {
|
||||
if ( $this->normalize( $value['name'] ) === $this->normalize( $plugin['Name'] ) && $this->normalize( $value['author'] ) === $this->normalize( $plugin['Author'] ) && file_exists( WP_PLUGIN_DIR . '/' . $slug ) ) {
|
||||
$installed[ $slug ] = $value;
|
||||
unset( $install[ $key ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ( $installed as $slug => $plugin ) {
|
||||
$condition = false;
|
||||
if ( ! empty( $args ) && $slug === $args['plugin'] ) {
|
||||
if ( true === $args['remove'] ) {
|
||||
continue;
|
||||
}
|
||||
$condition = true;
|
||||
}
|
||||
if ( $condition || is_plugin_active( $slug ) ) {
|
||||
$active[ $slug ] = $plugin;
|
||||
unset( $installed[ $slug ] );
|
||||
}
|
||||
}
|
||||
|
||||
self::$plugins['purchased'] = array_unique( $purchased, SORT_REGULAR );
|
||||
self::$plugins['active'] = array_unique( $active, SORT_REGULAR );
|
||||
self::$plugins['installed'] = array_unique( $installed, SORT_REGULAR );
|
||||
self::$plugins['install'] = array_unique( array_values( $install ), SORT_REGULAR );
|
||||
|
||||
set_site_transient( envato_market()->get_option_name() . '_plugins', self::$plugins, HOUR_IN_SECONDS );
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
498
wp-content/plugins/envato-market/inc/class-envato-market.php
Normal file
498
wp-content/plugins/envato-market/inc/class-envato-market.php
Normal file
@@ -0,0 +1,498 @@
|
||||
<?php
|
||||
/**
|
||||
* Envato Market class.
|
||||
*
|
||||
* @package Envato_Market
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
|
||||
if ( ! class_exists( 'Envato_Market' ) ) :
|
||||
|
||||
/**
|
||||
* It's the main class that does all the things.
|
||||
*
|
||||
* @class Envato_Market
|
||||
* @version 1.0.0
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class Envato_Market {
|
||||
|
||||
/**
|
||||
* The single class instance.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* Plugin data.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
private $data;
|
||||
|
||||
/**
|
||||
* The slug.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $slug;
|
||||
|
||||
/**
|
||||
* The version number.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $version;
|
||||
|
||||
/**
|
||||
* The web URL to the plugin directory.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $plugin_url;
|
||||
|
||||
/**
|
||||
* The server path to the plugin directory.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $plugin_path;
|
||||
|
||||
/**
|
||||
* The web URL to the plugin admin page.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $page_url;
|
||||
|
||||
/**
|
||||
* The setting option name.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $option_name;
|
||||
private $envato_api_domain;
|
||||
private $envato_api_headers;
|
||||
|
||||
/**
|
||||
* Main Envato_Market Instance
|
||||
*
|
||||
* Ensures only one instance of this class exists in memory at any one time.
|
||||
*
|
||||
* @see Envato_Market()
|
||||
* @uses Envato_Market::init_globals() Setup class globals.
|
||||
* @uses Envato_Market::init_includes() Include required files.
|
||||
* @uses Envato_Market::init_actions() Setup hooks and actions.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @static
|
||||
* @return Envato_Market.
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public static function instance() {
|
||||
if ( is_null( self::$_instance ) ) {
|
||||
self::$_instance = new self();
|
||||
self::$_instance->init_globals();
|
||||
self::$_instance->init_includes();
|
||||
self::$_instance->init_actions();
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* A dummy constructor to prevent this class from being loaded more than once.
|
||||
*
|
||||
* @see Envato_Market::instance()
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct() {
|
||||
/* We do nothing here! */
|
||||
}
|
||||
|
||||
/**
|
||||
* You cannot clone this class.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __clone() {
|
||||
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'envato-market' ), '1.0.0' );
|
||||
}
|
||||
|
||||
/**
|
||||
* You cannot unserialize instances of this class.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function __wakeup() {
|
||||
_doing_it_wrong( __FUNCTION__, __( 'Cheatin’ huh?', 'envato-market' ), '1.0.0' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the class globals.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function init_globals() {
|
||||
$this->data = new stdClass();
|
||||
$this->version = ENVATO_MARKET_VERSION;
|
||||
$this->slug = 'envato-market';
|
||||
$this->option_name = self::sanitize_key( $this->slug );
|
||||
$this->plugin_url = ENVATO_MARKET_URI;
|
||||
$this->plugin_path = ENVATO_MARKET_PATH;
|
||||
$this->page_url = ENVATO_MARKET_NETWORK_ACTIVATED ? network_admin_url( 'admin.php?page=' . $this->slug ) : admin_url( 'admin.php?page=' . $this->slug );
|
||||
$this->data->admin = true;
|
||||
if ( defined('ENVATO_LOCAL_DEVELOPMENT') ) {
|
||||
$this->envato_api_domain = ENVATO_API_DOMAIN;
|
||||
$this->envato_api_headers = ENVATO_API_HEADERS;
|
||||
} else {
|
||||
$this->envato_api_headers = [ 'Authorization' => 'Bearer ' . $this->get_option( 'token' ) ];
|
||||
$this->envato_api_domain = 'https://api.envato.com';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Include required files.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function init_includes() {
|
||||
require $this->plugin_path . '/inc/admin/class-envato-market-admin.php';
|
||||
require $this->plugin_path . '/inc/admin/functions.php';
|
||||
require $this->plugin_path . '/inc/class-envato-market-api.php';
|
||||
require $this->plugin_path . '/inc/class-envato-market-items.php';
|
||||
require $this->plugin_path . '/inc/class-envato-market-github.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup the hooks, actions and filters.
|
||||
*
|
||||
* @uses add_action() To add actions.
|
||||
* @uses add_filter() To add filters.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function init_actions() {
|
||||
// Activate plugin.
|
||||
register_activation_hook( ENVATO_MARKET_CORE_FILE, array( $this, 'activate' ) );
|
||||
|
||||
// Deactivate plugin.
|
||||
register_deactivation_hook( ENVATO_MARKET_CORE_FILE, array( $this, 'deactivate' ) );
|
||||
|
||||
// Load the textdomain.
|
||||
add_action( 'init', array( $this, 'load_textdomain' ) );
|
||||
|
||||
// Load OAuth.
|
||||
add_action( 'init', array( $this, 'admin' ) );
|
||||
|
||||
// Load Upgrader.
|
||||
add_action( 'init', array( $this, 'items' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function activate() {
|
||||
self::set_plugin_state( true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivate plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function deactivate() {
|
||||
self::set_plugin_state( false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the plugin's translated strings.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
public function load_textdomain() {
|
||||
load_plugin_textdomain( 'envato-market', false, ENVATO_MARKET_PATH . 'languages/' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize data key.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*
|
||||
* @param string $key An alpha numeric string to sanitize.
|
||||
* @return string
|
||||
*/
|
||||
private function sanitize_key( $key ) {
|
||||
return preg_replace( '/[^A-Za-z0-9\_]/i', '', str_replace( array( '-', ':' ), '_', $key ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively converts data arrays to objects.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*
|
||||
* @param array $array An array of data.
|
||||
* @return object
|
||||
*/
|
||||
private function convert_data( $array ) {
|
||||
foreach ( (array) $array as $key => $value ) {
|
||||
if ( is_array( $value ) ) {
|
||||
$array[ $key ] = self::convert_data( $value );
|
||||
}
|
||||
}
|
||||
return (object) $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the `is_plugin_active` option.
|
||||
*
|
||||
* This setting helps determine context. Since the plugin can be included in your theme root you
|
||||
* might want to hide the admin UI when the plugin is not activated and implement your own.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @access private
|
||||
*
|
||||
* @param bool $value Whether or not the plugin is active.
|
||||
*/
|
||||
private function set_plugin_state( $value ) {
|
||||
self::set_option( 'is_plugin_active', $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set option value.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $name Option name.
|
||||
* @param mixed $option Option data.
|
||||
*/
|
||||
public function set_option( $name, $option ) {
|
||||
$options = self::get_options();
|
||||
$name = self::sanitize_key( $name );
|
||||
$options[ $name ] = esc_html( $option );
|
||||
$this->set_options( $options );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set option.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param mixed $options Option data.
|
||||
*/
|
||||
public function set_options( $options ) {
|
||||
ENVATO_MARKET_NETWORK_ACTIVATED ? update_site_option( $this->option_name, $options ) : update_option( $this->option_name, $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the option settings array.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function get_options() {
|
||||
return ENVATO_MARKET_NETWORK_ACTIVATED ? get_site_option( $this->option_name, array() ) : get_option( $this->option_name, array() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a value from the option settings array.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $name Option name.
|
||||
* @param mixed $default The default value if nothing is set.
|
||||
* @return mixed
|
||||
*/
|
||||
public function get_option( $name, $default = '' ) {
|
||||
$options = self::get_options();
|
||||
$name = self::sanitize_key( $name );
|
||||
return isset( $options[ $name ] ) ? $options[ $name ] : $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set data.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $key Unique object key.
|
||||
* @param mixed $data Any kind of data.
|
||||
*/
|
||||
public function set_data( $key, $data ) {
|
||||
if ( ! empty( $key ) ) {
|
||||
if ( is_array( $data ) ) {
|
||||
$data = self::convert_data( $data );
|
||||
}
|
||||
$key = self::sanitize_key( $key );
|
||||
// @codingStandardsIgnoreStart
|
||||
$this->data->$key = $data;
|
||||
// @codingStandardsIgnoreEnd
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param string $key Unique object key.
|
||||
* @return string|object
|
||||
*/
|
||||
public function get_data( $key ) {
|
||||
return isset( $this->data->$key ) ? $this->data->$key : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the plugin slug.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_slug() {
|
||||
return $this->slug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the plugin version number.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_version() {
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the plugin URL.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_plugin_url() {
|
||||
return $this->plugin_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the plugin path.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_plugin_path() {
|
||||
return $this->plugin_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the plugin page URL.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_page_url() {
|
||||
return $this->page_url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the option settings name.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_option_name() {
|
||||
return $this->option_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin UI class.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return Envato_Market_Admin
|
||||
*/
|
||||
public function admin() {
|
||||
return Envato_Market_Admin::instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Envato API class.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return Envato_Market_API
|
||||
*/
|
||||
public function api() {
|
||||
return Envato_Market_API::instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Items class.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @return Envato_Market_Items
|
||||
*/
|
||||
public function items() {
|
||||
return Envato_Market_Items::instance();
|
||||
}
|
||||
|
||||
public function get_envato_api_domain() {
|
||||
return $this->envato_api_domain;
|
||||
}
|
||||
|
||||
public function get_envato_api_headers() {
|
||||
return $this->envato_api_headers;
|
||||
}
|
||||
}
|
||||
|
||||
endif;
|
||||
284
wp-content/plugins/envato-market/js/envato-market.js
Normal file
284
wp-content/plugins/envato-market/js/envato-market.js
Normal file
@@ -0,0 +1,284 @@
|
||||
/* global _envatoMarket, tb_click */
|
||||
|
||||
/**
|
||||
* Envato Market sripts.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
(function( $ ) {
|
||||
'use strict';
|
||||
var dialog, envatoMarket = {
|
||||
|
||||
cache: {},
|
||||
|
||||
init: function () {
|
||||
this.bindEvents()
|
||||
},
|
||||
|
||||
bindEvents: function () {
|
||||
const self = this
|
||||
|
||||
self.addItem()
|
||||
self.removeItem()
|
||||
self.tabbedNav()
|
||||
|
||||
$(document).on('click', '.envato-card a.thickbox', function () {
|
||||
tb_click.call(this)
|
||||
$('#TB_title').css({ 'background-color': '#23282d', color: '#cfcfcf' })
|
||||
return false
|
||||
})
|
||||
},
|
||||
|
||||
addItem: function () {
|
||||
$(document).on('click', '.add-envato-market-item', function (event) {
|
||||
const id = 'envato-market-dialog-form'
|
||||
event.preventDefault()
|
||||
|
||||
if ($('#' + id).length === 0) {
|
||||
$('body').append(wp.template(id))
|
||||
}
|
||||
|
||||
dialog = $('#' + id).dialog({
|
||||
autoOpen: true,
|
||||
modal: true,
|
||||
width: 350,
|
||||
buttons: {
|
||||
Save: {
|
||||
text: _envatoMarket.i18n.save,
|
||||
click: function () {
|
||||
const form = $(this)
|
||||
let request; let token; let input_id
|
||||
|
||||
form.on('submit', function (event) {
|
||||
event.preventDefault()
|
||||
})
|
||||
|
||||
token = form.find('input[name="token"]').val()
|
||||
input_id = form.find('input[name="id"]').val()
|
||||
|
||||
request = wp.ajax.post(_envatoMarket.action + '_add_item', {
|
||||
nonce: _envatoMarket.nonce,
|
||||
token,
|
||||
id: input_id
|
||||
})
|
||||
|
||||
request.done(function (response) {
|
||||
const item = wp.template('envato-market-item')
|
||||
const card = wp.template('envato-market-card')
|
||||
const button = wp.template('envato-market-auth-check-button')
|
||||
|
||||
$('.nav-tab-wrapper').find('[data-id="' + response.type + '"]').removeClass('hidden')
|
||||
|
||||
response.item.type = response.type
|
||||
$('#' + response.type + 's').append(card(response.item)).removeClass('hidden')
|
||||
|
||||
$('#envato-market-items').append(item({
|
||||
name: response.name,
|
||||
token: response.token,
|
||||
id: response.id,
|
||||
key: response.key,
|
||||
type: response.type,
|
||||
authorized: response.authorized
|
||||
}))
|
||||
|
||||
if ($('.auth-check-button').length === 0) {
|
||||
$('p.submit').append(button)
|
||||
}
|
||||
|
||||
dialog.dialog('close')
|
||||
envatoMarket.addReadmore()
|
||||
})
|
||||
|
||||
request.fail(function (response) {
|
||||
const template = wp.template('envato-market-dialog-error')
|
||||
const data = {
|
||||
message: (response.message ? response.message : _envatoMarket.i18n.error)
|
||||
}
|
||||
|
||||
dialog.find('.notice').remove()
|
||||
dialog.find('form').prepend(template(data))
|
||||
dialog.find('.notice').fadeIn('fast')
|
||||
})
|
||||
}
|
||||
},
|
||||
Cancel: {
|
||||
text: _envatoMarket.i18n.cancel,
|
||||
click: function () {
|
||||
dialog.dialog('close')
|
||||
}
|
||||
}
|
||||
},
|
||||
close: function () {
|
||||
dialog.find('.notice').remove()
|
||||
dialog.find('form')[0].reset()
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
removeItem: function () {
|
||||
$(document).on('click', '#envato-market-items .item-delete', function (event) {
|
||||
const self = this; const id = 'envato-market-dialog-remove'
|
||||
event.preventDefault()
|
||||
|
||||
if ($('#' + id).length === 0) {
|
||||
$('body').append(wp.template(id))
|
||||
}
|
||||
|
||||
dialog = $('#' + id).dialog({
|
||||
autoOpen: true,
|
||||
modal: true,
|
||||
width: 350,
|
||||
buttons: {
|
||||
Save: {
|
||||
text: _envatoMarket.i18n.remove,
|
||||
click: function () {
|
||||
const form = $(this)
|
||||
let request; let id
|
||||
|
||||
form.on('submit', function (submit_event) {
|
||||
submit_event.preventDefault()
|
||||
})
|
||||
|
||||
id = $(self).parents('li').data('id')
|
||||
|
||||
request = wp.ajax.post(_envatoMarket.action + '_remove_item', {
|
||||
nonce: _envatoMarket.nonce,
|
||||
id
|
||||
})
|
||||
|
||||
request.done(function () {
|
||||
const item = $('.col[data-id="' + id + '"]')
|
||||
const type = item.find('.envato-card').hasClass('theme') ? 'theme' : 'plugin'
|
||||
|
||||
item.remove()
|
||||
|
||||
if ($('#' + type + 's').find('.col').length === 0) {
|
||||
$('.nav-tab-wrapper').find('[data-id="' + type + '"]').addClass('hidden')
|
||||
$('#' + type + 's').addClass('hidden')
|
||||
}
|
||||
|
||||
$(self).parents('li').remove()
|
||||
|
||||
$('#envato-market-items li').each(function (index) {
|
||||
$(this).find('input').each(function () {
|
||||
$(this).attr('name', $(this).attr('name').replace(/\[\d\]/g, '[' + index + ']'))
|
||||
})
|
||||
})
|
||||
|
||||
if ($('.auth-check-button').length !== 0 && $('#envato-market-items li').length === 0) {
|
||||
$('p.submit .auth-check-button').remove()
|
||||
}
|
||||
|
||||
dialog.dialog('close')
|
||||
})
|
||||
|
||||
request.fail(function (response) {
|
||||
const template = wp.template('envato-market-dialog-error')
|
||||
const data = {
|
||||
message: response.message ? response.message : _envatoMarket.i18n.error
|
||||
}
|
||||
|
||||
dialog.find('.notice').remove()
|
||||
dialog.find('form').prepend(template(data))
|
||||
dialog.find('.notice').fadeIn('fast')
|
||||
})
|
||||
}
|
||||
},
|
||||
Cancel: {
|
||||
text: _envatoMarket.i18n.cancel,
|
||||
click: function () {
|
||||
dialog.dialog('close')
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
tabbedNav: function () {
|
||||
const self = this
|
||||
const $wrap = $('.about-wrap')
|
||||
|
||||
// Hide all panels
|
||||
$('div.panel', $wrap).hide()
|
||||
|
||||
const tab = self.getParameterByName('tab')
|
||||
const hashTab = window.location.hash.substr(1)
|
||||
|
||||
// Listen for the click event.
|
||||
$(document, $wrap).on('click', '.nav-tab-wrapper a', function () {
|
||||
// Deactivate and hide all tabs & panels.
|
||||
$('.nav-tab-wrapper a', $wrap).removeClass('nav-tab-active')
|
||||
$('div.panel', $wrap).hide()
|
||||
|
||||
// Activate and show the selected tab and panel.
|
||||
$(this).addClass('nav-tab-active')
|
||||
$('div' + $(this).attr('href'), $wrap).show()
|
||||
|
||||
self.maybeLoadhealthcheck()
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
if (tab) {
|
||||
$('.nav-tab-wrapper a[href="#' + tab + '"]', $wrap).click()
|
||||
} else if (hashTab) {
|
||||
$('.nav-tab-wrapper a[href="#' + hashTab + '"]', $wrap).click()
|
||||
} else {
|
||||
$('div.panel:not(.hidden)', $wrap).first().show()
|
||||
}
|
||||
},
|
||||
|
||||
getParameterByName: function (name) {
|
||||
let regex, results
|
||||
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]')
|
||||
regex = new RegExp('[\\?&]' + name + '=([^&#]*)')
|
||||
results = regex.exec(location.search)
|
||||
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '))
|
||||
},
|
||||
|
||||
maybeLoadhealthcheck: function () {
|
||||
// We only load the health check ajax call when the envato-market-healthcheck div is visible on the page.
|
||||
const $healthCheckOutput = $('.envato-market-healthcheck')
|
||||
if ($healthCheckOutput.is(':visible')) {
|
||||
$healthCheckOutput.text('Loading...')
|
||||
|
||||
// Use our existing wp.ajax.post pattern from above to call the healthcheck API endpoint
|
||||
const request = wp.ajax.post(_envatoMarket.action + '_healthcheck', {
|
||||
nonce: _envatoMarket.nonce
|
||||
})
|
||||
|
||||
request.done(function (response) {
|
||||
if (response && response.limits) {
|
||||
const $healthCheckUL = $('<ul></ul>')
|
||||
const limits = Object.keys(response.limits)
|
||||
for (let i = 0; i < limits.length; i++) {
|
||||
const $healthCheckLI = $('<li></li>')
|
||||
const healthCheckItem = response.limits[limits[i]]
|
||||
$healthCheckLI.addClass(healthCheckItem.ok ? 'healthcheck-ok' : 'healthcheck-error')
|
||||
$healthCheckLI.attr('data-limit', limits[i])
|
||||
$healthCheckLI.append('<span class="healthcheck-item-title">' + healthCheckItem.title + '</span>')
|
||||
$healthCheckLI.append('<span class="healthcheck-item-message">' + healthCheckItem.message + '</span>')
|
||||
$healthCheckUL.append($healthCheckLI)
|
||||
}
|
||||
$healthCheckOutput.html($healthCheckUL)
|
||||
} else {
|
||||
window.console.log(response)
|
||||
$healthCheckOutput.text('Health check failed to load. Please check console for errors.')
|
||||
}
|
||||
})
|
||||
|
||||
request.fail(function (response) {
|
||||
window.console.log(response)
|
||||
$healthCheckOutput.text('Health check failed to load. Please check console for errors.')
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$(window).on('load', function () {
|
||||
envatoMarket.init()
|
||||
})
|
||||
})(jQuery)
|
||||
1
wp-content/plugins/envato-market/js/envato-market.min.js
vendored
Normal file
1
wp-content/plugins/envato-market/js/envato-market.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
!function(r){"use strict";var o,i={cache:{},init:function(){this.bindEvents()},bindEvents:function(){var e=this;e.addItem(),e.removeItem(),e.tabbedNav(),r(document).on("click",".envato-card a.thickbox",function(){return tb_click.call(this),r("#TB_title").css({"background-color":"#23282d",color:"#cfcfcf"}),!1})},addItem:function(){r(document).on("click",".add-envato-market-item",function(e){var t="envato-market-dialog-form";e.preventDefault(),0===r("#"+t).length&&r("body").append(wp.template(t)),o=r("#"+t).dialog({autoOpen:!0,modal:!0,width:350,buttons:{Save:{text:_envatoMarket.i18n.save,click:function(){var e,t=r(this);t.on("submit",function(e){e.preventDefault()}),e=t.find('input[name="token"]').val(),t=t.find('input[name="id"]').val(),(e=wp.ajax.post(_envatoMarket.action+"_add_item",{nonce:_envatoMarket.nonce,token:e,id:t})).done(function(e){var t=wp.template("envato-market-item"),a=wp.template("envato-market-card"),n=wp.template("envato-market-auth-check-button");r(".nav-tab-wrapper").find('[data-id="'+e.type+'"]').removeClass("hidden"),e.item.type=e.type,r("#"+e.type+"s").append(a(e.item)).removeClass("hidden"),r("#envato-market-items").append(t({name:e.name,token:e.token,id:e.id,key:e.key,type:e.type,authorized:e.authorized})),0===r(".auth-check-button").length&&r("p.submit").append(n),o.dialog("close"),i.addReadmore()}),e.fail(function(e){var t=wp.template("envato-market-dialog-error"),e={message:e.message||_envatoMarket.i18n.error};o.find(".notice").remove(),o.find("form").prepend(t(e)),o.find(".notice").fadeIn("fast")})}},Cancel:{text:_envatoMarket.i18n.cancel,click:function(){o.dialog("close")}}},close:function(){o.find(".notice").remove(),o.find("form")[0].reset()}})})},removeItem:function(){r(document).on("click","#envato-market-items .item-delete",function(e){const n=this;var t="envato-market-dialog-remove";e.preventDefault(),0===r("#"+t).length&&r("body").append(wp.template(t)),o=r("#"+t).dialog({autoOpen:!0,modal:!0,width:350,buttons:{Save:{text:_envatoMarket.i18n.remove,click:function(){var e=r(this);let a;e.on("submit",function(e){e.preventDefault()}),a=r(n).parents("li").data("id"),(e=wp.ajax.post(_envatoMarket.action+"_remove_item",{nonce:_envatoMarket.nonce,id:a})).done(function(){var e=r('.col[data-id="'+a+'"]'),t=e.find(".envato-card").hasClass("theme")?"theme":"plugin";e.remove(),0===r("#"+t+"s").find(".col").length&&(r(".nav-tab-wrapper").find('[data-id="'+t+'"]').addClass("hidden"),r("#"+t+"s").addClass("hidden")),r(n).parents("li").remove(),r("#envato-market-items li").each(function(e){r(this).find("input").each(function(){r(this).attr("name",r(this).attr("name").replace(/\[\d\]/g,"["+e+"]"))})}),0!==r(".auth-check-button").length&&0===r("#envato-market-items li").length&&r("p.submit .auth-check-button").remove(),o.dialog("close")}),e.fail(function(e){var t=wp.template("envato-market-dialog-error"),e={message:e.message||_envatoMarket.i18n.error};o.find(".notice").remove(),o.find("form").prepend(t(e)),o.find(".notice").fadeIn("fast")})}},Cancel:{text:_envatoMarket.i18n.cancel,click:function(){o.dialog("close")}}}})})},tabbedNav:function(){const e=this,t=r(".about-wrap");r("div.panel",t).hide();var a=e.getParameterByName("tab"),n=window.location.hash.substr(1);r(document,t).on("click",".nav-tab-wrapper a",function(){return r(".nav-tab-wrapper a",t).removeClass("nav-tab-active"),r("div.panel",t).hide(),r(this).addClass("nav-tab-active"),r("div"+r(this).attr("href"),t).show(),e.maybeLoadhealthcheck(),!1}),a?r('.nav-tab-wrapper a[href="#'+a+'"]',t).click():n?r('.nav-tab-wrapper a[href="#'+n+'"]',t).click():r("div.panel:not(.hidden)",t).first().show()},getParameterByName:function(e){return e=e.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]"),null===(e=new RegExp("[\\?&]"+e+"=([^&#]*)").exec(location.search))?"":decodeURIComponent(e[1].replace(/\+/g," "))},maybeLoadhealthcheck:function(){const c=r(".envato-market-healthcheck");var e;c.is(":visible")&&(c.text("Loading..."),(e=wp.ajax.post(_envatoMarket.action+"_healthcheck",{nonce:_envatoMarket.nonce})).done(function(t){if(t&&t.limits){var a=r("<ul></ul>"),n=Object.keys(t.limits);for(let e=0;e<n.length;e++){var o=r("<li></li>"),i=t.limits[n[e]];o.addClass(i.ok?"healthcheck-ok":"healthcheck-error"),o.attr("data-limit",n[e]),o.append('<span class="healthcheck-item-title">'+i.title+"</span>"),o.append('<span class="healthcheck-item-message">'+i.message+"</span>"),a.append(o)}c.html(a)}else window.console.log(t),c.text("Health check failed to load. Please check console for errors.")}),e.fail(function(e){window.console.log(e),c.text("Health check failed to load. Please check console for errors.")}))}};r(window).on("load",function(){i.init()})}(jQuery);
|
||||
597
wp-content/plugins/envato-market/js/updates.js
Normal file
597
wp-content/plugins/envato-market/js/updates.js
Normal file
@@ -0,0 +1,597 @@
|
||||
/* global tb_remove, JSON */
|
||||
window.wp = window.wp || {};
|
||||
|
||||
(function ($, wp) {
|
||||
'use strict'
|
||||
|
||||
wp.envato = {}
|
||||
|
||||
/**
|
||||
* User nonce for ajax calls.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
wp.envato.ajaxNonce = window._wpUpdatesSettings.ajax_nonce
|
||||
|
||||
/**
|
||||
* Whether filesystem credentials need to be requested from the user.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
wp.envato.shouldRequestFilesystemCredentials = null
|
||||
|
||||
/**
|
||||
* Filesystem credentials to be packaged along with the request.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
wp.envato.filesystemCredentials = {
|
||||
ftp: {
|
||||
host: null,
|
||||
username: null,
|
||||
password: null,
|
||||
connectionType: null
|
||||
},
|
||||
ssh: {
|
||||
publicKey: null,
|
||||
privateKey: null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag if we're waiting for an update to complete.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
wp.envato.updateLock = false
|
||||
|
||||
/**
|
||||
* * Flag if we've done an update successfully.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
wp.envato.updateDoneSuccessfully = false
|
||||
|
||||
/**
|
||||
* If the user tries to update a plugin while an update is
|
||||
* already happening, it can be placed in this queue to perform later.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
wp.envato.updateQueue = []
|
||||
|
||||
/**
|
||||
* Store a jQuery reference to return focus to when exiting the request credentials modal.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @var jQuery object
|
||||
*/
|
||||
wp.envato.$elToReturnFocusToFromCredentialsModal = null
|
||||
|
||||
/**
|
||||
* Decrement update counts throughout the various menus.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @param {string} upgradeType
|
||||
*/
|
||||
wp.envato.decrementCount = function (upgradeType) {
|
||||
var count
|
||||
var pluginCount
|
||||
const $adminBarUpdateCount = $('#wp-admin-bar-updates .ab-label')
|
||||
const $dashboardNavMenuUpdateCount = $('a[href="update-core.php"] .update-plugins')
|
||||
const $pluginsMenuItem = $('#menu-plugins')
|
||||
|
||||
count = $adminBarUpdateCount.text()
|
||||
count = parseInt(count, 10) - 1
|
||||
if (count < 0 || isNaN(count)) {
|
||||
return
|
||||
}
|
||||
$('#wp-admin-bar-updates .ab-item').removeAttr('title')
|
||||
$adminBarUpdateCount.text(count)
|
||||
|
||||
$dashboardNavMenuUpdateCount.each(function (index, elem) {
|
||||
elem.className = elem.className.replace(/count-\d+/, 'count-' + count)
|
||||
})
|
||||
$dashboardNavMenuUpdateCount.removeAttr('title')
|
||||
$dashboardNavMenuUpdateCount.find('.update-count').text(count)
|
||||
|
||||
if (upgradeType === 'plugin') {
|
||||
pluginCount = $pluginsMenuItem.find('.plugin-count').eq(0).text()
|
||||
pluginCount = parseInt(pluginCount, 10) - 1
|
||||
if (pluginCount < 0 || isNaN(pluginCount)) {
|
||||
return
|
||||
}
|
||||
$pluginsMenuItem.find('.plugin-count').text(pluginCount)
|
||||
$pluginsMenuItem.find('.update-plugins').each(function (index, elem) {
|
||||
elem.className = elem.className.replace(/count-\d+/, 'count-' + pluginCount)
|
||||
})
|
||||
|
||||
if (pluginCount > 0) {
|
||||
$('.subsubsub .upgrade .count').text('(' + pluginCount + ')')
|
||||
} else {
|
||||
$('.subsubsub .upgrade').remove()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an Ajax request to the server to update a plugin.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param {string} plugin
|
||||
* @param {string} slug
|
||||
*/
|
||||
wp.envato.updatePlugin = function (plugin, slug) {
|
||||
let data
|
||||
const $message = $('.envato-card-' + slug).find('.update-now')
|
||||
const name = $message.data('name')
|
||||
|
||||
const updatingMessage = wp.i18n.sprintf(wp.i18n.__('Updating %s...', 'envato-market'), name)
|
||||
$message.attr('aria-label', updatingMessage)
|
||||
|
||||
$message.addClass('updating-message')
|
||||
if ($message.html() !== updatingMessage) {
|
||||
$message.data('originaltext', $message.html())
|
||||
}
|
||||
|
||||
$message.text(updatingMessage)
|
||||
|
||||
if (wp.envato.updateLock) {
|
||||
wp.envato.updateQueue.push({
|
||||
type: 'update-plugin',
|
||||
data: {
|
||||
plugin,
|
||||
slug
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
wp.envato.updateLock = true
|
||||
|
||||
data = {
|
||||
_ajax_nonce: wp.envato.ajaxNonce,
|
||||
plugin,
|
||||
slug,
|
||||
username: wp.envato.filesystemCredentials.ftp.username,
|
||||
password: wp.envato.filesystemCredentials.ftp.password,
|
||||
hostname: wp.envato.filesystemCredentials.ftp.hostname,
|
||||
connection_type: wp.envato.filesystemCredentials.ftp.connectionType,
|
||||
public_key: wp.envato.filesystemCredentials.ssh.publicKey,
|
||||
private_key: wp.envato.filesystemCredentials.ssh.privateKey
|
||||
}
|
||||
|
||||
wp.ajax.post('update-plugin', data)
|
||||
.done(wp.envato.updateSuccess)
|
||||
.fail(wp.envato.updateError)
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an Ajax request to the server to update a theme.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param {string} plugin
|
||||
* @param {string} slug
|
||||
*/
|
||||
wp.envato.updateTheme = function (slug) {
|
||||
let data
|
||||
const $message = $('.envato-card-' + slug).find('.update-now')
|
||||
const name = $message.data('name')
|
||||
|
||||
const updatingMessage = wp.i18n.sprintf(wp.i18n.__('Updating %s...', 'envato-market'), name)
|
||||
$message.attr('aria-label', updatingMessage)
|
||||
|
||||
$message.addClass('updating-message')
|
||||
if ($message.html() !== updatingMessage) {
|
||||
$message.data('originaltext', $message.html())
|
||||
}
|
||||
|
||||
$message.text(updatingMessage)
|
||||
|
||||
if (wp.envato.updateLock) {
|
||||
wp.envato.updateQueue.push({
|
||||
type: 'update-theme',
|
||||
data: {
|
||||
theme: slug
|
||||
}
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
wp.envato.updateLock = true
|
||||
|
||||
data = {
|
||||
_ajax_nonce: wp.envato.ajaxNonce,
|
||||
theme: slug,
|
||||
slug,
|
||||
username: wp.envato.filesystemCredentials.ftp.username,
|
||||
password: wp.envato.filesystemCredentials.ftp.password,
|
||||
hostname: wp.envato.filesystemCredentials.ftp.hostname,
|
||||
connection_type: wp.envato.filesystemCredentials.ftp.connectionType,
|
||||
public_key: wp.envato.filesystemCredentials.ssh.publicKey,
|
||||
private_key: wp.envato.filesystemCredentials.ssh.privateKey
|
||||
}
|
||||
|
||||
wp.ajax.post('update-theme', data)
|
||||
.done(wp.envato.updateSuccess)
|
||||
.fail(wp.envato.updateError)
|
||||
}
|
||||
|
||||
/**
|
||||
* On a successful plugin update, update the UI with the result.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param {object} response
|
||||
*/
|
||||
wp.envato.updateSuccess = function (response) {
|
||||
let $card, $updateColumn, $updateMessage, $updateVersion, name, version, versionText
|
||||
|
||||
$card = $('.envato-card-' + response.slug)
|
||||
$updateColumn = $card.find('.column-update')
|
||||
$updateMessage = $card.find('.update-now')
|
||||
$updateVersion = $card.find('.version')
|
||||
|
||||
name = $updateMessage.data('name')
|
||||
version = $updateMessage.data('version')
|
||||
versionText = $updateVersion.attr('aria-label').replace('%s', version)
|
||||
|
||||
$updateMessage.addClass('disabled')
|
||||
|
||||
const updateMessage = wp.i18n.sprintf(wp.i18n.__('Updating %s...', 'envato-market'), name)
|
||||
$updateMessage.attr('aria-label', updateMessage)
|
||||
$updateVersion.text(versionText)
|
||||
|
||||
$updateMessage.removeClass('updating-message').addClass('updated-message')
|
||||
$updateMessage.text(wp.i18n.__('Updated!', 'envato-market'))
|
||||
wp.a11y.speak(updateMessage)
|
||||
$updateColumn.addClass('update-complete').delay(1000).fadeOut()
|
||||
|
||||
wp.envato.decrementCount('plugin')
|
||||
|
||||
wp.envato.updateDoneSuccessfully = true
|
||||
|
||||
/*
|
||||
* The lock can be released since the update was successful,
|
||||
* and any other updates can commence.
|
||||
*/
|
||||
wp.envato.updateLock = false
|
||||
|
||||
$(document).trigger('envato-update-success', response)
|
||||
|
||||
wp.envato.queueChecker()
|
||||
}
|
||||
|
||||
/**
|
||||
* On a plugin update error, update the UI appropriately.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param {object} response
|
||||
*/
|
||||
wp.envato.updateError = function (response) {
|
||||
let $message, name
|
||||
wp.envato.updateDoneSuccessfully = false
|
||||
if (response.errorCode && response.errorCode === 'unable_to_connect_to_filesystem' && wp.envato.shouldRequestFilesystemCredentials) {
|
||||
wp.envato.credentialError(response, 'update-plugin')
|
||||
return
|
||||
}
|
||||
$message = $('.envato-card-' + response.slug).find('.update-now')
|
||||
|
||||
name = $message.data('name')
|
||||
$message.attr('aria-label', wp.i18n.__('Updating failed', 'envato-market'))
|
||||
|
||||
$message.removeClass('updating-message')
|
||||
$message.html(wp.i18n.sprintf(wp.i18n.__('Updating failed %s...', 'envato-market'), typeof 'undefined' !== response.errorMessage ? response.errorMessage : response.error))
|
||||
|
||||
/*
|
||||
* The lock can be released since this failure was
|
||||
* after the credentials form.
|
||||
*/
|
||||
wp.envato.updateLock = false
|
||||
|
||||
$(document).trigger('envato-update-error', response)
|
||||
|
||||
wp.envato.queueChecker()
|
||||
}
|
||||
|
||||
/**
|
||||
* Show an error message in the request for credentials form.
|
||||
*
|
||||
* @param {string} message
|
||||
* @since 1.0.0
|
||||
*/
|
||||
wp.envato.showErrorInCredentialsForm = function (message) {
|
||||
const $modal = $('.notification-dialog')
|
||||
|
||||
// Remove any existing error.
|
||||
$modal.find('.error').remove()
|
||||
|
||||
$modal.find('h3').after('<div class="error">' + message + '</div>')
|
||||
}
|
||||
|
||||
/**
|
||||
* Events that need to happen when there is a credential error
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
wp.envato.credentialError = function (response, type) {
|
||||
wp.envato.updateQueue.push({
|
||||
type,
|
||||
data: {
|
||||
|
||||
// Not cool that we're depending on response for this data.
|
||||
// This would feel more whole in a view all tied together.
|
||||
plugin: response.plugin,
|
||||
slug: response.slug
|
||||
}
|
||||
})
|
||||
wp.envato.showErrorInCredentialsForm(response.error)
|
||||
wp.envato.requestFilesystemCredentials()
|
||||
}
|
||||
|
||||
/**
|
||||
* If an update job has been placed in the queue, queueChecker pulls it out and runs it.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
wp.envato.queueChecker = function () {
|
||||
let job
|
||||
|
||||
if (wp.envato.updateLock || wp.envato.updateQueue.length <= 0) {
|
||||
return
|
||||
}
|
||||
|
||||
job = wp.envato.updateQueue.shift()
|
||||
|
||||
wp.envato.updatePlugin(job.data.plugin, job.data.slug)
|
||||
}
|
||||
|
||||
/**
|
||||
* Request the users filesystem credentials if we don't have them already.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
wp.envato.requestFilesystemCredentials = function (event) {
|
||||
if (wp.envato.updateDoneSuccessfully === false) {
|
||||
wp.envato.$elToReturnFocusToFromCredentialsModal = $(event.target)
|
||||
|
||||
wp.envato.updateLock = true
|
||||
|
||||
wp.envato.requestForCredentialsModalOpen()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Keydown handler for the request for credentials modal.
|
||||
*
|
||||
* Close the modal when the escape key is pressed.
|
||||
* Constrain keyboard navigation to inside the modal.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
wp.envato.keydown = function (event) {
|
||||
if (event.keyCode === 27) {
|
||||
wp.envato.requestForCredentialsModalCancel()
|
||||
} else if (event.keyCode === 9) {
|
||||
// #upgrade button must always be the last focusable element in the dialog.
|
||||
if (event.target.id === 'upgrade' && !event.shiftKey) {
|
||||
$('#hostname').focus()
|
||||
event.preventDefault()
|
||||
} else if (event.target.id === 'hostname' && event.shiftKey) {
|
||||
$('#upgrade').focus()
|
||||
event.preventDefault()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open the request for credentials modal.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
wp.envato.requestForCredentialsModalOpen = function () {
|
||||
const $modal = $('#request-filesystem-credentials-dialog')
|
||||
$('body').addClass('modal-open')
|
||||
$modal.show()
|
||||
|
||||
$modal.find('input:enabled:first').focus()
|
||||
$modal.keydown(wp.envato.keydown)
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the request for credentials modal.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
wp.envato.requestForCredentialsModalClose = function () {
|
||||
$('#request-filesystem-credentials-dialog').hide()
|
||||
$('body').removeClass('modal-open')
|
||||
wp.envato.$elToReturnFocusToFromCredentialsModal.focus()
|
||||
}
|
||||
|
||||
/**
|
||||
* The steps that need to happen when the modal is canceled out
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
wp.envato.requestForCredentialsModalCancel = function () {
|
||||
let slug, $message
|
||||
|
||||
// No updateLock and no updateQueue means we already have cleared things up
|
||||
if (wp.envato.updateLock === false && wp.envato.updateQueue.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
slug = wp.envato.updateQueue[0].data.slug,
|
||||
|
||||
// Remove the lock, and clear the queue
|
||||
wp.envato.updateLock = false
|
||||
wp.envato.updateQueue = []
|
||||
|
||||
wp.envato.requestForCredentialsModalClose()
|
||||
$message = $('.envato-card-' + slug).find('.update-now')
|
||||
|
||||
$message.removeClass('updating-message')
|
||||
$message.html($message.data('originaltext'))
|
||||
}
|
||||
/**
|
||||
* Potentially add an AYS to a user attempting to leave the page
|
||||
*
|
||||
* If an update is on-going and a user attempts to leave the page,
|
||||
* open an "Are you sure?" alert.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
|
||||
wp.envato.beforeunload = function () {
|
||||
if (wp.envato.updateLock) {
|
||||
return wp.i18n.__('Update in progress, really leave?', 'envato-market')
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
/*
|
||||
* Check whether a user needs to submit filesystem credentials based on whether
|
||||
* the form was output on the page server-side.
|
||||
*
|
||||
* @see {wp_print_request_filesystem_credentials_modal() in PHP}
|
||||
*/
|
||||
wp.envato.shouldRequestFilesystemCredentials = !(($('#request-filesystem-credentials-dialog').length <= 0))
|
||||
|
||||
// File system credentials form submit noop-er / handler.
|
||||
$('#request-filesystem-credentials-dialog form').on('submit', function () {
|
||||
// Persist the credentials input by the user for the duration of the page load.
|
||||
wp.envato.filesystemCredentials.ftp.hostname = $('#hostname').val()
|
||||
wp.envato.filesystemCredentials.ftp.username = $('#username').val()
|
||||
wp.envato.filesystemCredentials.ftp.password = $('#password').val()
|
||||
wp.envato.filesystemCredentials.ftp.connectionType = $('input[name="connection_type"]:checked').val()
|
||||
wp.envato.filesystemCredentials.ssh.publicKey = $('#public_key').val()
|
||||
wp.envato.filesystemCredentials.ssh.privateKey = $('#private_key').val()
|
||||
|
||||
wp.envato.requestForCredentialsModalClose()
|
||||
|
||||
// Unlock and invoke the queue.
|
||||
wp.envato.updateLock = false
|
||||
wp.envato.queueChecker()
|
||||
|
||||
return false
|
||||
})
|
||||
|
||||
// Close the request credentials modal when
|
||||
$('#request-filesystem-credentials-dialog [data-js-action="close"], .notification-dialog-background').on('click', function () {
|
||||
wp.envato.requestForCredentialsModalCancel()
|
||||
})
|
||||
|
||||
// Hide SSH fields when not selected
|
||||
$('#request-filesystem-credentials-dialog input[name="connection_type"]').on('change', function () {
|
||||
$(this).parents('form').find('#private_key, #public_key').parents('label').toggle(($(this).val() === 'ssh'))
|
||||
}).change()
|
||||
|
||||
// Click handler for plugin updates.
|
||||
$('.envato-card.plugin').on('click', '.update-now', function (e) {
|
||||
const $button = $(e.target)
|
||||
e.preventDefault()
|
||||
|
||||
if (wp.envato.shouldRequestFilesystemCredentials && !wp.envato.updateLock) {
|
||||
wp.envato.requestFilesystemCredentials(e)
|
||||
}
|
||||
|
||||
wp.envato.updatePlugin($button.data('plugin'), $button.data('slug'))
|
||||
})
|
||||
|
||||
// Click handler for theme updates.
|
||||
$('.envato-card.theme').on('click', '.update-now', function (e) {
|
||||
const $button = $(e.target)
|
||||
e.preventDefault()
|
||||
|
||||
if (wp.envato.shouldRequestFilesystemCredentials && !wp.envato.updateLock) {
|
||||
wp.envato.requestFilesystemCredentials(e)
|
||||
}
|
||||
|
||||
wp.envato.updateTheme($button.data('slug'))
|
||||
})
|
||||
|
||||
// @todo
|
||||
$('#plugin_update_from_iframe').on('click', function (e) {
|
||||
let target, data
|
||||
|
||||
target = window.parent === window ? null : window.parent,
|
||||
$.support.postMessage = !!window.postMessage
|
||||
|
||||
if ($.support.postMessage === false || target === null || window.parent.location.pathname.indexOf('update-core.php') !== -1) {
|
||||
return
|
||||
}
|
||||
|
||||
e.preventDefault()
|
||||
|
||||
data = {
|
||||
action: 'updatePlugin',
|
||||
slug: $(this).data('slug')
|
||||
}
|
||||
|
||||
target.postMessage(JSON.stringify(data), window.location.origin)
|
||||
})
|
||||
})
|
||||
|
||||
$(window).on('message', function (e) {
|
||||
const event = e.originalEvent
|
||||
let message
|
||||
const loc = document.location
|
||||
const expectedOrigin = loc.protocol + '//' + loc.hostname
|
||||
|
||||
if (event.origin !== expectedOrigin) {
|
||||
return
|
||||
}
|
||||
|
||||
if (event.data) {
|
||||
try {
|
||||
message = $.parseJSON(event.data)
|
||||
} catch (error) {
|
||||
message = event.data
|
||||
}
|
||||
|
||||
try {
|
||||
if (typeof message.action === 'undefined') {
|
||||
return
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
|
||||
try {
|
||||
switch (message.action) {
|
||||
case 'decrementUpdateCount' :
|
||||
wp.envato.decrementCount(message.upgradeType)
|
||||
break
|
||||
case 'updatePlugin' :
|
||||
tb_remove()
|
||||
$('.envato-card-' + message.slug).find('h4 a').focus()
|
||||
$('.envato-card-' + message.slug).find('[data-slug="' + message.slug + '"]').trigger('click')
|
||||
break
|
||||
default:
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
$(window).on('beforeunload', wp.envato.beforeunload)
|
||||
})(jQuery, window.wp, window.ajaxurl)
|
||||
1
wp-content/plugins/envato-market/js/updates.min.js
vendored
Normal file
1
wp-content/plugins/envato-market/js/updates.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
14
wp-content/plugins/envato-market/readme.txt
Normal file
14
wp-content/plugins/envato-market/readme.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
=== Envato Market ===
|
||||
Website: https://www.envato.com/lp/market-plugin/
|
||||
Contributors: valendesigns, dtbaker, aaronrutley
|
||||
Requires at least: 5.1
|
||||
Tested up to: 6.1
|
||||
Stable tag: 2.0.12
|
||||
License: GPLv2 or later
|
||||
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
|
||||
WordPress Theme & Plugin management for the Envato Market.
|
||||
|
||||
== Description ==
|
||||
|
||||
Please see https://www.envato.com/lp/market-plugin/ for more details.
|
||||
Reference in New Issue
Block a user