| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPAdminify\Inc\Admin\Options; |
| 4 |
|
| 5 |
use WPAdminify\Inc\Utils; |
| 6 |
use WPAdminify\Inc\Classes\Helper; |
| 7 |
use WPAdminify\Inc\Classes\Adminify_Rollback; |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
die; |
| 11 |
} // Cannot access directly. |
| 12 |
|
| 13 |
class RollbackVersion { |
| 14 |
|
| 15 |
private $prefix; |
| 16 |
public function __construct() { |
| 17 |
if ( is_multisite() && ! is_network_admin() ) { |
| 18 |
return; // only display to network admin if multisite is enbaled |
| 19 |
} |
| 20 |
|
| 21 |
$this->prefix = '_adminify_rollback'; |
| 22 |
$this->jltwp_adminify_rollback_options(); |
| 23 |
|
| 24 |
add_action( 'admin_enqueue_scripts', [ $this, 'jltwp_adminify_rollback_enqueue_scripts' ] ); |
| 25 |
} |
| 26 |
|
| 27 |
public function get_defaults() { |
| 28 |
return [ |
| 29 |
'adminify_rollback' => '', |
| 30 |
]; |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Scripts/Styles |
| 35 |
*/ |
| 36 |
public function jltwp_adminify_rollback_enqueue_scripts() { |
| 37 |
global $pagenow; |
| 38 |
|
| 39 |
// Load Scripts/Styles only WP Adminify Custom CSS/JS Page |
| 40 |
if ( ! empty( $_GET['page'] ) && ( 'admin.php' === $pagenow ) && ( 'adminify-rollback-version' === $_GET['page'] ) ) { |
| 41 |
$this->version_rollback_admin_script(); |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
public function version_rollback_admin_script() { |
| 47 |
$rollback_custom_admin_styles = '.adminify-rollback-version .adminify-container{ max-width:60%; margin:0 auto;} .adminify-rollback-version .adminify-header{display:none ;} |
| 48 |
.adminify-rollback-version .adminify-header-inner{padding:0;}.adminify-rollback-version .adminify-field-subheading{font-size:20px; padding-left:0;} .adminify-rollback-version .adminify-nav,.adminify-rollback-version .adminify-search,.adminify-rollback-version .adminify-footer,.adminify-rollback-version .adminify-reset-all,.adminify-rollback-version .adminify-expand-all,.adminify-rollback-version .adminify-header-left,.adminify-rollback-version .adminify-reset-section,.adminify-rollback-version .adminify-nav-background{display: none !important;}.adminify-rollback-version .adminify-nav-normal + .adminify-content{margin-left: 0;} |
| 49 |
/* If needed for white top-bar */ |
| 50 |
.adminify-rollback-version .adminify-header-inner { |
| 51 |
background-color: #fafafa !important; |
| 52 |
border-bottom: 1px solid #f5f5f5; |
| 53 |
} |
| 54 |
.adminify-rollback-version .adminify-field-callback a.dashicons{ width: inherit; }'; |
| 55 |
|
| 56 |
echo '<style>' . wp_strip_all_tags( $rollback_custom_admin_styles ) . '</style>'; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
public static function jltwp_adminify_rollback_contents() { ?> |
| 61 |
|
| 62 |
<div class="border border-muted"> |
| 63 |
|
| 64 |
<h3><?php echo esc_html__( 'Rollback Version', 'adminify' ); ?></h3> |
| 65 |
|
| 66 |
|
| 67 |
<?php |
| 68 |
$rollback_html = '<select class="wp-adminify-rollback-select">'; |
| 69 |
$ger_versions = Adminify_Rollback::get_instance(); |
| 70 |
|
| 71 |
foreach ( $ger_versions->get_rollback_versions() as $version ) { |
| 72 |
$rollback_html .= "<option value='{$version}'>$version</option>"; |
| 73 |
} |
| 74 |
$rollback_html .= '</select>'; |
| 75 |
echo Utils::wp_kses_custom( $rollback_html ); |
| 76 |
|
| 77 |
echo sprintf( |
| 78 |
wp_kses_post( '<a data-placeholder-text="%1$s" href="#" data-placeholder-url="%2$s" class="button button-primary wp-adminify-btn wp-adminify-rollback-button dashicons dashicons-update-alt ml-2">%3$s</a>' ), |
| 79 |
esc_html__( 'Reinstall', WP_ADMINIFY_VER ) . ' v' . esc_html( VERSION ), |
| 80 |
esc_url_raw( wp_nonce_url( admin_url( 'admin-post.php?action=wp_adminify_rollback_version&version=VERSION' ), 'wp_adminify_rollback_version' ) ), |
| 81 |
esc_html__( 'Reinstall', WP_ADMINIFY_VER ) |
| 82 |
); |
| 83 |
?> |
| 84 |
<p class="wp-adminify-roll-desc pt-2 has-text-danger"> |
| 85 |
<?php echo esc_html__( 'Warning: Please backup your database before making the rollback.', 'adminify' ); ?> |
| 86 |
</p> |
| 87 |
</div> |
| 88 |
|
| 89 |
|
| 90 |
<div class="wp-adminify--popup-area is-flex is-align-items-center is-justify-content-center"> |
| 91 |
<div class="wp-adminify--popup-container has-text-centered"> |
| 92 |
<div class="wp-adminify--popup-container_inner pt-6 pb-6"> |
| 93 |
<div class="wp-adminify-popup-header"> |
| 94 |
<?php echo esc_html__( 'Rollback to Previous Version', 'adminify' ); ?> |
| 95 |
</div> |
| 96 |
<div class="wp-adminify-dialog-message wp-adminify-dialog-confirm-message slow"> |
| 97 |
<?php echo esc_html__( 'Are you sure you want to reinstall previous version?', 'adminify' ); ?> |
| 98 |
</div> |
| 99 |
<div class="wp-adminify-dialog-buttons-wrapper wp-adminify-dialog-confirm-buttons-wrapper mt-5"> |
| 100 |
<button class="wp-adminify-dialog-button button-secondary wp-adminify-dialog-cancel wp-adminify-dialog-confirm-cancel"> |
| 101 |
<?php echo esc_html__( 'Cancel', 'adminify' ); ?> |
| 102 |
</button> |
| 103 |
<button class="wp-adminify-dialog-button button-primary wp-adminify-dialog-ok wp-adminify-dialog-confirm-ok"> |
| 104 |
<?php echo esc_html__( 'Continue', 'adminify' ); ?> |
| 105 |
</button> |
| 106 |
</div> |
| 107 |
</div> |
| 108 |
</div> |
| 109 |
</div> |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
<?php |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
public function jltwp_adminify_rollback_fields( &$fields ) { |
| 119 |
$fields[] = [ |
| 120 |
'type' => 'subheading', |
| 121 |
'content' => Utils::adminfiy_help_urls( |
| 122 |
__( 'Rollback to Previous Version', 'adminify' ), |
| 123 |
'https://wpadminify.com/kb/version-rollback/', |
| 124 |
'https://www.youtube.com/playlist?list=PLqpMw0NsHXV-EKj9Xm1DMGa6FGniHHly8', |
| 125 |
'https://www.facebook.com/groups/jeweltheme', |
| 126 |
\WPAdminify\Inc\Admin\AdminSettings::support_url() |
| 127 |
), |
| 128 |
]; |
| 129 |
|
| 130 |
$fields[] = [ |
| 131 |
'type' => 'submessage', |
| 132 |
'style' => 'info', |
| 133 |
'content' => sprintf( __( '<strong>Experiencing an issue with %1$s <em>v%2$s</em>? Rollback to a previous version before the issue appeared.</strong>', 'adminify' ), esc_html( WP_ADMINIFY ), esc_html( WP_ADMINIFY_VER ) ), |
| 134 |
]; |
| 135 |
|
| 136 |
$fields[] = [ |
| 137 |
'id' => 'adminify_rollback', |
| 138 |
'type' => 'callback', |
| 139 |
'function' => '\WPAdminify\Inc\Admin\Options\RollbackVersion::jltwp_adminify_rollback_contents', |
| 140 |
]; |
| 141 |
} |
| 142 |
|
| 143 |
public function jltwp_adminify_rollback_options() { |
| 144 |
if ( ! class_exists( 'ADMINIFY' ) ) { |
| 145 |
return; |
| 146 |
} |
| 147 |
|
| 148 |
// WP Adminify Custom Header & Footer Options |
| 149 |
\ADMINIFY::createOptions( |
| 150 |
$this->prefix, |
| 151 |
[ |
| 152 |
|
| 153 |
// Framework Title |
| 154 |
'framework_title' => __( 'Rollback Version <small>for WP Adminify</small>', 'adminify' ), |
| 155 |
'framework_class' => 'adminify-rollback-version', |
| 156 |
|
| 157 |
// menu settings |
| 158 |
'menu_title' => __( 'Rollback Version', 'adminify' ), |
| 159 |
'menu_slug' => 'adminify-rollback-version', |
| 160 |
'menu_type' => 'submenu', // menu, submenu, options, theme, etc. |
| 161 |
'menu_capability' => 'manage_options', |
| 162 |
'menu_icon' => '', |
| 163 |
'menu_position' => 54, |
| 164 |
'menu_hidden' => false, |
| 165 |
'menu_parent' => 'wp-adminify-settings', |
| 166 |
|
| 167 |
// footer |
| 168 |
'footer_text' => ' ', |
| 169 |
'footer_after' => ' ', |
| 170 |
'footer_credit' => ' ', |
| 171 |
|
| 172 |
// menu extras |
| 173 |
'show_bar_menu' => false, |
| 174 |
'show_sub_menu' => false, |
| 175 |
'show_in_network' => true, |
| 176 |
'show_in_customizer' => false, |
| 177 |
|
| 178 |
'show_search' => false, |
| 179 |
'show_reset_all' => false, |
| 180 |
'show_reset_section' => false, |
| 181 |
'show_header' => false, |
| 182 |
'show_footer' => false, |
| 183 |
'show_all_options' => false, |
| 184 |
'show_form_warning' => false, |
| 185 |
'sticky_header' => false, |
| 186 |
'save_defaults' => false, |
| 187 |
'ajax_save' => false, |
| 188 |
|
| 189 |
// admin bar menu settings |
| 190 |
'admin_bar_menu_icon' => '', |
| 191 |
'admin_bar_menu_priority' => 45, |
| 192 |
|
| 193 |
// database model |
| 194 |
'database' => 'network', // options, transient, theme_mod, network(multisite support) |
| 195 |
'transient_time' => 0, |
| 196 |
|
| 197 |
// typography options |
| 198 |
'enqueue_webfont' => false, |
| 199 |
'async_webfont' => false, |
| 200 |
|
| 201 |
// others |
| 202 |
'output_css' => false, |
| 203 |
|
| 204 |
// theme and wrapper classname |
| 205 |
'nav' => 'normal', |
| 206 |
'theme' => 'dark', |
| 207 |
'class' => 'wp-adminify-rollback', |
| 208 |
] |
| 209 |
); |
| 210 |
|
| 211 |
$fields = []; |
| 212 |
$this->jltwp_adminify_rollback_fields( $fields ); |
| 213 |
|
| 214 |
// Rollback Section |
| 215 |
\ADMINIFY::createSection( |
| 216 |
$this->prefix, |
| 217 |
[ |
| 218 |
'title' => __( 'Rollback Version', 'adminify' ), |
| 219 |
'icon' => 'fas fa-layer-group', |
| 220 |
'fields' => $fields, |
| 221 |
] |
| 222 |
); |
| 223 |
} |
| 224 |
} |
| 225 |
|