| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
die( 'Direct access forbidden.' ); |
| 4 |
} |
| 5 |
|
| 6 |
class Brizy_Admin_Main { |
| 7 |
|
| 8 |
public static function instance() { |
| 9 |
static $instance; |
| 10 |
if ( ! $instance ) { |
| 11 |
$instance = new self(); |
| 12 |
} |
| 13 |
|
| 14 |
return $instance; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Brizy_Admin_Main constructor. |
| 19 |
*/ |
| 20 |
protected function __construct() { |
| 21 |
|
| 22 |
if ( ! Brizy_Editor_User::is_user_allowed() ) { |
| 23 |
return; |
| 24 |
} |
| 25 |
// enqueue admin scripts |
| 26 |
add_action( 'admin_enqueue_scripts', [ $this, 'action_register_static' ] ); |
| 27 |
add_action( 'enqueue_block_editor_assets', [ $this, 'action_register_static' ] ); |
| 28 |
add_action( 'enqueue_block_assets', [ $this, 'action_register_static' ] ); |
| 29 |
if ( current_user_can( Brizy_Admin_Capabilities::CAP_EDIT_WHOLE_PAGE ) || Brizy_Editor_User::is_administrator() ) { |
| 30 |
add_action( 'admin_post__brizy_admin_editor_enable', array( |
| 31 |
$this, |
| 32 |
'action_request_enable' |
| 33 |
) ); // enable editor for a post |
| 34 |
add_action( 'admin_post__brizy_admin_editor_disable', array( |
| 35 |
$this, |
| 36 |
'action_request_disable' |
| 37 |
) ); // disable editor for a post |
| 38 |
add_action( 'admin_post__brizy_change_template', array( |
| 39 |
$this, |
| 40 |
'action_change_template' |
| 41 |
) ); |
| 42 |
// that this hook only works on the classic editor, |
| 43 |
// add button to enable disable editor |
| 44 |
add_action( 'edit_form_after_title', [ |
| 45 |
$this, |
| 46 |
'action_add_enable_disable_buttons' |
| 47 |
], - 1 ); |
| 48 |
} |
| 49 |
add_action( 'before_delete_post', array( $this, 'action_delete_page' ) ); |
| 50 |
add_filter( 'page_row_actions', array( $this, 'filter_add_brizy_edit_row_actions' ), 10, 2 ); |
| 51 |
add_filter( 'post_row_actions', array( $this, 'filter_add_brizy_edit_row_actions' ), 10, 2 ); |
| 52 |
add_filter( 'admin_body_class', array( $this, 'filter_add_body_class' ), 10, 2 ); |
| 53 |
add_action( 'admin_head', array( $this, 'hide_editor' ) ); |
| 54 |
add_action( 'admin_head', array( $this, 'custom_css_btns' ) ); |
| 55 |
add_filter( 'plugin_action_links_' . BRIZY_PLUGIN_BASE, array( $this, 'plugin_action_links' ) ); |
| 56 |
add_action( 'in_plugin_update_message-' . BRIZY_PLUGIN_BASE, [ $this, 'version_update_warning' ] ); |
| 57 |
add_filter( 'display_post_states', array( $this, 'display_post_states' ), 10, 2 ); |
| 58 |
//add_filter( 'save_post', array( $this, 'save_post' ), 10, 2 ); |
| 59 |
add_filter( 'save_post', array( $this, 'save_focal_point' ) ); |
| 60 |
add_filter( 'admin_post_thumbnail_html', array( $this, 'addFocalPoint' ), 10, 3 ); |
| 61 |
} |
| 62 |
|
| 63 |
public function addFocalPoint( $content, $postId, $thumbId ) { |
| 64 |
|
| 65 |
if ( ! $thumbId ) { |
| 66 |
return $content; |
| 67 |
} |
| 68 |
$urlBuilder = new Brizy_Editor_UrlBuilder(); |
| 69 |
$post = get_post( $postId ); |
| 70 |
$post_type_object = get_post_type_object( $post->post_type ); |
| 71 |
$focalPoint = Brizy_Editor_FocalPoint::sanitize( get_post_meta( $postId, 'brizy_attachment_focal_point', true ) ); |
| 72 |
|
| 73 |
return Brizy_Admin_View::render( 'featured-image', [ |
| 74 |
'focalPoint' => $focalPoint, |
| 75 |
'thumbnailId' => $thumbId, |
| 76 |
'thumbnailSrc' => wp_get_attachment_image_src( $thumbId, 'original' ), |
| 77 |
'postId' => $postId, |
| 78 |
'edit_update_label' => __( 'Edit or Update Image' ), |
| 79 |
'remove_label' => $post_type_object->labels->remove_featured_image, |
| 80 |
'pluginUrl' => $urlBuilder->editor_build_url() |
| 81 |
] ); |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* @param int $postId |
| 86 |
*/ |
| 87 |
public function action_delete_page( $postId = null ) { |
| 88 |
try { |
| 89 |
|
| 90 |
if ( ! current_user_can( 'edit_post', $postId ) ) { |
| 91 |
return; |
| 92 |
} |
| 93 |
if ( wp_is_post_autosave( $postId ) || wp_is_post_revision( $postId ) ) { |
| 94 |
return; |
| 95 |
} |
| 96 |
$urlBuilder = new Brizy_Editor_UrlBuilder( Brizy_Editor_Project::get(), $postId ); |
| 97 |
$pageUploadPath = $urlBuilder->page_upload_path( "assets/images" ); |
| 98 |
Brizy_Admin_FileSystem::deleteAllDirectories( $pageUploadPath ); |
| 99 |
$pageUploadPath = $urlBuilder->page_upload_path( "assets/icons" ); |
| 100 |
Brizy_Admin_FileSystem::deleteFilesAndDirectory( $pageUploadPath ); |
| 101 |
|
| 102 |
|
| 103 |
} catch ( Exception $e ) { |
| 104 |
// ignore this. |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* @param array $post_states |
| 110 |
* @param WP_Post $post |
| 111 |
* |
| 112 |
* @return mixed |
| 113 |
*/ |
| 114 |
public function display_post_states( $post_states, $post ) { |
| 115 |
|
| 116 |
if ( ! $post ) { |
| 117 |
return $post_states; |
| 118 |
} |
| 119 |
try { |
| 120 |
if ( Brizy_Editor_Entity::isBrizyEnabled( $post->ID ) ) { |
| 121 |
$post_states['brizy'] = __( Brizy_Editor::get()->get_name() ); |
| 122 |
} |
| 123 |
} catch ( Exception $e ) { |
| 124 |
// ignore this. |
| 125 |
} |
| 126 |
|
| 127 |
return $post_states; |
| 128 |
} |
| 129 |
|
| 130 |
// public function save_post( $post_id, $post ) { |
| 131 |
// try { |
| 132 |
// |
| 133 |
// $brizy_post = null; |
| 134 |
// |
| 135 |
// $parent_id = wp_is_post_revision( $post_id ); |
| 136 |
// |
| 137 |
// if ( $parent_id ) { |
| 138 |
// $brizy_post = Brizy_Editor_Post::get( $parent_id ); |
| 139 |
// |
| 140 |
// if ( $brizy_post->uses_editor() ) { |
| 141 |
// $brizy_post->save( $post_id ); |
| 142 |
// } |
| 143 |
// } |
| 144 |
// |
| 145 |
// } catch ( Exception $e ) { |
| 146 |
// Brizy_Logger::instance()->exception( $e ); |
| 147 |
// |
| 148 |
// return; |
| 149 |
// } |
| 150 |
// } |
| 151 |
/** |
| 152 |
* @param $post_id |
| 153 |
*/ |
| 154 |
public function save_focal_point( $post_id ) { |
| 155 |
|
| 156 |
if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || wp_is_post_revision( $post_id ) ) { |
| 157 |
return; |
| 158 |
} |
| 159 |
if ( isset( $_REQUEST['_thumbnail_focal_point_x'], $_REQUEST['_thumbnail_focal_point_y'] ) && $post_id ) { |
| 160 |
update_post_meta( $post_id, 'brizy_attachment_focal_point', Brizy_Editor_FocalPoint::sanitize( [ |
| 161 |
'x' => $_REQUEST['_thumbnail_focal_point_x'], |
| 162 |
'y' => $_REQUEST['_thumbnail_focal_point_y'] |
| 163 |
] ) ); |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
public function hide_editor() { |
| 168 |
|
| 169 |
$post_type = get_post_type(); |
| 170 |
if ( in_array( $post_type, Brizy_Editor::get()->supported_post_types() ) ) { |
| 171 |
$p = get_post(); |
| 172 |
try { |
| 173 |
$is_using_brizy = Brizy_Editor_Entity::isBrizyEnabled( $p->ID ); |
| 174 |
} catch ( Exception $e ) { |
| 175 |
$is_using_brizy = false; |
| 176 |
} |
| 177 |
if ( $is_using_brizy ) { |
| 178 |
//remove_post_type_support( $post_type, 'editor' ); |
| 179 |
// hide the default editor |
| 180 |
add_filter( 'the_editor', function ( $editor_html ) { |
| 181 |
$args = func_get_args(); |
| 182 |
if ( strpos( $editor_html, 'id="wp-content-editor-container"' ) !== false ) { |
| 183 |
return "<div style='display: none'>{$editor_html}</div>"; |
| 184 |
} |
| 185 |
|
| 186 |
return $editor_html; |
| 187 |
} ); |
| 188 |
} |
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
public function custom_css_btns() { |
| 193 |
|
| 194 |
$prefix = 'brizy'; |
| 195 |
if ( apply_filters( 'brizy_wl_enabled', false ) ) { |
| 196 |
$prefix = method_exists( 'BrizyPro_Admin_WhiteLabel', 'getPrefix' ) ? BrizyPro_Admin_WhiteLabel::_init()->getPrefix() : get_option( 'brizy_prefix', 'brizy' ); |
| 197 |
} |
| 198 |
$cssId = '#toplevel_page_' . $prefix . '-settings'; |
| 199 |
$svg = __bt( 'brizy-logo', plugins_url( '../admin/static/img/brizy-logo.svg', __FILE__ ) ); |
| 200 |
echo '<style>' . $cssId . ' .wp-menu-image::before { |
| 201 |
background-color: rgba(240,246,252,.6); |
| 202 |
content: "\00a0"; |
| 203 |
-webkit-mask: url(' . $svg . ') no-repeat center; |
| 204 |
mask: url(' . $svg . ') no-repeat center; |
| 205 |
mask-size: contain; |
| 206 |
-webkit-mask-size: contain; |
| 207 |
}' . $cssId . '.wp-has-current-submenu .wp-menu-image::before { |
| 208 |
background-color: white; |
| 209 |
}' . $cssId . '.wp-not-current-submenu:hover .wp-menu-image::before { |
| 210 |
background-color: #72aee6; |
| 211 |
} |
| 212 |
</style>'; |
| 213 |
} |
| 214 |
|
| 215 |
public function plugin_action_links( $links ) { |
| 216 |
$settings_link = sprintf( '<a href="%s">%s</a>', admin_url( 'admin.php?page=' . Brizy_Admin_Settings::menu_slug() ), __( 'Settings', 'brizy' ) ); |
| 217 |
array_unshift( $links, $settings_link ); |
| 218 |
if ( ! class_exists( 'BrizyPro_Main' ) ) { |
| 219 |
|
| 220 |
$links['go_pro'] = sprintf( '<a href="%1$s" target="_blank" style="color:#39b54a;font-weight:700;">%2$s</a>', Brizy_Config::getUpgradeUrl(), __( 'Go Pro', 'brizy' ) ); |
| 221 |
} |
| 222 |
|
| 223 |
return $links; |
| 224 |
} |
| 225 |
|
| 226 |
/** |
| 227 |
* @internal |
| 228 |
*/ |
| 229 |
public function action_register_static() { |
| 230 |
|
| 231 |
$urlBuilder = new Brizy_Editor_UrlBuilder(); |
| 232 |
wp_enqueue_style( Brizy_Editor::get_slug() . '-admin-css', $urlBuilder->plugin_url( 'admin/static/css/style.css' ), array(), BRIZY_VERSION ); |
| 233 |
wp_enqueue_script( Brizy_Editor::get_slug() . '-admin-js', $urlBuilder->plugin_url( 'admin/static/js/script.js' ), array( |
| 234 |
'jquery', |
| 235 |
'underscore' |
| 236 |
), BRIZY_VERSION, true ); |
| 237 |
wp_enqueue_script( Brizy_Editor::get_slug() . '-admin-featured-image-js', $urlBuilder->plugin_url( 'admin/static/js/featured-image.js' ), array( |
| 238 |
'jquery', |
| 239 |
'underscore' |
| 240 |
), BRIZY_VERSION, true ); |
| 241 |
$get_post_focal = Brizy_Editor_FocalPoint::sanitize( get_post_meta( get_the_ID(), 'brizy_attachment_focal_point', true ) ); |
| 242 |
wp_localize_script( Brizy_Editor::get_slug() . '-admin-js', 'Brizy_Admin_Data', array( |
| 243 |
'url' => admin_url( 'admin-ajax.php' ), |
| 244 |
'prefix' => Brizy_Editor::prefix(), |
| 245 |
'pluginUrl' => $urlBuilder->editor_build_url(), |
| 246 |
'ruleApiHash' => wp_create_nonce( Brizy_Admin_Rules_Api::nonce ), |
| 247 |
'id' => get_the_ID(), |
| 248 |
'page' => array( |
| 249 |
'focalPoint' => $get_post_focal ? $get_post_focal : array( 'x' => 50, 'y' => 50 ) |
| 250 |
), |
| 251 |
'actions' => array( |
| 252 |
'enable' => '_brizy_admin_editor_enable', |
| 253 |
'disable' => '_brizy_admin_editor_disable', |
| 254 |
), |
| 255 |
'editorVersion' => BRIZY_EDITOR_VERSION, |
| 256 |
'pluginVersion' => BRIZY_VERSION, |
| 257 |
'aiNonce' => wp_create_nonce( 'brizy-api' ), |
| 258 |
'nonce' => wp_create_nonce( 'brizy-admin-nonce' ), |
| 259 |
'isWhiteLabel' => apply_filters( 'brizy_wl_enabled', false ), |
| 260 |
'l10n' => [ |
| 261 |
'deactivateFeedbackSubmitBtn' => __( 'Submit & Deactivate', 'brizy' ), |
| 262 |
'deactivateFeedbackSkipBtn' => __( 'Skip & Deactivate', 'brizy' ), |
| 263 |
'aiCreatingSessionTitle' => __( 'Creating AI session', 'brizy' ), |
| 264 |
'aiCreatingSessionDesc' => __( 'Waiting for server response. Please wait…', 'brizy' ), |
| 265 |
'aiSendingProjectTitle' => __( 'Sending project', 'brizy' ), |
| 266 |
'aiSendingProjectDesc' => __( 'Please wait while we send your project data...', 'brizy' ), |
| 267 |
'aiGenerateTemplateTitle' => __( 'Generating website', 'brizy' ), |
| 268 |
'aiGenerateTemplateDesc' => __( 'Please wait. This may take a few moments.', 'brizy' ), |
| 269 |
'aiBannerImportTitle' => __( 'Importing Website Content', 'brizy' ), |
| 270 |
'aiBannerImportDesc' => __( 'Please don\'t close this window until the installation is finished.', 'brizy' ), |
| 271 |
'aiBannerSuccessTitle' => __( 'Website Content Successfully Imported', 'brizy' ), |
| 272 |
'aiBannerSuccessDesc' => __( 'Good news, your new content successfully installed.', 'brizy' ), |
| 273 |
'aiBannerErrorDesc' => __( 'Bad news, your website was not installed. Something went wrong and we couldn\'t do it. Please contact us.', 'brizy' ), |
| 274 |
'aiContinueButton' => __( 'Continue', 'brizy' ), |
| 275 |
'aiGenerateButton' => __( 'Generate With', 'brizy' ) . ' ' . __( 'Brizy', 'brizy' ) . ' - ' . __( 'AI', 'brizy' ), |
| 276 |
], |
| 277 |
) ); |
| 278 |
} |
| 279 |
|
| 280 |
/** |
| 281 |
* @internal |
| 282 |
*/ |
| 283 |
public function action_request_enable() { |
| 284 |
|
| 285 |
if ( ( ! isset( $_REQUEST['post'] ) || ! ( $p = get_post( (int) $_REQUEST['post'] ) ) ) || ( ! isset( $_REQUEST['hash'] ) || ! wp_verify_nonce( $_REQUEST['hash'], 'brizy-admin-nonce' ) ) ) { |
| 286 |
Brizy_Admin_Flash::instance()->add_error( 'Invalid Request.' ); |
| 287 |
wp_safe_redirect( $_SERVER['HTTP_REFERER'] ); |
| 288 |
exit(); |
| 289 |
} |
| 290 |
if ( ! current_user_can( 'edit_post', $p->ID ) ) { |
| 291 |
Brizy_Admin_Flash::instance()->add_error( 'You do not have sufficient permissions.' ); |
| 292 |
wp_safe_redirect( $_SERVER['HTTP_REFERER'] ); |
| 293 |
exit(); |
| 294 |
} |
| 295 |
try { |
| 296 |
$this->enable_brizy_for_post( $p ); |
| 297 |
} catch ( Exception $e ) { |
| 298 |
Brizy_Admin_Flash::instance()->add_error( 'Unable to create the page. Please try again later.' ); |
| 299 |
wp_safe_redirect( $_SERVER['HTTP_REFERER'] ); |
| 300 |
} |
| 301 |
} |
| 302 |
|
| 303 |
/** |
| 304 |
* @internal |
| 305 |
*/ |
| 306 |
public function action_request_disable() { |
| 307 |
|
| 308 |
if ( ( ! isset( $_REQUEST['post'] ) || ! ( $p = get_post( (int) $_REQUEST['post'] ) ) ) || ( ! isset( $_REQUEST['hash'] ) || ! wp_verify_nonce( $_REQUEST['hash'], 'brizy-admin-nonce' ) ) ) { |
| 309 |
Brizy_Admin_Flash::instance()->add_error( 'Invalid Request.' ); |
| 310 |
wp_safe_redirect( $_SERVER['HTTP_REFERER'] ); |
| 311 |
exit(); |
| 312 |
} |
| 313 |
if ( ! current_user_can( 'edit_post', $p->ID ) ) { |
| 314 |
Brizy_Admin_Flash::instance()->add_error( 'You do not have sufficient permissions.' ); |
| 315 |
wp_safe_redirect( $_SERVER['HTTP_REFERER'] ); |
| 316 |
exit(); |
| 317 |
} |
| 318 |
try { |
| 319 |
do_action( 'brizy_before_disable_for_post', $p ); |
| 320 |
Brizy_Editor_Entity::setBrizyEnabled( $p, false ); |
| 321 |
do_action( 'brizy_after_disable_for_post', $p ); |
| 322 |
} catch ( Brizy_Editor_Exceptions_Exception $exception ) { |
| 323 |
Brizy_Admin_Flash::instance()->add_error( 'Unable to disabled the editor. Please try again later.' ); |
| 324 |
} |
| 325 |
wp_safe_redirect( $_SERVER['HTTP_REFERER'] ); |
| 326 |
exit; |
| 327 |
} |
| 328 |
|
| 329 |
public function action_change_template() { |
| 330 |
|
| 331 |
|
| 332 |
if ( ( ! isset( $_REQUEST['post'], $_REQUEST['template'] ) || ! ( $p = get_post( $_REQUEST['post'] ) ) ) || ( ( ! isset( $_REQUEST['hash'] ) || ! wp_verify_nonce( $_REQUEST['hash'], 'brizy-admin-nonce' ) ) ) ) { |
| 333 |
Brizy_Admin_Flash::instance()->add_error( 'Invalid Request.' ); |
| 334 |
wp_send_json_error( [ 'message' => 'You do not have sufficient permissions.' ] ); |
| 335 |
exit(); |
| 336 |
} |
| 337 |
if ( ! current_user_can( 'edit_post', $p->ID ) ) { |
| 338 |
Brizy_Admin_Flash::instance()->add_error( 'You do not have sufficient permissions.' ); |
| 339 |
wp_send_json_error( [ 'message' => 'You do not have sufficient permissions.' ] ); |
| 340 |
exit(); |
| 341 |
} |
| 342 |
try { |
| 343 |
Brizy_Editor_Post::get( $p->ID )->set_template( $_REQUEST['template'] ); |
| 344 |
wp_safe_redirect( Brizy_Editor_Post::get( $p->ID )->edit_url() ); |
| 345 |
exit; |
| 346 |
} catch ( Brizy_Editor_Exceptions_Exception $exception ) { |
| 347 |
Brizy_Admin_Flash::instance()->add_error( 'Unable to disabled the editor. Please try again later.' ); |
| 348 |
wp_safe_redirect( $_SERVER['HTTP_REFERER'] ); |
| 349 |
exit(); |
| 350 |
} |
| 351 |
wp_safe_redirect( $_SERVER['HTTP_REFERER'] ); |
| 352 |
exit; |
| 353 |
} |
| 354 |
|
| 355 |
|
| 356 |
/** |
| 357 |
* @internal |
| 358 |
**/ |
| 359 |
public function action_add_enable_disable_buttons() { |
| 360 |
$get_post_type = get_post_type(); |
| 361 |
$supported_post_types = Brizy_Editor::get()->supported_post_types(); |
| 362 |
if ( in_array( $get_post_type, $supported_post_types ) ) { |
| 363 |
|
| 364 |
$p = get_post(); |
| 365 |
if ( ! current_user_can( 'edit_post', $p->ID ) ) { |
| 366 |
Brizy_Admin_Flash::instance()->add_error( 'You do not have sufficient permissions.' ); |
| 367 |
wp_safe_redirect( $_SERVER['HTTP_REFERER'] ); |
| 368 |
exit(); |
| 369 |
} |
| 370 |
try { |
| 371 |
$is_using_brizy = Brizy_Editor_Entity::isBrizyEnabled( $p->ID ); |
| 372 |
} catch ( Exception $e ) { |
| 373 |
$is_using_brizy = false; |
| 374 |
} |
| 375 |
echo Brizy_Admin_View::render( 'button', array( |
| 376 |
'id' => get_the_ID(), |
| 377 |
'post' => $p, |
| 378 |
'is_using_brizy' => $is_using_brizy, |
| 379 |
'url' => Brizy_Editor_Entity::getEditUrl( get_the_ID() ) |
| 380 |
) ); |
| 381 |
} |
| 382 |
} |
| 383 |
|
| 384 |
/** |
| 385 |
* @param array $actions |
| 386 |
* @param WP_Post $post |
| 387 |
* |
| 388 |
* @return array |
| 389 |
**@internal |
| 390 |
* |
| 391 |
*/ |
| 392 |
public function filter_add_brizy_edit_row_actions( $actions, $post ) { |
| 393 |
|
| 394 |
$is_allowed = Brizy_Editor_User::is_user_allowed(); |
| 395 |
if ( ! $is_allowed || ! in_array( get_post_type(), Brizy_Editor::get()->supported_post_types() ) ) { |
| 396 |
return $actions; |
| 397 |
} |
| 398 |
if ( ! current_user_can( 'edit_post', $post->ID ) ) { |
| 399 |
return $actions; |
| 400 |
} |
| 401 |
try { |
| 402 |
if ( Brizy_Editor_Entity::isBrizyEnabled( $post->ID ) ) { |
| 403 |
$editUrl = Brizy_Editor_Entity::getEditUrl( $post->ID ); |
| 404 |
$actions['brizy-edit'] = "<a href='{$editUrl}'>" . sprintf( __( 'Edit with %s', 'brizy' ), __bt( 'brizy', 'Brizy' ) ) . "</a>"; |
| 405 |
} |
| 406 |
} catch ( Exception $exception ) { |
| 407 |
$t = 0; |
| 408 |
} |
| 409 |
|
| 410 |
return $actions; |
| 411 |
} |
| 412 |
|
| 413 |
/** |
| 414 |
* @param string $body |
| 415 |
* |
| 416 |
* @return string |
| 417 |
**@internal |
| 418 |
* |
| 419 |
*/ |
| 420 |
public function filter_add_body_class( $body ) { |
| 421 |
if ( ! ( $id = get_the_ID() ) ) { |
| 422 |
return $body; |
| 423 |
} |
| 424 |
|
| 425 |
return $body . ( Brizy_Editor_Entity::isBrizyEnabled( $id ) ? ' brizy-editor-enabled ' : '' ); |
| 426 |
} |
| 427 |
|
| 428 |
/** |
| 429 |
* @param $p |
| 430 |
* |
| 431 |
* @throws Brizy_Editor_Exceptions_UnsupportedPostType |
| 432 |
* @throws Exception |
| 433 |
*/ |
| 434 |
private function enable_brizy_for_post( $p ) { |
| 435 |
|
| 436 |
$post = null; |
| 437 |
// obtain the post |
| 438 |
try { |
| 439 |
$post = Brizy_Editor_Post::get( $p->ID ); |
| 440 |
} catch ( Exception $exception ) { |
| 441 |
|
| 442 |
} |
| 443 |
if ( ! $post ) { |
| 444 |
Brizy_Admin_Flash::instance()->add_error( 'Failed to enable the editor for this post.' ); |
| 445 |
wp_redirect( $_SERVER['HTTP_REFERER'] ); |
| 446 |
} |
| 447 |
try { |
| 448 |
|
| 449 |
$update_post = false; |
| 450 |
if ( $p->post_status == 'auto-draft' ) { |
| 451 |
$p->post_status = 'draft'; |
| 452 |
$update_post = true; |
| 453 |
} |
| 454 |
if ( $p->post_title == __( 'Auto Draft' ) ) { |
| 455 |
$p->post_title = __bt( 'brizy', 'Brizy' ) . ' #' . $p->ID; |
| 456 |
$update_post = true; |
| 457 |
} |
| 458 |
if ( false === strpos( $p->post_content, 'brz-root__container' ) ) { |
| 459 |
$p->post_content .= '<div class="brz-root__container"></div>'; |
| 460 |
$update_post = true; |
| 461 |
} |
| 462 |
if ( $update_post ) { |
| 463 |
wp_update_post( $p ); |
| 464 |
} |
| 465 |
do_action( 'brizy_before_enabled_for_post', $p ); |
| 466 |
$post->enable_editor(); |
| 467 |
$post->set_template( Brizy_Config::BRIZY_BLANK_TEMPLATE_FILE_NAME ); |
| 468 |
$post->set_plugin_version( BRIZY_VERSION ); |
| 469 |
$post->set_pro_plugin_version( defined( 'BRIZY_PRO_VERSION' ) ? BRIZY_PRO_VERSION : null ); |
| 470 |
$post->saveStorage(); |
| 471 |
do_action( 'brizy_after_enabled_for_post', $p ); |
| 472 |
// redirect |
| 473 |
wp_redirect( $post->edit_url() ); |
| 474 |
|
| 475 |
} catch ( Exception $exception ) { |
| 476 |
|
| 477 |
Brizy_Admin_Flash::instance()->add_error( 'Failed to enable the editor for this post.' ); |
| 478 |
wp_redirect( $_SERVER['HTTP_REFERER'] ); |
| 479 |
} |
| 480 |
exit; |
| 481 |
} |
| 482 |
|
| 483 |
public function version_update_warning( $data ) { |
| 484 |
|
| 485 |
$current_version_minor_part = explode( '.', BRIZY_VERSION )[1]; |
| 486 |
$new_version_minor_part = explode( '.', $data['new_version'] )[1]; |
| 487 |
if ( $current_version_minor_part === $new_version_minor_part ) { |
| 488 |
return; |
| 489 |
} |
| 490 |
?> |
| 491 |
<hr class="brz-major-update-warning__separator"/> |
| 492 |
<div class="brz-major-update-warning"> |
| 493 |
<div class="brz-major-update-warning__icon"> |
| 494 |
<i class="dashicons dashicons-warning"></i> |
| 495 |
</div> |
| 496 |
<div> |
| 497 |
<div class="brz-major-update-warning__title"> |
| 498 |
<?php echo esc_html__( 'Heads up, Please backup before upgrade!', 'brizy' ); ?> |
| 499 |
</div> |
| 500 |
<div class="brz-major-update-warning__message"> |
| 501 |
<?php |
| 502 |
printf( /* translators: %1$s Link open tag, %2$s: Link close tag. */ esc_html__( 'The latest update includes some substantial changes across different areas of the plugin. We highly recommend you %1$sbackup your site before upgrading%2$s, and make sure you first update in a staging environment', 'brizy' ), '<a href="https://wordpress.org/support/article/wordpress-backups/">', '</a>' ); |
| 503 |
?> |
| 504 |
</div> |
| 505 |
</div> |
| 506 |
</div> |
| 507 |
<?php |
| 508 |
} |
| 509 |
} |
| 510 |
|