Making WordPress.org

Changeset 8309


Ignore:
Timestamp:
02/21/2019 06:15:15 PM (6 years ago)
Author:
iandunn
Message:

CampTix Admin Flags: Apply coding standards.

Location:
sites/trunk/wordcamp.org/public_html/wp-content/plugins/camptix-admin-flags
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/camptix-admin-flags/addons/admin-flags.php

    r8308 r8309  
    1010 */
    1111class CampTix_Admin_Flags_Addon extends CampTix_Addon {
    12 
     12    protected $flags = array();
     13
     14    /**
     15     * Constructor.
     16     */
    1317    public function __construct() {
    1418        add_action( 'camptix_init', array( $this, 'camptix_init' ) );
     
    2832        }
    2933
    30         $this->flags = array();
    3134        $camptix_options = $camptix->get_options();
    3235
    3336        // No further actions if we don't have any configured flags.
    34         if ( empty( $camptix_options['camptix-admin-flags-data-parsed'] ) )
    35             return;
     37        if ( empty( $camptix_options['camptix-admin-flags-data-parsed'] ) ) {
     38            return;
     39        }
    3640
    3741        $this->flags = (array) $camptix_options['camptix-admin-flags-data-parsed'];
    3842
    3943        if ( current_user_can( $camptix->caps['manage_attendees'] ) ) {
    40             // Individual editing from Edit Attendee screen
     44            // Individual editing from Edit Attendee screen.
    4145            add_action( 'save_post', array( $this, 'save_post' ), 11, 1 );
    4246            add_action( 'camptix_attendee_submitdiv_misc', array( $this, 'publish_metabox_actions' ) );
    4347
    44             // Bulk editing from Attendees screen
     48            // Bulk editing from Attendees screen.
    4549            add_filter( 'manage_tix_attendee_posts_columns', array( $this, 'add_custom_columns' ) );
    4650            add_action( 'manage_tix_attendee_posts_custom_column', array( $this, 'render_custom_columns' ), 10, 2 );
     
    6771    public function shortcode_attendees_atts( $out, $pairs, $atts ) {
    6872        $admin_flags = array();
    69         if ( ! empty( $atts['has_admin_flag'] ) )
     73        if ( ! empty( $atts['has_admin_flag'] ) ) {
    7074            $admin_flags = array_map( 'trim', explode( ',', $atts['has_admin_flag'] ) );
     75        }
    7176
    7277        $admin_flags_clean = array();
    73         foreach ( $this->flags as $key => $label )
    74             if ( in_array( $key, $admin_flags ) )
     78        foreach ( $this->flags as $key => $label ) {
     79            if ( in_array( $key, $admin_flags, true ) ) {
    7580                $admin_flags_clean[] = $key;
     81            }
     82        }
    7683
    7784        $out['has_admin_flag'] = $admin_flags;
     
    8390     */
    8491    public function shortcode_attendees_query( $query_args, $shortcode_args ) {
    85         if ( empty( $shortcode_args['has_admin_flag'] ) )
     92        if ( empty( $shortcode_args['has_admin_flag'] ) ) {
    8693            return $query_args;
     94        }
    8795
    8896        // Sanitized in self::shortcode_attendees_atts.
    8997        $flags = $shortcode_args['has_admin_flag'];
    9098
    91         if ( empty( $query_args['meta_query'] ) )
     99        if ( empty( $query_args['meta_query'] ) ) {
    92100            $query_args['meta_query'] = array();
     101        }
    93102
    94103        foreach ( $flags as $flag ) {
    95104            $query_args['meta_query'][] = array(
    96                 'key' => 'camptix-admin-flag',
    97                 'value' => $flag,
     105                'key'     => 'camptix-admin-flag',
     106                'value'   => $flag,
    98107                'compare' => '=',
    99                 'type' => 'CHAR',
     108                'type'    => 'CHAR',
    100109            );
    101110        }
     
    109118    public function export_columns( $columns ) {
    110119        foreach ( $this->flags as $key => $label ) {
    111             $column_key = sprintf( 'camptix-admin-flags-%s', $key );
     120            $column_key             = sprintf( 'camptix-admin-flags-%s', $key );
    112121            $columns[ $column_key ] = $label;
    113122        }
     
    123132     */
    124133    public function export_columns_values( $value, $index, $attendee ) {
    125         if ( 0 !== strpos( $index, 'camptix-admin-flags-' ) )
     134        if ( 0 !== strpos( $index, 'camptix-admin-flags-' ) ) {
    126135            return $value;
     136        }
    127137
    128138        // See self::export_columns() for key format.
    129139        $key = str_replace( 'camptix-admin-flags-', '', $index );
    130         if ( ! array_key_exists( $key, $this->flags ) )
     140        if ( ! array_key_exists( $key, $this->flags ) ) {
    131141            return $value;
     142        }
    132143
    133144        $attendee_flags = (array) get_post_meta( $attendee->ID, 'camptix-admin-flag' );
    134         return in_array( $key, $attendee_flags ) ? 'Yes' : 'No';
     145        return in_array( $key, $attendee_flags, true ) ? 'Yes' : 'No';
    135146    }
    136147
     
    149160        global $camptix;
    150161
    151         if ( 'admin-flags' != $section )
    152             return;
     162        if ( 'admin-flags' !== $section ) {
     163            return;
     164        }
    153165
    154166        add_settings_section( 'general', __( 'Admin Flags', 'camptix' ), array( $this, 'setup_controls_section' ), 'camptix_options' );
     
    171183     */
    172184    public function validate_options( $output, $input ) {
    173         if ( ! isset( $input['camptix-admin-flags-data'] ) )
     185        if ( ! isset( $input['camptix-admin-flags-data'] ) ) {
    174186            return $output;
     187        }
    175188
    176189        $has_error = false;
    177         $flags = array();
    178         $data = explode( "\n", $input['camptix-admin-flags-data'] );
     190        $flags     = array();
     191        $data      = explode( "\n", $input['camptix-admin-flags-data'] );
    179192
    180193        foreach ( $data as $line ) {
    181194
    182             if ( empty( $line ) )
     195            if ( empty( $line ) ) {
    183196                continue;
    184 
    185             // flag-key: Flag Label
     197            }
     198
     199            // flag-key: Flag Label.
    186200            if ( ! preg_match( '#^([^:]+?):(.+)$#', $line, $matches ) ) {
    187201                $has_error = true;
     
    189203            }
    190204
    191             $key = sanitize_html_class( sanitize_title_with_dashes( trim( $matches[1] ) ) );
    192             $label = trim( $matches[2] );
     205            $key           = sanitize_html_class( sanitize_title_with_dashes( trim( $matches[1] ) ) );
     206            $label         = trim( $matches[2] );
    193207            $flags[ $key ] = $label;
    194208        }
    195209
    196210        $lines = array();
    197         foreach ( $flags as $key => $label )
     211        foreach ( $flags as $key => $label ) {
    198212            $lines[] = sprintf( '%s: %s', $key, $label );
    199 
    200         $output['camptix-admin-flags-data'] = implode( "\n", $lines );
     213        }
     214
     215        $output['camptix-admin-flags-data']        = implode( "\n", $lines );
    201216        $output['camptix-admin-flags-data-parsed'] = $flags;
    202217
    203         if ( $has_error )
     218        if ( $has_error ) {
    204219            add_settings_error( 'tix', 'error', __( 'Flags data has been saved, but one or more flags was invalid, so it has been stripped.', 'camptix' ), 'error' );
     220        }
    205221
    206222        return $output;
     
    211227     */
    212228    public function save_post( $post_id ) {
    213         if ( wp_is_post_revision( $post_id ) || 'tix_attendee' != get_post_type( $post_id ) )
    214             return;
    215 
    216         if ( empty( $_POST['camptix-admin-flags-nonce'] ) || ! wp_verify_nonce( $_POST['camptix-admin-flags-nonce'], 'camptix-admin-flags-update' ) )
    217             return;
     229        if ( wp_is_post_revision( $post_id ) || 'tix_attendee' !== get_post_type( $post_id ) ) {
     230            return;
     231        }
     232
     233        if ( empty( $_POST['camptix-admin-flags-nonce'] ) || ! wp_verify_nonce( $_POST['camptix-admin-flags-nonce'], 'camptix-admin-flags-update' ) ) {
     234            return;
     235        }
    218236
    219237        delete_post_meta( $post_id, 'camptix-admin-flag' );
    220238
    221         foreach ( $this->flags as $key => $label )
    222             if ( ! empty( $_POST['camptix-admin-flags'][ $key ] ) )
     239        foreach ( $this->flags as $key => $label ) {
     240            if ( ! empty( $_POST['camptix-admin-flags'][ $key ] ) ) {
    223241                add_post_meta( $post_id, 'camptix-admin-flag', $key );
     242            }
     243        }
    224244    }
    225245
     
    228248     */
    229249    public function publish_metabox_actions() {
    230         $post = get_post();
     250        $post           = get_post();
    231251        $attendee_flags = (array) get_post_meta( $post->ID, 'camptix-admin-flag' );
    232252        ?>
     
    237257
    238258                <div class="tix-pub-section-item">
    239                     <input id="camptix-admin-flags-<?php echo sanitize_html_class( $key ); ?>" name="camptix-admin-flags[<?php echo esc_attr( $key ); ?>]" type="checkbox" <?php checked( in_array( $key, $attendee_flags ) ); ?> value="1" />
     259                    <input id="camptix-admin-flags-<?php echo sanitize_html_class( $key ); ?>" name="camptix-admin-flags[<?php echo esc_attr( $key ); ?>]" type="checkbox" <?php checked( in_array( $key, $attendee_flags, true ) ); ?> value="1" />
    240260                    <label for="camptix-admin-flags-<?php echo sanitize_html_class( $key ); ?>"><?php echo esc_html( $label ); ?></label>
    241261                </div>
     
    263283     *
    264284     * @param string $column
    265      * @param int $attendee_id
     285     * @param int    $attendee_id
    266286     */
    267287    public function render_custom_columns( $column, $attendee_id ) {
     
    271291            case 'admin-flags':
    272292                echo '<ul>';
    273                     foreach ( $this->flags as $key => $label ) {
    274                         $enabled = in_array( $key, $attendee_flags );
    275 
    276                         ?>
    277 
    278                         <li>
    279                             <span class="tix-admin-flag-label"><?php echo esc_html( $label ); ?></span>:
    280 
    281                             <a
    282                                 href="#"
    283                                 data-attendee-id="<?php echo esc_attr( $attendee_id ); ?>"
    284                                 data-key="<?php echo esc_attr( $key ); ?>"
    285                                 data-nonce="<?php echo esc_attr( wp_create_nonce( sprintf( 'tix_toggle_flag_%s_%s', $attendee_id, $key ) ) ); ?>"
    286                                 data-command="<?php echo esc_attr( $enabled ? 'disable' : 'enable' ); ?>"
    287                                 class="tix-toggle-flag">
    288 
    289                                 <?php if ( $enabled ) : ?>
    290                                     <?php _e( 'Disable', 'camptix' ); ?>
    291                                 <?php else : ?>
    292                                     <?php _e( 'Enable', 'camptix' ); ?>
    293                                 <?php endif; ?>
    294                             </a>
    295                         </li>
    296 
    297                         <?php
    298                     }
     293
     294                foreach ( $this->flags as $key => $label ) {
     295                    $enabled = in_array( $key, $attendee_flags, true );
     296
     297                    ?>
     298
     299                    <li>
     300                        <span class="tix-admin-flag-label">
     301                            <?php echo esc_html( $label ); ?>
     302                        </span>:
     303
     304                        <a
     305                            href="#"
     306                            data-attendee-id="<?php echo esc_attr( $attendee_id ); ?>"
     307                            data-key="<?php echo esc_attr( $key ); ?>"
     308                            data-nonce="<?php echo esc_attr( wp_create_nonce( sprintf( 'tix_toggle_flag_%s_%s', $attendee_id, $key ) ) ); ?>"
     309                            data-command="<?php echo esc_attr( $enabled ? 'disable' : 'enable' ); ?>"
     310                            class="tix-toggle-flag">
     311
     312                            <?php if ( $enabled ) : ?>
     313                                <?php esc_html_e( 'Disable', 'camptix' ); ?>
     314                            <?php else : ?>
     315                                <?php esc_html_e( 'Enable', 'camptix' ); ?>
     316                            <?php endif; ?>
     317                        </a>
     318                    </li>
     319
     320                    <?php
     321                }
     322
    299323                echo '</ul>';
    300 
    301324                break;
    302325        }
     
    334357
    335358        foreach ( $this->flags as $flag => $label ) {
    336             $count = 0;
     359            $count      = 0;
    337360            $class_html = '';
    338361            $url        = add_query_arg( 'camptix_flag', $flag, $base_url );
    339362
    340             if ( $currently_viewed_flag && $currently_viewed_flag == $flag ) {
     363            if ( $currently_viewed_flag && $currently_viewed_flag === $flag ) {
    341364                $class_html = ' class="current"';
    342365            }
     
    392415     */
    393416    public function render_client_side_templates() {
    394         if ( 'tix_attendee' != $GLOBALS['typenow'] ) {
     417        if ( 'tix_attendee' !== $GLOBALS['typenow'] ) {
    395418            return;
    396419        }
     
    413436                class="tix-toggle-flag">
    414437
    415                 {{data.command}}    <?php // todo use i18n var ?>
     438                {{data.command}}    <?php // todo use i18n var. ?>
    416439            </a>
    417440        </script>
     
    424447     */
    425448    public function toggle_flag() {
    426         /** @var $camptix CampTix_Plugin */
     449        /** @var CampTix_Plugin $camptix */
    427450        global $camptix;
    428451
     
    441464        $attendee = get_post( $attendee_id );
    442465
    443         if ( ! is_a( $attendee, 'WP_Post' ) || 'tix_attendee' != $attendee->post_type ) {
     466        if ( ! is_a( $attendee, 'WP_Post' ) || 'tix_attendee' !== $attendee->post_type ) {
    444467            wp_send_json_error( array( 'error' => 'Invalid attendee.' ) );
    445468        }
    446469
    447         if ( 'enable' == $command ) {
     470        if ( 'enable' === $command ) {
    448471            add_post_meta( $attendee_id, 'camptix-admin-flag', $key );
    449         } elseif ( 'disable' == $command ) {
     472        } elseif ( 'disable' === $command ) {
    450473            delete_post_meta( $attendee_id, 'camptix-admin-flag', $key );
    451474        }
     
    458481     */
    459482    public function print_javascript() {
    460         if ( 'tix_attendee' != $GLOBALS['typenow'] ) {
     483        if ( 'tix_attendee' !== $GLOBALS['typenow'] ) {
    461484            return;
    462485        }
     
    526549     */
    527550    public function print_css() {
    528         if ( 'tix_attendee' != $GLOBALS['typenow'] ) {
     551        if ( 'tix_attendee' !== $GLOBALS['typenow'] ) {
    529552            return;
    530553        }
  • sites/trunk/wordcamp.org/public_html/wp-content/plugins/camptix-admin-flags/camptix-admin-flags.php

    r907 r8309  
    11<?php
     2
    23/**
    34 * Plugin Name: CampTix - Admin Flags
    45 * Description: An addon for CampTix that allows admins to configure and set private per-attendee flags.
    5  * Version: 0.1
    6  * Author: Konstantin Kovshenin
    7  * Author URI: http://kovshenin.com
     6 * Version:     0.1
     7 * Author:      Konstantin Kovshenin
     8 * Author URI:  http://kovshenin.com
    89 */
    910
    10 add_action( 'camptix_load_addons', 'camptix_admin_flags_register' );
     11/**
     12 * Register this addon with CampTix.
     13 */
    1114function camptix_admin_flags_register() {
    1215    require_once( plugin_dir_path( __FILE__ ) . 'addons/admin-flags.php' );
    1316}
     17add_action( 'camptix_load_addons', 'camptix_admin_flags_register' );
Note: See TracChangeset for help on using the changeset viewer.