The MU forums have moved to WordPress.org

Category Slug (41 posts)

  1. dancing dragon
    Member
    Posted 15 years ago #

    ^ Isn't it actually the other way around? The filter is being defined in mu.php. So if you comment it out there, that will make the filter completely unavailable. In taxonomy.php, it's being called through apply_filter within a specific function, wp_update_term, which is called in the 3 cases I mentioned earlier (edit category, edit tag, and I think also edit link) which is what is desired.

  2. MrBrian
    Member
    Posted 15 years ago #

    Actually it's not. apply_filter defines a filter and add_filter hooks into it. I know, it's a little confusing when you compare it to action hooks. That's wordpress for ya.

  3. dancing dragon
    Member
    Posted 15 years ago #

    ^ Hmm... I'm not quite buying that yet. I don't have any plugins (that I know use that filter) though so I can't test it out right now.

    In this line, apply_filters is converting the $args with said filter. So I am just commenting out the line that is reassigning the new $args values (that contain the slug value overwrite) to $args. And why would one define a filter within a function called wp_update_term? It doesn't make sense.

    //$args = apply_filters( 'pre_update_term', $term, $taxonomy, $args );

  4. MrBrian
    Member
    Posted 15 years ago #

    At least look it up before arguing with me. If it doesn't make sense to you why the filter is defined inside of the function, then you don't understand hooks.
    http://codex.wordpress.org/Plugin_API#Hook_to_WordPress

  5. dancing dragon
    Member
    Posted 15 years ago #

    double post - ignore

  6. dancing dragon
    Member
    Posted 15 years ago #

    Um, that page is supporting what I said. sync_slugs is defined in mu.php and then registered by the add_filter call.

    mu.php is written like an include file, and it's used as one. The only place in the entire codebase where mu.php is referenced is in a require statement in admin.php. That is pretty much the basic standard of "define"-ing things in programming languages.

    I think you need to read what I wrote. You don't "define" global things - filters, functions, whatever - in assignment statements inside another function, and one that is called from multiple places at specific times.

  7. dancing dragon
    Member
    Posted 15 years ago #

    Anyway, I'm thinking why we were arguing is because you were talking about plugins and what I meant was actually I don't want to necessarily unregister the pre_update_terms filter in case it were to be used elsewhere in the code. I was not actually thinking about plugins. If pre_update_terms only makes sense to be applied in one place in the code ever, then I guess what I was thinking is irrelevant. For my purposes, I don't want slugs to be overwritten in the cases where I see wp_update_term is called.

  8. dancing dragon
    Member
    Posted 15 years ago #

    I actually see why you would want to remove the add_filter line instead of the apply_filter line. I'll update the workaround in the next post. What was throwing me off was the use of the word "define". I see how the filters and hooks work now, but I still think of what's in mu.php as "define"s and the apply_filter calls in the code as function calls, calling a filter, or applying a filter. Ie. the apply_filter name is accurate.

  9. dancing dragon
    Member
    Posted 15 years ago #

    This is just an update so that people don't have to wade through the entire thread.

    To make both category and tag slugs editable (in WPMU 2.6.1):

    wp-admin/edit-category-form.php

    To make the input box for "Category Slug" in the admin interface, add the following between the table rows for "Category Name" and "Category Parent":

    <tr class="form-field">
            <th scope="row" valign="top"><label for="category_nicename"><?php _e('Category Slug') ?></label></th>
            <td><input name="category_nicename" id="category_nicename" type="text" value="<?php echo attribute_escape($category->category_nicename); ?>" size="40" />
            <?php _e('The “slug” is the URL-friendly version of the name. It is usually all lowercase and contains only letters, numbers, and hyphens.'); ?></td>
        </tr>

    wp-admin/includes/mu.php

    To stop overwriting the slug to always match the name, comment out line 384:

    function sync_slugs( $term, $taxonomy, $args ) {
            $args[ 'slug' ] = sanitize_title( $args[ 'name' ] );
            return $args;
    }
    //add_filter( 'pre_update_term', 'sync_slugs', 10, 3 );
  10. MrBrian
    Member
    Posted 15 years ago #

    Edit: You got the point.

    Also, plugins are just php includes full of hooks and filters, and essentially mu.php is a plugin itself. In the past, most MU modifications were placed as separate files in the mu-plugins folder, but in later versions they were moved out of mu-plugins and into the core folders for less confusion and cleaner structure. In any case, i took the liberty to file the bug and Donncha made the change to remove the tag slugs input and explained the reason for removing this functionality.
    http://trac.mu.wordpress.org/ticket/739

  11. binh
    Member
    Posted 15 years ago #

    I found out that the following code doesn't work as it return "Category not Updated" message:

    function sync_slugs( $term, $taxonomy, $args ) {
            $args[ 'slug' ] = sanitize_title( $args[ 'name' ] );
            return $args;
    }
    //add_filter( 'pre_update_term', 'sync_slugs', 10, 3 );

    However, the following code work:

    function sync_slugs( $term, $taxonomy, $args ) {
            //$args[ 'slug' ] = sanitize_title( $args[ 'name' ] );
            return $args;
    }
    add_filter( 'pre_update_term', 'sync_slugs', 10, 3 );

    I don't know why that happen, but if the filter sync_slugs is removed, it doesn't save the category.

    Applied on cars.apmart.com.

  12. Viennese
    Member
    Posted 15 years ago #

    I tried commenting out the add_filter line and get this in my error_log:

    PHP Warning: array_merge() [<a href='function.array-merge'>function.array-merge</a>]: Argument #2 is not an array in .../wp-includes/taxonomy.php on line 1483

    I am on WPMU 2.6.5.

    I will try binh's modification, but I am puzzled why commenting out the add_filter doesn't work and causes an error.

About this Topic

  • Started 17 years ago by yashnikov
  • Latest reply from Viennese