page_title = __( '1-Click', 'insert-headers-and-footers' ); parent::__construct(); } /** * Register hook on admin init just for this page. * * @return void */ public function page_hooks() { add_action( 'admin_init', array( $this, 'submit_listener' ) ); } /** * Override to hide default header on this page. * * @return void */ public function output_header() { } /** * Wrap this page in a form tag. * * @return void */ public function output() { ?>
logo_image(); ?>
library_auth->has_auth() ) { ?>

library_auth->has_auth() && ! isset( $_GET['snippet'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended // We have a snippet hash so let's continue the snippet install process. $snippet_url = wpcode()->library_auth->library_url . '/snippet/' . $snippet_hash . '/?deploy=1'; ?>

library_auth->has_auth() ) { // Let's make sure the site is authenticated with the library. ?>

library->get_public_snippet( $snippet_hash, $auth ); if ( ! isset( $snippet_request['status'] ) || 'success' !== $snippet_request['status'] ) { // We have an error. Let's default to a generic message. $error = __( 'We encountered an error loading your snippet, please try again in a few minutes', 'insert-headers-and-footers' ); if ( isset( $snippet_request['message'] ) ) { // If there is a message, let's use that instead. $error = sprintf( /* translators: %s: The error message from the API. */ __( 'We encountered the following error loading your snippet: %s', 'insert-headers-and-footers' ), $snippet_request['message'] ); } $go_back_url = wpcode()->library_auth->library_url . '/snippet/' . $snippet_hash; ?>

execute->get_options(); // Let's show a preview of the snippet and ask the user to confirm. ?>

set_setting( 'readOnly', 'nocursor' ); $editor->register_editor( 'wpcode-code-preview' ); $editor->init_editor(); } wp_nonce_field( $this->action, $this->nonce_name ); } ?>

nonce_name ] ) || ! wp_verify_nonce( sanitize_key( $_REQUEST[ $this->nonce_name ] ), $this->action ) ) { // Nonce is missing, so we're not even going to try. return; } if ( ! current_user_can( 'wpcode_edit_snippets' ) ) { // Should not be able to load this page at all without that permission but let's check anyway. return; } $snippet_hash = isset( $_REQUEST['snippet'] ) ? sanitize_key( $_REQUEST['snippet'] ) : false; $auth = isset( $_REQUEST['auth'] ) ? sanitize_key( $_REQUEST['auth'] ) : false; // Let's load the data reliably again - it's saved in a transient so it should be fast. $snippet_data = wpcode()->library->get_public_snippet( $snippet_hash, $auth ); // You should not be able to submit this form if the hash is invalid but let's check anyway. if ( ! isset( $snippet_data['status'] ) || 'success' !== $snippet_data['status'] ) { // This should not happen if you did not manually change the hash, so we can just return. return; } // Let's create a new snippet. $snippet = new WPCode_Snippet( $snippet_data['data'] ); // Let's save the snippet. if ( $snippet->save() ) { // If successfully saved let's redirect to the edit screen. wp_safe_redirect( add_query_arg( array( 'page' => 'wpcode-snippet-manager', 'snippet_id' => $snippet->get_id(), ), admin_url( 'admin.php' ) ) ); exit; } } }