Skip to content

Instantly share code, notes, and snippets.

@ajgagnon
Last active December 16, 2020 17:03
Show Gist options
  • Select an option

  • Save ajgagnon/7a028a12c9230a833fc2461496eb2afd to your computer and use it in GitHub Desktop.

Select an option

Save ajgagnon/7a028a12c9230a833fc2461496eb2afd to your computer and use it in GitHub Desktop.
Limit tasks for clients
<?php
add_filter("rest_pre_insert_phw_comment_loc", "wp_145_limit_tasks", 10, 2);
function wp_145_limit_tasks($prepared_post, $request) {
if(!$project_id = $prepared_post->meta_input['project_id']) {
return $prepared_post;
}
// if it's our project
if ($project_id === 5) {
$status = ph_get_website_resolve_status($project_id);
$active = $status['total'] = $status['resolved'];
// if we have more than 5 active tasks
if ($active > 5) {
return new WP_Error('task_limit', 'You have reached your task limit.');
}
}
return $prepared_post;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment