| @@ -72,16 +72,14 @@ | ||
| 72 | 72 | 'wp-editor', |
| 73 | 73 | 'wp-block-editor' |
| 74 | 74 | ]; |
| 75 | 75 | |
| 76 | - $current_screen = get_current_screen(); | |
| 77 | - | |
| 78 | 76 | $_style_handler_object = [ |
| 79 | 77 | 'sth_nonce' => wp_create_nonce( 'betterdocs_style_handler_nonce' ), |
| 80 | 78 | 'editor_type' => 'edit-site' |
| 81 | 79 | ]; |
| 82 | 80 | |
| 83 | - if ( $hook == 'post-new.php' && $current_screen->is_block_editor || $hook == 'post.php' && $current_screen->is_block_editor ) { | |
| 81 | + if ( $hook == 'post-new.php' || $hook == 'post.php' ) { | |
| 84 | 82 | $_style_handler_deps[] = 'wp-edit-post'; |
| 85 | 83 | $_style_handler_object['editor_type'] = 'edit-post'; |
| 86 | 84 | } elseif ( $hook == 'site-editor.php' ) { |
| 87 | 85 | $_style_handler_deps[] = 'wp-edit-site'; |
| @@ -97,21 +95,18 @@ | ||
| 97 | 95 | * @retun void |
| 98 | 96 | * @since 1.0.2 |
| 99 | 97 | */ |
| 100 | 98 | public function write_block_css() { |
| 101 | - $nonce = isset( $_POST['nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['nonce'] ) ) : ''; | |
| 102 | - if ( ! wp_verify_nonce( $nonce, 'betterdocs_style_handler_nonce' ) || ! current_user_can( 'manage_options' ) ) { | |
| 99 | + if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( $_POST['nonce'], 'betterdocs_style_handler_nonce' ) || ! current_user_can( 'manage_options' ) ) { | |
| 103 | 100 | echo 'Invalid request'; |
| 104 | 101 | wp_die(); |
| 105 | 102 | } |
| 106 | 103 | |
| 107 | - $raw_data = isset( $_POST['data'] ) ? wp_unslash( $_POST['data'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- decoded JSON; values are sanitized in build_css(). | |
| 108 | - $block_styles = (array) json_decode( $raw_data ); | |
| 104 | + $block_styles = (array) json_decode( stripslashes( $_POST['data'] ) ); | |
| 109 | 105 | |
| 110 | - $editor_type = isset( $_POST['editorType'] ) ? sanitize_key( wp_unslash( $_POST['editorType'] ) ) : ''; | |
| 111 | - if ( 'edit-site' === $editor_type ) { | |
| 106 | + if ( isset( $_POST['editorType'] ) && $_POST['editorType'] === 'edit-site' ) { | |
| 112 | 107 | $upload_dir = wp_upload_dir()['basedir'] . '/betterdocs-style/'; |
| 113 | - $editSiteCssPath = $upload_dir . 'betterdocs-style-' . $editor_type . '.min.css'; | |
| 108 | + $editSiteCssPath = $upload_dir . 'betterdocs-style-' . $_POST['editorType'] . '.min.css'; | |
| 114 | 109 | if ( file_exists( $editSiteCssPath ) ) { |
| 115 | 110 | $existingCss = file_get_contents( $editSiteCssPath ); |
| 116 | 111 | $pattern = '~\/\*(.*?)\*\/~'; |
| 117 | 112 | preg_match_all( $pattern, $existingCss, $result, PREG_PATTERN_ORDER ); |
| @@ -137,9 +132,9 @@ | ||
| 137 | 132 | |
| 138 | 133 | if ( ! empty( $css = $this->build_css( $finalCSSArray ) ) ) { |
| 139 | 134 | $upload_dir = wp_upload_dir()['basedir'] . '/betterdocs-style/'; |
| 140 | 135 | if ( ! file_exists( $upload_dir ) ) { |
| 141 | - wp_mkdir_p( $upload_dir ); | |
| 136 | + mkdir( $upload_dir ); | |
| 142 | 137 | } |
| 143 | 138 | |
| 144 | 139 | file_put_contents( $editSiteCssPath, $css ); |
| 145 | 140 | } |
| @@ -145,9 +140,9 @@ | ||
| 145 | 140 | } |
| 146 | 141 | } elseif ( ! empty( $css = $this->build_css( $block_styles ) ) ) { |
| 147 | 142 | $upload_dir = wp_upload_dir()['basedir'] . '/betterdocs-style/'; |
| 148 | 143 | if ( ! file_exists( $upload_dir ) ) { |
| 149 | - wp_mkdir_p( $upload_dir ); | |
| 144 | + mkdir( $upload_dir ); | |
| 150 | 145 | } |
| 151 | 146 | |
| 152 | 147 | file_put_contents( $editSiteCssPath, $css ); |
| 153 | 148 | } |
| @@ -153,12 +148,11 @@ | ||
| 153 | 148 | } |
| 154 | 149 | } elseif ( ! empty( $css = $this->build_css( $block_styles ) ) ) { |
| 155 | 150 | $upload_dir = wp_upload_dir()['basedir'] . '/betterdocs-style/'; |
| 156 | 151 | if ( ! file_exists( $upload_dir ) ) { |
| 157 | - wp_mkdir_p( $upload_dir ); | |
| 152 | + mkdir( $upload_dir ); | |
| 158 | 153 | } |
| 159 | - $post_id = isset( $_POST['id'] ) ? absint( wp_unslash( $_POST['id'] ) ) : 0; | |
| 160 | - file_put_contents( $upload_dir . 'betterdocs-style-' . $post_id . '.min.css', $css ); | |
| 154 | + file_put_contents( $upload_dir . 'betterdocs-style-' . abs( $_POST['id'] ) . '.min.css', $css ); | |
| 161 | 155 | } |
| 162 | 156 | |
| 163 | 157 | wp_send_json_success( 'done' ); |
| 164 | 158 | } |