رفتن به مطلب

محدودیت در ارسال پست


پست های پیشنهاد شده

من میخوام توی سایتم واسه کاربران (نویسندگان) محدودیت ایجاد کنم. به طوری که هر 24 ساعت فقط 30 تا مطلب رو ارسال کنن. بیش از 30 مطلب رو نتونن ارسال کنن

فقط مدیریت کل سایت بتونه بیشتر از 3 تا ارسال کنه

لینک به ارسال

این افزونه را تست کنید

http://wordpress.org/plugins/bainternet-posts-creation-limits/

این کد هم برای کمک به افزونه بالا


add_action( 'post_creation_limits_custom_checks', 'post_per_day_limit' );
function post_per_day_limit( $type, $user_id ) {
global $bapl,$wpdb;
// safe check: Plugin installed?
! isset( $bapl ) AND _doing_it_wrong( __FUNCTION__, sprintf( 'You need to %sinstall the needed Plugin%s', '<a href="http://wordpress.org/extend/plugins/bainternet-posts-creation-limits/">', '</a>' ), 0 );
$time_in_days = 1; // 1 means in last day
$count = $wpdb->get_var(
$wpdb->prepare("
SELECT COUNT(*)
FROM $wpdb->posts
WHERE post_status = 'publish'
AND post_type = %s
AND post_author = %s
AND post_date >= DATE_SUB(CURDATE(),INTERVAL %s DAY)",
$type,
$user_id,
$time_in_days
)
);
if ( 0 < $count )
$count = number_format( $count );
// here you can check since we have the $count ex:
// limit for 2 posts a day
if ( 5 < $count ) {
// return limit reached message using the plugin class
exit( $bapl->bapl_not_allowed( 'you can not posts more them two posts a day' ) );
}
// else do nothing
}

عدد 5 تعداد محدودیت ارسال برای هر کاربر هست

لینک به ارسال

افزونه رو نصب کردم و کد رو توی استایل قرار دادم

نقش کاربری رو هم معین کردم

اما افزونه جواب نداد

الآن کاربر میتونه هر چی دلش خواست پست ارسال کنه :(

لینک به ارسال

میشه یه توضیح فارسی هم بدید؟

یا ترجمه اون رو توی انجمن بزارید

لینک به ارسال

با مترجم گوگل هم پیش رفتم

اما چیزی رو متوجه نشدم

4 تا کد رو داده که فقط میدونم اولی رو کجا بزارم

اون 3 تا رو نمیدونم کجا بزارم

لینک به ارسال

کد اول رو در فایل functions


// limit number of posts per user
// provided by cleverness.org
if ( !current_user_can('manage_options') ) {
$default = 1; // default number of posts
$count_posts = 0;
global $wpdb;
$poststable = $wpdb->prefix.'posts';
$postlimit = get_user_meta($current_user->id, 'postlimit', true);
if ( $postlimit == '' ) $postlimit = $default;
$query = "SELECT COUNT(*) FROM $poststable WHERE post_author = '$current_user->id' AND (post_status = 'pending' OR post_status = 'draft' OR post_status = 'publish' ) ";
$count_posts = $wpdb->get_var($query);
if ($count_posts >= $postlimit) {
if ( $_SERVER['REQUEST_URI'] == '/wp-admin/post-new.php' )
Header("Location: index.php");//redirects to dashboard
if ( is_admin() ){
$stylesheet = get_stylesheet_directory_uri() . '/css/limitposts.css';
wp_register_style('limitpost_admin_css', $stylesheet, false, '1', 'screen');
wp_enqueue_style('limitpost_admin_css');
}
}
}

// add post limit option to profile
add_filter('user_contactmethods','hide_profile_fields',10,1);

function hide_profile_fields( $contactmethods ) {
if( current_user_can( 'manage_options' ) )
$contactmethods['postlimit'] = 'Post Limit';
return $contactmethods;
}

در پوشه پوسته پوشه‌ای به نام css ایجاد و فایل limitposts.css ایجاد کنید. کد زیر را در آن قرار دهید


#menu-posts .wp-first-item + li {
display: none;
}

لینک به ارسال

ممنون

کجای این کد میتونم تعیین کنم که کاربر در هر ساعت بتونه 1 پست ارسال کنه؟

لینک به ارسال

کد مشکل داشت

این رو تست کنید


if ( !current_user_can('level_10') ) {
$default = 1; // default number of posts
$hour = 1;
$count_posts = 0;
global $wpdb,$current_user;
$time = date('Y-m-d H:i:s', strtotime('-'.$hour.' hours'));
$poststable = $wpdb->prefix.'posts';
$postlimit = get_user_meta($current_user->id, 'postlimit', true);
if ( $postlimit == '' ) $postlimit = $default;
$query = "SELECT COUNT(*) FROM $poststable WHERE post_date > '$time' post_author = '$current_user->id' AND (post_status = 'pending' OR post_status = 'draft' OR post_status = 'publish' ) ";
$count_posts = $wpdb->get_var($query);
if ($count_posts >= $postlimit) {
if ( $_SERVER['REQUEST_URI'] == '/wp-admin/post-new.php' )
Header("Location: index.php");//redirects to dashboard
if ( is_admin() ){
$stylesheet = get_stylesheet_directory_uri() . '/css/limitposts.css';
wp_register_style('limitpost_admin_css', $stylesheet, false, '1', 'screen');
wp_enqueue_style('limitpost_admin_css');
}
}
}

مقدار default برای تعداد پست

مقدار hour برای ساعت هست

