/** * Get redirect type. * * This function is used to get the redirect * status code selected by the user. * Registering filter - jj4t3_redirect_type * to alter redirect status code. * * @since 3.0.0 * @access private * * @return int Redirect status code. */ function jj4t3_redirect_type() { $type = (int) jj4t3_get_option('redirect_type'); /** * Filter to modify currently set redirect type. * * Return only valid HTTP status codes. * If you are returning custom status codes other than the default * values, please make sure that you have added that to "jj4t3_redirect_statuses" * filter first. Otherwise it will be ignored. * * @since 2.0.0 */ $status = apply_filters('jj4t3_redirect_type', $type); // Verify that redirect status is allowed. if (in_array($status, array_keys(jj4t3_redirect_statuses()))) { return $status; } return 301; }
/** * Set email recipients. * * Registering filter - "jj4t3_email_recipient". * * @since 3.0.0 * @access private */ private function set_recipient() { // Get email recipient if set. $recipient = jj4t3_get_option('email_notify_address', get_option('admin_email')); /** * Filter to alter email recipient. * * @since 3.0.0 */ $this->recipient = apply_filters('jj4t3_email_recipient', $recipient); }
?> <tr> <th><?php _e('Redirect type', JJ4T3_DOMAIN); ?> </th> <td> <select name="jj4t3_custom_redirect_type" id="jj4t3_custom_redirect_type"> <?php foreach ($statuses as $status => $label) { ?> <option value='<?php echo $status; ?> ' <?php selected(jj4t3_get_option('redirect_type'), $status); ?> ><?php echo $label; ?> </option> <?php } ?> </select> <p class="description jj4t3-p-desc"><?php _e('Select redirect type to override default one.', JJ4T3_DOMAIN); ?> </p> </td> </tr>
/** * Get custom redirect modal content * * @global object $wpdb WP DB object * @since 2.2.0 * @access public * * @return void */ public static function open_redirect() { // Yes, security check is a must when you alter something. check_ajax_referer('jj4t3_redirect_nonce', 'nonce'); // Verify if the 404 value is found. if (empty($_POST['url_404'])) { wp_die(); } $url_404 = $_POST['url_404']; global $wpdb; // Get custom redirect value from db, if exist. $result = $wpdb->get_row($wpdb->prepare("SELECT redirect, options FROM " . JJ4T3_TABLE . " WHERE url = '%s' AND redirect IS NOT NULL LIMIT 0,1", esc_url($url_404)), 'OBJECT'); // Get custom redirect type and url. $url = empty($result->redirect) ? '' : esc_url($result->redirect); // Get custom options. $options = empty($result->options) ? array() : maybe_unserialize($result->options); // Get result in an array. $data = array('url_404' => esc_url($url_404), 'url' => esc_url($url)); // Set the custom options for the 404. $data['type'] = empty($options['type']) ? jj4t3_get_option('redirect_type') : intval($options['type']); $data['redirect'] = isset($options['redirect']) ? intval($options['redirect']) : -1; $data['log'] = isset($options['log']) ? intval($options['log']) : -1; $data['alert'] = isset($options['alert']) ? intval($options['alert']) : -1; /** * Filter to alter custom redirect modal response array. * * You should return response in array. * * @since 3.0.0 */ wp_send_json(apply_filters('jj4t3_log_list_custom_redirect_open', $data)); }
/** * Get url to redirect to. * * This function is used to get the url * for redirecting to. * If a custom redirect is set through admin dashboard or even through * the filter "jj4t3_custom_redirect_url" for the current 404 page, it will be prioratised. * Otherwise global redirect link. * Registering filter - jj4t3_redirect_url. * * @param object $options Current 404 options. * * @since 3.0.0 * @access private * * @return void */ private function set_redirect_url($options) { $url = false; $custom_redirect = empty($options->redirect) ? '' : $options->redirect; /** * Filter for modify/set current 404's custom redirect. * * Using this filter you can modify or set custom redirect * for any 404 path. * @note : If you want to remove custom redirect for a path, you can * use this filter and return an empty/false value. * If you have set a value here, this will get priority over global redirect. * * @since 3.0.0 */ $custom_redirect = apply_filters('jj4t3_custom_redirect_url', $custom_redirect, $this->url); if (!empty($custom_redirect)) { $url = esc_url($custom_redirect); $this->custom_redirect_url = esc_url($custom_redirect); } else { // Get redirect to. $to = jj4t3_get_option('redirect_to'); if ('page' === $to) { // If an existing page is selected, get permalink. $url = get_permalink(jj4t3_get_option('redirect_page')); } elseif ('link' === $to) { // If a link. $url = jj4t3_get_option('redirect_link'); } } /** * Filter hook to change redirect url. * * To alter redirect link. Return full absolute * path to redirect. * * @since 3.0.0 */ $this->redirect_url = esc_url(apply_filters('jj4t3_redirect_url', $url)); }
?> /> <p class="description jj4t3-p-desc"><?php _e('Enable/Disable Logging', JJ4T3_DOMAIN); ?> </p> </td> </tr> <tr> <th><?php _e('Email notifications', JJ4T3_DOMAIN); ?> </th> <td> <input type="checkbox" name="i4t3_gnrl_options[email_notify]" value="1" <?php checked(jj4t3_get_option('email_notify'), 1); ?> /> <p class="description jj4t3-p-desc"><?php _e('If you check this, an email will be sent on every 404 log on the admin email account.', JJ4T3_DOMAIN); ?> </p> </td> </tr> <tr> <th><?php _e('Email address', JJ4T3_DOMAIN); ?> </th> <td> <?php
/** * Exclude specified paths from 404. * * If paths entered in exclude paths option is * found in current 404 page, skip this from * 404 actions. * * @since 2.0.8 * @access private * * @return boolean */ public function is_excluded() { $excluded = jj4t3_get_option('exclude_paths', ''); $paths = array(); // If no exclude path set, return false early. if (!empty($excluded)) { // Split by line break. $paths = explode("\n", $excluded); } /** * Filter to alter exclude path values. * * @note You should return array if strings . * * @since 3.0.0 */ $paths = apply_filters('jj4t3_404_excluded_paths', $paths); // If split failed, return false. if (empty($paths)) { return false; } // Verify that the excluded path is not matching current page. foreach ($paths as $path) { if (strpos($this->url, trim($path)) !== false) { return true; } } return false; }