' . esc_html__( 'Setting', 'advance-wp-redirect' ) . ''; array_unshift( $xsawrlite_link, $setting_link ); return $xsawrlite_link; } /** * Echo checked attribute for master option checkboxes. * * @param string $option_name Option name. * @param string $value Array key under option. */ function xsawrlite_check_option( $option_name, $value ) { $xsawrlite_getopt = get_option( $option_name ); if ( isset( $xsawrlite_getopt[ $value ] ) && ! empty( $xsawrlite_getopt ) ) { if ( (int) $xsawrlite_getopt[ $value ] === 1 || $xsawrlite_getopt[ $value ] === $value ) { echo 'checked="checked"'; } } } /** * Sanitize master options (Options tab). * * @param mixed $input Raw input. * @return array */ function xsawrlite_sanitize_master_options( $input ) { if ( ! is_array( $input ) ) { return array(); } $out = array(); if ( ! empty( $input['off-redirect'] ) ) { $out['off-redirect'] = '1'; } if ( ! empty( $input['404-redirect'] ) ) { $out['404-redirect'] = '1'; } if ( ! empty( $input['nf-redirect'] ) ) { $out['nf-redirect'] = '1'; } if ( ! empty( $input['nw-redirect'] ) ) { $out['nw-redirect'] = '1'; } if ( isset( $input['gt_redirect'] ) && $input['gt_redirect'] !== '' ) { $out['gt_redirect'] = sanitize_text_field( $input['gt_redirect'] ); } $allowed_mq = array( 'exact', 'ignore', 'ignore-and-pass' ); $mq = isset( $input['mq_redirect'] ) ? sanitize_text_field( $input['mq_redirect'] ) : 'exact'; $out['mq_redirect'] = in_array( $mq, $allowed_mq, true ) ? $mq : 'exact'; return $out; } /** * Build a redirectable URL from stored target (absolute or site-relative). * * @param string $raw Raw target from settings. * @return string */ function xsawrlite_normalize_redirect_target( $raw ) { $raw = trim( (string) $raw ); if ( '' === $raw ) { return ''; } if ( preg_match( '#^https?://#i', $raw ) ) { return esc_url_raw( $raw ); } return esc_url_raw( home_url( '/' . ltrim( $raw, '/' ) ) ); } /** * Sanitize one redirect rule row. * * @param mixed $item Row data. * @return array */ function xsawrlite_sanitize_redirect_entry( $item ) { if ( ! is_array( $item ) ) { return array(); } $qp_rule_allowed = array( '301', '302', '303', '304', '307', '308' ); $qp_rule = isset( $item['qp_rule'] ) ? sanitize_text_field( $item['qp_rule'] ) : '302'; if ( ! in_array( $qp_rule, $qp_rule_allowed, true ) ) { $qp_rule = '302'; } $qp_allowed = array( 'exact', 'ignore', 'ignore-and-pass' ); $qp = isset( $item['qp'] ) ? sanitize_text_field( $item['qp'] ) : 'exact'; if ( ! in_array( $qp, $qp_allowed, true ) ) { $qp = 'exact'; } $match_allowed = array( 'durl', 'url_login', 'url_role', 'url_ip' ); $match = isset( $item['match'] ) ? sanitize_text_field( $item['match'] ) : 'durl'; if ( ! in_array( $match, $match_allowed, true ) ) { $match = 'durl'; } $matched_allowed = array( 'redirect_url', 'random_post', 'pass_through', '404', 'nothing' ); $matched = isset( $item['matched'] ) ? sanitize_text_field( $item['matched'] ) : 'redirect_url'; if ( ! in_array( $matched, $matched_allowed, true ) ) { $matched = 'redirect_url'; } return array( 'rurl' => isset( $item['rurl'] ) ? sanitize_text_field( $item['rurl'] ) : '', 'durl' => isset( $item['durl'] ) ? sanitize_text_field( $item['durl'] ) : '', 'qp' => $qp, 'match' => $match, 'matched' => $matched, 'qp_rule' => $qp_rule, 'title' => isset( $item['title'] ) ? sanitize_text_field( $item['title'] ) : '', 'nf' => ! empty( $item['nf'] ) ? '1' : '0', 'nw' => ! empty( $item['nw'] ) ? '1' : '0', ); }