A Code Commentary

Panelists

Mike

Robert

Zack

1

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;
    }
  }
}
					

2

function TOsaveAjaxOrder()
{
  global $wpdb;
  $taxonomy = stripslashes($_POST['taxonomy']);
  $data = stripslashes($_POST['order']);
  $unserialised_data = unserialize($data);

  if (is_array($unserialised_data))
  foreach($unserialised_data as $key => $values )
    {
      //$key_parent = str_replace("item_", "", $key);
      $items = explode("&", $values);

      if (is_array($items) && count($items) > 0)
      foreach( $items as $item_key => $term_id )
        {
          $wpdb->update( $wpdb->terms, array('term_order' => ($item_key + 1)), array('term_id' => $term_id) );
        }
  }
}

3

// Show quotes that are stored as "funny-quote" post type on the site
function quotes( $number_to_show ) {
	global $wpdb;
	$sql = "SELECT * FROM wp_posts WHERE post_type = 'funny-quote'";
	$quotes = $wpdb->get_results( $sql, ARRAY_A );

	$output = 'Showing '.$number_to_show.' quotes:';
	foreach ( $quotes as $quote ) {
	  $output .= wpautop( $quote['post_content'] );
	}
	return $output;
}

4

document.addEventListener( 'DOMContentLoaded', function () {
		/* global player, title_block */
		if ( typeof player !== 'undefined' && typeof title_block !== 'undefined' ) {
			title_block.forEach( function ( item ) {
				player.onInit( function () {
					player.addEventListener( 'OnMediaStart', function () {
						var cid = document.getElementById( item.container_id );
						var title = cid.getElementsByClassName( item.title_classname );
						if ( title && title.length > 0 ) {
							title[0].style.visibility = 'hidden';
						}
					}, item.player_id );
				});
			});
		}
	});

5

if(isset($_POST['disable']))
{
  foreach ( $_POST['users'] as $userid ) {
    $wpdb->query("UPDATE ".$wpdb->prefix."usercontrol SET disable_status = 'disabled' WHERE ID = ".$wpdb->escape($userid));
  }
}

if(isset($_POST['enable']))
{
  foreach ( $_POST['users'] as $userid ) {
    $wpdb->query("UPDATE ".$wpdb->prefix."usercontrol SET disable_status = 'enabled' WHERE ID = ".$wpdb->escape($userid));
  }
}

6

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

7

$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 .= "
  • ";

    8

    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' ] );
    					}
    				}
    			}
    		}
    	}
    }
    	

    Thank you! 👏

    Q&A