質問: insert_complogo($file,$user_id); } } またこれ:if ( !empty( $_post['authorphoto'] ) ) update_usermeta( $current_user->id, 'comp_logo', esc_attr($_post['comp_logo'] ) ); そして私の入力タイプは:<p> <label><?php _e('add company logo', 'comp_logo') ?></label><br /> <input type="file" name="comp_logo" id="comp_logo" value="upload logo" size="50" /> </p> 上記のコードの最初の3ブロックからわかるように、post_idの参照をuser_idに変更しました。今度は会社のロゴのアップロードはうまくいきます、しかしuser_idとupdate_usermetaを使っても情報はwp_postmetaテーブルに保存されています。だから私の質問(結局のところ)私はupdate_usermetaを使用してimがwp_postmetaに入って添付ファイル情報であるとき、なぜそれがどこに行くかに関係なく画像添付ファイルは投稿のタイプだwp_postmetaからその画像を取得して、正しい作者と関連付けますか?
回答: 実際にはフロントエンドからユーザ編集ページにフックをショートコードすることができるプラグインを作成するかサイドバーに別のショートコードを使用することによってそれを回避しました。その根本は以下のとおりです。エラー報告に関してちょっとした作業を行う必要があります。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&nbsp;" . get_option(wpal_width) ."px and max allowable height is&nbsp;" . 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 } ?>