コード例 #1
0
/**
 * Save per-post options
 *
 * @package CustomPermalinks
 * @since 0.1
 */
function custom_permalinks_save_post($id)
{
    if (!isset($_REQUEST['custom_permalinks_edit'])) {
        return;
    }
    delete_post_meta($id, 'custom_permalink');
    $original_link = custom_permalinks_original_post_link($id);
    $permalink_structure = get_option('permalink_structure');
    if ($_REQUEST['custom_permalink'] && $_REQUEST['custom_permalink'] != $original_link) {
        add_post_meta($id, 'custom_permalink', str_replace('%2F', '/', urlencode(ltrim(stripcslashes($_REQUEST['custom_permalink']), "/"))));
    }
}
コード例 #2
0
/**
 * Save per-post options
 *
 * @package CustomPermalinks
 * @since 0.1
 */
function custom_permalinks_save_post($id)
{
    if (!isset($_REQUEST['custom_permalinks_edit'])) {
        return;
    }
    delete_post_meta($id, 'custom_permalink');
    // http://wordpress.org/support/topic/404-error-potentially-caused-by-revisions
    // not sure why we should create permalinks on something except actual version of post/page
    // so... quick and dirty - remove revision's premalink if exists but don't create a new one
    if (isset($_REQUEST['post_ID']) && $id != $_REQUEST['post_ID']) {
        return;
    }
    $original_link = custom_permalinks_original_post_link($id);
    $permalink_structure = get_option('permalink_structure');
    if ($_REQUEST['custom_permalink'] && $_REQUEST['custom_permalink'] != $original_link) {
        add_post_meta($id, 'custom_permalink', str_replace('%2F', '/', urlencode(ltrim(stripcslashes($_REQUEST['custom_permalink']), "/"))));
    }
}