Find Jobs
Hire Freelancers

464643 MySQL Count- Wordpress Limit

N/A

Completed
Posted over 13 years ago

N/A

Paid on delivery
The following code limits a wordpress USER from adding new posts once they have hit a limit set by the site administrator. I also need it to check the table in the attached image and limit that same USER when they have uploaded their limit of images through another plugin. This means the USER will be limited in either scenario. Please tell me how to get a COUNT from the table shown in the attached image and add the code that will limit the USER when they have either hit their limit of posts or their limit of images in the second MySQL Table. The new code needs to make sure that the current logged in USER matches the one listed in the q_fk_author_id column of this table. When you narrow the query by this USER, you can look for the number of rows they have listed in this table. NOTE: when the admin published those pending images, this table will be cleared so there are no rows for the USER. And the user's images will become posts and be limited by the existing code. --------------------------------- <?php /* Plugin Name: WP Post Limits Plugin URI: [login to view URL] Description: Set per-role limits on the number of posts a user can make on your wordpress blog Author: James Stewart Version: 1.0 Author URI: [login to view URL] */ function post_limits_check_capability($capabilities, $required_capability = FALSE, $arguments = array()) { $current_user = wp_get_current_user(); if (! $current_user) { return FALSE; } /* Admin can do anything it wants! */ if (array_search('administrator', $current_user->roles) !== FALSE) { return $capabilities; } /* Anyone can edit their own posts */ /* Check per-role limits */ $limits = get_option('posts_per_role'); $limit = 0; foreach ($current_user->roles as $role) { if (isset($limits[$role])) { if ($limits[$role] == -1) { return $capabilities; } else if ($limits[$role] > $limit) { $limit = $limits[$role]; } } } $posts = get_posts(array('author' => $current_user->ID, 'post_status' => 'pending,publish')); $count_posts = count($posts); if ($count_posts >= $limit) { if (isset($_REQUEST['post_ID']) || isset($_REQUEST['post'])) { $post_id = isset($_REQUEST['post_ID']) ? $_REQUEST['post_ID'] : $_REQUEST['post']; $p = get_post($post_id); if ($p->post_author == $current_user->ID && ($p->post_status == 'draft' || $p->post_status == 'pending review')) { return $capabilities; } } unset($capabilities['edit_posts']); unset($capabilities['access_photoq']); } return $capabilities; } function post_limits_menu() { global $user_level; get_currentuserinfo(); if ($user_level < 10) { return; } if (function_exists('add_options_page')) { add_options_page(__('Post Limits'), __('Post Limits'), 1, __FILE__, 'post_limits_page'); } } function post_limits_page() { global $wp_roles; if (! isset($wp_roles)) { $wp_roles = new WP_Roles(); } if (isset($_POST['role_limits']) && is_array($_POST['role_limits'])) { $options = array('posts_per_role' => $_POST['role_limits']); update_option('posts_per_role', $options['posts_per_role']); echo '<div class="updated"><p>' . __('Options saved') . '</p></div>'; } else { $options = array('posts_per_role' => get_option('posts_per_role')); } include 'templates/[login to view URL]'; } add_filter('user_has_cap', 'post_limits_check_capability'); add_action('admin_menu', 'post_limits_menu'); if (! defined('PHP_VERSION_ID')) { $version = explode('.', PHP_VERSION); define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2])); } if (PHP_VERSION_ID < 50207) { define('PHP_MAJOR_VERSION', $version[0]); define('PHP_MINOR_VERSION', $version[1]); define('PHP_RELEASE_VERSION', $version[2]); } if (PHP_MAJOR_VERSION < 5) { function post_limits_version_warning() { echo "<div id='countdown-to-warning' class='updated fade'>"; echo "<p><strong>" . __('WP Post Limits only tested on PHP5.2 and above. You are running PHP4 so the plugin may not work correctly') . "</strong></p>"; echo "</div>"; } add_action('admin_notices', 'post_limits_version_warning'); } ---------------------------------
Project ID: 2210539

About the project

1 proposal
Remote project
Active 12 yrs ago

Looking to make some money?

Benefits of bidding on Freelancer

Set your budget and timeframe
Get paid for your work
Outline your proposal
It's free to sign up and bid on jobs
Awarded to:
User Avatar
As discussed in PMB! Thank you,
$15 USD in 0 day
0.0 (0 reviews)
0.0
0.0

About the client

Flag of UNITED STATES
san francisco, United States
5.0
7
Member since Nov 20, 2007

Client Verification

Thanks! We’ve emailed you a link to claim your free credit.
Something went wrong while sending your email. Please try again.
Registered Users Total Jobs Posted
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
Loading preview
Permission granted for Geolocation.
Your login session has expired and you have been logged out. Please log in again.