function WPSR_get_post_redirection($post_id) { global $wpdb, $util, $table_prefix; $table_name = $table_prefix . 'WP_SEO_Redirection'; // Autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } // AJAX if (defined('DOING_AJAX') && DOING_AJAX) { return; } // Post revision if (false !== wp_is_post_revision($post_id)) { return; } $redirect_from = $util->post('wp_seo_redirection_url_from'); $redirect_to = $util->post('wp_seo_redirection_url'); if ($redirect_to != '') { $wpdb->get_results($wpdb->prepare("select ID from {$table_name} where postID=%d ", $post_id)); if ($wpdb->num_rows > 0) { $sql = $wpdb->prepare("update {$table_name} set redirect_to=%s,redirect_from=%s,redirect_type='301',url_type=2 where postID=%d", $redirect_to, $redirect_from, $post_id); $wpdb->query($sql); } else { $wpdb->query($wpdb->prepare("delete from {$table_name} where redirect_from=%s", $redirect_from)); $sql = $wpdb->prepare("insert into {$table_name}(redirect_from,redirect_to,redirect_type,url_type,postID) values (%s,%s,'301',2,%d) ", $redirect_from, $redirect_to, $post_id); $wpdb->query($sql); } } else { $wpdb->query($wpdb->prepare("delete from {$table_name} where postID=%d", $post_id)); } $SR_redirect_cache = new free_SR_redirect_cache(); $SR_redirect_cache->free_cache(); }
} else { if ($redirect_from == '' || $redirect_to == '' || $redirect_type == '') { $util->failure_option_msg('Please input all required fields!'); } else { $wpdb->query(" insert into {$table_name}(redirect_from,redirect_to,redirect_type,url_type,redirect_from_type,redirect_from_folder_settings,redirect_from_subfolders,redirect_to_type,redirect_to_folder_settings,regex,enabled) values('{$redirect_from}','{$redirect_to}','{$redirect_type}',1,'{$redirect_from_type}','{$redirect_from_folder_settings}','{$redirect_from_subfolders}','{$redirect_to_type}','{$redirect_to_folder_settings}','{$regex}','{$enabled}') "); $wpdb->query($wpdb->prepare(" delete from {$table_name_404} where link=%s ", $redirect_from)); $SR_redirect_cache = new free_SR_redirect_cache(); $SR_redirect_cache->free_cache(); } } } else { if ($util->post('edit_exist') != '') { $edit = $util->post('edit'); if ($redirect_from == '' || $redirect_to == '' || $redirect_type == '') { $util->failure_option_msg('Please input all required fields!'); } else { $wpdb->query("update {$table_name} set redirect_from='{$redirect_from}',redirect_to='{$redirect_to}',redirect_type='{$redirect_type}',redirect_from_type='{$redirect_from_type}' ,redirect_from_folder_settings='{$redirect_from_folder_settings}',redirect_from_subfolders='{$redirect_from_subfolders}' ,redirect_to_type='{$redirect_to_type}' ,redirect_to_folder_settings='{$redirect_to_folder_settings}' ,regex='{$regex}',enabled='{$enabled}' where ID='{$edit}' "); $SR_redirect_cache = new free_SR_redirect_cache(); $SR_redirect_cache->free_cache(); } } } if ($util->there_is_cache() != '') { $util->info_option_msg("You have a cache plugin installed <b>'" . $util->there_is_cache() . "'</b>, you have to clear cache after any changes to get the changes reflected immediately! "); } } if ($util->get('add') != '' || $util->get('edit') != '') { include "option_page_custome_redirection_add_update.php"; } else { include "option_page_custome_redirection_list.php"; }