Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions classes/Tutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@
*/
add_action( 'admin_init', array( $this, 'redirect_to_setup_page' ) );

// add_filter( 'rest_request_before_callbacks', array( $this, 'enforce_courses_privacy_rest_api' ), 10, 3 );

Check failure on line 592 in classes/Tutor.php

View workflow job for this annotation

GitHub Actions / WPCS

Inline comments must end in full-stops, exclamation marks, or question marks
}

/**
Expand Down Expand Up @@ -1114,6 +1114,7 @@
if ( $instructor ) {
$instructor_cap = array(
'edit_posts',
'edit_published_posts',
'read',
'upload_files',
);
Expand Down Expand Up @@ -1147,7 +1148,7 @@
/**
* Add Instructor role to administrator
*/
if ( current_user_can( 'administrator' ) ) {

Check failure on line 1151 in classes/Tutor.php

View workflow job for this annotation

GitHub Actions / WPCS

Capabilities should be used instead of roles. Found "administrator" in function call to current_user_can()
tutor_utils()->add_instructor_role( get_current_user_id() );
}
}
Expand Down
132 changes: 132 additions & 0 deletions migrations/InstructorCapabilityMigrator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php
/**
* Migration instructor to add capability.
*
* @package Tutor
* @author Themeum <support@themeum.com>
* @link https://themeum.com
* @since 4.0.8
*/

namespace Tutor\Migrations;

use Tutor\Migrations\Contracts\SingleProcessor;
use Tutor\Models\UserModel;

/**
* Class InstructorCapabilityMigrator
*
* @since 4.0.8
*/
class InstructorCapabilityMigrator extends BatchProcessor implements SingleProcessor {

/**
* User model
*
* @var UserModel
*/
private $user_model;

/**
* Name of the migration
*
* @since 4.0.8
*
* @var string
*/
protected $name = 'Instructor Capability Migrator';

/**
* Action
*
* @since 4.0.8
*
* @var string
*/
protected $action = 'instructor_capability_migrator';

/**
* Batch size
*
* @since 4.0.8
*
* @var integer
*/
protected $batch_size = 100;

/**
* Schedule interval.
*
* @since 4.0.8
*
* @var integer
*/
protected $schedule_interval = 10;

/**
* Get total unprocessed result.
*
* @since 4.0.8
*
* @return int
*/
protected function get_total_items(): int {
$this->user_model = new UserModel();
$users = $this->user_model->get_users_list(
array(
'role' => tutor()->instructor_role,
'fields' => 'ID',
)
);
return $users->get_total();
}

/**
* Get items to batch process.
*
* @since 4.0.8
*
* @param int $offset offset.
* @param int $limit limit.
*
* @return array
*/
protected function get_items( $offset, $limit ): array {
$this->user_model = new UserModel();
$users = $this->user_model->get_users_list(
array(
'role' => tutor()->instructor_role,
'number' => $limit,
'offset' => $offset,
)
);
return $users->get_results();
}

/**
* Process instructor to add capability.
*
* @since 4.0.8
*
* @param object $item item.
*
* @return void
*/
public function process_item( $item ): void {
$user = new \WP_User( $item->ID );
if ( ! $user->has_cap( 'edit_published_posts' ) ) {
$user->add_cap( 'edit_published_posts' );
}
}

/**
* On migration complete event.
*
* @since 4.0.8
*
* @return void
*/
protected function on_complete() {
error_log( 'Instructor capability migration completed!' );
}
}
1 change: 1 addition & 0 deletions migrations/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function __construct() {
*/
public function schedule_migrations() {
$migrators = array(
InstructorCapabilityMigrator::instance(),
QuizAttemptMigrator::instance(),
);

Expand Down
Loading