لینک به ارسال

متاسفانه قالب من از دستورات وردپرس پیروی نمیکنه

مثلا: بخش نظرات رو از وردپرس غیر فعال کردم، اما توی این قالب غیر فعال نشده و راحت میشه نظر گذاشت

تا حالا همچین چیزی رو ندیده بودم

به نظر شما این کد رو کجای قالب بزارم تا بتونه ارسال پست رو محدود کنه؟

آدرس سایت: http://www.balyan.ir/sms

لینک به ارسال

کد برای پست هست نه نظرها

کد رو هم به functions.php پوسته اضافه و تست کنید

لینک به ارسال

کد مشکل داشت

این رو تست کنید


if ( !current_user_can('level_10') ) {
$default = 1; // default number of posts
$hour = 1;
$count_posts = 0;
global $wpdb,$current_user;
$time = date('Y-m-d H:i:s', strtotime('-'.$hour.' hours'));
$poststable = $wpdb->prefix.'posts';
$postlimit = get_user_meta($current_user->id, 'postlimit', true);
if ( $postlimit == '' ) $postlimit = $default;
$query = "SELECT COUNT(*) FROM $poststable WHERE post_date > '$time' post_author = '$current_user->id' AND (post_status = 'pending' OR post_status = 'draft' OR post_status = 'publish' ) ";
$count_posts = $wpdb->get_var($query);
if ($count_posts >= $postlimit) {
if ( $_SERVER['REQUEST_URI'] == '/wp-admin/post-new.php' )
Header("Location: index.php");//redirects to dashboard
if ( is_admin() ){
$stylesheet = get_stylesheet_directory_uri() . '/css/limitposts.css';
wp_register_style('limitpost_admin_css', $stylesheet, false, '1', 'screen');
wp_enqueue_style('limitpost_admin_css');
}
}
}

مقدار default برای تعداد پست

مقدار hour برای ساعت هست

دقیقا عدد رو کجای اون بزارم؟

مثلا میخوام بزارم هر ساعت 1 پست بتونه ارسال کنه

لینک به ارسال

کد رو امتحان کردم. اما کار نمیکنه

اصلا وردپرس همچین امکاناتی داره یا نه؟

لطفا راهنمایی کنید

لینک به ارسال

اما من کد نویسی این بخش رو بلد نیستم

یه برنامه نویس حرفه ای چقدر پول میگیره این کد رو برام بسازه؟

لینک به ارسال

تست کنید


add_action("init","wpp_test_function");

function wpp_test_function(){
global $wpdb,$pagenow;

if (is_admin() && $pagenow=="post-new.php" && (! current_user_can('level_10')) ) {
$default = 1; // default number of posts
$hour = 1;
$count_posts = 0;

$time = date('Y-m-d H:i:s', strtotime('-'.$hour.' hours'));
$poststable = $wpdb->prefix.'posts';
$userid = get_current_user_id();
if ( $postlimit == '' ) $postlimit = $default;
$query = "SELECT COUNT(*) FROM $poststable WHERE post_date > '$time' AND post_author = $userid AND (post_status = 'pending' OR post_status = 'draft' OR post_status = 'publish' ) ";

$count_posts = $wpdb->get_var($query);

if ($count_posts >= $postlimit) {
wp_redirect("edit.php"); //redirects to dashboard
}
}
}

لینک به ارسال
  • 2 هفته بعد...

تست کنید


add_action("init","wpp_test_function");

function wpp_test_function(){
global $wpdb,$pagenow;

if (is_admin() && $pagenow=="post-new.php" && (! current_user_can('level_10')) ) {
$default = 1; // default number of posts
$hour = 1;
$count_posts = 0;

$time = date('Y-m-d H:i:s', strtotime('-'.$hour.' hours'));
$poststable = $wpdb->prefix.'posts';
$userid = get_current_user_id();
if ( $postlimit == '' ) $postlimit = $default;
$query = "SELECT COUNT(*) FROM $poststable WHERE post_date > '$time' AND post_author = $userid AND (post_status = 'pending' OR post_status = 'draft' OR post_status = 'publish' ) ";

$count_posts = $wpdb->get_var($query);

if ($count_posts >= $postlimit) {
wp_redirect("edit.php"); //redirects to dashboard
}
}
}

کد رو در فانکشن گذاشتم. اما باز هم جواب نداد

فکر کنم کد درست باشه و دلیل کار نکردن کد این باشه که قالب اون بسیار پیچیده ساخته شده (خیلی از وب نویس های بزرگ از طراحی عجیب این قالب تعجب کردند... :o)

post-new.php و edit.php در قالب وجود نداره

لطفا باز هم تلاش کنید تا این مشکل رفع بشه :wub:

لینک به ارسال

کد رو من تست کردم

مشکل ندارد

post-new.php و edit.php فایلهای وردپرس هستند نه پوسته

لینک به ارسال

به گفتگو بپیوندید

هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .

مهمان
ارسال پاسخ به این موضوع ...

×   شما در حال چسباندن محتوایی با قالب بندی هستید.   حذف قالب بندی

  تنها استفاده از 75 اموجی مجاز می باشد.

×   لینک شما به صورت اتوماتیک جای گذاری شد.   نمایش به صورت لینک

×   محتوای قبلی شما بازگردانی شد.   پاک کردن محتوای ویرایشگر

×   شما مستقیما نمی توانید تصویر خود را قرار دهید. یا آن را اینجا بارگذاری کنید یا از یک URL قرار دهید.

×
×
  • اضافه کردن...