Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
get image media info call now uses wp ajax
- Loading branch information
Showing
5 changed files
with
68 additions
and
36 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,48 @@ | ||
<?php | ||
// use wp-load. Normally right here, but if it's not... | ||
if( file_exists('../../../wp-load.php') ) | ||
{ | ||
require_once('../../../wp-load.php'); | ||
$loaded = true; | ||
} // ...then look over here | ||
elseif( file_exists('./mf-config.php') ) | ||
{ | ||
include_once('./mf-config.php'); | ||
require_once(MF_WP_LOAD); | ||
$loaded = true; | ||
} | ||
|
||
if( $loaded !== true ){ | ||
die('Could not load wp-load.php, edit/add mf-config.php and define MF_WP_LOAD to point to a valid wp-load file.'); | ||
} | ||
class MF_ImageMedia { | ||
|
||
public function __construct() { | ||
add_action( 'wp_ajax_mf_get_image_media_info', array( $this, 'get_info' ) ); | ||
} | ||
|
||
function get_info() { | ||
global $mf_domain; | ||
|
||
require_once(ABSPATH."/wp-admin/includes/image.php"); | ||
require_once(ABSPATH."/wp-includes/media.php"); | ||
check_ajax_referer( 'nonce_ajax_get_image_media_info', 'nonce_ajax_get_image_media_info'); | ||
|
||
// remove text aditional in attachment | ||
$image_id = preg_replace('/del_attachment_/','',$_POST['image_id']); | ||
$info = wp_get_attachment_image_src($image_id,'original'); | ||
if( !( is_user_logged_in() && current_user_can('upload_files') ) ) { | ||
echo json_encode( | ||
array( | ||
'success' => false, | ||
'error' => "You don't have permission to upload files, contact to the administrator for more information!",$mf_domain | ||
) | ||
); | ||
wp_die(); | ||
} | ||
|
||
$field_id = preg_replace('/thumb_/','',$_POST['field_id']); | ||
// remove text aditional in attachment | ||
$image_id = preg_replace('/del_attachment_/','',$_POST['image_id']); | ||
$info = wp_get_attachment_image_src($image_id,'original'); | ||
|
||
if( count($info)){ | ||
$image_thumb = PHPTHUMB.'?&w=150&h=120&src='.$info[0]; | ||
$data = array('image' => $image_thumb,'field_id' => $field_id,'image_value' => $image_id); | ||
echo json_encode($data); | ||
$field_id = preg_replace('/thumb_/','',$_POST['field_id']); | ||
|
||
if( count($info) ){ | ||
$image_thumb = PHPTHUMB.'?&w=150&h=120&src='.$info[0]; | ||
$data = array('image' => $image_thumb,'field_id' => $field_id,'image_value' => $image_id); | ||
echo json_encode($data); | ||
} else { | ||
echo json_encode( | ||
array( | ||
'success' => false, | ||
'error' => "The image does not exist",$mf_domain | ||
) | ||
); | ||
|
||
} | ||
|
||
wp_die(); | ||
} | ||
} | ||
?> | ||
|
||
$mf_get_image_media = new MF_ImageMedia(); |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
a.mf_media_upload { | ||
color: green; | ||
font-weight: bold; | ||
padding-right: 10px; | ||
} |
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