Showing posts with label tricks. Show all posts
Showing posts with label tricks. Show all posts
WordPress Front End Multiple File Upload
While customizing Wordpress for our suitable cms solutions. We have certain things required from our customers. So it requires front end media upload. Even few things require to gather details and posts from users. If it requires you can also provide your user to upload media files from the front end of your site. May be of my following code can help you to create front end upload with multiple files simultaneously from single from .
You don't need to use any of the following things : flash ,js, jquery, and ajax . It works on all the browsers and simple HTML 5 codes and php code. This will work well on your old browsers like IE 6 . Also works well on your mobile devices.
create HTML form like this
<form action="upload.php" method="post" name="front_end_upload" >
<label> Attach all your files here :<input type="file" name="upload_attachments[]" multiple="multiple" > </label>
<input type="submit" name="Upload" >
</form>
The above HTML form handles the user upload files at your sites front-end. Now code for your back end to store the files.
//upload.php
if( 'POST' == $_SERVER['REQUEST_METHOD'] ) {
if ( $_FILES ) {
$files = $_FILES["upload_attachments"];
foreach ($files['name'] as $key => $value) {
if ($files['name'][$key]) {
$file = array(
'name' => $files['name'][$key],
'type' => $files['type'][$key],
'tmp_name' => $files['tmp_name'][$key],
'error' => $files['error'][$key],
'size' => $files['size'][$key]
);
$_FILES = array ("screenshots" => $file);
foreach ($_FILES as $file => $array) {
$newupload = insert_attachment($file,$pid);
}
}
}
}
}
The above code will handle the operation of getting files and send to your Wordpress function insert_attachment that we have added on your theme fiel "function.php" or your plugin's init action function.
here is the code for insert attachment function
################################################################################
// image Attachment
################################################################################
function insert_attachment($file_handler,$post_id,$set_thu=false) {
// check to make sure its a successful upload
if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
$attach_id = media_handle_upload( $file_handler, $post_id );
if ($set_thu) set_post_thumbnail($post_id, $attach_id);
return $attach_id;
}
that's it. to perform front end multiple file upload.
21:32 by Moviiee Thandura · 1
How to Manage Wordpress Pluse through Programmatically

Which beats every 15 seconds. Also you can change the interval of beat. You can also stop beating for low processors. because it will take few CPU usage which is avoided on low processors.
Manage time gap :
<?php
/**
* Plugin Name: MyWP Tuts - Set Heartbeat pulse
*/
! defined( 'ABSPATH' ) and exit;
add_filter( 'heartbeat_settings', 'mywp_tuts_heartbeat_settings' );
function mywp_tuts_heartbeat_settings( $settings = array() ) {
$settings['interval'] = 60;
return $settings;
}
?>
remove the action by using the following code.
<?php
/**
* Plugin Name: MyWP Tuts - Set Heartbeat pulse
*/
! defined( 'ABSPATH' ) and exit;
remove_action( 'admin_init', 'wp_auth_check_load' );
?>
Debugging of the Tool
if you want to debug the tools. wp.heartbeat.debug of javascript function will give you the debugging informations and tools make it as TRUE we will debug heartbeat.
<?php
if ( typeof console !== 'undefined' )
wp.heartbeat.debug = true; // Show debugging info of heartbeat
?>
00:18 by Unknown · 0
Wordpress Remove Default Widgets
I was tried to find a solution to remove all the default widgets from my WP blog. I spend huge time to find s simple solution.Here is a complete code to remove all the default widget from your wordpress default widget.
function unregister_default_widgets() {
unregister_widget('WP_Widget_Pages');
unregister_widget('WP_Widget_Calendar');
unregister_widget('WP_Widget_Archives');
unregister_widget('WP_Widget_Links');
unregister_widget('WP_Widget_Meta');
unregister_widget('WP_Widget_Search');
unregister_widget('WP_Widget_Text');
unregister_widget('WP_Widget_Categories');
unregister_widget('WP_Widget_Recent_Posts');
unregister_widget('WP_Widget_Recent_Comments');
unregister_widget('WP_Widget_RSS');
unregister_widget('WP_Widget_Tag_Cloud');
unregister_widget('WP_Nav_Menu_Widget');
unregister_widget('Twenty_Eleven_Ephemera_Widget');
}
if you get advanced trick just post your comment below.
20:12 by Moviiee Thandura · 0
Subscribe to:
Posts (Atom)