Custom code to upload image ?

This topic contains 2 reply and 2 voices, and was last updated by Janet 9 years, 11 months ago
Viewing 2 Posts - 1 through 2 (of 2 total)
Author Posts
May 25, 2014 at 11:24 pm 21013
Janet How do I put my code uploads in the plugin. Here is my code.

<?php
if (class_exists('Walker_Nav_Menu')) {
	class description_walker extends Walker_Nav_Menu
	{
		function start_el(&$output, $item, $depth, $args) {
			global $wp_query;
			$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';

			$class_names = $value = '';

			$classes = empty( $item->classes ) ? array() : (array) $item->classes;

			$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
			$class_names = ' class="'. esc_attr( $class_names ) . '"';

			$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';

			$attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
			$attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
			$attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
			$attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';

			$prepend = '<strong>';
			$append = '</strong>';

			if($depth != 0) { $description = $append = $prepend = ""; }

			$item_output = $args->before;
			$item_output .= '<a'. $attributes .'>';
			$item_output .= $args->link_before .$prepend.apply_filters( 'the_title', $item->title, $item->ID ).$append;
			$item_output .= '<span>' . $description. '</span>' . $args->link_after;
			$item_output .= '</a>';
			$item_output .= $args->after;

			$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
		}
	}
}

function ahomely_display_options($callback_args) {
	global $post;
	$thumbs = array();
	$custom = get_post_custom($post->ID);
	$custom["thumbs"] = isset( $custom["thumbs"][0] ) ? unserialize($custom["thumbs"][0]) : '';
	$thumbnail1 =  isset($custom["thumbs"][0]) ? $custom["thumbs"][0] : '';
	$thumbnail2 =  isset($custom["thumbs"][1]) ? $custom["thumbs"][1] : '';
	$thumbnail3 =  isset($custom["thumbs"][2]) ? $custom["thumbs"][2] : '';
	$thumbnail4 =  isset($custom["thumbs"][3]) ? $custom["thumbs"][3] : '';
	$thumbnail5 =  isset($custom["thumbs"][4]) ? $custom["thumbs"][4] : '';
	if ($callback_args->post_type == 'page') $asc_page_template =  isset($custom["asc_page_template"][0]) ? $custom["asc_page_template"][0] : '';

	wp_nonce_field( basename( __FILE__ ), 'asc_settings_nonce' );
?>

	<?php if ($callback_args->post_type == 'page') { ?>
		<p style="margin-bottom: 22px;">
			<label for="asc_page_template">Page Type</label>
			<select id="asc_page_template" name="asc_page_template">
				<option value="">Product Page</option>
				<option <?php if (htmlspecialchars($asc_page_template) == 'usual') echo('selected="selected"')?> value="usual">Usual Page</option>
			</select>
		</p>
	<?php }; ?>

	<p style="margin-bottom: 22px;">
		<label for="asc_upload_image">Product Thumbnail 1: </label><br/>
		<input id="asc_upload_image" type="text" size="90" name="asc_upload_image" value="<?php echo esc_attr($thumbnail1); ?>" />
		<input class="upload_image_button" type="button" value="Upload Image" /><br/>
		<small>(enter an URL or upload an image for the first Product Image)</small>
	</p>

	<p style="margin-bottom: 22px;">
		<label for="asc_upload_image2">Product Thumbnail 2: </label><br/>
		<input id="asc_upload_image2" type="text" size="90" name="asc_upload_image2" value="<?php echo esc_attr($thumbnail2); ?>" />
		<input class="upload_image_button" type="button" value="Upload Image" /><br/>
		<small>(enter an URL or upload an image for the second Product Image)</small>
	</p>

	<p style="margin-bottom: 22px;">
		<label for="asc_upload_image3">Product Thumbnail 3: </label><br/>
		<input id="asc_upload_image3" type="text" size="90" name="asc_upload_image3" value="<?php echo esc_attr($thumbnail3); ?>" />
		<input class="upload_image_button" type="button" value="Upload Image" /><br/>
		<small>(enter an URL or upload an image for the third Product Image)</small>
	</p>

	<p style="margin-bottom: 22px;">
		<label for="asc_upload_image4">Product Thumbnail 4: </label><br/>
		<input id="asc_upload_image4" type="text" size="90" name="asc_upload_image4" value="<?php echo esc_attr($thumbnail4); ?>" />
		<input class="upload_image_button" type="button" value="Upload Image" /><br/>
		<small>(enter an URL or upload an image for the fourth Product Image)</small>
	</p>
    
    <p style="margin-bottom: 22px;">
		<label for="asc_upload_image5">Product Thumbnail 5: </label><br/>
		<input id="asc_upload_image5" type="text" size="90" name="asc_upload_image5" value="<?php echo esc_attr($thumbnail5); ?>" />
		<input class="upload_image_button" type="button" value="Upload Image" /><br/>
		<small>(enter an URL or upload an image for the fourth Product Image)</small>
	</p>

<?php }
function ahomely_save_details( $post_id, $post ){
	global $pagenow;

	if ( 'post.php' != $pagenow ) return $post_id;

	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
		return $post_id;

	$post_type = get_post_type_object( $post->post_type );
	if ( ! current_user_can( $post_type->cap->edit_post, $post_id ) )
		return $post_id;

	if ( !isset( $_POST['asc_settings_nonce'] ) || ! wp_verify_nonce( $_POST['asc_settings_nonce'], basename( __FILE__ ) ) )
        return $post_id;

	if ( isset( $_POST["asc_upload_image"] ) && $_POST["asc_upload_image"] <> '' )
		$thumbs[] = esc_url_raw( $_POST["asc_upload_image"] );
	if ( isset( $_POST["asc_upload_image2"] ) && $_POST["asc_upload_image2"] <> '' )
		$thumbs[] = esc_url_raw( $_POST["asc_upload_image2"] );
	if ( isset( $_POST["asc_upload_image3"] ) && $_POST["asc_upload_image3"] <> '' )
		$thumbs[] = esc_url_raw( $_POST["asc_upload_image3"] );
	if ( isset( $_POST["asc_upload_image4"] ) && $_POST["asc_upload_image4"] <> '' )
		$thumbs[] = esc_url_raw( $_POST["asc_upload_image4"] );
	if ( isset( $_POST["asc_upload_image5"] ) && $_POST["asc_upload_image5"] <> '' )
		$thumbs[] = esc_url_raw( $_POST["asc_upload_image5"] );

	if ( ! empty( $thumbs ) )
		update_post_meta( $post_id, "thumbs", $thumbs );
	else
		delete_post_meta( $post_id, "thumbs" );
		
	if ( isset( $_POST["asc_page_template"] ) )
		update_post_meta( $post_id, "asc_page_template", sanitize_text_field( $_POST["asc_page_template"] ) );
	else
		delete_post_meta( $post_id, "asc_page_template" );
}
add_action( 'save_post', 'ahomely_save_details', 10, 2 );

