:\([^)]+\))?\s*)([^\s:]+)/',
function ( $matches ) use ( $variation_class ) {
return $matches[1] . $matches[2] . $variation_class;
},
$part,
$limit
);
}
return implode( ',', $result );
}
}
urchases you\'ve made',
)
);
}
/**
* Return the URL a user needs to click to generate a personal token.
*
* @single 2.0.1
*
* @return string The full URL to request a token.
*/
public function get_generate_token_url() {
return 'https://build.envato.com/create-token/?' . implode(
'&',
array_map(
function ( $val ) {
return $val . '=t';
},
array_keys( $this->get_required_permissions() )
)
);
}
/**
* Check that themes are authorized.
*
* @return bool
* @since 1.0.0
*/
public function authorize_token_permissions() {
if ( defined('ENVATO_LOCAL_DEVELOPMENT') ) {
return 'success';
}
$notice = 'success';
$response = envato_market()->api()->request( 'https://api.envato.com/whoami' );
if ( is_wp_error( $response ) && ( $response->get_error_code() === 'http_error' || $response->get_error_code() == 500 ) ) {
$this->store_additional_error_debug_information( 'An error occured checking token permissions', $response->get_error_message(), $response->get_error_data() );
$notice = 'http_error';
} elseif ( is_wp_error( $response ) || ! isset( $response['scopes'] ) || ! is_array( $response['scopes'] ) ) {
$this->store_additional_error_debug_information( 'No scopes found in API response message', $response->get_error_message(), $response->get_error_data() );
$notice = 'error';
} else {
$minimum_scopes = $this->get_required_permissions();
$maximum_scopes = array( 'default' => 'Default' ) + $minimum_scopes;
foreach ( $minimum_scopes as $required_scope => $required_scope_name ) {
if ( ! in_array( $required_scope, $response['scopes'] ) ) {
// The scope minimum required scope doesn't exist.
$this->store_additional_error_debug_information( 'Could not find required API permission scope in output.', $required_scope );
$notice = 'missing-permissions';
}
}
foreach ( $response['scopes'] as $scope ) {
if ( ! isset( $maximum_scopes[ $scope ] ) ) {
// The available scope is outside our maximum bounds.
$this->store_additional_error_debug_information( 'Found too many permissions on token.', $scope );
$notice = 'too-many-permissions';
}
}
}
return $notice;
}
/**
* Check that themes or plugins are authorized and downloadable.
*
* @param string $type The filter type, either 'themes' or 'plugins'. Default 'themes'.
*
* @return bool|null
* @since 1.0.0
*/
public function authorize_items( $type = 'themes' ) {
$domain = envato_market()->get_envato_api_domain();
$path = envato_market()->api()->api_path_for('list-purchases');
$api_url = $domain . $path . '?filter_by=wordpress-' . $type;
$response = envato_market()->api()->request( $api_url );
$notice = 'success';
if ( is_wp_error( $response ) ) {
$notice = 'error';
$this->store_additional_error_debug_information( 'Error listing buyer purchases.', $response->get_error_message(), $response->get_error_data() );
} elseif ( empty( $response ) ) {
$notice = 'error';
$this->store_additional_error_debug_information( 'Empty API result listing buyer purchases' );
} elseif ( empty( $response['results'] ) ) {
$notice = 'success-no-' . $type;
} else {
shuffle( $response['results'] );
$item = array_shift( $response['results'] );
if ( ! isset( $item['item']['id'] ) || ! envato_market()->api()->download( $item['item']['id'] ) ) {
$this->store_additional_error_debug_information( 'Failed to find the correct item format in API response' );
$notice = 'error';
}
}
return $notice;
}
/**
* Check that themes are authorized.
*
* @return bool
* @since 1.0.0
*/
public function authorize_themes() {
return $this->authorize_items( 'themes' );
}
/**
* Check that plugins are authorized.
*
* @return bool
* @since 1.0.0
*/
public function authorize_plugins() {
return $this->authorize_items( 'plugins' );
}
/**
* Install plugin.
*
* @param string $plugin The plugin item ID.
*
* @since 1.0.0
* @codeCoverageIgnore
*/
public function install_plugin( $plugin ) {
if ( ! current_user_can( 'install_plugins' ) ) {
$msg = '
';
wp_die( $msg );
}
check_admin_referer( 'install-plugin_' . $plugin );
envato_market()->items()->set_plugins( true );
$install = envato_market()->items()->plugins( 'install' );
$api = new stdClass();
foreach ( $install as $value ) {
if ( absint( $value['id'] ) === absint( $plugin ) ) {
$api->name = $value['name'];
$api->version = $value['version'];
}
}
$array_api = (array) $api;
if ( empty( $array_api ) ) {
$msg = '
';
wp_die( $msg );
}
$title = sprintf( __( 'Installing Plugin: %s', 'envato-market' ), esc_html( $api->name . ' ' . $api->version ) );
$nonce = 'install-plugin_' . $plugin;
$url = 'admin.php?page=' . envato_market()->get_slug() . '&action=install-plugin&plugin=' . urlencode( $plugin );
$type = 'web'; // Install plugin type, From Web or an Upload.
$api->download_link = envato_market()->api()->download( $plugin, $this->set_bearer_args( $plugin ) );
// Must have the upgrader & skin.
require envato_market()->get_plugin_path() . '/inc/admin/class-envato-market-theme-upgrader.php';
require envato_market()->get_plugin_path() . '/inc/admin/class-envato-market-theme-installer-skin.php';
$upgrader = new Envato_Market_Plugin_Upgrader( new Envato_Market_Plugin_Installer_Skin( compact( 'title', 'url', 'nonce', 'plugin', 'api' ) ) );
$upgrader->install( $api->download_link );
}
/**
* Install theme.
*
* @param string $theme The theme item ID.
*
* @since 1.0.0
* @codeCoverageIgnore
*/
public function install_theme( $theme ) {
if ( ! current_user_can( 'install_themes' ) ) {
$msg = '
';
wp_die( $msg );
}
check_admin_referer( 'install-theme_' . $theme );
envato_market()->items()->set_themes( true );
$install = envato_market()->items()->themes( 'install' );
$api = new stdClass();
foreach ( $install as $value ) {
if ( absint( $value['id'] ) === absint( $theme ) ) {
$api->name = $value['name'];
$api->version = $value['version'];
}
}
$array_api = (array) $api;
if ( empty( $array_api ) ) {
$msg = '
';
wp_die( $msg );
}
wp_enqueue_script( 'customize-loader' );
$title = sprintf( __( 'Installing Theme: %s', 'envato-market' ), esc_html( $api->name . ' ' . $api->version ) );
$nonce = 'install-theme_' . $theme;
$url = 'admin.php?page=' . envato_market()->get_slug() . '&action=install-theme&theme=' . urlencode( $theme );
$type = 'web'; // Install theme type, From Web or an Upload.
$api->download_link = envato_market()->api()->download( $theme, $this->set_bearer_args( $theme ) );
// Must have the upgrader & skin.
require_once envato_market()->get_plugin_path() . '/inc/admin/class-envato-market-theme-upgrader.php';
require_once envato_market()->get_plugin_path() . '/inc/admin/class-envato-market-theme-installer-skin.php';
$upgrader = new Envato_Market_Theme_Upgrader( new Envato_Market_Theme_Installer_Skin( compact( 'title', 'url', 'nonce', 'api' ) ) );
$upgrader->install( $api->download_link );
}
/**
* AJAX handler for adding items that use a non global token.
*
* @since 1.0.0
* @codeCoverageIgnore
*/
public function ajax_add_item() {
if ( ! check_ajax_referer( self::AJAX_ACTION, 'nonce', false ) ) {
status_header( 400 );
wp_send_json_error( 'bad_nonce' );
} elseif ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) {
status_header( 405 );
wp_send_json_error( 'bad_method' );
} elseif ( empty( $_POST['token'] ) ) {
wp_send_json_error( array( 'message' => __( 'The Token is missing.', 'envato-market' ) ) );
} elseif ( empty( $_POST['id'] ) ) {
wp_send_json_error( array( 'message' => __( 'The Item ID is missing.', 'envato-market' ) ) );
} elseif ( ! current_user_can( 'install_themes' ) || ! current_user_can( 'install_plugins' ) ) {
wp_send_json_error( array( 'message' => __( 'User not allowed to install items.', 'envato-market' ) ) );
}
$args = array(
'headers' => array(
'Authorization' => 'Bearer ' . $_POST['token'],
),
);
$request = envato_market()->api()->item( $_POST['id'], $args );
if ( false === $request ) {
wp_send_json_error( array( 'message' => __( 'The Token or Item ID is incorrect.', 'envato-market' ) ) );
}
if ( false === envato_market()->api()->download( $_POST['id'], $args ) ) {
wp_send_json_error( array( 'message' => __( 'The item cannot be downloaded.', 'envato-market' ) ) );
}
if ( isset( $request['number_of_sales'] ) ) {
$type = 'plugin';
} else {
$type = 'theme';
}
if ( isset( $type ) ) {
$response = array(
'name' => $request['name'],
'token' => $_POST['token'],
'id' => $_POST['id'],
'type' => $type,
'authorized' => 'success',
);
$options = get_option( envato_market()->get_option_name(), array() );
if ( ! empty( $options['items'] ) ) {
$options['items'] = array_values( $options['items'] );
$key = count( $options['items'] );
} else {
$options['items'] = array();
$key = 0;
}
$options['items'][] = $response;
envato_market()->set_options( $options );
// Rebuild the theme cache.
if ( 'theme' === $type ) {
envato_market()->items()->set_themes( true, false );
$install_link = add_query_arg(
array(
'page' => envato_market()->get_slug(),
'action' => 'install-theme',
'id' => $_POST['id'],
),
self_admin_url( 'admin.php' )
);
$request['install'] = wp_nonce_url( $install_link, 'install-theme_' . $_POST['id'] );
}
// Rebuild the plugin cache.
if ( 'plugin' === $type ) {
envato_market()->items()->set_plugins( true, false );
$install_link = add_query_arg(
array(
'page' => envato_market()->get_slug(),
'action' => 'install-plugin',
'id' => $_POST['id'],
),
self_admin_url( 'admin.php' )
);
$request['install'] = wp_nonce_url( $install_link, 'install-plugin_' . $_POST['id'] );
}
$response['key'] = $key;
$response['item'] = $request;
wp_send_json_success( $response );
}
wp_send_json_error( array( 'message' => __( 'An unknown error occurred.', 'envato-market' ) ) );
}
/**
* AJAX handler for removing items that use a non global token.
*
* @since 1.0.0
* @codeCoverageIgnore
*/
public function ajax_remove_item() {
if ( ! check_ajax_referer( self::AJAX_ACTION, 'nonce', false ) ) {
status_header( 400 );
wp_send_json_error( 'bad_nonce' );
} elseif ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) {
status_header( 405 );
wp_send_json_error( 'bad_method' );
} elseif ( empty( $_POST['id'] ) ) {
wp_send_json_error( array( 'message' => __( 'The Item ID is missing.', 'envato-market' ) ) );
} elseif ( ! current_user_can( 'delete_plugins' ) || ! current_user_can( 'delete_themes' ) ) {
wp_send_json_error( array( 'message' => __( 'User not allowed to update items.', 'envato-market' ) ) );
}
$options = get_option( envato_market()->get_option_name(), array() );
$type = '';
foreach ( $options['items'] as $key => $item ) {
if ( $item['id'] === $_POST['id'] ) {
$type = $item['type'];
unset( $options['items'][ $key ] );
break;
}
}
$options['items'] = array_values( $options['items'] );
envato_market()->set_options( $options );
// Rebuild the theme cache.
if ( 'theme' === $type ) {
envato_market()->items()->set_themes( true, false );
}
// Rebuild the plugin cache.
if ( 'plugin' === $type ) {
envato_market()->items()->set_plugins( true, false );
}
wp_send_json_success();
}
/**
* AJAX handler for performing a healthcheck of the current website.
*
* @since 2.0.6
* @codeCoverageIgnore
*/
public function ajax_healthcheck() {
if ( ! check_ajax_referer( self::AJAX_ACTION, 'nonce', false ) ) {
status_header( 400 );
wp_send_json_error( 'bad_nonce' );
} elseif ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) {
status_header( 405 );
wp_send_json_error( 'bad_method' );
} elseif ( ! current_user_can( 'install_themes' ) || ! current_user_can( 'install_plugins' ) ) {
wp_send_json_error( array( 'message' => __( 'User not allowed to install items.', 'envato-market' ) ) );
}
$limits = $this->get_server_limits();
wp_send_json_success( array(
'limits' => $limits
) );
}
/**
* AJAX handler for performing a healthcheck of the current website.
*
* @since 2.0.6
* @codeCoverageIgnore
*/
public function get_server_limits() {
$limits = [];
// Check memory limit is > 256 M
try {
$memory_limit = wp_convert_hr_to_bytes( ini_get( 'memory_limit' ) );
$memory_limit_desired = 256;
$memory_limit_ok = $memory_limit < 0 || $memory_limit >= $memory_limit_desired * 1024 * 1024;
$memory_limit_in_mb = $memory_limit < 0 ? 'Unlimited' : floor( $memory_limit / ( 1024 * 1024 ) ) . 'M';
$limits['memory_limit'] = [
'title' => 'PHP Memory Limit',
'ok' => $memory_limit_ok,
'message' => $memory_limit_ok ? "is ok at {$memory_limit_in_mb}." : "{$memory_limit_in_mb} may be too small. If you are having issues please set your PHP memory limit to at least 256M - or ask your hosting provider to do this if you're unsure."
];
} catch ( \Exception $e ) {
$limits['memory_limit'] = [
'title' => 'PHP Memory Limit',
'ok' => false,
'message' => 'Failed to check memory limit. If you are having issues please ask hosting provider to raise the memory limit for you.'
];
}
// Check upload size.
try {
$upload_size_desired = 80;
$upload_max_filesize = wp_max_upload_size();
$upload_max_filesize_ok = $upload_max_filesize < 0 || $upload_max_filesize >= $upload_size_desired * 1024 * 1024;
$upload_max_filesize_in_mb = $upload_max_filesize < 0 ? 'Unlimited' : floor( $upload_max_filesize / ( 1024 * 1024 ) ) . 'M';
$limits['upload'] = [
'ok' => $upload_max_filesize_ok,
'title' => 'PHP Upload Limits',
'message' => $upload_max_filesize_ok ? "is ok at $upload_max_filesize_in_mb." : "$upload_max_filesize_in_mb may be too small. If you are having issues please set your PHP upload limits to at least {$upload_size_desired}M - or ask your hosting provider to do this if you're unsure.",
];
} catch ( \Exception $e ) {
$limits['upload'] = [
'title' => 'PHP Upload Limits',
'ok' => false,
'message' => 'Failed to check upload limit. If you are having issues please ask hosting provider to raise the upload limit for you.'
];
}
// Check max_input_vars.
try {
$max_input_vars = ini_get( 'max_input_vars' );
$max_input_vars_desired = 1000;
$max_input_vars_ok = $max_input_vars < 0 || $max_input_vars >= $max_input_vars_desired;
$limits['max_input_vars'] = [
'ok' => $max_input_vars_ok,
'title' => 'PHP Max Input Vars',
'message' => $max_input_vars_ok ? "is ok at $max_input_vars." : "$max_input_vars may be too small. If you are having issues please set your PHP max input vars to at least $max_input_vars_desired - or ask your hosting provider to do this if you're unsure.",
];
} catch ( \Exception $e ) {
$limits['max_input_vars'] = [
'title' => 'PHP Max Input Vars',
'ok' => false,
'message' => 'Failed to check input vars limit. If you are having issues please ask hosting provider to raise the input vars limit for you.'
];
}
// Check max_execution_time.
try {
$max_execution_time = ini_get( 'max_execution_time' );
$max_execution_time_desired = 60;
$max_execution_time_ok = $max_execution_time <= 0 || $max_execution_time >= $max_execution_time_desired;
$limits['max_execution_time'] = [
'ok' => $max_execution_time_ok,
'title' => 'PHP Execution Time',
'message' => $max_execution_time_ok ? "PHP execution time limit is ok at {$max_execution_time}." : "$max_execution_time is too small. Please set your PHP max execution time to at least $max_execution_time_desired - or ask your hosting provider to do this if you're unsure.",
];
} catch ( \Exception $e ) {
$limits['max_execution_time'] = [
'title' => 'PHP Execution Time',
'ok' => false,
'message' => 'Failed to check PHP execution time limit. Please ask hosting provider to raise this limit for you.'
];
}
// Check various hostname connectivity.
$hosts_to_check = array(
array(
'hostname' => 'envato.github.io',
'url' => 'https://envato.github.io/wp-envato-market/dist/update-check.json',
'title' => 'Plugin Update API',
),
array(
'hostname' => 'api.envato.com',
'url' => 'https://api.envato.com/ping',
'title' => 'Envato Market API',
),
array(
'hostname' => 'marketplace.envato.com',
'url' => 'https://marketplace.envato.com/robots.txt',
'title' => 'Download API',
),
);
foreach ( $hosts_to_check as $host ) {
try {
$response = wp_remote_get( $host['url'], [
'user-agent' => 'WordPress - Envato Market ' . envato_market()->get_version(),
'timeout' => 5,
] );
$response_code = wp_remote_retrieve_response_code( $response );
if ( $response && ! is_wp_error( $response ) && $response_code === 200 ) {
$limits[ $host['hostname'] ] = [
'ok' => true,
'title' => $host['title'],
'message' => 'Connected ok.',
];
} else {
$limits[ $host['hostname'] ] = [
'ok' => false,
'title' => $host['title'],
'message' => "Connection failed. Status '$response_code'. Please ensure PHP is allowed to connect to the host '" . $host['hostname'] . "' - or ask your hosting provider to do this if you’re unsure. " . ( is_wp_error( $response ) ? $response->get_error_message() : '' ),
];
}
} catch ( \Exception $e ) {
$limits[ $host['hostname'] ] = [
'ok' => true,
'title' => $host['title'],
'message' => "Connection failed. Please contact the hosting provider and ensure PHP is allowed to connect to the host '" . $host['hostname'] . "'. " . $e->getMessage(),
];
}
}
// Check authenticated API request
if ( !defined('ENVATO_LOCAL_DEVELOPMENT') ) {
$response = envato_market()->api()->request( 'https://api.envato.com/whoami' );
if ( is_wp_error( $response ) ) {
$limits['authentication'] = [
'ok' => false,
'title' => 'Envato API Authentication',
'message' => "Not currently authenticated with the Envato API. Please add your API token. " . $response->get_error_message(),
];
} elseif ( ! isset( $response['scopes'] ) ) {
$limits['authentication'] = [
'ok' => false,
'title' => 'Envato API Authentication',
'message' => "Missing API permissions. Please re-create your Envato API token with the correct permissions. ",
];
} else {
$minimum_scopes = $this->get_required_permissions();
$maximum_scopes = array( 'default' => 'Default' ) + $minimum_scopes;
$missing_scopes = array();
$additional_scopes = array();
foreach ( $minimum_scopes as $required_scope => $required_scope_name ) {
if ( ! in_array( $required_scope, $response['scopes'] ) ) {
// The scope minimum required scope doesn't exist.
$missing_scopes [] = $required_scope;
}
}
foreach ( $response['scopes'] as $scope ) {
if ( ! isset( $maximum_scopes[ $scope ] ) ) {
// The available scope is outside our maximum bounds.
$additional_scopes [] = $scope;
}
}
$limits['authentication'] = [
'ok' => true,
'title' => 'Envato API Authentication',
'message' => "Authenticated successfully with correct scopes: " . implode( ', ', $response['scopes'] ),
];
}
}
$debug_enabled = defined( 'WP_DEBUG' ) && WP_DEBUG;
$limits['wp_debug'] = [
'ok' => ! $debug_enabled,
'title' => 'WP Debug',
'message' => $debug_enabled ? 'If you’re on a production website, it’s best to set WP_DEBUG to false, please ask your hosting provider to do this if you’re unsure.' : 'WP Debug is disabled, all ok.',
];
$zip_archive_installed = class_exists( '\ZipArchive' );
$limits['zip_archive'] = [
'ok' => $zip_archive_installed,
'title' => 'ZipArchive Support',
'message' => $zip_archive_installed ? 'ZipArchive is available.' : 'ZipArchive is not available. If you have issues installing or updating items please ask your hosting provider to enable ZipArchive.',
];
$php_version_ok = version_compare( PHP_VERSION, '7.0', '>=' );
$limits['php_version'] = [
'ok' => $php_version_ok,
'title' => 'PHP Version',
'message' => $php_version_ok ? 'PHP version is ok at ' . PHP_VERSION . '.' : 'Please ask the hosting provider to upgrade your PHP version to at least 7.0 or above.',
];
require_once( ABSPATH . 'wp-admin/includes/file.php' );
$current_filesystem_method = get_filesystem_method();
if ( $current_filesystem_method !== 'direct' ) {
$limits['filesystem_method'] = [
'ok' => false,
'title' => 'WordPress Filesystem',
'message' => 'Please enable WordPress FS_METHOD direct - or ask your hosting provider to do this if you’re unsure.',
];
}
$wp_upload_dir = wp_upload_dir();
$upload_base_dir = $wp_upload_dir['basedir'];
$upload_base_dir_writable = is_writable( $upload_base_dir );
$limits['wp_content_writable'] = [
'ok' => $upload_base_dir_writable,
'title' => 'WordPress File Permissions',
'message' => $upload_base_dir_writable ? 'is ok.' : 'Please set correct WordPress PHP write permissions for the wp-content directory - or ask your hosting provider to do this if you’re unsure.',
];
$active_plugins = get_option( 'active_plugins' );
$active_plugins_ok = count( $active_plugins ) < 15;
if ( ! $active_plugins_ok ) {
$limits['active_plugins'] = [
'ok' => false,
'title' => 'Active Plugins',
'message' => 'Please try to reduce the number of active plugins on your WordPress site, as this will slow things down.',
];
}
return $limits;
}
/**
* Admin page callback.
*
* @since 1.0.0
*/
public function render_admin_callback() {
require( envato_market()->get_plugin_path() . 'inc/admin/view/callback/admin.php' );
}
/**
* OAuth section callback.
*
* @since 1.0.0
*/
public function render_oauth_section_callback() {
require( envato_market()->get_plugin_path() . 'inc/admin/view/callback/section/oauth.php' );
}
/**
* Items section callback.
*
* @since 1.0.0
*/
public function render_items_section_callback() {
require( envato_market()->get_plugin_path() . 'inc/admin/view/callback/section/items.php' );
}
/**
* Token setting callback.
*
* @since 1.0.0
*/
public function render_token_setting_callback() {
require( envato_market()->get_plugin_path() . 'inc/admin/view/callback/setting/token.php' );
}
/**
* Items setting callback.
*
* @since 1.0.0
*/
public function render_items_setting_callback() {
require( envato_market()->get_plugin_path() . 'inc/admin/view/callback/setting/items.php' );
}
/**
* Intro
*
* @since 1.0.0
*/
public function render_intro_partial() {
require( envato_market()->get_plugin_path() . 'inc/admin/view/partials/intro.php' );
}
/**
* Tabs
*
* @since 1.0.0
*/
public function render_tabs_partial() {
require( envato_market()->get_plugin_path() . 'inc/admin/view/partials/tabs.php' );
}
/**
* Settings panel
*
* @since 1.0.0
*/
public function render_settings_panel_partial() {
require( envato_market()->get_plugin_path() . 'inc/admin/view/partials/settings.php' );
}
/**
* Help panel
*
* @since 2.0.1
*/
public function render_help_panel_partial() {
require( envato_market()->get_plugin_path() . 'inc/admin/view/partials/help.php' );
}
/**
* Themes panel
*
* @since 1.0.0
*/
public function render_themes_panel_partial() {
require( envato_market()->get_plugin_path() . 'inc/admin/view/partials/themes.php' );
}
/**
* Plugins panel
*
* @since 1.0.0
*/
public function render_plugins_panel_partial() {
require( envato_market()->get_plugin_path() . 'inc/admin/view/partials/plugins.php' );
}
/**
* Success notice.
*
* @since 1.0.0
*/
public function render_success_notice() {
require( envato_market()->get_plugin_path() . 'inc/admin/view/notice/success.php' );
}
/**
* Success no-items notice.
*
* @since 1.0.0
*/
public function render_success_no_items_notice() {
require( envato_market()->get_plugin_path() . 'inc/admin/view/notice/success-no-items.php' );
}
/**
* Success single-use notice.
*
* @since 1.0.0
*/
public function render_success_single_use_notice() {
require( envato_market()->get_plugin_path() . 'inc/admin/view/notice/success-single-use.php' );
}
/**
* Error details.
*
* @since 2.0.2
*/
public function render_additional_error_details() {
$error_details = get_site_transient( envato_market()->get_option_name() . '_error_information' );
if ( $error_details && ! empty( $error_details['title'] ) ) {
extract( $error_details );
require( envato_market()->get_plugin_path() . 'inc/admin/view/notice/error-details.php' );
}
}
/**
* Error notice.
*
* @since 1.0.0
*/
public function render_error_notice() {
require( envato_market()->get_plugin_path() . 'inc/admin/view/notice/error.php' );
$this->render_additional_error_details();
}
/**
* Permission error notice.
*
* @since 2.0.1
*/
public function render_error_permissions() {
require( envato_market()->get_plugin_path() . 'inc/admin/view/notice/error-permissions.php' );
$this->render_additional_error_details();
}
/**
* Error single-use notice.
*
* @since 1.0.0
*/
public function render_error_single_use_notice() {
require( envato_market()->get_plugin_path() . 'inc/admin/view/notice/error-single-use.php' );
$this->render_additional_error_details();
}
/**
* Error missing zip.
*
* @since 2.0.1
*/
public function render_error_missing_zip() {
require( envato_market()->get_plugin_path() . 'inc/admin/view/notice/error-missing-zip.php' );
$this->render_additional_error_details();
}
/**
* Error http
*
* @since 2.0.1
*/
public function render_error_http() {
require( envato_market()->get_plugin_path() . 'inc/admin/view/notice/error-http.php' );
$this->render_additional_error_details();
}
/**
* Use the Settings API when in network mode.
*
* This allows us to make use of the same WordPress Settings API when displaying the menu item in network mode.
*
* @since 2.0.0
*/
public function save_network_settings() {
check_admin_referer( envato_market()->get_slug() . '-options' );
global $new_whitelist_options;
$options = $new_whitelist_options[ envato_market()->get_slug() ];
foreach ( $options as $option ) {
if ( isset( $_POST[ $option ] ) ) {
update_site_option( $option, $_POST[ $option ] );
} else {
delete_site_option( $option );
}
}
wp_redirect( envato_market()->get_page_url() );
exit;
}
/**
* Store additional error information in transient so users can self debug.
*
* @since 2.0.2
*/
public function store_additional_error_debug_information( $title, $message = '', $data = [] ) {
set_site_transient(
envato_market()->get_option_name() . '_error_information',
[
'title' => $title,
'message' => $message,
'data' => $data,
],
120
);
}
}
endif;