'ASC', 'orderby' => 'menu_order ID', 'id' => $post ? $post->ID : 0, 'itemtag' => $html5 ? 'figure' : 'dl', 'icontag' => $html5 ? 'div' : 'dt', 'captiontag' => $html5 ? 'figcaption' : 'dd', 'columns' => 3, 'size' => 'thumbnail', 'include' => '', 'exclude' => '', 'link' => '', 'mkslideshow' => false, ), $attr, 'gallery' ) ); $id = intval( $id ); if ( 'RAND' == $order ) { $orderby = 'none'; } if ( ! empty( $include ) ) { $_attachments = get_posts( array( 'include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) ); $attachments = array(); foreach ( $_attachments as $key => $val ) { $attachments[ $val->ID ] = $_attachments[ $key ]; } } elseif ( ! empty( $exclude ) ) { $attachments = get_children( array( 'post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) ); } else { $attachments = get_children( array( 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby ) ); } if ( empty( $attachments ) ) { return ''; } if ( is_feed() ) { $output = "\n"; foreach ( $attachments as $att_id => $attachment ) { $output .= wp_get_attachment_link( $att_id, $size, true ) . "\n"; } return $output; } //If we need to make a slideshow out of this gallery if ( "true" === $mkslideshow ) { $output .= ' '; } else { //just a normal grid gallery $itemtag = tag_escape( $itemtag ); $captiontag = tag_escape( $captiontag ); $icontag = tag_escape( $icontag ); $valid_tags = wp_kses_allowed_html( 'post' ); if ( ! isset( $valid_tags[ $itemtag ] ) ) { $itemtag = 'dl'; } if ( ! isset( $valid_tags[ $captiontag ] ) ) { $captiontag = 'dd'; } if ( ! isset( $valid_tags[ $icontag ] ) ) { $icontag = 'dt'; } $columns = intval( $columns ); $itemwidth = $columns > 0 ? floor( 100 / $columns ) : 100; $float = is_rtl() ? 'right' : 'left'; $selector = "gallery-{$instance}"; $gallery_style = $gallery_div = ''; /** * Filter whether to print default gallery styles. * * @since 3.1.0 * * @param bool $print Whether to print default gallery styles. * Defaults to false if the theme supports HTML5 galleries. * Otherwise, defaults to true. */ if ( apply_filters( 'use_default_gallery_style', true ) ) { $gallery_style = " \n\t\t"; } $size_class = sanitize_html_class( $size ); $gallery_div = "\n"; } return $output; } // Hook into the 'after_setup_theme' action //add_action( 'after_setup_theme', 'wpgrade_custom_backgrounds_support' ); function wpgrade_custom_backgrounds_support() { $background_args = array( 'default-color' => '1a1717', 'default-image' => '', 'wp-head-callback' => '_custom_background_cb', 'admin-head-callback' => '', 'admin-preview-callback' => '', ); add_theme_support( 'custom-background', $background_args ); } add_action( 'wp_head', 'wpgrade_add_desktop_icons' ); function wpgrade_add_desktop_icons() { if ( wpgrade::image_src( 'favicon' ) ) { echo "\n"; } if ( wpgrade::image_src( 'apple_touch_icon' ) ) { echo "\n"; } if ( wpgrade::image_src( 'metro_icon' ) ) { echo "\n"; echo "\n"; } } add_action('admin_head', 'wpgrade_add_admin_favicon'); function wpgrade_add_admin_favicon() { if ( wpgrade::image_src( 'favicon' ) ) { echo "\n"; } } add_action( 'wp', 'wpgrade_prepare_password_for_custom_post_types' ); function wpgrade_prepare_password_for_custom_post_types() { global $wpgrade_private_post; $wpgrade_private_post = rosa::is_password_protected(); } add_filter( 'mce_buttons', 'add_next_page_button' ); // Add "Next page" button to TinyMCE function add_next_page_button( $mce_buttons ) { $pos = array_search( 'wp_more', $mce_buttons, true ); if ( $pos !== false ) { $tmp_buttons = array_slice( $mce_buttons, 0, $pos + 1 ); $tmp_buttons[] = 'wp_page'; $mce_buttons = array_merge( $tmp_buttons, array_slice( $mce_buttons, $pos + 1 ) ); } return $mce_buttons; } add_filter( 'wp_link_pages_args', 'add_next_and_number' ); // Customize the "wp_link_pages()" to be able to display both numbers and prev/next links function add_next_and_number( $args ) { if ( $args['next_or_number'] == 'next_and_number' ) { global $page, $numpages, $multipage, $more, $pagenow; $args['next_or_number'] = 'number'; $prev = ''; $next = ''; if ( $multipage and $more ) { $i = $page - 1; if ( $i and $more ) { $prev .= _wp_link_page( $i ); $prev .= $args['link_before'] . $args['previouspagelink'] . $args['link_after'] . ''; $prev = apply_filters( 'wp_link_pages_link', $prev, 'prev' ); } $i = $page + 1; if ( $i <= $numpages and $more ) { $next .= _wp_link_page( $i ); $next .= $args['link_before'] . $args['nextpagelink'] . $args['link_after'] . ''; $next = apply_filters( 'wp_link_pages_link', $next, 'next' ); } } $args['before'] = $args['before'] . $prev; $args['after'] = $next . $args['after']; } return $args; } /* * Add custom fields to attachments */ add_action( 'init', 'wpgrade_register_attachments_custom_fields' ); function wpgrade_register_attachments_custom_fields() { //add video support for attachments if ( ! function_exists( 'add_video_url_field_to_attachments' ) ) { function add_video_url_field_to_attachments( $form_fields, $post ) { if ( ! isset( $form_fields["video_url"] ) ) { $form_fields["video_url"] = array( "label" => __( "Video URL", 'rosa_txtd' ), "input" => "text", // this is default if "input" is omitted "value" => esc_url( get_post_meta( $post->ID, "_video_url", true ) ), "helps" => __( "

