Wordpress te bir Soru Cevap template i üzerine bir site kurdum. İstediğim şey, sorulan soruların admin onayından geçtikten sonra yayınlanması. Fakat kullanıcı rolünü "içerik sağlayıcı" olarak değiştirmeme rağmen, gönderiler otomatik olarak sisteme gönderiliyor. Template in yapımcısının dediği şey ise, benim modifiye etmem gerektiği. şöyle diyor:
"Gönderi fonksiyonunu pending olarak ayarla ve kullanıcıya "gönderiniz admin tarafından onaylandıktan sonra sistemde yayınlanacaktır" gibisinden bir mesaj göndermeye ayarla. Ve kullanıcı tipini birkaç yerde güncelle" diyor.
Php konusunda çok yeniyim, lütfen yardımlarınızı bekliyorum.
web sitemiz ise www.sorunolmadansorun.com
Template function php kodu şöyle:
/**
* @package WordPress
* @subpackage Instant Q&A - WPQA
*/
ob_start();
// Block access to wp-admin unless you are admin
$access_min_type = 'edit_others_posts';
$admin_redirect_to = get_option('siteurl').'/my-account/';
if (defined('ACCESS_MIN_TYPE'))
$access_min_type = ACCESS_MIN_TYPE;
if (defined('ADMIN_REDIRECT_TO'))
$admin_redirect_to = ADMIN_REDIRECT_TO;
if (!function_exists('wpba_init')) {
function wpba_init() {
global $access_min_type, $admin_redirect_to;
if (strpos(strtolower($_SERVER['REQUEST_URI']),'/wp-admin/') !== false) {
if (!current_user_can($access_min_type)) {
if ($admin_redirect_to == '') {
$admin_redirect_to = get_option('siteurl');
}
// Send a temporary redirect
wp_redirect($admin_redirect_to,302);
}
}
}
}
add_action('init','wpba_init',0);
// Change URL for Author to Profile :: Now reads /profile/username
global $wp_rewrite;
$wp_rewrite->author_base = 'profile';
$wp_rewrite->flush_rules();
// Instant SPAM protection :: Checks for browser request method
function check_referrer() {
if (!isset($_SERVER['HTTP_REFERER']) || $_SERVER['HTTP_REFERER'] == "") {
wp_die( __('Please enable referrers in your browser, or, if you\'re a spammer, bugger off!') );
}
}
add_action('check_comment_flood', 'check_referrer');
// Sidebar Structure
if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => '
',
)
);
// Check to see if items in loop are pages
function is_type_page() {
global $post;
return ($post->post_type == 'page');
}
// Admin Options
$themename = "Instant Q&A";
$shortname = "instant_qa";
$options = array (
array( "name" => $themename." Options",
"type" => "title"),
array( "name" => "Color Scheme
More Color Schemes avalible at http://www.wordpressqa.com ",
"desc" => "Select a color scheme",
"id" => $shortname."_color_scheme",
"type" => "select",
"options" => array("blue-meadow", "green-leaves", "blue-bird"),
"std" => "blue-meadow"),
array( "name" => "Logo URL
max-width 450px - max-height 60px",
"desc" => "Enter the link to your logo image",
"id" => $shortname."_logo",
"type" => "text",
"std" => ""),
array( "name" => "160x600 (left) Banner Ad",
"desc" => "Enter your 160x600 ad tag code",
"id" => $shortname."_ad160",
"type" => "textarea",
"std" => ""),
array( "name" => "125x125 (right) Banner Ad #1",
"desc" => "Enter your 125x125 #1 ad tag code",
"id" => $shortname."_ad125-1",
"type" => "textarea",
"std" => ""),
array( "name" => "125x125 (right) Banner Ad #2",
"desc" => "Enter your 125x125 #2 ad tag code",
"id" => $shortname."_ad125-2",
"type" => "textarea",
"std" => ""),
array( "name" => "728x90 (Bottom) Banner Ad",
"desc" => "Enter your 728x90 ad tag code",
"id" => $shortname."_ad728",
"type" => "textarea",
"std" => ""),
array( "name" => "Google Analytics Code",
"desc" => "Enter your tracking code
ex. 1234567-8
( Leave off the UA- )",
"id" => $shortname."_google_code",
"type" => "text",
"std" => ""),
);
function mytheme_add_admin() {
global $themename, $shortname, $options;
if ( $_GET['page'] == basename(__FILE__) ) {
if ( 'save' == $_REQUEST['action'] ) {
foreach ($options as $value) {
update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }
foreach ($options as $value) {
if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ] ); } else { delete_option( $value['id'] ); } }
header("Location: admin.php?page=functions.php&saved=true");
die;
}
else if( 'reset' == $_REQUEST['action'] ) {
foreach ($options as $value) {
delete_option( $value['id'] ); }
header("Location: admin.php?page=functions.php&reset=true");
die;
}
}
add_menu_page($themename, $themename, 'administrator', basename(__FILE__), 'mytheme_admin');
}
function mytheme_add_init() {
$file_dir=get_bloginfo('template_directory');
wp_enqueue_style("functions", $file_dir."/admin_options.css", false, "1.0", "all");
}
function mytheme_admin() {
global $themename, $shortname, $options;
$i=0;
if ( $_REQUEST['saved'] ) echo ''.$themename.' settings saved.
';
?>
Settings
case "title":
?>
Easily customize . Fill out the options below to activate them. If options are not set they will not display.
case 'text':
?>
" />
break;
case 'textarea':
?>
break;
case 'select':
?>
break;
?>
}
}
?>
}
?>
add_action('admin_init', 'mytheme_add_init');
add_action('admin_menu', 'mytheme_add_admin');
?>
// Get the Point Count and Set the Star Rating
function getPointLevel($authorId) {
$points = get_usermeta($authorId,'points');
if($points < 26) {
return '' . $points . ''. '
';
} elseif($points < 50 && $points > 25) {
return '' . $points . ''. '
';
} elseif($points < 500 && $points > 50) {
return '' . $points . ''. '
';
} elseif($points < 5000 && $points > 500) {
return '' . $points . ''. '
';
} elseif($points < 25000 && $points > 5000) {
return '' . $points . ''. '
';
} elseif($points >= 25001) {
return '' . $points . ''. '
';
}
}
// Get the Larger Point Count and Set the Star Rating
function getPointLevelBig($authorId) {
$points = get_usermeta($authorId,'points');
if($points < 26) {
return '' . $points . ''. '
';
} elseif($points < 50 && $points > 25) {
return '' . $points . ''. '
';
} elseif($points < 500 && $points > 50) {
return '' . $points . ''. '
';
} elseif($points < 5000 && $points > 500) {
return '' . $points . ''. '
';
} elseif($points < 25000 && $points > 5000) {
return '' . $points . ''. '
';
} elseif($points >= 25001) {
return '' . $points . ''. '
';
}
}
// Original PHP code by Chirp Internet:www.chirp.com.au
// Please acknowledge use of this code by including this header.
function myTruncate($string, $limit, $break=".", $pad="...")
{
// return with no change if string is shorter than $limit
if(strlen($string) <= $limit) return $string;
// is $break present between $limit and the end of the string?
if(false !== ($breakpoint = strpos($string, $break, $limit))) {
if($breakpoint < strlen($string) - 1) {
$string = substr($string, 0, $breakpoint) . $pad;
}
}
return $string;
}
// Get User Answers - My Account and Profile Pages
function getUserAnswers($user_id){
global $wpdb;
$gather_comments = "SELECT * FROM ".$wpdb->prefix."comments WHERE user_id = '" . $user_id . "' ORDER BY comment_date DESC LIMIT 10";
$user_comments = $wpdb->get_results($gather_comments);
return $user_comments;
}
// Format Date for Start of Membership
function formatDate($val) {
$arr = explode("-", $val);
return date("M d, Y", mktime(0,0,0, $arr[1], $arr[2], $arr[0]));
}
// Check to see if the input has no chars or has spaces/returns and return them as blank data
function isEmptyString($data)
{
return (trim($data) === "" or $data === null);
}
// Add New Answer
function post_new_answer($answer_content){
include ( ABSPATH . 'wp-load.php' );
//Strip any tags then may have been put into the array
$answer_content_stripped = strip_tags($answer_content);
// Get the Question ID
global $wp_query;
$question_id = $wp_query->post->ID;
$question_author_id = $wp_query->post->post_author;
// Get the Current User Info
$user = wp_get_current_user();
global $wpdb;
$gather_comments = "SELECT * FROM ".$wpdb->prefix."comments WHERE comment_post_ID = '" . $question_id . "' ORDER BY comment_date";
$user_comments = $wpdb->get_results($gather_comments);
// Validate the Form Data
if(isEmptyString($answer_content_stripped)) return new WP_Error('forgot_answer', 'You forgot to enter your Answer.');
// Validate - Check to see if user already posted this exact answer for this question
foreach ($user_comments as $user_comment) {
if ($user_comment->comment_author == $user->user_login ) {
if ($user_comment->comment_content == $answer_content_stripped) {
return new WP_Error('duplicate_user_comment_on_question', 'You have already answered this exact answer for this question.');
} else {}
} else {}
}
// Define the Answer Data
$comment_author = $user->user_login;
$comment_author_email = $user->user_email;
$comment_post_ID = $question_id;
$comment_parent = $question_id;
$comment_content = $answer_content_stripped;
$user_ID = $user->ID;
// Build the Answer Array
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_content', 'comment_parent', 'user_ID');
// Insert the Answer into the DB
$comment_id = wp_new_comment( $commentdata );
// Add a Point to the User's Point Score only if They are not the Question Owner (prevents a user from gaining points from answering their own questions)
if ($user->ID != $question_author_id) {
addPointToUser($user->ID);
}
}
// Add point to User After Answer is Added
function addPointToUser($id) {
$currentPointNumber = get_usermeta($id, 'points');
//Add 1 to the current Point Score
$newPointNumber = $currentPointNumber + 1;
update_usermeta( $id, 'points', $newPointNumber);
}
// Site Messaging - Error & Success Messages
function display_message( $message = false ) {
if( is_wp_error( $message ) ) {
echo '' . $message->get_error_message() . '
';
}
elseif ($message != '') {
echo '' . $message . '
';
}
}
// Log In User
function log_in_user($username, $password) {
// Get the user based on the username from the POST
$user = parse_user($username);
// Remove html tags from the title and content fields
$username_stripped = strip_tags($username);
$password_stripped = strip_tags($password);
// Validate the Form Data
if(isEmptyString($username_stripped)) return new WP_Error('forgot_username', 'You forgot to enter your Username');
if(isEmptyString($password_stripped)) return new WP_Error('incorrect_password', "You forgot to enter your Password.");
if(!wp_check_password( $password_stripped, $user->user_pass ) ) return new WP_Error('incorrect_password', "You seem to have entered a wrong password.");
wp_set_auth_cookie($user->ID, $remember);
wp_login($username_stripped, $password_stripped);
redirect_to_myaccount_url();
}
// Parse the User Info
function parse_user($info = null, $return = 'object') {
if ( is_null( $info ) ) {
global $current_user;
if ( empty( $current_user->ID ) ) return null;
$info = get_userdata( $current_user->ID );
}
elseif ( empty( $info ) ) {
return null;
}
if( $return == 'ID' ) {
if ( is_object( $info ) ) return $info->ID;
if ( is_numeric( $info ) ) return $info;
}
elseif( $return == 'object' ) {
if ( is_object( $info ) && $info->ID) return $info;
if ( is_object( $info )) return get_userdata( $info->ID );
if ( is_numeric( $info ) ) return get_userdata( $info );
if ( is_string( $info ) ) return get_userdatabylogin( $info );
}
else {
return null;
}
}
// Add New User - Sign Up
function add_new_user($username, $password, $confirm, $email) {
require ( ABSPATH . WPINC . '/registration.php' );
// Remove html tags from the title and content fields
$username_stripped = strip_tags($username);
$password_stripped = strip_tags($password);
$confirm_stripped = strip_tags($confirm);
$email_stripped = strip_tags($email);
// Check to see if User Registration is turned OFF
if (get_option('users_can_register') == '0') return new WP_Error('reg_off', 'We\'re sorry, registration is currently disabled.');
// Validate the Form Data
if(isEmptyString($username_stripped)) return new WP_Error('forgot_username', 'Please Choose a Username');
if(username_exists($username_stripped)) return new WP_Error('username_exists', 'Sorry, that Username already exists');
if(isEmptyString($password_stripped)) return new WP_Error('forgot_password', 'Please Choose a Password');
if($password_stripped != $confirm_stripped) return new WP_Error('passwords_no_match', 'Your Passwords don\'t match.');
if(!is_email($email_stripped)) return new WP_Error('verify_email', 'Please enter a valid Email Address');
if(email_exists($email_stripped)) return new WP_Error('email_exists', 'Sorry, that email is already in use with another account');
// Create the user
$user_data = array(
'user_login' => $username_stripped,
'user_pass' => $password_stripped,
'user_email' => $email_stripped,
);
$user_id = wp_insert_user($user_data);
$user = get_userdata($user_id);
// Set the users Point Rating to 1 for new member
update_usermeta( $user_id, 'points', '1' );
// Set a flag for a newuser for first time messaging on My Account
update_usermeta( $user_id, 'newuser', 'yes' );
update_usermeta( $user_id, 'user_default_icon', '1');
// Log the User In
wp_login($user->user_login, $password_stripped);
wp_clearcookie();
wp_setcookie($user->user_login, $remember, false);
// Email User with Login Info
$site = get_bloginfo("name");
$sitename = str_replace("&", "&", $site);
$headers = 'From: '.$sitename.' ' . "\r\n";
$to = $user->user_email;
$subject = sprintf(__('Welcome to %s - Your Member Information'), $sitename) . "\r\n\r\n";
$message = sprintf(__('Dear %s,'), $user->user_login) . "\r\n\r\n";
$message .= sprintf(__('Thank you for signing up with %s. We are happy to have you as a member and look forward to your quesitons and answers. Remember that every question that you ask or answer will increase your member Star Level. So, start increasing your Star points today!'), $sitename) . "\r\n\r\n";
$message .= sprintf(__('-------------------------------------------------------------------------------------')). "\r\n\r\n";
$message .= sprintf(__('Your Member Information is: (save for future reference)')). "\r\n\r\n";
$message .= sprintf(__('Username: %s'), $user->user_login) . "\r\n\r\n";
$message .= sprintf(__('Password: %s'), $password_stripped) . "\r\n\r\n";
$message .= sprintf(__('-------------------------------------------------------------------------------------')). "\r\n\r\n";
$message .= sprintf(__('We look forward to having you on the site. Thank you again for Signing Up.'), $ip) . "\r\n\r\n";
$message .= sprintf(__('Have a great day!')) . "\r\n\r\n";
$message .= sprintf(__('-------------------------------------------------------------------------------------')). "\r\n\r\n";
$message .= sprintf(__('Sincerely,')) . "\r\n\r\n";
$message .= sprintf(__('The %s team.'), $sitename) . "\r\n\r\n";
wp_mail($to, $subject, $message, $headers);
// Redirect the User to My Account
redirect_to_myaccount_url();
}
// Change User Password
function change_user_password($currentPass, $newPass1, $newPass2) {
require ( ABSPATH . WPINC . '/registration.php' );
global $uriData;
$uriData->author = wp_get_current_user();
$oldPass = $uriData->author->user_pass;
//Strip any tags then may have been put into the array
$currentPass_stripped = strip_tags($currentPass);
$newPass1_stripped = strip_tags($newPass1);
$newPass2_stripped = strip_tags($newPass2);
// Validate the Form Data
if (isEmptyString($currentPass_stripped)) return new WP_Error('no_old_password_entered','Enter your Current Password');
if (isEmptyString($newPass1_stripped)) return new WP_Error('no_new_password_entered','Enter a new Password');
if (isEmptyString($newPass2_stripped)) return new WP_Error('no_new_password_confirm_entered','Confirm your new Password');
if ($newPass1_stripped != $newPass2_stripped) return new WP_Error('new_pass_no_match','New Password and Confirm Password must be the same');
if (!wp_check_password($currentPass_stripped, $oldPass)) return new WP_Error('current_pass_incorrect','Current Password is Incorrect');
// Change User's Password
wp_update_user( array(
'ID' => $uriData->author->ID,
'user_pass' => $newPass1_stripped
)
);
// Update the Password Cookie
$cookie_info = wp_get_cookie_login();
$login = $cookie_info['login'];
wp_clearcookie();
wp_setcookie($uriData->author->user_login, $newPass1);
$user = wp_get_current_user();
// Add a flag for Messaging the user that they have successfully changed their password
update_usermeta($user->ID, 'changed_password_my_account', 'yes');
// Redirect the User to My Account
redirect_to_myaccount_url();
}
// Reset User Password
function reset_user_password($email_address, $ip) {
// Strip out tags from email field
$email_address_stripped = strip_tags($email_address);
// Get user data based on email address
$user = get_user_by_email($email_address_stripped);
// Generate new password 10 Characters Long
$newPass = wp_generate_password(10);
// Check to see if the email is assigned to a member
require ( ABSPATH . WPINC . '/registration.php' );
if (!username_exists($user->user_login)) {
return new WP_Error('email_doesnt_exist','There is no member with this email address.');
}
else {
// Check to see if email is an admin with ID of 1 (could add other ids here too with an OR (||) statement)
if ($user->ID == 1) {
return new WP_Error('cant_change_admin_pass','You are not allowed to change that user\'s password, Sorry.');
}
// If non-admin email address, change password and then email them the new password
else {
wp_set_password($newPass, $user->ID);
$site = get_bloginfo("name");
$sitename = str_replace("&", "&", $site);
$headers = 'From: '.$sitename.' ' . "\r\n";
$to = $user->user_email;
$subject = 'Account Update - Your password has been reset';
$message = sprintf(__('Dear %s,'), $user->user_login) . "\r\n\r\n";
$message .= sprintf(__('Your password has been reset because you recently filled out the Forgot Password form on %s.'), $sitename) . "\r\n\r\n";
$message .= sprintf(__('-------------------------------------------------------------------------------------')). "\r\n\r\n";
$message .= sprintf(__('Username: %s'), $user->user_login) . "\r\n\r\n";
$message .= sprintf(__('New Password: %s'), $newPass) . "\r\n\r\n";
$message .= sprintf(__('-------------------------------------------------------------------------------------')). "\r\n\r\n";
$message .= sprintf(__('This request was submitted by the following IP address: %s.'), $ip) . "\r\n\r\n";
$message .= sprintf(__('Thank you,')) . "\r\n\r\n";
$message .= sprintf(__('Have a great day!')) . "\r\n\r\n";
wp_mail($to, $subject, $message, $headers);
// Set a flag on this user - Will show a message to the user once they log in for the first time on My Account. Then my-account.php will set it to 'no' so it wont show again.
update_usermeta( $user->ID, 'passwordreset', 'yes');
// Let the user know they have reset their password successfully
return $message = 'You have successfully reset your password. Your username and new password have been sent to your email:'.$email_address. '.';
}
}
}
// Edit Profile
function edit_user_profile($about_me_text, $member_icon) {
// Strip out tags from email field
$about_me_text_stripped = strip_tags($about_me_text);
$member_icon_stripped = strip_tags($member_icon);
$user = wp_get_current_user();
update_usermeta( $user->ID, 'user_about_me', $about_me_text_stripped);
update_usermeta( $user->ID, 'user_default_icon', $member_icon_stripped);
update_usermeta( $user->ID, 'edit_profile_changed', 'yes');
// Redirect the User to My Account
redirect_to_myaccount_url();
}
// Get Default User Icon
function get_user_default_icon($author_id) {
// Get Current User Default Icon
$user_icon = get_usermeta( $author_id, 'user_default_icon');
return $user_icon;
}
// Post a new Question
function post_new_question($question_title, $question_content, $question_category) {
//Strip any tags then may have been put into the array
$question_title_stripped = strip_tags($question_title);
$question_content_stripped = strip_tags($question_content);
// Get the Current User Info
$user = wp_get_current_user();
global $wpdb;
$gather_questions = "SELECT * FROM wp_posts WHERE post_author = '" . $user->ID . "'";
$user_questions = $wpdb->get_results($gather_questions);
// Validate the Form Data
if (isEmptyString($question_title_stripped)) return new WP_Error('no_title_entered', 'Enter a title for your quesion');
if (isEmptyString($question_content_stripped)) return new WP_Error('no_content', 'Enter a breif description for your quesion');
// Validate - Check to see if user already posted this exact question
foreach ($user_questions as $user_question) {
if ($user_question->post_author == $user->ID ) {
if ($user_question->post_title == $question_title_stripped) {
return new WP_Error('duplicate_user_question', 'You have already asked this exact question.');
} else {}
} else {}
}
$question_author = $user->ID;
$post = array(
'ID' => '',
'post_author' => $question_author,
'post_category' => array($question_category),
'post_content' => $question_content_stripped,
'post_title' => $question_title_stripped,
'post_status' => 'publish'
);
// Insert the Question into the DB
$question_id = wp_insert_post($post);
// Add a Point to the User's Point Score
addPointToUser($user->ID);
// Get the newly created post info for redirection
$question = get_post($question_id);
// Redirect to the newly posted Question
wp_redirect($question->guid);
}
///////////////////
// Redirections //
//////////////////
// Redirect Once Logged in to My Account
function user_account_url( $user = null ) {
$user = parse_user( $user );
return get_bloginfo('url') . '/my-account/';
}
// Redirect To My Account Page if Trying to Access non Logged in Pages (eg. Log In, Sign Up, Forgot Password etc)
function redirect_to_myaccount_url() {
wp_redirect(get_bloginfo('url') . '/my-account/');
}
// Redirect To Log In Page if Trying to Access a Logged in Pages (eg. Change Password, Add a Question etc)
function redirect_to_login_url() {
wp_redirect(get_bloginfo('url') . '/log-in/');
}
?>
Ek Olarak: Üstatlar, bu konuda yardımınıza ihtiyacım var, yok mu bir bilen?