post_type && 'trash' !== $page->post_status ? $page : null; } /** * Creates and publishes a page containing the check block. */ public function create_page() { if ( ! current_user_can( NovoVerify_Config::CAPABILITY ) || ! current_user_can( 'publish_pages' ) ) { wp_die( esc_html__( 'You do not have permission to access this page.', 'novoverify' ), 403 ); } check_admin_referer( self::ACTION ); $page = self::check_page(); if ( ! $page ) { $page_id = wp_insert_post( array( 'post_type' => 'page', 'post_status' => 'publish', 'post_title' => __( 'Verify your product', 'novoverify' ), 'post_name' => sanitize_title( _x( 'verify', 'page slug of the check page', 'novoverify' ) ), 'post_content' => '', ), true ); if ( is_wp_error( $page_id ) ) { wp_safe_redirect( add_query_arg( 'novoverify_notice', 'page_failed', admin_url( 'admin.php?page=novoverify' ) ) ); exit; } update_option( self::PAGE_OPTION, (int) $page_id, false ); } wp_safe_redirect( add_query_arg( 'novoverify_notice', 'page_created', admin_url( 'admin.php?page=novoverify' ) ) ); exit; } /** * Renders the screen. */ public function render() { if ( ! current_user_can( NovoVerify_Config::CAPABILITY ) ) { wp_die( esc_html__( 'You do not have permission to access this page.', 'novoverify' ) ); } $page = self::check_page(); $code_counts = NovoVerify_DB::count_codes_by_status(); $stats = array( 'codes' => $code_counts['all'], 'checks' => NovoVerify_DB::count_checks(), 'checks_week' => NovoVerify_DB::count_checks_since( WEEK_IN_SECONDS ), ); $recent = NovoVerify_DB::get_recent_checks( 5 ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Display only. $notice = isset( $_GET['novoverify_notice'] ) ? sanitize_key( wp_unslash( $_GET['novoverify_notice'] ) ) : ''; include NOVOVERIFY_PATH . 'admin/views/getting-started.php'; } }