Attach a video to this image (YouTube or Vimeo).

", 'rosa_txtd' ), ); } if ( ! isset( $form_fields["video_autoplay"] ) ) { $meta = get_post_meta( $post->ID, "_video_autoplay", true ); // Set the checkbox checked or not if ( $meta == 'on' ) { $checked = ' checked="checked"'; } else { $checked = ''; } $form_fields["video_autoplay"] = array( "label" => __( "Video Autoplay", 'rosa_txtd' ), "input" => "html", "html" => '' ); } // if ( ! isset( $form_fields["external_url"] ) ) { // $form_fields["external_url"] = array( // "label" => __( "External URL", 'rosa_txtd' ), // "input" => "text", // "value" => esc_url( get_post_meta( $post->ID, "_external_url", true ) ), // "helps" => __( "

Set this image to link to an external website.

", 'rosa_txtd' ), // ); // } return $form_fields; } // add_filter( "attachment_fields_to_edit", "add_video_url_field_to_attachments", 99999, 2 ); } /** * Save custom media metadata fields * Be sure to validate your data before saving it * http://codex.wordpress.org/Data_Validation * * @param $post The $post data for the attachment * @param $attachment The $attachment part of the form $_POST ($_POST[attachments][postID]) * * @return $post */ if ( ! function_exists( 'add_image_attachment_fields_to_save' ) ) { // add_filter( "attachment_fields_to_save", "add_image_attachment_fields_to_save", 9999, 2 ); function add_image_attachment_fields_to_save( $post, $attachment ) { if ( isset( $attachment['video_url'] ) ) { update_post_meta( $post['ID'], '_video_url', esc_url( $attachment['video_url'] ) ); } if ( isset( $attachment['video_autoplay'] ) ) { update_post_meta( $post['ID'], '_video_autoplay', 'on' ); } else { update_post_meta( $post['ID'], '_video_autoplay', 'off' ); } // if ( isset( $attachment['external_url'] ) ) { // update_post_meta( $post['ID'], '_external_url', esc_url( $attachment['external_url'] ) ); // } return $post; } } } /* * Add custom styling for the media popup */ add_action( 'print_media_templates', 'wpgrade_custom_style_for_mediabox' ); function wpgrade_custom_style_for_mediabox() { ?> '; } echo '
' . PHP_EOL; }