'aa_pdf_reader_sanitize_options', ]); }); /** * Sanitize settings */ function aa_pdf_reader_sanitize_options($input) { $output = []; $output['theme'] = in_array($input['theme'] ?? '', ['light', 'dark']) ? $input['theme'] : 'light'; $output['default_height'] = absint($input['default_height'] ?? 800); $output['show_download'] = !empty($input['show_download']) ? 1 : 0; $output['show_share'] = !empty($input['show_share']) ? 1 : 0; $output['show_email'] = !empty($input['show_email']) ? 1 : 0; return $output; } /** * Admin Settings Page */ function aa_pdf_reader_settings_page() { if (!current_user_can('manage_options')) { wp_die(__('You do not have sufficient permissions to access this page.', 'aa-pdf-reader')); } $options = get_option('aa_pdf_reader_options'); $defaults = [ 'theme' => 'light', 'default_height' => 800, 'show_download' => 1, 'show_share' => 1, 'show_email' => 1, ]; $options = wp_parse_args($options, $defaults); ?>

[aa_pdf_reader link="https://example.com/file.pdf" height="800" theme="dark" download="yes" share="yes" email="yes" lazy="yes" password="1234" expire="2025-07-01"]
'', 'height' => $options['default_height'] ?? 800, 'theme' => $options['theme'] ?? 'light', 'download' => !empty($options['show_download']) ? 'yes' : 'no', 'share' => !empty($options['show_share']) ? 'yes' : 'no', 'email' => !empty($options['show_email']) ? 'yes' : 'no', 'lazy' => 'no', 'password' => '', 'expire' => '', 'viewer' => 'google', ]; $a = shortcode_atts($defaults, $atts, 'aa_pdf_reader'); // Sanitize $a['link'] = esc_url_raw($a['link']); $a['height'] = absint($a['height']); $a['theme'] = in_array($a['theme'], ['light', 'dark'], true) ? $a['theme'] : 'light'; $a['download'] = ($a['download'] === 'yes') ? 'yes' : 'no'; $a['share'] = ($a['share'] === 'yes') ? 'yes' : 'no'; $a['email'] = ($a['email'] === 'yes') ? 'yes' : 'no'; $a['lazy'] = ($a['lazy'] === 'yes') ? 'lazy' : 'eager'; $a['password'] = sanitize_text_field($a['password']); $a['expire'] = sanitize_text_field($a['expire']); $a['viewer'] = ($a['viewer'] === 'google') ? 'google' : 'native'; if (empty($a['link'])) { return '

' . esc_html__('No PDF link provided.', 'aa-pdf-reader') . '

'; } if (!empty($a['password'])) { if ( !isset($_POST['aa_pdf_pass_nonce']) || !wp_verify_nonce($_POST['aa_pdf_pass_nonce'], 'aa_pdf_pass_action') || !isset($_POST['aa_pdf_pass']) || $_POST['aa_pdf_pass'] !== $a['password'] ) { ob_start(); ?>

' . esc_html__('This PDF is no longer available.', 'aa-pdf-reader') . '

'; } $pdf_url = ($a['viewer'] === 'google') ? 'https://docs.google.com/gview?embedded=true&url=' . urlencode($a['link']) : $a['link']; ob_start(); ?>