Slide 1

Slide 1 text

A CODE COMMENTARY MIKE SELANDER, TYREL KELSEY

Slide 2

Slide 2 text

MIKE TYREL

Slide 3

Slide 3 text

SNIPPET 1

Slide 4

Slide 4 text

function save_options() { global $themename, $shortname, $options; if ( $_GET['page'] == basename(__FILE__) ) { if ( 'save' == $_REQUEST['action'] ) { foreach ($options as $value) { update_option( $value['id'], $_REQUEST[ $value['id'] ] ); } foreach ($options as $value) { if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ] ); } else { delete_option( $value['id'] ); } } header("Location: themes.php?page=functions.php&saved=true"); die; } else if( 'reset' == $_REQUEST['action'] ) { foreach ($options as $value) { delete_option( $value['id'] ); } header("Location: themes.php?page=functions.php&reset=true"); die; } } }

Slide 5

Slide 5 text

function save_options() { // Nonce check. if ( ! isset( $_POST['my_nonce'] ) || ! wp_verify_nonce( $_POST['my_nonce'], 'nonce_action' ) ) { return; } // Validate that option is being pushed. if ( ! isset( $_POST['my_value'] ) ) { return; } // Only update one option at a time. // Sanitize and unslash before saving. update_option( 'my_value', sanitize_text_field( wp_unslash( $_POST['my_value'] ) ) ); }

Slide 6

Slide 6 text

SNIPPET 2

Slide 7

Slide 7 text

function find_partners( $partners ) { $links = array(); if ( isset( $partners ) ) { foreach( $partners as $partner ) { if( $partner['partner_name'] == 'AngelList' ) { for( $i = 1; $i <= 3; $i++ ) { if( isset( $partner['link_' . $i . '_url' ] ) && !empty( $partner['link_' . $i . '_url' ] ) && isset( $partner['link_' . $i . '_name' ] ) && ! empty( $partner['link_' . $i . '_name' ] ) ) { $links[] = array( 'label' => $partner['link_' . $i . '_name' ], 'url' => $partner['link_' . $i . '_url' ] ); } } } } } }

Slide 8

Slide 8 text

function find_partners( $partners ) { // Make sure that we have valid partners first. if ( empty( $partners ) ) { return []; } // We only want to look at AngelList partners. $angellist_partners = array_filter( $partners, function( $partner ) { return 'AngelList' === $partner['partner_name']; } ); // Map AngelList partners to their links and append to our links array. $links = []; foreach ( $angellist_partners as $partner ) { $i = 1; while ( ! empty( $partner[ 'link_' . $i . '_url' ] ) ) { $links[] = [ 'label' => $partner[ 'link_' . $i . '_name' ], 'url' => $partner[ 'link_' . $i . '_url' ], ]; $i++; } } return $links; }

Slide 9

Slide 9 text

SNIPPET 3

Slide 10

Slide 10 text

$html .= "
  • "; $html .= ""; if ( $image ) $html .= ""; $html .= ""; $html .= "

    Boat Name: ".get_the_title()."

    "; $html .= "

    Location: $marina_list

    "; if ( current_user_can('view_boats') ) $html .= "<$title_tag>Rate: $$price"; $html .= "$button_string"; $html .= "
  • ";

    Slide 11

    Slide 11 text

  • ".get_the_title()."

    $

  • Slide 12

    Slide 12 text

    SNIPPET 4

    Slide 13

    Slide 13 text

    $posts = new WP_Query( [ 'orderby' => 'title', 'order' => 'ASC', 'nopaging' => true, 'posts_per_page' => '-1', 'meta_query' => [ [ 'key' => 'featured', 'value' => 1, 'compare' => '=', ], ], 'orderby' => 'RAND', ] );

    Slide 14

    Slide 14 text

    $posts = new WP_Query( [ 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => '100', 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'meta_query' => [ [ 'key' => 'featured', 'value' => 'bug #23268', 'compare' => 'EXISTS', ], ], ] ); shuffle( $posts->posts );

    Slide 15

    Slide 15 text

    SNIPPET 5

    Slide 16

    Slide 16 text

    function hello_dashboard_widget() { global $wpdb; echo "

    Hello!

    "; echo "

    What would you like to do today?

    "; $querystr = "SELECT DISTINCT post_type\n"; $querystr .= "FROM $wpdb->posts\n"; $types = $wpdb->get_results($querystr, ARRAY_A); // Declare post types we don't want to show $bad_types[] = 'attachment'; $bad_types[] = 'deprecated_log'; $bad_types[] = 'nav_menu_item'; $bad_types[] = 'revision'; foreach ( $types as $type ) { // if post type isn't one of the ones we declared if ( !in_array( $type['post_type'], $bad_types ) ) { $type_clean = ucwords($type['post_type']); echo "
  • Create a new $type_clean
  • "; } } } __( 'Create a new %s', 'my-theme' ), $type->labels->singular ) ); ?>

    Slide 17

    Slide 17 text

    function hello_dashboard_widget() { global $wpdb; ?>

    true ], 'objects' ); array_walk( $post_types, function( $type ) { ?>
  • labels->singular ) ); ?>
  • Slide 18

    Slide 18 text

    END Q & A