20, 'ocr_lang' => 'deu+eng', 'pdf_max_pages' => 50, 'search_mode' => 'like', 'delete_on_uninstall' => 0, ); } /** * All options merged with the defaults. * * @return array */ public static function all() { $saved = get_option( self::OPTION, array() ); return array_merge( self::defaults(), is_array( $saved ) ? $saved : array() ); } /** * One option. * * @param string $key Option key. * @return mixed */ public static function get( $key ) { $all = self::all(); return isset( $all[ $key ] ) ? $all[ $key ] : null; } /** * Sanitize callback for register_setting(). * * @param mixed $input Raw form values. * @return array */ public static function sanitize( $input ) { $input = is_array( $input ) ? $input : array(); $out = self::defaults(); $out['max_upload_mb'] = min( 2048, max( 1, absint( $input['max_upload_mb'] ?? $out['max_upload_mb'] ) ) ); $out['pdf_max_pages'] = min( 500, max( 1, absint( $input['pdf_max_pages'] ?? $out['pdf_max_pages'] ) ) ); $lang = sanitize_text_field( $input['ocr_lang'] ?? '' ); $out['ocr_lang'] = in_array( $lang, self::LANGUAGES, true ) ? $lang : 'deu+eng'; $mode = sanitize_key( $input['search_mode'] ?? '' ); $out['search_mode'] = 'fulltext' === $mode ? 'fulltext' : 'like'; $out['delete_on_uninstall'] = empty( $input['delete_on_uninstall'] ) ? 0 : 1; return $out; } /** * Largest file that can be uploaded: plugin option, PHP limits (wp_max_upload_size) and the database * packet size (see DropDMS_Storage::max_file_size()). */ public static function max_upload_bytes() { return (int) min( (int) self::get( 'max_upload_mb' ) * MB_IN_BYTES, wp_max_upload_size(), DropDMS_Storage::max_file_size() ); } }