'manage_woocommerce' ); } /** * Add the ProofKit submenu under WooCommerce. */ public static function register_menu(): void { add_submenu_page( 'woocommerce', __( 'ProofKit', 'proofkit' ), __( 'ProofKit', 'proofkit' ), 'manage_woocommerce', self::PAGE_SLUG, [ __CLASS__, 'settings_page' ] ); } /** * Register the single settings option. */ public static function register_settings(): void { register_setting( self::SETTINGS_GROUP, Settings::option_name(), [ 'type' => 'array', 'default' => Settings::defaults(), 'show_in_rest' => false, 'sanitize_callback' => [ self::class, 'sanitize_settings' ], ] ); } /** * Persist settings through Settings, then return the merged result. * * Settings::update() writes the option itself. The sanitize filter is * removed while it runs so the inner update cannot re-enter this method. * * @param mixed $input Raw option value. */ public static function sanitize_settings( mixed $input ): array { $input = is_array( $input ) ? $input : []; // Nested write from Settings::update(): the value is already clean. if ( self::$sanitizing ) { return $input; } // Unchecked checkboxes are absent from POST; normalise them on full-form saves. if ( ! empty( $input['proofkit_settings_form'] ) ) { $input['enable_svg'] = empty( $input['enable_svg'] ) ? 0 : 1; $input['delete_data'] = empty( $input['delete_data'] ) ? 0 : 1; } unset( $input['proofkit_settings_form'] ); $option = Settings::option_name(); $callback = [ self::class, 'sanitize_settings' ]; self::$sanitizing = true; remove_filter( 'sanitize_option_' . $option, $callback ); try { Settings::update( $input ); } finally { add_filter( 'sanitize_option_' . $option, $callback ); self::$sanitizing = false; } Settings::reset_cache(); return Settings::all(); } /** * Render the settings screen. */ public static function settings_page(): void { if ( ! current_user_can( 'manage_woocommerce' ) ) { wp_die( esc_html__( 'You do not have permission to manage ProofKit settings.', 'proofkit' ), '', [ 'response' => 403 ] ); } $settings = Settings::all(); // Show the stored allow-list, not the SVG-filtered runtime list, so // saving the form with SVG disabled does not erase "svg" permanently. $exts = Settings::normalise_extensions( $settings['allowed_exts'] ?? array() ); $field_name = static function ( string $key ): string { return 'proofkit_settings[' . $key . ']'; }; ?>

get_results( $wpdb->prepare( 'SELECT status, COUNT(*) AS total FROM %i WHERE status IN (%s, %s, %s) GROUP BY status', $table, 'draft', 'sent', 'changes_requested' ) ); $counts = [ 'draft' => 0, 'sent' => 0, 'changes_requested' => 0, ]; foreach ( (array) $rows as $row ) { $key = isset( $row->status ) ? (string) $row->status : ''; if ( array_key_exists( $key, $counts ) ) { $counts[ $key ] = (int) $row->total; } } ?> ' . esc_html__( 'Orders needing action', 'proofkit' ) . '

'; } else { echo '

' . esc_html__( 'Nothing is waiting for artwork or proof approval right now.', 'proofkit' ) . '

'; } } /** * Warn Nginx admins that .htaccess does not protect the private directory. */ public static function nginx_notice(): void { if ( ! current_user_can( 'manage_woocommerce' ) ) { return; } $screen = get_current_screen(); if ( ! $screen || 'woocommerce_page_' . self::PAGE_SLUG !== $screen->id ) { return; } $software = isset( $_SERVER['SERVER_SOFTWARE'] ) && is_string( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : ''; if ( false === stripos( $software, 'nginx' ) ) { return; } $rule = "location ^~ /wp-content/uploads/proofkit-private/ {\n deny all;\n return 403;\n}"; ?>

%2$s', esc_url( admin_url( 'admin.php?page=' . self::PAGE_SLUG ) ), esc_html__( 'Settings', 'proofkit' ) ) ); return $links; } }