Created
July 9, 2017 13:57
-
-
Save oneguy9/add0f06c30437c583d137cca823cb05a to your computer and use it in GitHub Desktop.
Gravity Form Upload images to gallery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function royeyal_enqueue_styles() { | |
if ( is_rtl() ) { | |
wp_enqueue_style('parent-theme-rtl', get_template_directory_uri() .'/rtl.css'); | |
wp_enqueue_style('local-theme-rtl', get_stylesheet_directory_uri() .'/css/rtl.min.css'); | |
} | |
} | |
add_action('wp_enqueue_scripts', 'royeyal_enqueue_styles', 100); | |
add_action( 'generate_inside_navigation','lh_inside_navigation' ); | |
function lh_inside_navigation() { | |
?> | |
<div class="grid-100 navigation-right"> | |
<?php echo do_shortcode("[widget id='login_logout-2']"); ?> | |
</div> | |
<?php | |
} | |
if ( ! function_exists( 'custom_navigation_mega' ) ) { | |
// Register Navigation Menus | |
function custom_navigation_mega() { | |
$locations = array( | |
'Mega' => __( 'תפריט חיפוש ראשי', 'text_domain' ), | |
); | |
register_nav_menus( $locations ); | |
} | |
add_action( 'init', 'custom_navigation_mega' ); | |
} | |
function wpcontent_svg_mime_type( $mimes = array() ) { | |
$mimes['svg'] = 'image/svg+xml'; | |
$mimes['svgz'] = 'image/svg+xml'; | |
return $mimes; | |
} | |
add_filter( 'upload_mimes', 'wpcontent_svg_mime_type' ); | |
function df_disable_comments_post_types_support() { | |
$post_types = get_post_types(); | |
foreach ($post_types as $post_type) { | |
if(post_type_supports($post_type, 'comments')) { | |
remove_post_type_support($post_type, 'comments'); | |
remove_post_type_support($post_type, 'trackbacks'); | |
} | |
} | |
} | |
add_action('admin_init', 'df_disable_comments_post_types_support'); | |
// Close comments on the front-end | |
function df_disable_comments_status() { | |
return false; | |
} | |
add_filter('comments_open', 'df_disable_comments_status', 20, 2); | |
add_filter('pings_open', 'df_disable_comments_status', 20, 2); | |
// Hide existing comments | |
function df_disable_comments_hide_existing_comments($comments) { | |
$comments = array(); | |
return $comments; | |
} | |
add_filter('comments_array', 'df_disable_comments_hide_existing_comments', 10, 2); | |
// Remove comments page in menu | |
function df_disable_comments_admin_menu() { | |
remove_menu_page('edit-comments.php'); | |
} | |
add_action('admin_menu', 'df_disable_comments_admin_menu'); | |
// Redirect any user trying to access comments page | |
function df_disable_comments_admin_menu_redirect() { | |
global $pagenow; | |
if ($pagenow === 'edit-comments.php') { | |
wp_redirect(admin_url()); exit; | |
} | |
} | |
add_action('admin_init', 'df_disable_comments_admin_menu_redirect'); | |
// Remove comments metabox from dashboard | |
function df_disable_comments_dashboard() { | |
remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal'); | |
} | |
add_action('admin_init', 'df_disable_comments_dashboard'); | |
// Remove comments links from admin bar | |
function df_disable_comments_admin_bar() { | |
if (is_admin_bar_showing()) { | |
remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60); | |
} | |
} | |
add_action('init', 'df_disable_comments_admin_bar'); | |
if ( class_exists( 'Tribe__Events__Main' ) ) { | |
class ContinualMonthViewPagination { | |
public function __construct() { | |
add_filter( 'tribe_events_the_next_month_link', array( $this, 'next_month' ) ); | |
add_filter( 'tribe_events_the_previous_month_link', array( $this, 'previous_month' ) ); | |
} | |
public function next_month() { | |
$url = tribe_get_next_month_link(); | |
$text = tribe_get_next_month_text(); | |
$date = Tribe__Events__Main::instance()->nextMonth( tribe_get_month_view_date() ); | |
return '<a data-month="' . $date . '" href="' . $url . '" rel="next">' . $text . ' <span>»</span></a>'; | |
} | |
public function previous_month() { | |
$url = tribe_get_previous_month_link(); | |
$text = tribe_get_previous_month_text(); | |
$date = Tribe__Events__Main::instance()->previousMonth( tribe_get_month_view_date() ); | |
return '<a data-month="' . $date . '" href="' . $url . '" rel="prev"><span>«</span> ' . $text . ' </a>'; | |
} | |
} | |
new ContinualMonthViewPagination; | |
} | |
add_filter( 'get_the_archive_title', function ($title) { | |
if ( is_archive() ) { | |
$title = post_type_archive_title( '', false ); | |
} | |
if ( '' == $title ){ | |
$title = 'לוח ארועים'; | |
} | |
return $title; | |
}); | |
if ( ! function_exists('cars_create') ) { | |
// Register Custom Post Type | |
function cars_create() { | |
$labels = array( | |
'name' => _x( 'cars', 'Post Type General Name', 'text_domain' ), | |
'singular_name' => _x( 'car', 'Post Type Singular Name', 'text_domain' ), | |
'menu_name' => __( 'מכוניות', 'text_domain' ), | |
'name_admin_bar' => __( 'מכוניות', 'text_domain' ), | |
'archives' => __( 'Item Archives', 'text_domain' ), | |
'attributes' => __( 'Item Attributes', 'text_domain' ), | |
'parent_item_colon' => __( 'Parent Item:', 'text_domain' ), | |
'all_items' => __( 'כל המכוניות', 'text_domain' ), | |
'add_new_item' => __( 'הוסף מכונית', 'text_domain' ), | |
'add_new' => __( 'הוסף מכונית', 'text_domain' ), | |
'new_item' => __( 'מכונית חדשה', 'text_domain' ), | |
'edit_item' => __( 'ערוך מכונית', 'text_domain' ), | |
'update_item' => __( 'עדכן מכונית', 'text_domain' ), | |
'view_item' => __( 'צפה במכונית', 'text_domain' ), | |
'view_items' => __( 'צפה במכוניות', 'text_domain' ), | |
'search_items' => __( 'חפש מכוניות', 'text_domain' ), | |
'not_found' => __( 'לא נמצא', 'text_domain' ), | |
'not_found_in_trash' => __( 'לא נמצא בפח האשפה', 'text_domain' ), | |
'featured_image' => __( 'תמונה ראשית', 'text_domain' ), | |
'set_featured_image' => __( 'עדכן תמונה ראשית', 'text_domain' ), | |
'remove_featured_image' => __( 'הסר תמונה ראשית', 'text_domain' ), | |
'use_featured_image' => __( 'השתמש כתמונה ראשית', 'text_domain' ), | |
'insert_into_item' => __( 'הכנס למכונית', 'text_domain' ), | |
'uploaded_to_this_item' => __( 'Uploaded to this item', 'text_domain' ), | |
'items_list' => __( 'Items list', 'text_domain' ), | |
'items_list_navigation' => __( 'Items list navigation', 'text_domain' ), | |
'filter_items_list' => __( 'Filter items list', 'text_domain' ), | |
); | |
$args = array( | |
'label' => __( 'car', 'text_domain' ), | |
'description' => __( 'cars', 'text_domain' ), | |
'labels' => $labels, | |
'supports' => array( 'title', 'thumbnail', 'revisions', ), | |
'taxonomies' => array( '' ), | |
'hierarchical' => false, | |
'public' => true, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'menu_position' => 5, | |
'menu_icon' => 'dashicons-performance', | |
'show_in_admin_bar' => true, | |
'show_in_nav_menus' => true, | |
'can_export' => true, | |
'has_archive' => true, | |
'exclude_from_search' => false, | |
'publicly_queryable' => true, | |
'capability_type' => 'page', | |
'show_in_rest' => false, | |
'rest_base' => 'cars', | |
); | |
register_post_type( 'cars', $args ); | |
} | |
add_action( 'init', 'cars_create', 0 ); | |
} | |
if ( ! function_exists( 'maker' ) ) { | |
// Register Custom Taxonomy | |
function maker() { | |
$labels = array( | |
'name' => _x( 'יצרנים', 'Taxonomy General Name', 'יצרן' ), | |
'singular_name' => _x( 'יצרן', 'Taxonomy Singular Name', 'יצרן' ), | |
'menu_name' => __( 'יצרנים', 'יצרן' ), | |
'all_items' => __( 'כל היצרנים', 'יצרן' ), | |
'parent_item' => __( 'Parent Item', 'יצרן' ), | |
'parent_item_colon' => __( 'Parent Item:', 'יצרן' ), | |
'new_item_name' => __( 'יצרן חדש', 'יצרן' ), | |
'add_new_item' => __( 'הוסף יצרן', 'יצרן' ), | |
'edit_item' => __( 'ערוך יצרן', 'יצרן' ), | |
'update_item' => __( 'עדכן יצרן', 'יצרן' ), | |
'view_item' => __( 'הצג יצרן', 'יצרן' ), | |
'separate_items_with_commas' => __( 'Separate items with commas', 'יצרן' ), | |
'add_or_remove_items' => __( 'Add or remove items', 'יצרן' ), | |
'choose_from_most_used' => __( 'Choose from the most used', 'יצרן' ), | |
'popular_items' => __( 'Popular Items', 'יצרן' ), | |
'search_items' => __( 'Search Items', 'יצרן' ), | |
'not_found' => __( 'Not Found', 'יצרן' ), | |
'no_terms' => __( 'No items', 'יצרן' ), | |
'items_list' => __( 'Items list', 'יצרן' ), | |
'items_list_navigation' => __( 'Items list navigation', 'יצרן' ), | |
); | |
$args = array( | |
'labels' => $labels, | |
'hierarchical' => true, | |
'public' => true, | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'show_in_nav_menus' => true, | |
'show_tagcloud' => true, | |
); | |
register_taxonomy( 'create', array( 'cars' ), $args ); | |
} | |
add_action( 'init', 'maker', 0 ); | |
} | |
if ( ! function_exists( 'degem' ) ) { | |
// Register Custom Taxonomy | |
function degem() { | |
$labels = array( | |
'name' => _x( ' דגמים', 'Taxonomy General Name', 'ֿדגמים' ), | |
'singular_name' => _x( 'דגם', 'Taxonomy Singular Name', 'דגמים' ), | |
'menu_name' => __( 'דגמים', 'דגמים' ), | |
'all_items' => __( 'כל הדגמים', 'דגמים' ), | |
'parent_item' => __( 'Parent Item', 'דגמים' ), | |
'parent_item_colon' => __( 'Parent Item:', 'דגמים' ), | |
'new_item_name' => __( 'תת דגם חדש', 'דגמים' ), | |
'add_new_item' => __( 'הוסף דגם', 'תתדגמים' ), | |
'edit_item' => __( 'ערוך דגם', ' דגמים' ), | |
'update_item' => __( 'עדכן דגם', ' דגמים' ), | |
'view_item' => __( 'צפה בדגם', 'דגמים' ), | |
'separate_items_with_commas' => __( 'Separate items with commas', ' דגמים' ), | |
'add_or_remove_items' => __( '', ' דגמים' ), | |
'choose_from_most_used' => __( 'Choose from the most used', ' דגמים' ), | |
'popular_items' => __( 'Popular Items', 'דגמים' ), | |
'search_items' => __( 'Search Items', ' דגמים' ), | |
'not_found' => __( 'Not Found', ' דגמים' ), | |
'no_terms' => __( 'No items', ' דגמים' ), | |
'items_list' => __( 'Items list', ' דגמים' ), | |
'items_list_navigation' => __( 'Items list navigation', ' דגמים' ), | |
); | |
$args = array( | |
'labels' => $labels, | |
'hierarchical' => true, | |
'public' => true, | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'show_in_nav_menus' => true, | |
'show_tagcloud' => true, | |
); | |
register_taxonomy( 'degem', array( 'cars' ), $args ); | |
} | |
add_action( 'init', 'degem', 0 ); | |
} | |
if ( ! function_exists( 'subdegem' ) ) { | |
// Register Custom Taxonomy | |
function subdegem() { | |
$labels = array( | |
'name' => _x( 'תת דגמים', 'Taxonomy General Name', 'תת דגמים' ), | |
'singular_name' => _x( 'תת דגם', 'Taxonomy Singular Name', 'דגמים' ), | |
'menu_name' => __( 'תת דגמים', 'תת דגמים' ), | |
'all_items' => __( 'כל הדגמים', 'תת דגמים' ), | |
'parent_item' => __( 'Parent Item', 'דגמים' ), | |
'parent_item_colon' => __( 'Parent Item:', 'דגמים' ), | |
'new_item_name' => __( 'תת דגם חדש', 'דגמים' ), | |
'add_new_item' => __( 'הוסף תת דגם', 'תת דגמים' ), | |
'edit_item' => __( 'ערוך תת דגם', 'תת דגמים' ), | |
'update_item' => __( 'עדכן תת דגם', 'תת דגמים' ), | |
'view_item' => __( 'צפה בדגם', 'דגמים' ), | |
'separate_items_with_commas' => __( 'Separate items with commas', 'תת דגמים' ), | |
'add_or_remove_items' => __( '', 'תת דגמים' ), | |
'choose_from_most_used' => __( 'Choose from the most used', 'תת דגמים' ), | |
'popular_items' => __( 'Popular Items', 'תת דגמים' ), | |
'search_items' => __( 'Search Items', 'תת דגמים' ), | |
'not_found' => __( 'Not Found', 'תת דגמים' ), | |
'no_terms' => __( 'No items', 'תת דגמים' ), | |
'items_list' => __( 'Items list', 'תת דגמים' ), | |
'items_list_navigation' => __( 'Items list navigation', 'תת דגמים' ), | |
); | |
$args = array( | |
'labels' => $labels, | |
'hierarchical' => false, | |
'public' => true, | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'show_in_nav_menus' => true, | |
'show_tagcloud' => true, | |
); | |
register_taxonomy( 'subdegem', array( 'cars' ), $args ); | |
} | |
add_action( 'init', 'subdegem', 0 ); | |
} | |
if ( ! function_exists( 'region' ) ) { | |
// Register Custom Taxonomy | |
function region() { | |
$labels = array( | |
'name' => _x( 'ישובים', 'Taxonomy General Name', 'ישובים' ), | |
'singular_name' => _x( 'ישוב', 'Taxonomy Singular Name', 'ישובים' ), | |
'menu_name' => __( 'ישובים', 'ישובים' ), | |
'all_items' => __( 'כל הישובים', 'ישובים' ), | |
'parent_item' => __( 'Parent Item', 'ישובים' ), | |
'parent_item_colon' => __( 'Parent Item:', 'ישובים' ), | |
'new_item_name' => __( 'דגם חדש', 'ישובים' ), | |
'add_new_item' => __( 'הוסף ישוב', 'ישובים' ), | |
'edit_item' => __( 'ערוך ישוב', 'ישובים' ), | |
'update_item' => __( 'עדכן ישוב', 'ישובים' ), | |
'view_item' => __( 'צפה בישוב', 'ישובים' ), | |
'separate_items_with_commas' => __( 'Separate items with commas', 'ישובים' ), | |
'add_or_remove_items' => __( '', 'ישובים' ), | |
'choose_from_most_used' => __( 'Choose from the most used', 'ישובים' ), | |
'popular_items' => __( 'Popular Items', 'ישובים' ), | |
'search_items' => __( 'Search Items', 'ישובים' ), | |
'not_found' => __( 'Not Found', 'ישובים' ), | |
'no_terms' => __( 'No items', 'ישובים' ), | |
'items_list' => __( 'Items list', 'ישובים' ), | |
'items_list_navigation' => __( 'Items list navigation', 'ישובים' ), | |
); | |
$args = array( | |
'labels' => $labels, | |
'hierarchical' => false, | |
'public' => true, | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'show_in_nav_menus' => true, | |
'show_tagcloud' => true, | |
); | |
register_taxonomy( 'region', array( 'cars' ), $args ); | |
} | |
add_action( 'init', 'region', 0 ); | |
} | |
if ( ! function_exists( 'typeof' ) ) { | |
// Register Custom Taxonomy | |
function typeof() { | |
$labels = array( | |
'name' => _x( 'סוג', 'Taxonomy General Name', 'סוגי רכב' ), | |
'singular_name' => _x( 'סוג', 'Taxonomy Singular Name', 'סוגי רכב' ), | |
'menu_name' => __( 'סוגי רכב', 'סוגי רכב' ), | |
'all_items' => __( 'כל סוגי הרכב', 'סוגי רכב' ), | |
'parent_item' => __( 'Parent Item', 'סוגי רכב' ), | |
'parent_item_colon' => __( 'Parent Item:', 'סוגי רכב' ), | |
'new_item_name' => __( 'סוג רכב חדש', 'סוגי רכב' ), | |
'add_new_item' => __( 'הוסף סוג', 'סוגי רכב' ), | |
'edit_item' => __( 'ערוך סוג', 'סוגי רכב' ), | |
'update_item' => __( 'עדכן סוג', 'סוגי רכב' ), | |
'view_item' => __( 'צפה בסוג', 'סוגי רכב' ), | |
'separate_items_with_commas' => __( 'Separate items with commas', 'סוגי רכב' ), | |
'add_or_remove_items' => __( '', 'סוגי רכב' ), | |
'choose_from_most_used' => __( 'Choose from the most used', 'סוגי רכב' ), | |
'popular_items' => __( 'Popular Items', 'סוגי רכב' ), | |
'search_items' => __( 'Search Items', 'סוגי רכב' ), | |
'not_found' => __( 'Not Found', 'סוגי רכב' ), | |
'no_terms' => __( 'No items', 'סוגי רכב' ), | |
'items_list' => __( 'Items list', 'סוגי רכב' ), | |
'items_list_navigation' => __( 'Items list navigation', 'סוגי רכב' ), | |
); | |
$args = array( | |
'labels' => $labels, | |
'hierarchical' => false, | |
'public' => true, | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'show_in_nav_menus' => true, | |
'show_tagcloud' => true, | |
); | |
register_taxonomy( 'typeof', array( 'cars' ), $args ); | |
} | |
add_action( 'init', 'typeof', 0 ); | |
} | |
function year_shortcode2() { | |
echo '<p class="margin5">'; | |
$field_name = "year_make"; | |
$field = get_field_object($field_name); | |
echo '<span class="label">'; | |
echo $field['label']; | |
echo '</span>'; | |
echo $field['value']; | |
echo '</p>'; | |
the_field('year_make'); | |
} | |
add_shortcode( 'year2', 'year_shortcode2' ); | |
function year_shortcode() { | |
while ( have_posts() ) : the_post(); | |
echo '<div class="cartitlewrap">'; | |
echo '<span class="cartitle">'; | |
the_title(); | |
echo '</span>'; | |
echo '<span class="cartitle">'; | |
the_field('year_make'); | |
echo '</span>'; | |
global $post; | |
$terms = get_the_terms( $post->ID , 'subdegem' ); | |
// Loop over each item since it's an array | |
if ( $terms != null ){ | |
foreach( $terms as $term ) { | |
// Print the name method from $term which is an OBJECT | |
echo '<span class="cartitle">'; | |
print $term->slug ; | |
echo '</span>'; | |
echo '</div>'; | |
// Get rid of the other data stored in the object, since it's not needed | |
unset($term); | |
} } | |
endwhile; // end of the loop. | |
} | |
add_shortcode( 'year', 'year_shortcode' ); | |
add_filter( 'generate_logo', 'generate_category_logo' ); | |
function generate_category_logo() | |
{ | |
if ( is_front_page() ) { | |
return 'http://carsil.co.il/wp-content/uploads/2017/05/logo.png'; | |
} | |
return 'http://carsil.co.il/wp-content/uploads/2017/05/logob.png'; | |
} | |
$gravity_form_id = 2; // gravity form id, or replace {$gravity_form_id} below with this number | |
add_filter( "gform_after_submission_{$gravity_form_id}", 'jdn_set_post_acf_gallery_field', 10, 2 ); | |
function jdn_set_post_acf_gallery_field( $entry, $form ) { | |
$gf_images_field_id = 18; // the upload field id | |
$acf_field_id = 'field_59539f3ba437e'; // the acf gallery field id | |
// get post, if there isn't one, bail | |
if( isset( $entry['post_id'] ) ) { | |
$post = get_post( $entry['post_id'] ); | |
if( is_null( $post ) ) | |
return; | |
} else { | |
return; | |
} | |
// Clean up images upload and create array for gallery field | |
if( isset( $entry[ $gf_images_field_id ] ) ) { | |
$images = stripslashes( $entry[ $gf_images_field_id ] ); | |
$images = json_decode( $images, true ); | |
if( !empty( $images ) && is_array( $images ) ) { | |
$gallery = array(); | |
foreach( $images as $key => $value ) { | |
// NOTE: this is the other function you need: https://gist.github.com/joshuadavidnelson/164a0a0744f0693d5746 | |
if( ! class_exists( 'JDN_Create_Media_File' ) ) | |
break; | |
// Create the media library attachment and store the attachment id in the gallery array | |
$create_image = new JDN_Create_Media_File( $value, $post->ID ); | |
$image_id = $create_image->attachment_id; | |
if( absint( $image_id ) ) { | |
$gallery[] = $image_id; | |
} | |
} | |
} | |
} | |
// Update gallery field with array | |
if( ! empty( $gallery ) ) { | |
update_field( $acf_field_id, $gallery, $post->ID ); | |
} | |
} | |
add_filter("gform_upload_path", "change_upload_path", 20, 2); | |
function change_upload_path($path_info, $form_id){ | |
$wp_upload_path = wp_upload_dir(); | |
$path_info["path"] = $wp_upload_path['path'] . '/'; | |
$path_info["url"] = $wp_upload_path['url'] . '/'; | |
return $path_info; | |
} | |
/** | |
* Create the image attachment and return the new media upload id. | |
* @based on: http://codex.wordpress.org/Function_Reference/wp_insert_attachment#Example | |
* @since 2.0.0 | |
* now includes thumbnail processing and better path logic | |
*/ | |
function jdn_create_image_id( $image_url, $parent_post_id = null ) { | |
if( !isset( $image_url ) ) | |
return false; | |
global $_wp_additional_image_sizes; | |
// Cache info on the wp uploads dir | |
$wp_upload_dir = wp_upload_dir(); | |
// get the file path | |
$path = parse_url( $image_url, PHP_URL_PATH ); | |
// File base name | |
$file_base_name = basename( $image_url ); | |
$uploaded_file_path = ABSPATH . $path; | |
// Check the type of file. We'll use this as the 'post_mime_type'. | |
$filetype = wp_check_filetype( $file_base_name, null ); | |
// error check | |
if( !empty( $filetype ) && is_array( $filetype ) ) { | |
// Create attachment title | |
$post_title = preg_replace( '/\.[^.]+$/', '', $file_base_name ); | |
// Prepare an array of post data for the attachment. | |
$attachment = array( | |
'guid' => $wp_upload_dir['url'] . '/' . basename( $uploaded_file_path ), | |
'post_mime_type' => $filetype['type'], | |
'post_title' => esc_attr( $post_title ), | |
'post_content' => '', | |
'post_status' => 'inherit' | |
); | |
// Set the post parent id if there is one | |
if( !is_null( $parent_post_id ) ) | |
$attachment['post_parent'] = $parent_post_id; | |
foreach( get_intermediate_image_sizes() as $s ) { | |
$sizes[$s] = array( 'width' => '', 'height' => '', 'crop' => true ); | |
if( in_array( $s, array( 'thumbnail', 'medium', 'large' ) ) ) { | |
$sizes[$s]['width'] = get_option( "{$s}_size_w" ); // For default sizes set in options | |
$sizes[$s]['height'] = get_option( "{$s}_size_h" ); // For default sizes set in options | |
$sizes[$s]['crop'] = get_option( "{$s}_crop" ); // For default sizes set in options | |
} | |
if( isset( $_wp_additional_image_sizes[ $s ] ) ) { | |
$sizes[ $s ] = array( | |
'width' => $_wp_additional_image_sizes[ $s ]['width'], | |
'height' => $_wp_additional_image_sizes[ $s ]['height'], | |
'crop' => $_wp_additional_image_sizes[ $s ]['crop'], | |
); | |
} | |
} | |
$sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes ); | |
foreach( $sizes as $size => $size_data ) { | |
$resized = image_make_intermediate_size( $uploaded_file_path, $size_data['width'], $size_data['height'], $size_data['crop'] ); | |
if ( $resized ) | |
$attachment['sizes'][$size] = $resized; | |
} | |
// Insert the attachment. | |
$attach_id = wp_insert_attachment( $attachment, $uploaded_file_path ); | |
//Error check | |
if( !is_wp_error( $attach_id ) ) { | |
//Generate wp attachment meta data | |
if( file_exists( ABSPATH . 'wp-admin/includes/image.php') && file_exists( ABSPATH . 'wp-admin/includes/media.php') ) { | |
require_once( ABSPATH . 'wp-admin/includes/image.php' ); | |
require_once( ABSPATH . 'wp-admin/includes/media.php' ); | |
$attach_data = wp_generate_attachment_metadata( $attach_id, $uploaded_file_path ); | |
wp_update_attachment_metadata( $attach_id, $attach_data ); | |
} // end if file exists check | |
} // end if error check | |
return $attach_id; | |
} else { | |
return false; | |
} // end if $$filetype | |
} // end function get_image_id | |
/** | |
* Repeater field update for Add Team Member | |
* @author Adam LaBarge | |
* @param $entry array required | |
* @param $form array required input by user | |
* | |
* @return none | |
*/ | |
add_action("gform_after_submission_11", "add_team_member_11", 10, 2); | |
function add_team_member_11($entry, $form) | |
{ | |
$team_member_name = $entry['1']; | |
$team_member_title = $entry['4']; | |
$team_member_bio = $entry['2']; | |
$team_member_image = $entry['3']; | |
$team_member_email = $entry['5']; | |
$field_key = "field_54f61acd460bb"; // Form - Project Add Team Member Repeater field key | |
$post_id = $_SESSION['project_id']; | |
$value = get_field( $field_key, $post_id ); // must return image as ID | |
$value = ( $value == '0' ? array() : $value ); // if value empty, set it as array | |
if( function_exists( 'jdn_create_image_id' ) ) : | |
$att_id = jdn_create_image_id( $entry[3], $post_id ); | |
endif; | |
$value[] = array( | |
'name' => $team_member_name, | |
'bio' => $team_member_bio, | |
'image' => $att_id, // must be an ID | |
'email' => $team_member_email, | |
'title' => $team_member_title, | |
); | |
update_field( $field_key, $value, $post_id ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment