patcher = $patcher;
// If the product is bundled, early exit.
$is_bundled = $this->patcher->is_bundled();
if ( $is_bundled ) {
return;
}
// Get the patches when we're in the patcher page.
$args = $this->patcher->get_args();
if ( isset( $args['is_patcher_page'] ) && true === $args['is_patcher_page'] ) {
$this->patches = Fusion_Patcher_Client::get_patches( $args );
}
// Add menu page.
add_action( 'avada_add_admin_menu_maintenance_pages', [ $this, 'admin_menu' ], 10 );
// Call register settings function.
add_action( 'admin_init', [ $this, 'settings' ] );
add_action( 'admin_init', [ $this, 'init' ], 999 );
if ( function_exists( 'add_allowed_options' ) ) {
add_filter( 'allowed_options', [ $this, 'allowed_options' ] );
} else {
add_filter( 'whitelist_options', [ $this, 'allowed_options' ] );
}
}
/**
* Additional actions.
*
* @access public
* @since 1.0.0
*/
public function init() {
$is_patcher_page = $this->patcher->get_args( 'is_patcher_page' );
if ( null === $is_patcher_page || false === $is_patcher_page ) {
return;
}
// Add the patcher to the support screen.
add_action( 'fusion_admin_pages_patcher', [ $this, 'form' ] );
}
/**
* Adds a submenu page.
*
* @access public
* @since 1.0.0
*/
public function admin_menu() {
if ( isset( self::$menu_added[ $this->patcher->get_args( 'context' ) ] ) && self::$menu_added[ $this->patcher->get_args( 'context' ) ] ) {
return;
}
add_submenu_page( // phpcs:ignore WPThemeReview.PluginTerritory.NoAddAdminPages
$this->patcher->get_args( 'parent_slug' ),
$this->patcher->get_args( 'page_title' ),
$this->patcher->get_args( 'menu_title' ),
'manage_options',
$this->patcher->get_args( 'context' ) . '-patcher',
[ $this, 'admin_page' ],
13
);
self::$menu_added[ $this->patcher->get_args( 'context' ) ] = true;
}
/**
* The admin-page contents.
*
* @access public
* @since 1.0.0
*/
public function admin_page() {
if ( class_exists( 'Avada_Admin' ) ) {
Avada_Admin::get_admin_screens_header( 'patcher' );
}
/**
* Make sure that any patches marked as manually applied
* using the FUSION_MANUALLY_APPLIED_PATCHES constant are marked as complete.
*/
$this->manually_applied_patches();
/**
* Adds the content of the form.
*/
do_action( 'fusion_admin_pages_patcher' );
if ( class_exists( 'Avada_Admin' ) ) {
Avada_Admin::get_admin_screens_footer();
}
}
/**
* Register the settings.
*
* @access public
* @return void
*/
public function settings() {
if ( empty( $this->patches ) ) {
return;
}
// Register settings for the patch contents.
foreach ( $this->patches as $key => $value ) {
register_setting( 'fusion_patcher_' . $key, 'fusion_patch_contents_' . $key );
}
}
/**
* The page contents.
*
* @access public
* @return void
*/
public function form() {
if ( isset( self::$printed_forms[ $this->patcher->get_args( 'context' ) ] ) ) {
return;
}
// Determine if there are available patches, and build an array of them.
$available_patches = [];
foreach ( $this->patches as $patch_id => $patch_args ) {
if ( ! isset( $patch_args['patch'] ) ) {
continue;
}
foreach ( $patch_args['patch'] as $key => $unique_patch_args ) {
// Make sure the context is right - Avada.
if ( $this->patcher->get_args( 'context' ) === $unique_patch_args['context'] ) {
// Make sure the version is right.
if ( $this->patcher->get_args( 'version' ) === $unique_patch_args['version'] ) {
$available_patches[] = $patch_id;
$context[ $this->patcher->get_args( 'context' ) ] = true;
}
}
// Check for bundled products - plugins.
$bundles = $this->patcher->get_args( 'bundled' );
if ( ! $bundles ) {
$bundles = [];
}
foreach ( $bundles as $bundle ) {
// Make sure the context is right.
if ( $bundle === $unique_patch_args['context'] ) {
// Make sure the version is right.
if ( $this->patcher->get_bundled_version( $bundle ) === $unique_patch_args['version'] ) {
$available_patches[] = $patch_id;
$context[ $bundle ] = true;
}
}
}
}
}
// Make sure we have a unique array.
$available_patches = array_unique( $available_patches );
// Sort the array by value and re-index the keys.
sort( $available_patches );
// Get an array of the already applied patches.
$applied_patches = get_site_option( 'fusion_applied_patches', [] );
// Get an array of patches that failed to be applied.
$failed_patches = get_site_option( 'fusion_failed_patches', [] );
// Get the array of messages to display.
$messages = Fusion_Patcher_Admin_Notices::get_messages();
?>
', '' );
?>
|
#
|
|