Commit realizado el 12:13:52 08-04-2024
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
namespace DeployerForGit\Subpages\DashboardPage;
|
||||
|
||||
use DeployerForGit\DataManager;
|
||||
use DeployerForGit\Helper;
|
||||
|
||||
/**
|
||||
* Class Dashboard
|
||||
*
|
||||
* @package DeployerForGit\Subpages\DashboardPage
|
||||
*/
|
||||
class Dashboard {
|
||||
|
||||
/**
|
||||
* Dashboard constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', array( $this, 'init_menu' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the menu.
|
||||
*/
|
||||
public function init_menu() {
|
||||
$menu_slug = Helper::menu_slug();
|
||||
$capability = is_multisite() ? 'manage_network_options' : 'manage_options';
|
||||
|
||||
add_menu_page(
|
||||
esc_attr__( 'Dashboard', 'deployer-for-git' ),
|
||||
esc_attr__( 'Deployer for Git', 'deployer-for-git' ),
|
||||
$capability,
|
||||
$menu_slug,
|
||||
array( $this, 'init_page' ),
|
||||
'dashicons-randomize'
|
||||
);
|
||||
|
||||
add_submenu_page(
|
||||
$menu_slug,
|
||||
esc_attr__( 'Dashboard', 'deployer-for-git' ),
|
||||
esc_attr__( 'Dashboard', 'deployer-for-git' ),
|
||||
$capability,
|
||||
$menu_slug,
|
||||
array( $this, 'init_page' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the page.
|
||||
*/
|
||||
public function init_page() {
|
||||
$data_manager = new DataManager();
|
||||
|
||||
include_once __DIR__ . '/template.php';
|
||||
}
|
||||
}
|
@@ -0,0 +1 @@
|
||||
<?php // Silence is golden
|
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
use DeployerForGit\ApiRequests\PackageUpdate;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<h3>
|
||||
<span class="dashicons dashicons-admin-plugins"></span>
|
||||
<?php echo esc_attr__( 'Installed Plugins', 'deployer-for-git' ); ?> (<?php echo count( $plugin_list ); ?>)
|
||||
</h3>
|
||||
|
||||
<?php if ( empty( $plugin_list ) ) : ?>
|
||||
<?php
|
||||
$plugin_istall_page_url = \DeployerForGit\Helper::install_plugin_url();
|
||||
?>
|
||||
<div><?php echo esc_attr__( 'No plugins installed yet... Go and install one.', 'deployer-for-git' ); ?></div>
|
||||
<div class="dfg_mt_10" >
|
||||
<a href="<?php echo esc_url( $plugin_istall_page_url ); ?>" class="button">
|
||||
<?php echo esc_attr__( 'Install Plugin', 'deployer-for-git' ); ?>
|
||||
</a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="dfg_package_boxes">
|
||||
<?php foreach ( $plugin_list as $plugin_info ) : ?>
|
||||
<?php $endpoint_url = PackageUpdate::package_update_url( $plugin_info['slug'], 'plugin' ); ?>
|
||||
<div class="dfg_package_box">
|
||||
<div>
|
||||
<h3>
|
||||
<?php
|
||||
$provider_logo_url = plugin_dir_url( DFG_FILE ) . 'assets/img/' . $plugin_info['provider'] . '-logo.svg';
|
||||
?>
|
||||
<img src="<?php echo esc_url( $provider_logo_url ); ?>" alt="<?php echo esc_attr( DeployerForGit\Helper::available_providers()[ $plugin_info['provider'] ] ); ?>" >
|
||||
<?php echo esc_attr( $plugin_info['slug'] ); ?>
|
||||
<?php if ( $plugin_info['is_private_repository'] ) : ?>
|
||||
<i class="dashicons dashicons-lock" title="<?php echo esc_attr__( 'Private Repo', 'deployer-for-git' ); ?>"></i>
|
||||
<?php else : ?>
|
||||
<i class="dashicons dashicons-unlock" title="<?php echo esc_attr__( 'Public Repo', 'deployer-for-git' ); ?>"></i>
|
||||
<?php endif; ?>
|
||||
</h3>
|
||||
<ul>
|
||||
<li>
|
||||
<i class="dashicons dashicons-randomize" title="<?php echo esc_attr__( 'Branch', 'deployer-for-git' ); ?>"></i>
|
||||
<code><?php echo esc_attr( $plugin_info['branch'] ); ?></code>
|
||||
</li>
|
||||
<li>
|
||||
<pre style="white-space: normal;"><?php echo esc_attr( $plugin_info['repo_url'] ); ?></pre>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#" data-show-ptd-btn >
|
||||
<?php echo esc_attr__( '» Show Push-to-Deploy URL', 'deployer-for-git' ); ?>
|
||||
</a>
|
||||
<div class="dfg_package_box_action">
|
||||
<input type="url" disabled value="<?php echo esc_url( $endpoint_url ); ?>">
|
||||
<a data-copy-url-btn="<?php echo esc_url( $endpoint_url ); ?>" class="button" href="#" aria-label="<?php echo esc_attr__( 'Copy URL', 'deployer-for-git' ); ?>">
|
||||
<span class="dashicons dashicons-admin-page"></span>
|
||||
<span class="text" ><?php echo esc_attr__( 'Copy URL', 'deployer-for-git' ); ?></span>
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="dfg_package_box_buttons" >
|
||||
<button data-package-type="plugin"
|
||||
data-trigger-ptd-btn="<?php echo esc_url( $endpoint_url ); ?>"
|
||||
title="<?php echo esc_attr__( 'Remove', 'deployer-for-git' ); ?>"
|
||||
class="button button-primary update-package-btn" >
|
||||
<span class="dashicons dashicons-update"></span>
|
||||
<span class="text" ><?php echo esc_attr__( 'Update Plugin', 'deployer-for-git' ); ?></span>
|
||||
</button>
|
||||
|
||||
<?php
|
||||
$plugins_url = is_multisite() ? network_admin_url( 'plugins.php' ) : admin_url( 'plugins.php' );
|
||||
?>
|
||||
<a href="<?php echo esc_url( $plugins_url ); ?>"
|
||||
title="<?php echo esc_attr__( 'Remove', 'deployer-for-git' ); ?>"
|
||||
class="delete-theme button" ><span class="dashicons dashicons-trash"></span></a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
use DeployerForGit\ApiRequests\PackageUpdate;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<h3>
|
||||
<span class="dashicons dashicons-admin-appearance"></span>
|
||||
<?php echo esc_attr__( 'Installed Themes', 'deployer-for-git' ); ?> (<?php echo count( $theme_list ); ?>)
|
||||
</h3>
|
||||
|
||||
<?php if ( empty( $theme_list ) ) : ?>
|
||||
<?php
|
||||
$theme_istall_page_url = \DeployerForGit\Helper::install_theme_url();
|
||||
?>
|
||||
<div><?php echo esc_attr__( 'No themes installed yet... Go and install one.', 'deployer-for-git' ); ?></div>
|
||||
<div class="dfg_mt_10" >
|
||||
<a href="<?php echo esc_url( $theme_istall_page_url ); ?>" class="button">
|
||||
<?php echo esc_attr__( 'Install Theme', 'deployer-for-git' ); ?>
|
||||
</a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="dfg_package_boxes">
|
||||
<?php foreach ( $theme_list as $theme_info ) : ?>
|
||||
<?php $endpoint_url = PackageUpdate::package_update_url( $theme_info['slug'], 'theme' ); ?>
|
||||
<div class="dfg_package_box">
|
||||
<div>
|
||||
<h3>
|
||||
<?php
|
||||
$provider_logo_url = plugin_dir_url( DFG_FILE ) . 'assets/img/' . $theme_info['provider'] . '-logo.svg';
|
||||
?>
|
||||
<img src="<?php echo esc_url( $provider_logo_url ); ?>" alt="<?php echo esc_attr( DeployerForGit\Helper::available_providers()[ $theme_info['provider'] ] ); ?>" >
|
||||
<?php echo esc_attr( $theme_info['slug'] ); ?>
|
||||
<?php if ( $theme_info['is_private_repository'] ) : ?>
|
||||
<i class="dashicons dashicons-lock" title="<?php echo esc_attr__( 'Private Repo', 'deployer-for-git' ); ?>"></i>
|
||||
<?php else : ?>
|
||||
<i class="dashicons dashicons-unlock" title="<?php echo esc_attr__( 'Public Repo', 'deployer-for-git' ); ?>"></i>
|
||||
<?php endif; ?>
|
||||
<?php
|
||||
$current_theme = wp_get_theme();
|
||||
if ( $current_theme->get_template() === $theme_info['slug'] ) :
|
||||
?>
|
||||
| <span><?php echo esc_attr__( 'Active', 'deployer-for-git' ); ?></span>
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
</h3>
|
||||
<ul>
|
||||
<li>
|
||||
<?php echo esc_attr__( 'Branch', 'deployer-for-git' ); ?>
|
||||
<i class="dashicons dashicons-randomize" title="<?php echo esc_attr__( 'Branch', 'deployer-for-git' ); ?>"></i>:
|
||||
<code><?php echo esc_attr( $theme_info['branch'] ); ?></code>
|
||||
</li>
|
||||
<li>
|
||||
<pre style="white-space: normal;"><?php echo esc_attr( $theme_info['repo_url'] ); ?></pre>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#" data-show-ptd-btn >
|
||||
<?php echo esc_attr__( '» Show Push-to-Deploy URL', 'deployer-for-git' ); ?>
|
||||
</a>
|
||||
<div class="dfg_package_box_action">
|
||||
<input type="url" disabled value="<?php echo esc_url( $endpoint_url ); ?>">
|
||||
<a data-copy-url-btn="<?php echo esc_url( $endpoint_url ); ?>" class="button" href="#" aria-label="<?php echo esc_attr__( 'Copy URL', 'deployer-for-git' ); ?>">
|
||||
<span class="dashicons dashicons-admin-page"></span>
|
||||
<span class="text" ><?php echo esc_attr__( 'Copy URL', 'deployer-for-git' ); ?></span>
|
||||
</a>
|
||||
</div>
|
||||
</li>
|
||||
<li class="dfg_package_box_buttons" >
|
||||
<button data-package-type="theme"
|
||||
data-trigger-ptd-btn="<?php echo esc_url( $endpoint_url ); ?>"
|
||||
title="<?php echo esc_attr__( 'Remove', 'deployer-for-git' ); ?>"
|
||||
class="button button-primary update-package-btn" >
|
||||
<span class="dashicons dashicons-update"></span>
|
||||
<span class="text" ><?php echo esc_attr__( 'Update Theme', 'deployer-for-git' ); ?></span>
|
||||
</button>
|
||||
|
||||
<?php
|
||||
$themes_url = is_multisite() ? network_admin_url( 'themes.php' ) : admin_url( 'themes.php' );
|
||||
$theme_url = add_query_arg( 'theme', $theme_info['slug'], $themes_url );
|
||||
?>
|
||||
<a href="<?php echo esc_url( $theme_url ); ?>"
|
||||
title="<?php echo esc_attr__( 'Remove', 'deployer-for-git' ); ?>"
|
||||
class="delete-theme button" ><span class="dashicons dashicons-trash"></span></a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
@@ -0,0 +1 @@
|
||||
<?php // Silence is golden
|
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$theme_list = $data_manager->get_theme_list();
|
||||
$plugin_list = $data_manager->get_plugin_list();
|
||||
?>
|
||||
|
||||
<div class="wrap">
|
||||
<h1><?php echo esc_attr__( 'Dashboard', 'deployer-for-git' ); ?></h1>
|
||||
|
||||
<?php require_once 'partials/_themes.php'; ?>
|
||||
<hr>
|
||||
<?php require_once 'partials/_plugins.php'; ?>
|
||||
</div>
|
@@ -0,0 +1,238 @@
|
||||
<?php
|
||||
|
||||
namespace DeployerForGit\Subpages;
|
||||
|
||||
use DeployerForGit\DataManager ;
|
||||
use DeployerForGit\Logger ;
|
||||
use DeployerForGit\Helper ;
|
||||
/**
|
||||
* Class InstallPackage
|
||||
*
|
||||
* @package Wp_Git_Deployer
|
||||
*/
|
||||
class InstallPackage
|
||||
{
|
||||
/**
|
||||
* Init package menu hook.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
add_action( ( is_multisite() ? 'network_admin_menu' : 'admin_menu' ), array( $this, 'init_menu' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the menu.
|
||||
*/
|
||||
public function init_menu()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the package installation form.
|
||||
*/
|
||||
private function validate_install_package_form()
|
||||
{
|
||||
if ( !isset( $_POST[DFG_SLUG . '_install_package_submitted'] ) ) {
|
||||
return;
|
||||
}
|
||||
// Vefiry form nonce.
|
||||
$nonce = ( isset( $_POST[DFG_SLUG . '_nonce'] ) ? sanitize_text_field( wp_unslash( $_POST[DFG_SLUG . '_nonce'] ) ) : '' );
|
||||
if ( !wp_verify_nonce( $nonce, DFG_SLUG . '_install_package_form' ) ) {
|
||||
return new \WP_Error( 'invalid', __( 'Invalid nonce', 'deployer-for-git' ) );
|
||||
}
|
||||
$provider_type = ( isset( $_POST['provider_type'] ) ? sanitize_text_field( wp_unslash( $_POST['provider_type'] ) ) : '' );
|
||||
// Check if provider type is valid.
|
||||
if ( !in_array( $provider_type, array_keys( Helper::available_providers() ), true ) ) {
|
||||
return new \WP_Error( 'invalid', __( 'Invalid provider type', 'deployer-for-git' ) );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the package installation form.
|
||||
*
|
||||
* @return WP_Error|bool Returns WP_Error object for failure or true for success.
|
||||
*/
|
||||
public function handle_package_install_form()
|
||||
{
|
||||
// Validate form.
|
||||
$validation_result = $this->validate_install_package_form();
|
||||
if ( $validation_result !== true ) {
|
||||
return $validation_result;
|
||||
}
|
||||
// phpcs:disable WordPress.Security.NonceVerification.Missing
|
||||
// Sanitize form data.
|
||||
$package_type = ( isset( $_POST['package_type'] ) ? sanitize_text_field( wp_unslash( $_POST['package_type'] ) ) : '' );
|
||||
$package_type = ( $package_type === 'plugin' ? 'plugin' : 'theme' );
|
||||
$provider_type = ( isset( $_POST['provider_type'] ) ? sanitize_text_field( wp_unslash( $_POST['provider_type'] ) ) : '' );
|
||||
$branch = ( isset( $_POST['repository_branch'] ) && !empty($_POST['repository_branch']) ? sanitize_text_field( wp_unslash( $_POST['repository_branch'] ) ) : 'master' );
|
||||
$repository_url = ( isset( $_POST['repository_url'] ) ? esc_url_raw( wp_unslash( $_POST['repository_url'] ) ) : '' );
|
||||
$is_private_repository = isset( $_POST['is_private_repository'] );
|
||||
$username = ( isset( $_POST['username'] ) ? sanitize_text_field( wp_unslash( $_POST['username'] ) ) : '' );
|
||||
$password = ( isset( $_POST['password'] ) ? sanitize_text_field( wp_unslash( $_POST['password'] ) ) : '' );
|
||||
$access_token = ( isset( $_POST['access_token'] ) ? sanitize_text_field( wp_unslash( $_POST['access_token'] ) ) : '' );
|
||||
// phpcs:enable WordPress.Security.NonceVerification.Missing
|
||||
$package_install_options = array();
|
||||
if ( $is_private_repository ) {
|
||||
$package_install_options = array(
|
||||
'is_private_repository' => true,
|
||||
'username' => $username,
|
||||
'password' => $password,
|
||||
'access_token' => $access_token,
|
||||
);
|
||||
}
|
||||
$provider_class_name = Helper::get_provider_class( $provider_type );
|
||||
$logger = new Logger();
|
||||
try {
|
||||
$provider = new $provider_class_name( $repository_url );
|
||||
$package_slug = $provider->get_package_slug();
|
||||
$package_zip_url = $provider->get_zip_repo_url( $branch );
|
||||
$install_result = self::install_package_from_zip_url(
|
||||
$package_zip_url,
|
||||
$package_slug,
|
||||
$package_type,
|
||||
$provider_type,
|
||||
$package_install_options
|
||||
);
|
||||
// TODO: maybe move this piece to a method?
|
||||
|
||||
if ( $install_result === true ) {
|
||||
$data_manager = new DataManager();
|
||||
$package_data = array(
|
||||
'slug' => $package_slug,
|
||||
'repo_url' => $repository_url,
|
||||
'branch' => $branch,
|
||||
'provider' => $provider_type,
|
||||
'is_private_repository' => $is_private_repository,
|
||||
'options' => array(
|
||||
'username' => $username,
|
||||
'password' => $password,
|
||||
'access_token' => $access_token,
|
||||
),
|
||||
);
|
||||
$data_manager->store_package_details( $package_data, $package_type );
|
||||
$logger->log( "Package ({$package_type}) \"{$package_slug}\" successfully updated or installed via wp-admin" );
|
||||
} else {
|
||||
$logger->log( "Error occured while installing a {$package_type} \"{$package_slug}\" via wp-admin \"{$install_result->get_error_message()}\"" );
|
||||
}
|
||||
|
||||
} catch ( \Exception $e ) {
|
||||
// Invalid repository URL.
|
||||
$install_result = new \WP_Error( 'invalid', $e->getMessage() );
|
||||
$logger->log( "Error occured while installing a package via wp-admin \"{$e->getMessage()}\"" );
|
||||
}
|
||||
$success = $install_result === true;
|
||||
do_action( 'dfg_after_package_install', $success );
|
||||
return $install_result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the page.
|
||||
*/
|
||||
public function init_page()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the request is a WP JSON request.
|
||||
*
|
||||
* @param array $options Additional options for the installation.
|
||||
*/
|
||||
private static function is_wp_json_request( $options = array() )
|
||||
{
|
||||
return array_key_exists( 'wp_json_request', $options ) && $options['wp_json_request'] === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the current user can proceed with the installation.
|
||||
*
|
||||
* @param string $package_type Type of the package (theme|plugin).
|
||||
*/
|
||||
private static function current_user_can_proceed( $package_type )
|
||||
{
|
||||
$type_in_plural = "{$package_type}s";
|
||||
return current_user_can( "install_{$type_in_plural}" );
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs a package from a zip file URL.
|
||||
*
|
||||
* @param string $package_zip_url The URL of the package zip file.
|
||||
* @param string $package_slug The slug of the package.
|
||||
* @param string $type Type of the package (theme|plugin).
|
||||
* @param string $provider_type Type of the provider (bitbucket|github|gitlab|gitea).
|
||||
* @param array $options Additional options for the installation.
|
||||
*
|
||||
* @return WP_Error|bool Returns WP_Error object for failure or true for success.
|
||||
*/
|
||||
public static function install_package_from_zip_url(
|
||||
$package_zip_url,
|
||||
$package_slug,
|
||||
$type,
|
||||
$provider_type,
|
||||
$options = array()
|
||||
)
|
||||
{
|
||||
if ( empty($provider_type) ) {
|
||||
return new \WP_Error( 'invalid', __( 'Provider does not exist.', 'deployer-for-git' ) );
|
||||
}
|
||||
// Check if provider type is valid.
|
||||
if ( !in_array( $provider_type, array_keys( Helper::available_providers() ), true ) ) {
|
||||
return new \WP_Error( 'invalid', __( 'Invalid provider type', 'deployer-for-git' ) );
|
||||
}
|
||||
$type = ( $type === 'theme' ? 'theme' : 'plugin' );
|
||||
// Check for empty URL and slug.
|
||||
if ( empty($package_zip_url) || empty($package_slug) ) {
|
||||
return new \WP_Error( 'invalid', __( 'Package zip URL and package slug must exist', 'deployer-for-git' ) );
|
||||
}
|
||||
$is_wp_json_request = self::is_wp_json_request( $options );
|
||||
// Check user capabilities.
|
||||
if ( !self::current_user_can_proceed( $type ) && !$is_wp_json_request ) {
|
||||
return new \WP_Error( 'invalid', __( 'User should have enough permissions', 'deployer-for-git' ) );
|
||||
}
|
||||
// Initialize WordPress filesystem.
|
||||
if ( !function_exists( 'WP_Filesystem' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/file.php';
|
||||
}
|
||||
WP_Filesystem();
|
||||
// load file which loads most of the classes needed for package installation.
|
||||
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
|
||||
// Set up package installation parameters.
|
||||
|
||||
if ( $type === 'theme' ) {
|
||||
$package_destination_dir = WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $package_slug;
|
||||
$skin = new \DeployerForGit\ThemeInstallerSkin();
|
||||
// Create a new instance of the Theme_Upgrader class.
|
||||
$package_upgrader = new \Theme_Upgrader( $skin );
|
||||
} else {
|
||||
$package_destination_dir = WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . $package_slug;
|
||||
$skin = new \DeployerForGit\PluginInstallerSkin();
|
||||
// Create a new instance of the Plugin_Upgrader class.
|
||||
$package_upgrader = new \Plugin_Upgrader( $skin );
|
||||
}
|
||||
|
||||
// Set upgrader arguments.
|
||||
$package_upgrader->generic_strings();
|
||||
// Run the package installation.
|
||||
$result = $package_upgrader->run( array(
|
||||
'package' => $package_zip_url,
|
||||
'destination' => $package_destination_dir,
|
||||
'clear_destination' => true,
|
||||
'clear_working' => true,
|
||||
'hook_extra' => array(
|
||||
'type' => $type,
|
||||
'action' => 'install',
|
||||
),
|
||||
) );
|
||||
$package_upgrader->maintenance_mode( false );
|
||||
|
||||
if ( $result === false ) {
|
||||
return new \WP_Error( 'invalid', __( 'Some error occurred', 'deployer-for-git' ) );
|
||||
} elseif ( is_wp_error( $result ) ) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace DeployerForGit\Subpages\InstallPluginPage;
|
||||
|
||||
use DeployerForGit\Subpages\InstallPackage;
|
||||
|
||||
/**
|
||||
* Class InstallPlugin
|
||||
*
|
||||
* @package DeployerForGit\Subpages\InstallPluginPage
|
||||
*/
|
||||
class InstallPlugin extends InstallPackage {
|
||||
|
||||
/**
|
||||
* Initializes the menu.
|
||||
*/
|
||||
public function init_menu() {
|
||||
$menu_slug = \DeployerForGit\Helper::menu_slug();
|
||||
$page_title = esc_attr__( 'Install Plugin', 'deployer-for-git' );
|
||||
$capability = is_multisite() ? 'manage_network_options' : 'manage_options';
|
||||
|
||||
add_submenu_page(
|
||||
$menu_slug,
|
||||
$page_title,
|
||||
$page_title,
|
||||
$capability,
|
||||
"{$menu_slug}-install-plugin",
|
||||
array( $this, 'init_page' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs a plugin from a zip file.
|
||||
*
|
||||
* @param string $package_zip_url The URL of the zip file.
|
||||
* @param string $package_slug The slug of the package.
|
||||
* @param string $package_provider The provider of the package (github, bitbucket, gitlab, gitea).
|
||||
* @param array $options The options.
|
||||
* @return WP_Error|bool Returns WP_Error object for failure or true for success.
|
||||
*/
|
||||
public static function install_plugin_from_zip_url( $package_zip_url, $package_slug, $package_provider, $options = array() ) {
|
||||
return parent::install_package_from_zip_url( $package_zip_url, $package_slug, 'plugin', $package_provider, $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the page.
|
||||
*/
|
||||
public function init_page() {
|
||||
// Handle package installation form.
|
||||
$install_result = parent::handle_package_install_form();
|
||||
|
||||
include_once __DIR__ . '/template.php';
|
||||
}
|
||||
}
|
@@ -0,0 +1 @@
|
||||
<?php // Silence is golden
|
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
if ( !defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<?php
|
||||
|
||||
if ( isset( $install_result ) ) {
|
||||
?>
|
||||
<?php
|
||||
|
||||
if ( !is_wp_error( $install_result ) ) {
|
||||
?>
|
||||
<div class="updated">
|
||||
<p>
|
||||
<?php
|
||||
echo esc_attr__( 'Plugin was successfully installed', 'deployer-for-git' ) ;
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<div class="error">
|
||||
<p>
|
||||
<!-- <strong><?php
|
||||
echo esc_attr( $install_result->get_error_code() ) ;
|
||||
?></strong> -->
|
||||
<?php
|
||||
echo esc_attr( $install_result->get_error_message() ) ;
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="wrap">
|
||||
<h1><?php
|
||||
echo esc_attr__( 'Install Plugin', 'deployer-for-git' ) ;
|
||||
?></h1>
|
||||
<form class="dfg_install_package_form" method="post" action="">
|
||||
<input type="hidden" name="<?php
|
||||
echo esc_attr( DFG_SLUG . '_install_package_submitted' ) ;
|
||||
?>" value="1">
|
||||
<input type="hidden" name="package_type" value="plugin">
|
||||
|
||||
<?php
|
||||
wp_nonce_field( DFG_SLUG . '_install_package_form', DFG_SLUG . '_nonce' );
|
||||
?>
|
||||
<table class="form-table">
|
||||
<tr valign="top">
|
||||
<th scope="row">
|
||||
<?php
|
||||
echo esc_attr__( 'Provider Type', 'deployer-for-git' ) ;
|
||||
?>
|
||||
</th>
|
||||
<td>
|
||||
<select name='provider_type'>
|
||||
<option value="" selected disabled><?php
|
||||
echo esc_attr__( 'Choose a provider', 'deployer-for-git' ) ;
|
||||
?></option>
|
||||
<?php
|
||||
foreach ( \DeployerForGit\Helper::available_providers() as $provider_id => $name ) {
|
||||
?>
|
||||
<option value="<?php
|
||||
echo esc_attr( $provider_id ) ;
|
||||
?>"><?php
|
||||
echo esc_attr( $name ) ;
|
||||
?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<th scope="row"><?php
|
||||
echo esc_attr__( 'Repository URL', 'deployer-for-git' ) ;
|
||||
?></th>
|
||||
<td>
|
||||
<input type="url" class="regular-text code" name="repository_url" value="" />
|
||||
<p class="description dfg_repo_url_description dfg_hidden" id="bitbucket-repo-url-description"><?php
|
||||
echo esc_attr__( 'Example: https://bitbucket.org/owner/wordpress-plugin-name', 'deployer-for-git' ) ;
|
||||
?></p>
|
||||
<p class="description dfg_repo_url_description dfg_hidden" id="github-repo-url-description"><?php
|
||||
echo esc_attr__( 'Example: https://github.com/owner/wordpress-plugin-name', 'deployer-for-git' ) ;
|
||||
?></p>
|
||||
<p class="description dfg_repo_url_description dfg_hidden" id="gitea-repo-url-description"><?php
|
||||
echo esc_attr__( 'Example: https://gitea.com/owner/wordpress-plugin-name', 'deployer-for-git' ) ;
|
||||
?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<th scope="row"><?php
|
||||
echo esc_attr__( 'Branch', 'deployer-for-git' ) ;
|
||||
?> <span class="dashicons dashicons-randomize"></span></th>
|
||||
<td>
|
||||
<input type="text" class="" placeholder="master" name="repository_branch" value="" />
|
||||
<p class="description"><?php
|
||||
echo esc_attr__( 'default is "master"', 'deployer-for-git' ) ;
|
||||
?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
$private_repository_row_class = 'free';
|
||||
?>
|
||||
|
||||
<tr valign="top" class="dfg_hidden dfg_is_private_repository_row <?php
|
||||
echo esc_attr( $private_repository_row_class ) ;
|
||||
?>">
|
||||
<th scope="row">
|
||||
<?php
|
||||
echo esc_attr__( 'Is Private Repository', 'deployer-for-git' ) ;
|
||||
?>
|
||||
|
||||
<?php
|
||||
?>
|
||||
<br>
|
||||
<small><?php
|
||||
echo esc_attr__( '[Available in PRO version]', 'deployer-for-git' ) ;
|
||||
?></small>
|
||||
<?php
|
||||
?>
|
||||
|
||||
<span class="dashicons dashicons-lock"></span>
|
||||
</th>
|
||||
<td><input type="checkbox" name="is_private_repository" value="1"></td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
?>
|
||||
</table>
|
||||
<div class="submit">
|
||||
<input type="submit" class="button-primary" value="<?php
|
||||
echo esc_attr__( 'Install Plugin', 'deployer-for-git' ) ;
|
||||
?>" /><br><br>
|
||||
<p class="description"><i><?php
|
||||
echo esc_attr__( 'Note that if a plugin with specified slug is already installed, this action will overwrite the already existing plugin.', 'deployer-for-git' ) ;
|
||||
?><i></p>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
namespace DeployerForGit\Subpages\InstallThemePage;
|
||||
|
||||
use DeployerForGit\DataManager;
|
||||
use DeployerForGit\Logger;
|
||||
use DeployerForGit\Subpages\InstallPackage;
|
||||
|
||||
/**
|
||||
* Class InstallTheme
|
||||
*
|
||||
* @package DeployerForGit\Subpages\InstallThemePage
|
||||
*/
|
||||
class InstallTheme extends InstallPackage {
|
||||
|
||||
/**
|
||||
* Initializes the menu.
|
||||
*/
|
||||
public function init_menu() {
|
||||
$menu_slug = \DeployerForGit\Helper::menu_slug();
|
||||
$page_title = esc_attr__( 'Install Theme', 'deployer-for-git' );
|
||||
$capability = is_multisite() ? 'manage_network_options' : 'manage_options';
|
||||
|
||||
add_submenu_page(
|
||||
$menu_slug,
|
||||
$page_title,
|
||||
$page_title,
|
||||
$capability,
|
||||
"{$menu_slug}-install-theme",
|
||||
array( $this, 'init_page' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Installs a theme from a zip file.
|
||||
*
|
||||
* @param string $package_zip_url The URL of the zip file.
|
||||
* @param string $package_slug The slug of the package.
|
||||
* @param string $package_provider The provider of the package (github|bitbucket|gitlab|gitea).
|
||||
* @param array $options The options.
|
||||
* @return WP_Error|bool Returns WP_Error object for failure or true for success.
|
||||
*/
|
||||
public static function install_theme_from_zip_url( $package_zip_url, $package_slug, $package_provider, $options = array() ) {
|
||||
return parent::install_package_from_zip_url( $package_zip_url, $package_slug, 'theme', $package_provider, $options );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the page.
|
||||
*/
|
||||
public function init_page() {
|
||||
// Handle package installation form.
|
||||
$install_result = parent::handle_package_install_form();
|
||||
|
||||
include_once __DIR__ . '/template.php';
|
||||
}
|
||||
}
|
@@ -0,0 +1 @@
|
||||
<?php // Silence is golden
|
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
use DeployerForGit\Helper ;
|
||||
if ( !defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( isset( $install_result ) ) {
|
||||
?>
|
||||
<?php
|
||||
|
||||
if ( !is_wp_error( $install_result ) ) {
|
||||
?>
|
||||
<div class="updated">
|
||||
<p>
|
||||
<?php
|
||||
echo esc_attr__( 'Theme was successfully installed', 'deployer-for-git' ) ;
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
} else {
|
||||
?>
|
||||
<div class="error">
|
||||
<p>
|
||||
<!-- <strong><?php
|
||||
echo esc_attr( $install_result->get_error_code() ) ;
|
||||
?></strong> -->
|
||||
<?php
|
||||
echo esc_attr( $install_result->get_error_message() ) ;
|
||||
?>
|
||||
</p>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="wrap">
|
||||
<h1><?php
|
||||
echo esc_attr__( 'Install Theme', 'deployer-for-git' ) ;
|
||||
?></h1>
|
||||
<form class="dfg_install_package_form" method="post" action="">
|
||||
<input type="hidden" name="<?php
|
||||
echo esc_attr( DFG_SLUG . '_install_package_submitted' ) ;
|
||||
?>" value="1">
|
||||
<input type="hidden" name="package_type" value="theme">
|
||||
|
||||
<?php
|
||||
wp_nonce_field( DFG_SLUG . '_install_package_form', DFG_SLUG . '_nonce' );
|
||||
?>
|
||||
<table class="form-table">
|
||||
<tr valign="top">
|
||||
<th scope="row"><?php
|
||||
echo esc_attr__( 'Provider Type', 'deployer-for-git' ) ;
|
||||
?></th>
|
||||
<td>
|
||||
<select name='provider_type'>
|
||||
<option value="" selected disabled><?php
|
||||
echo esc_attr__( 'Choose a provider', 'deployer-for-git' ) ;
|
||||
?></option>
|
||||
<?php
|
||||
foreach ( Helper::available_providers() as $provider_id => $name ) {
|
||||
?>
|
||||
<option value="<?php
|
||||
echo esc_attr( $provider_id ) ;
|
||||
?>"><?php
|
||||
echo esc_attr( $name ) ;
|
||||
?></option>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<th scope="row"><?php
|
||||
echo esc_attr__( 'Repository URL', 'deployer-for-git' ) ;
|
||||
?></th>
|
||||
<td>
|
||||
<input type="url" class="regular-text code" name="repository_url" value="" />
|
||||
<p class="description dfg_repo_url_description dfg_hidden" id="bitbucket-repo-url-description"><?php
|
||||
echo esc_attr__( 'Example: https://bitbucket.org/owner/wordpress-theme-name', 'deployer-for-git' ) ;
|
||||
?></p>
|
||||
<p class="description dfg_repo_url_description dfg_hidden" id="github-repo-url-description"><?php
|
||||
echo esc_attr__( 'Example: https://github.com/owner/wordpress-theme-name', 'deployer-for-git' ) ;
|
||||
?></p>
|
||||
<p class="description dfg_repo_url_description dfg_hidden" id="gitea-repo-url-description"><?php
|
||||
echo esc_attr__( 'Example: https://gitea.com/owner/wordpress-theme-name', 'deployer-for-git' ) ;
|
||||
?></p>
|
||||
<p class="description dfg_repo_url_description dfg_hidden" id="gitlab-repo-url-description"><?php
|
||||
echo esc_attr__( 'Example: https://gitlab.com/owner/wordpress-theme-name', 'deployer-for-git' ) ;
|
||||
?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr valign="top">
|
||||
<th scope="row"><?php
|
||||
echo esc_attr__( 'Branch', 'deployer-for-git' ) ;
|
||||
?> <span class="dashicons dashicons-randomize"></span></th>
|
||||
<td>
|
||||
<input type="text" class="" placeholder="master" name="repository_branch" value="" />
|
||||
<p class="description"><?php
|
||||
echo esc_attr__( 'default is "master"', 'deployer-for-git' ) ;
|
||||
?></p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
$private_repository_row_class = 'free';
|
||||
?>
|
||||
|
||||
<tr valign="top" class="dfg_hidden dfg_is_private_repository_row <?php
|
||||
echo esc_attr( $private_repository_row_class ) ;
|
||||
?>" >
|
||||
<th scope="row">
|
||||
<?php
|
||||
echo esc_attr__( 'Is Private Repository', 'deployer-for-git' ) ;
|
||||
?>
|
||||
|
||||
<?php
|
||||
?>
|
||||
<br>
|
||||
<small><?php
|
||||
echo esc_attr__( '[Available in PRO version]', 'deployer-for-git' ) ;
|
||||
?></small>
|
||||
<?php
|
||||
?>
|
||||
|
||||
<span class="dashicons dashicons-lock"></span>
|
||||
</th>
|
||||
<td><input type="checkbox" name="is_private_repository" value="1"></td>
|
||||
</tr>
|
||||
|
||||
<?php
|
||||
?>
|
||||
</table>
|
||||
<div class="submit">
|
||||
<input type="submit" class="button-primary" value="<?php
|
||||
echo esc_attr__( 'Install Theme', 'deployer-for-git' ) ;
|
||||
?>" /><br><br>
|
||||
<p class="description"><i><?php
|
||||
echo esc_attr__( 'Note that if a theme with specified slug is already installed, this action will overwrite the already existing theme.', 'deployer-for-git' ) ;
|
||||
?><i></p>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace DeployerForGit\Subpages\LogsPage;
|
||||
|
||||
use DeployerForGit\DataManager;
|
||||
use DeployerForGit\Logger;
|
||||
|
||||
/**
|
||||
* Logs page
|
||||
*/
|
||||
class Logs {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', array( $this, 'init_menu' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize menu
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init_menu() {
|
||||
$menu_slug = \DeployerForGit\Helper::menu_slug();
|
||||
$capability = is_multisite() ? 'manage_network_options' : 'manage_options';
|
||||
|
||||
add_submenu_page(
|
||||
$menu_slug,
|
||||
esc_attr__( 'Logs', 'deployer-for-git' ),
|
||||
esc_attr__( 'Logs', 'deployer-for-git' ),
|
||||
$capability,
|
||||
"{$menu_slug}-logs",
|
||||
array( $this, 'init_page' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize page
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init_page() {
|
||||
$data_manager = new DataManager();
|
||||
$this->handle_clear_log_form();
|
||||
|
||||
include_once __DIR__ . '/template.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle clear log form
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle_clear_log_form() {
|
||||
$form_submitted = false;
|
||||
|
||||
if ( isset( $_POST[ DFG_SLUG . '_nonce' ] ) && wp_verify_nonce( ( sanitize_text_field( wp_unslash( $_POST[ DFG_SLUG . '_nonce' ] ) ) ), DFG_SLUG . '_clear_log_file' ) ) {
|
||||
$logger = new Logger();
|
||||
$clear_log_result = $logger->clear_log_file();
|
||||
$form_submitted = true;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1 @@
|
||||
<?php // Silence is golden
|
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
use DeployerForGit\Logger;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1>
|
||||
<?php echo esc_attr__( 'Logs', 'deployer-for-git' ); ?>
|
||||
</h1>
|
||||
|
||||
<?php if ( isset( $form_submitted ) && $form_submitted ) : ?>
|
||||
<?php if ( isset( $clear_log_result ) && $clear_log_result ) : ?>
|
||||
<div class="updated">
|
||||
<p><?php echo esc_attr__( 'Log file cleared', 'deployer-for-git' ); ?></p>
|
||||
</div>
|
||||
<?php else : ?>
|
||||
<div class="error">
|
||||
<p><?php echo esc_attr__( 'Can\'t clear the log file.', 'deployer-for-git' ); ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php $logger = new Logger(); ?>
|
||||
<textarea class="large-text code dfg_log_textarea" readonly><?php echo esc_textarea( $logger->display_log_content() ); ?></textarea>
|
||||
|
||||
<form method="post" action="" onsubmit="return confirm('<?php echo esc_attr__( 'Are you sure?', 'deployer-for-git' ); ?>');">
|
||||
<input type="hidden" name="action" value="clear_log_file">
|
||||
<?php wp_nonce_field( DFG_SLUG . '_clear_log_file', DFG_SLUG . '_nonce' ); ?>
|
||||
<input type="submit" class="button button-primary" value="<?php echo esc_attr__( 'Clear log file', 'deployer-for-git' ); ?>">
|
||||
</form>
|
||||
</div>
|
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
namespace DeployerForGit\Subpages\MiscellaneousPage;
|
||||
|
||||
use DeployerForGit\DataManager;
|
||||
use DeployerForGit\Helper;
|
||||
|
||||
/**
|
||||
* Miscellaneous page
|
||||
*/
|
||||
class Miscellaneous {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', array( $this, 'init_menu' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize menu
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init_menu() {
|
||||
$menu_slug = Helper::menu_slug();
|
||||
$capability = is_multisite() ? 'manage_network_options' : 'manage_options';
|
||||
|
||||
add_submenu_page(
|
||||
$menu_slug,
|
||||
esc_attr__( 'Miscellaneous', 'deployer-for-git' ),
|
||||
esc_attr__( 'Miscellaneous', 'deployer-for-git' ),
|
||||
$capability,
|
||||
"{$menu_slug}-miscellaneous",
|
||||
array( $this, 'init_page' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize page
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init_page() {
|
||||
$regenerate_secret_key_result = $this->handle_regenerate_secret_key_form();
|
||||
$flush_cache_result = $this->handle_flush_cache_form();
|
||||
$alert_notification_result = $this->handle_alert_notification_form();
|
||||
$data_manager = new DataManager();
|
||||
|
||||
include_once __DIR__ . '/template.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle regenerate secret key form
|
||||
*
|
||||
* @return boolean|null
|
||||
*/
|
||||
public function handle_regenerate_secret_key_form() {
|
||||
$result = null;
|
||||
|
||||
if ( isset( $_POST['action'] ) && $_POST['action'] === 'regenerate_secret_key' ) {
|
||||
$result = false;
|
||||
|
||||
if ( isset( $_POST[ DFG_SLUG . '_nonce' ] ) || wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST[ DFG_SLUG . '_nonce' ] ) ), DFG_SLUG . '_regenerate_secret_key' ) ) {
|
||||
$result = true;
|
||||
Helper::generate_api_secret();
|
||||
|
||||
do_action( 'dfg_after_secret_key_regenerate' );
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle flush cache form
|
||||
*
|
||||
* @return boolean|null
|
||||
*/
|
||||
public function handle_flush_cache_form() {
|
||||
$result = null;
|
||||
|
||||
if ( isset( $_POST['action'] ) && $_POST['action'] === 'flush_cache' ) {
|
||||
$result = false;
|
||||
|
||||
if ( isset( $_POST[ DFG_SLUG . '_nonce' ] ) || wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST[ DFG_SLUG . '_nonce' ] ) ), DFG_SLUG . '_flush_cache' ) ) {
|
||||
$data_manager = new DataManager();
|
||||
|
||||
$result = $data_manager->update_flush_cache_setting( isset( $_POST['flush_cache_setting'] ) );
|
||||
|
||||
do_action( 'dfg_after_flush_cache_setting_update' );
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle alert notification form
|
||||
*
|
||||
* @return boolean|null
|
||||
*/
|
||||
public function handle_alert_notification_form() {
|
||||
$result = null;
|
||||
|
||||
if ( isset( $_POST['action'] ) && $_POST['action'] === 'alert_notification' ) {
|
||||
$result = false;
|
||||
|
||||
if ( isset( $_POST[ DFG_SLUG . '_nonce' ] ) || wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST[ DFG_SLUG . '_nonce' ] ) ), DFG_SLUG . '_alert_notification' ) ) {
|
||||
$data_manager = new DataManager();
|
||||
|
||||
$result = $data_manager->update_alert_notification_setting( isset( $_POST['alert_notification_setting'] ) );
|
||||
|
||||
do_action( 'dfg_after_alert_notification_setting_update' );
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
@@ -0,0 +1 @@
|
||||
<?php // Silence is golden
|
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
use DeployerForGit\Helper;
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="wrap">
|
||||
<h1>
|
||||
<?php echo esc_attr__( 'Miscellaneous', 'deployer-for-git' ); ?>
|
||||
</h1>
|
||||
|
||||
<?php
|
||||
if ( isset( $regenerate_secret_key_result ) && $regenerate_secret_key_result !== null ) {
|
||||
if ( $regenerate_secret_key_result === false ) {
|
||||
echo '<div class="notice notice-error is-dismissible"><p>' . esc_attr__( 'Error while regenerating secret key.', 'deployer-for-git' ) . '</p></div>';
|
||||
} else {
|
||||
echo '<div class="notice notice-success is-dismissible"><p>' . esc_attr__( 'Secret key has been successfully regenerated.', 'deployer-for-git' ) . '</p></div>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<?php
|
||||
if ( isset( $flush_cache_result ) && $flush_cache_result !== null ) {
|
||||
echo '<div class="notice notice-success is-dismissible"><p>' . esc_attr__( 'Cache setting has been updated.', 'deployer-for-git' ) . '</p></div>';
|
||||
}
|
||||
?>
|
||||
|
||||
<?php
|
||||
if ( isset( $alert_notification_result ) && $alert_notification_result !== null ) {
|
||||
echo '<div class="notice notice-success is-dismissible"><p>' . esc_attr__( 'Alert notification setting has been updated.', 'deployer-for-git' ) . '</p></div>';
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="dfg_form_box">
|
||||
<h3><span class="dashicons dashicons-admin-network"></span> <?php echo esc_attr__( 'Secret Key management', 'deployer-for-git' ); ?></h3>
|
||||
|
||||
<table class="form-table">
|
||||
<tr valign="top">
|
||||
<th scope="row">
|
||||
<?php echo esc_attr__( 'Current secret key:', 'deployer-for-git' ); ?>
|
||||
</th>
|
||||
<td>
|
||||
<span><?php echo esc_attr( Helper::get_api_secret() ); ?></span>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<form method="post" action="" onsubmit="return confirm( '<?php echo esc_attr__( 'Are you sure?', 'deployer-for-git' ); ?>' );">
|
||||
<input type="hidden" name="action" value="regenerate_secret_key">
|
||||
<?php wp_nonce_field( DFG_SLUG . '_regenerate_secret_key', DFG_SLUG . '_nonce' ); ?>
|
||||
|
||||
<input type="submit" class="button button-primary" value="<?php echo esc_attr__( 'Regenerate Secret Key', 'deployer-for-git' ); ?>">
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="dfg_form_box">
|
||||
<h3><span class="dashicons dashicons-database"></span> <?php echo esc_attr__( 'Flush cache', 'deployer-for-git' ); ?></h3>
|
||||
|
||||
<p class="description">
|
||||
<?php echo esc_attr__( 'Activate this option if you want the plugin to clear the cache every time the package update link is triggered. We support next list of plugins:', 'deployer-for-git' ); ?>
|
||||
<ul>
|
||||
<li>
|
||||
WP Rocket |
|
||||
<?php if ( Helper::wp_rocket_activated() ) : ?>
|
||||
<span class="wp-ui-text-highlight">
|
||||
<?php echo esc_attr__( 'Active plugin found', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php else : ?>
|
||||
<span class="wp-ui-text-notification">
|
||||
<?php echo esc_attr__( 'No plugin detected', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<li>
|
||||
WP-Optimize |
|
||||
<?php if ( Helper::wp_optimize_activated() ) : ?>
|
||||
<span class="wp-ui-text-highlight">
|
||||
<?php echo esc_attr__( 'Active plugin found', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php else : ?>
|
||||
<span class="wp-ui-text-notification">
|
||||
<?php echo esc_attr__( 'No plugin detected', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<li>W3 Total Cache |
|
||||
<?php if ( Helper::w3tc_activated() ) : ?>
|
||||
<span class="wp-ui-text-highlight">
|
||||
<?php echo esc_attr__( 'Active plugin found', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php else : ?>
|
||||
<span class="wp-ui-text-notification">
|
||||
<?php echo esc_attr__( 'No plugin detected', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<li>
|
||||
LiteSpeed Cache |
|
||||
<?php if ( Helper::litespeed_cache_activated() ) : ?>
|
||||
<span class="wp-ui-text-highlight">
|
||||
<?php echo esc_attr__( 'Active plugin found', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php else : ?>
|
||||
<span class="wp-ui-text-notification">
|
||||
<?php echo esc_attr__( 'No plugin detected', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<li>
|
||||
WP Super Cache |
|
||||
<?php if ( Helper::wp_super_cache_activated() ) : ?>
|
||||
<span class="wp-ui-text-highlight">
|
||||
<?php echo esc_attr__( 'Active plugin found', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php else : ?>
|
||||
<span class="wp-ui-text-notification">
|
||||
<?php echo esc_attr__( 'No plugin detected', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<li>
|
||||
WP Fastest Cache |
|
||||
<?php if ( Helper::wp_fastest_cache_activated() ) : ?>
|
||||
<span class="wp-ui-text-highlight">
|
||||
<?php echo esc_attr__( 'Active plugin found', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php else : ?>
|
||||
<span class="wp-ui-text-notification">
|
||||
<?php echo esc_attr__( 'No plugin detected', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
<li>
|
||||
Autoptimize |
|
||||
<?php if ( Helper::autoptimize_activated() ) : ?>
|
||||
<span class="wp-ui-text-highlight">
|
||||
<?php echo esc_attr__( 'Active plugin found', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php else : ?>
|
||||
<span class="wp-ui-text-notification">
|
||||
<?php echo esc_attr__( 'No plugin detected', 'deployer-for-git' ); ?>
|
||||
</span>
|
||||
<?php endif; ?>
|
||||
</li>
|
||||
</ul>
|
||||
</p>
|
||||
|
||||
<form method="post" action="">
|
||||
<input type="hidden" name="action" value="flush_cache">
|
||||
<?php wp_nonce_field( DFG_SLUG . '_flush_cache', DFG_SLUG . '_nonce' ); ?>
|
||||
|
||||
<table class="form-table">
|
||||
<tr valign="top">
|
||||
<th scope="row">
|
||||
<?php echo esc_attr__( 'Enable', 'deployer-for-git' ); ?>
|
||||
</th>
|
||||
<td>
|
||||
<input type="checkbox" name="flush_cache_setting" <?php echo $data_manager->get_flush_cache_setting() === true ? 'checked' : ''; ?> value="1">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p class="submit">
|
||||
<input type="submit" class="button-primary" value="<?php echo esc_attr__( 'Save Caching Settings', 'deployer-for-git' ); ?>" />
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="dfg_form_box">
|
||||
<h3><span class="dashicons dashicons-feedback"></span> <?php echo esc_attr__( 'Alert notification', 'deployer-for-git' ); ?></h3>
|
||||
|
||||
<p class="description">
|
||||
<?php echo esc_attr__( 'Enable this option if you wish to display a notification message at the top of WordPress Admin interface (/wp-admin). The message is intended for developers, reminding them not to make any changes to the theme or plugin directly on this site, but rather use Git for such modifications.', 'deployer-for-git' ); ?>
|
||||
</p>
|
||||
|
||||
<form method="post" action="">
|
||||
<input type="hidden" name="action" value="alert_notification">
|
||||
<?php wp_nonce_field( DFG_SLUG . '_alert_notification', DFG_SLUG . '_nonce' ); ?>
|
||||
|
||||
<table class="form-table">
|
||||
<tr valign="top">
|
||||
<th scope="row">
|
||||
<?php echo esc_attr__( 'Enable', 'deployer-for-git' ); ?>
|
||||
</th>
|
||||
<td>
|
||||
<input type="checkbox" name="alert_notification_setting" <?php echo $data_manager->get_alert_notification_setting() === true ? 'checked' : ''; ?> value="1">
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p class="submit">
|
||||
<input type="submit" class="button-primary" value="<?php echo esc_attr__( 'Save Alert Notification Settings', 'deployer-for-git' ); ?>" />
|
||||
</p>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</div>
|
@@ -0,0 +1 @@
|
||||
<?php // Silence is golden
|
Reference in New Issue
Block a user