实际上,通过制作一个插件,可以将钩子从前端短接到用户编辑页面,或者在侧边栏中使用一个单独的短接代码,可以绕过它。下面是问题的症结所在,只需对错误报告进行一些BIT和BOB。
require(ABSPATH . WPINC . \'/pluggable.php\');
define(\'WP-AUTHOR-LOGO_VERSION\', \'0.3.0\');
define(\'WP-AUTHOR-LOGO_PLUGIN_URL\', plugin_dir_url( __FILE__ ));
register_activation_hook(__FILE__, \'wpal_createfolder\');
function wpal_createfolder() {
$target = ABSPATH . \'wp-content/uploads/wpal_logos\';
wp_mkdir_p( $target );
}
// Directory for uploaded images
$uploaddir = ABSPATH . \'wp-content/uploads/wpal_logos\';
// Allowed mimes
$allowed_ext = "jpg, gif, png";
// Default is 50kb
$max_size = get_option(wpal_size);
// height in pixels, default is 175px
$max_height = get_option(wpal_height);
// width in pixels, default is 450px
$max_width = get_option(wpal_width);
// Check mime types are allowed
$extension = pathinfo($_FILES[\'wpaluploader\'][\'name\']);
$extension = $extension[extension];
$allowed_paths = explode(", ", $allowed_ext);
for($i = 0; $i < count($allowed_paths); $i++) {
if ($allowed_paths[$i] == "$extension") {
$ok = "1";
}
}
// Check File Size
if ($ok == "1") {
if($_FILES[\'wpaluploader\'][\'size\'] > $max_size)
{
print "Image size is too big!";
exit;
}
// Check Height & Width
if ($max_width && $max_height) {
list($width, $height, $type, $w) = getimagesize($_FILES[\'wpaluploader\'][\'tmp_name\']);
if($width > $max_width || $height > $max_height)
{
print "Image is too big! max allowable width is " . get_option(wpal_width) ."px and max allowable height is " . get_option(wpal_width) ."px";
exit;
}
}
global $user_id;
get_currentuserinfo();
$image_name=$current_user->id.\'.\'.$extension;
//the new name will be containing the full path where will be stored (images folder)
// Rename file and move to folder
$newname="$uploaddir./".$image_name;
if(is_uploaded_file($_FILES[\'wpaluploader\'][\'tmp_name\']))
{
move_uploaded_file($_FILES[\'wpaluploader\'][\'tmp_name\'], $newname);
}
print "Your image has been uploaded successfully!";
}
// Create shortcode for adding to edit user page
add_shortcode("wp-author-logo", "wpaluploader_input");
function wpaluploader_input() {
$wpaluploader_output = wpaluploader_showform();
return $wpaluploader_output;
}
function wpaluploader_showform() {
$wpaluploader_output = \'<p><label for="wpauploader">Upload Company Logo:</label><br />
<input type="file" name="wpaluploader" id="wpaluploader" />
<br />
<small style="color:#ff0000; font-size:0.7em;">Allowed image types are .jpg, .gif, .png.<br />
Max image width = \' . get_option(wpal_width) . \'px, Max image height = \' . get_option(wpal_height) . \'px </small>\';
return $wpaluploader_output;
}
// Create other Shortcode for full form
add_shortcode("wp-author-logofull", "wpaluploader_inputfull");
function wpaluploader_inputfull() {
$wpaluploader_outputfull = wpaluploader_showformfull();
return $wpaluploader_outputfull;
}
function wpaluploader_showformfull() {
$wpaluploader_outputfull = \'<form method="post" id="adduser" action="\' . str_replace( \'%7E\', \'~\', $_SERVER[\'REQUEST_URI\']) .\'" enctype="multipart/form-data">
<p><label for="wpauploader">Upload Company Logo:</label><br />
<input type="file" name="wpaluploader" id="wpaluploader" />
<br />
<input name="updateuser" type="submit" id="updateuser" class="submit button" value="Upload" />
\' . wp_nonce_field( \'update-user\' ) . \'
<input name="action" type="hidden" id="action" value="update-user" />
<small style="color:#ff0000; font-size:0.7em;">Allowed image types are .jpg, .gif, .png.<br />
Max image width = \' . get_option(wpal_width) . \'px, Max image height = \' . get_option(wpal_height) . \'px </small>\';
return $wpaluploader_outputfull;
}
add_action(\'admin_menu\', \'wpal_menu\');
function wpal_menu() {
add_options_page(\'WP Author Logo\', \'WP Author Logo\', \'manage_options\', \'wpal_wp-author-logo\', \'wpal\');
}
function wpal() {
if (!current_user_can(\'manage_options\')) {
wp_die( __(\'You do not have sufficient permissions to access this page.\') );
}
?>
<div class="wrap">
<div class="leftwrap">
<?php echo "<h2>" . __( \'Wordpress Author Logo Plugin\', \'wpal_lang\' ) . "</h2>"; ?>
<?php
if($_POST[\'wpal_author_logo_success\'] == \'Y\') {
//Form data sent
$wpal_width = $_POST[\'wpal_width\'];
update_option(\'wpal_width\', $wpal_width);
$wpal_height = $_POST[\'wpal_height\'];
update_option(\'wpal_height\', $wpal_height);
$wpal_size = $_POST[\'wpal_size\'];
update_option(\'wpal_size\', $wpal_size);
$wpal_logos = $_POST[\'wpal_logos\'];
update_option(\'wpal_logos\', $wpal_logos);
?>
<div class="updated"><p><strong><?php _e(\'WP Author Logo Plugin Options Saved.\' ); ?></strong></p></div>
<?php
} else {
//Normal page display
$wpal_width = get_option(\'wpal_width\');
$wpal_height = get_option(\'wpal_height\');
$wpal_size = get_option(\'wpal_size\');
$wpal_logos = get_option(\'wpal_logos\');
}
?>
<form name="wpal_settingsform" method="post" action="<?php echo str_replace( \'%7E\', \'~\', $_SERVER[\'REQUEST_URI\']); ?>">
<input type="hidden" name="wpal_author_logo_success" value="Y">
<?php echo "<h4>" . __( \'Wordpress Author Logo Settings\', \'wpal_lang\' ) . "</h4>"; ?>
<p><label for="wpal_width"><?php _e("Maximum Width: " ); ?></label><br /><input type="text" name="wpal_width" value="<?php echo $wpal_width; ?>" size="20"><?php _e("px"); ?></p>
<p><label for="wpal_height"><?php _e("Maximum Height: " ); ?></label><br /><input type="text" name="wpal_height" value="<?php echo $wpal_height; ?>" size="20"><?php _e("px" ); ?></p>
<p><label for="wpal_size"><?php _e("Maximum Size: " ); ?></label><br /><input type="text" name="wpal_size" value="<?php echo $wpal_size; ?>" size="20"><?php _e("Bytes: hint 50000 bytes = 50Kbs" ); ?></p>
<p><label for="wpal_logos"><?php _e("Logo Images Folder: " ); ?></label><br /><input type="text" name="wpal_logos" value="<?php echo $wpal_logos; ?>" size="20"><?php _e(" ex: /wpal_logo_images/" ); ?></p>
<p class="submit">
<input type="submit" name="Submit" value="<?php _e(\'Update Options\', \'wpal_lang\' ) ?>" />
</p>
</form>
</div><!-- / leftwrap -->
</div><!-- / wrap -->
<?php } ?>