function ahomely_upload_scripts() {
	wp_enqueue_script('media-upload');
	wp_enqueue_script('thickbox');
	wp_register_script('my-upload', get_bloginfo('template_directory').'/js/custom_uploader.js', array('jquery','media-upload','thickbox'));
	wp_enqueue_script('my-upload');
}

function ahomely_upload_styles() {
	wp_enqueue_style('thickbox');
}

function asc_ahomely_post_scripts_styles( $hook ) {
	global $typenow;

	if ( ! in_array( $hook, array( 'post-new.php', 'post.php' ) ) ) return;

	if ( isset( $typenow ) && in_array( $typenow, array( 'post', 'posthome' ) ) ) {
		ahomely_upload_scripts();
		ahomely_upload_styles();
	}
}
add_action( 'admin_enqueue_scripts', 'asc_ahomely_post_scripts_styles', 10, 1 );

/* Plugin Integrations */
May 26, 2014 at 2:50 pm 21025
Tareq Hasan Tareq Hasan

I think the code is for admin panel, right? User frontend uses ajax and a custom media uploader, so I guess what you are trying to do won’t work.

May 26, 2014 at 3:42 pm 21029
Janet Janet

How i have to customize out post form. Please help me. Thank you.

Viewing 2 Posts - 1 through 2 (of 2 total)