Skip to:
Content

BuddyPress.org

Changeset 9942


Ignore:
Timestamp:
06/12/2015 03:09:17 PM (5 years ago)
Author:
johnjamesjacoby
Message:

Groups: bp_get_group_creation_previous_link() improvements

  • Add documentation
  • Use modern coding standards
  • Move URL creation out of apply_filters() call to improve readability
  • Escape output of bp_group_creation_previous_link() with esc_url()

This change improves the readibility of the code used to generate the URL to the previous group creation step, and also ensures the URL is properly escaped when output (in the event the return value is intercepted with otherwise unpredictable results.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-groups/bp-groups-template.php

    r9941 r9942  
    47114711    }
    47124712
     4713/**
     4714 * Escape & output the URL to the previous group creation step
     4715 *
     4716 * @since BuddyPress (1.1.0)
     4717 */
    47134718function bp_group_creation_previous_link() {
    4714     echo bp_get_group_creation_previous_link();
    4715 }
     4719    echo esc_url( bp_get_group_creation_previous_link() );
     4720}
     4721    /**
     4722     * Return the URL to the previous group creation step
     4723     *
     4724     * @since BuddyPress (1.1.0)
     4725     *
     4726     * @return string
     4727     */
    47164728    function bp_get_group_creation_previous_link() {
    4717         $bp = buddypress();
    4718 
    4719         foreach ( (array) $bp->groups->group_creation_steps as $slug => $name ) {
     4729        $bp    = buddypress();
     4730        $steps = array_keys( $bp->groups->group_creation_steps );
     4731
     4732        // Loop through steps
     4733        foreach ( $steps as $slug ) {
     4734
     4735            // Break when the current step is found
    47204736            if ( bp_is_action_variable( $slug ) ) {
    47214737                break;
    47224738            }
    47234739
     4740            // Add slug to previous steps
    47244741            $previous_steps[] = $slug;
    47254742        }
    47264743
     4744        // Generate the URL for the previous step
     4745        $group_directory = bp_get_groups_directory_permalink();
     4746        $create_step     = 'create/step/';
     4747        $previous_step   = array_pop( $previous_steps );
     4748        $url             = trailingslashit( $group_directory . $create_step . $previous_step );
     4749
    47274750        /**
    47284751         * Filters the permalink for the previous step with the group creation process.
     
    47324755         * @param string $value Permalink for the previous step.
    47334756         */
    4734         return apply_filters( 'bp_get_group_creation_previous_link', trailingslashit( bp_get_groups_directory_permalink() . 'create/step/' . array_pop( $previous_steps ) ) );
     4757        return apply_filters( 'bp_get_group_creation_previous_link', $url );
    47354758    }
    47364759
Note: See TracChangeset for help on using the changeset viewer.