effective_learndash 0.1.4 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83cc9e6d5daa0a6e08e491f1ea9edec7f8e394b045801a2d704eaacab5c93f18
4
- data.tar.gz: 467de056d4e11255c927a212e0f893b54ddcac8720ec12bf80299873ff5e2910
3
+ metadata.gz: 47f234d26d444d3ba71d72409db15186e4b1db00e1bf3c6aa007853143307265
4
+ data.tar.gz: d97eea26d3a6cce1d8df2f154b06b8dbc558e8df8c731fdbff268185cb3d465c
5
5
  SHA512:
6
- metadata.gz: 1cbb48faa89c8d2a6fee3f47b78cdb41f3cf20871b354f7e88852a5103e0a294d4b2dd1d2eca63be1525dd546e365fd8143416e35942d714039ecd6031a12a0c
7
- data.tar.gz: ee47891e98f74e0c8ecdbacbd76f37071a16d95a347bca7014f421a4aeb007b7ffc92d0f96c080dea39c8d57b15b92aa83f06f5558a0ee2182049dfa442952c0
6
+ metadata.gz: 6aeaa81878fe93276c6bcdc366ec2f61f1fdc5ee952a6b9328890387619605ddb7883210765f203bef8ae053065c781eb59c109b084b06d164be079ebe7689b8
7
+ data.tar.gz: 2d53168beee83ee8766389eaec11b48f6208e97e202d63ba3155f85278357b673ff1fab06de53cf9e8570fb57397ed5cf4cbfb4a2500a870c42691512fe061b8
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Effective Learndash
1
+ # Effective LearnDash
2
2
 
3
- Create Wordpress users and read Learndash course progress. This is an unoffocial integration that is not supported or affiliated with WordPress or Learndash.
3
+ Create Wordpress users and read LearnDash course progress. This is an unofficial integration that is not supported or affiliated with WordPress or LearnDash.
4
4
 
5
5
  ## Getting Started
6
6
 
@@ -91,29 +91,29 @@ if user.admin?
91
91
  end
92
92
  ```
93
93
 
94
- ## Configuring Learndash
94
+ ## Configuring LearnDash
95
95
 
96
- Your Wordpress should be configured ahead of time with the Learndash plugin.
96
+ Your WordPress should be configured ahead of time with the LearnDash plugin.
97
97
 
98
98
  Please generate an application password via:
99
99
 
100
100
  https://make.wordpress.org/core/2020/11/05/application-passwords-integration-guide/
101
101
 
102
- and fill in the username/password details in config/initializers/effective_leardash.rb
102
+ and fill in the username/password details in config/initializers/effective_learndash.rb
103
103
 
104
- ## Working with Learndash
104
+ ## Working with LearnDash
105
105
 
106
106
  Visit `/admin/learndash_courses` and Refresh the list of Courses.
107
107
 
108
- Create a New Learndash User will create a new Wordpress/Learndash account with a username/password according to the settings in the config file.
108
+ Create a New LearnDash User will create a new WordPress/LearnDash account with a username/password according to the settings in the config file.
109
109
 
110
110
  When you create a user, you only get access to the password once. So any existing users will have an unknown password.
111
111
 
112
- Create a new Learndash Enrollment to enroll a learndash user into a course. This will begin tracking their progress.
112
+ Create a new LearnDash Enrollment to enroll a LearnDash user into a course. This will begin tracking their progress.
113
113
 
114
- There are no webhooks or callbacks from Learndash, everything is a GET request that updates the local database.
114
+ There are no webhooks or callbacks from LearnDash, everything is a GET request that updates the local database.
115
115
 
116
- You can refresh an entire learndash user in one operation and it will sync the entire user at once, `user.learndash_user.refresh!`
116
+ You can refresh an entire LearnDash user in one operation and it will sync the entire user at once, `user.learndash_user.refresh!`
117
117
 
118
118
  ## License
119
119
 
@@ -7,7 +7,7 @@ module Admin
7
7
 
8
8
  def refresh
9
9
  resource_scope.refresh!
10
- flash[:success] = "Successfully refreshed Courses from Learndash"
10
+ flash[:success] = "Successfully refreshed Courses from LearnDash"
11
11
  redirect_to effective_learndash.admin_learndash_courses_path
12
12
  end
13
13
 
@@ -4,7 +4,7 @@ module Admin
4
4
  order :title
5
5
 
6
6
  col :id, visible: false
7
- col :course_id, label: 'Learndash Id', visible: false
7
+ col :course_id, label: 'LearnDash Id', visible: false
8
8
 
9
9
  col :title
10
10
  col :status
@@ -2,7 +2,7 @@ module Admin
2
2
  class EffectiveLearndashUsersDatatable < Effective::Datatable
3
3
  datatable do
4
4
  col :id, visible: false
5
- col :user_id, label: 'Learndash Id', visible: false
5
+ col :user_id, label: 'LearnDash Id', visible: false
6
6
 
7
7
  col :last_refreshed, visible: true do |user|
8
8
  time_ago_in_words(user.last_synced_at) + ' ago'
@@ -6,12 +6,12 @@ class EffectiveCourseRegistrationsDatatable < Effective::Datatable
6
6
  col :token, visible: false
7
7
  col :created_at, visible: false
8
8
 
9
- col(:submitted_at, label: 'Registered on') do |registration|
10
- registration.submitted_at&.strftime('%F') || 'Incomplete'
9
+ col :learndash_course, label: 'Title', search: :string do |registration|
10
+ registration.learndash_course.to_s
11
11
  end
12
12
 
13
- col :learndash_course, search: :string do |registration|
14
- registration.learndash_course.to_s
13
+ col(:submitted_at, label: 'Registered on') do |registration|
14
+ registration.submitted_at&.strftime('%F') || 'Incomplete'
15
15
  end
16
16
 
17
17
  col :owner, visible: false, search: :string
@@ -10,12 +10,14 @@ class EffectiveLearndashCoursesDatatable < Effective::Datatable
10
10
  order :title
11
11
  col :id, visible: false
12
12
 
13
- col :title, label: 'Title' do |learndash_course|
14
- link_to(learndash_course.to_s, effective_learndash.learndash_course_path(learndash_course))
13
+ col :title do |learndash_course|
14
+ learndash_course.to_s
15
15
  end
16
16
 
17
17
  actions_col show: false do |learndash_course|
18
- if learndash_course.can_register?
18
+ if current_user.learndash_enrollment(course: learndash_course).present?
19
+ 'Registered. Please access from the home dashboard or applicant wizard.'
20
+ elsif learndash_course.can_register?
19
21
  dropdown_link_to('Register', effective_learndash.new_learndash_course_course_registration_path(learndash_course))
20
22
  end
21
23
  end
@@ -1,11 +1,11 @@
1
1
  # Dashboard LearndashUsers
2
2
  class EffectiveLearndashEnrollmentsDatatable < Effective::Datatable
3
3
  datatable do
4
- col :learndash_course do |enrollment|
5
- link_to(enrollment.learndash_course, EffectiveLearndash.learndash_url, target: '_blank')
4
+ col :learndash_course, label: 'Title' do |enrollment|
5
+ enrollment.learndash_course.to_s
6
6
  end
7
7
 
8
- col :progress_status
8
+ col :progress_status, label: 'Status'
9
9
 
10
10
  col :last_step, visible: false
11
11
  col :steps_completed, visible: false
@@ -16,9 +16,9 @@ class EffectiveLearndashEnrollmentsDatatable < Effective::Datatable
16
16
 
17
17
  actions_col(show: false) do |enrollment|
18
18
  if enrollment.not_started?
19
- dropdown_link_to('Start', EffectiveLearndash.learndash_url, target: '_blank')
19
+ dropdown_link_to('Access Course', EffectiveLearndash.learndash_url, target: '_blank')
20
20
  elsif enrollment.in_progress?
21
- dropdown_link_to('Continue', EffectiveLearndash.learndash_url, target: '_blank')
21
+ dropdown_link_to('Continue Course', EffectiveLearndash.learndash_url, target: '_blank')
22
22
  else
23
23
  dropdown_link_to('Show', EffectiveLearndash.learndash_url, target: '_blank')
24
24
  end
@@ -87,9 +87,9 @@ module EffectiveLearndashCourseRegistration
87
87
  course_registrants
88
88
  end
89
89
 
90
+ # Enroll them in all courses.
90
91
  def after_submit_purchased!
91
- # Enroll them in the course!
92
- learndash_owner.create_learndash_enrollment(course: learndash_course)
92
+ course_registrants.each { |registrant| registrant.owner.create_learndash_enrollment(course: registrant.learndash_course) }
93
93
  end
94
94
 
95
95
  end
@@ -116,7 +116,7 @@ module EffectiveLearndashCourseRegistration
116
116
  end
117
117
 
118
118
  def build_course_registrant
119
- course_registrants.build(owner: owner)
119
+ course_registrants.build(owner: owner, learndash_course: learndash_course)
120
120
  end
121
121
 
122
122
  def learndash_owner
@@ -127,11 +127,16 @@ module EffectiveLearndashCourseRegistration
127
127
  learndash_owner.membership_present?
128
128
  end
129
129
 
130
- def assign_pricing
131
- price = (member_pricing? ? learndash_course.member_price : learndash_course.regular_price)
130
+ def registration_price
131
+ raise('expected a learndash course') unless learndash_course.present?
132
+ raise('expected a learndash owner') unless learndash_owner.present?
132
133
 
134
+ member_pricing? ? learndash_course.member_price : learndash_course.regular_price
135
+ end
136
+
137
+ def assign_pricing
133
138
  course_registrant.assign_attributes(
134
- price: price,
139
+ price: registration_price,
135
140
  qb_item_name: learndash_course.qb_item_name,
136
141
  tax_exempt: learndash_course.tax_exempt
137
142
  )
@@ -146,7 +151,7 @@ module EffectiveLearndashCourseRegistration
146
151
 
147
152
  # Assign prices
148
153
  assign_pricing()
149
- raise('expected course_registrant to have a price') if course_registrant.price.blank?
154
+ raise('expected course_registrants to have a price') if course_registrants.any? { |registrant| registrant.price.blank? }
150
155
 
151
156
  # Save record
152
157
  save!
@@ -30,7 +30,7 @@ module Effective
30
30
  def find_user(value)
31
31
  # Find by email
32
32
  if value.kind_of?(String) && value.include?('@')
33
- return find_by("/wp/v2/users", :email, value)
33
+ return find_by("/wp/v2/users", :email, email_for(value))
34
34
  end
35
35
 
36
36
  # Fetch by saved param value
@@ -39,7 +39,7 @@ module Effective
39
39
  return user if user.present?
40
40
 
41
41
  # Find by email
42
- email = value.try(:email)
42
+ email = email_for(value)
43
43
  user = find_by("/wp/v2/users", :email, email) if email
44
44
  return user if user.present?
45
45
 
@@ -122,7 +122,6 @@ module Effective
122
122
 
123
123
  # private under this point
124
124
 
125
-
126
125
  def user_id(resource)
127
126
  if resource.class.respond_to?(:effective_learndash_owner?) # This is a user
128
127
  resource.learndash_user&.user_id
@@ -146,26 +145,24 @@ module Effective
146
145
  end
147
146
 
148
147
  def username_for(resource)
149
- raise('expected a learndash owner') unless resource.class.respond_to?(:effective_learndash_owner?) # This is a user
150
-
148
+ raise('expected a LearnDash owner') unless resource.class.respond_to?(:effective_learndash_owner?) # This is a user
151
149
  name = EffectiveLearndash.wp_username_for(resource)
152
- name = "test#{name}" unless Rails.env.production?
153
- name
154
- end
155
-
156
- def email_for(resource)
157
- raise('expected a learndash owner') unless resource.class.respond_to?(:effective_learndash_owner?) # This is a user
158
150
 
159
- email = resource.email
160
- email = "test#{email}" unless Rails.env.production?
161
- email
151
+ Rails.env.production? ? name : "test#{name}"
162
152
  end
163
153
 
164
154
  def password_for(resource)
165
- raise('expected a learndash owner') unless resource.class.respond_to?(:effective_learndash_owner?) # This is a user
155
+ raise('expected a LearnDash owner') unless resource.class.respond_to?(:effective_learndash_owner?) # This is a user
166
156
  EffectiveLearndash.wp_password_for(resource)
167
157
  end
168
158
 
159
+ def email_for(value)
160
+ email = value.try(:email) || value.to_s
161
+ return nil unless email.present? && email.include?('@')
162
+
163
+ Rails.env.production? ? email : "test#{email}"
164
+ end
165
+
169
166
  def find(endpoint, params = nil)
170
167
  response = get(endpoint, params)
171
168
 
@@ -178,7 +175,7 @@ module Effective
178
175
  elsif response.kind_of?(Array)
179
176
  response.first
180
177
  else
181
- raise("unexpected Learndash API response #{response}")
178
+ raise("unexpected LearnDash API response #{response}")
182
179
  end
183
180
  end
184
181
 
@@ -199,7 +196,7 @@ module Effective
199
196
  elsif response.kind_of?(Array)
200
197
  response
201
198
  else
202
- raise("unexpected Learndash API find_by response #{response}")
199
+ raise("unexpected LearnDash API find_by response #{response}")
203
200
  end
204
201
  )
205
202
 
@@ -6,7 +6,7 @@
6
6
  = tab 'Enrollments' do
7
7
  %h2 Enrollments
8
8
  %p Click the New button from the below table to enroll a user into this course.
9
- %p Enrolling a user here will enroll them on the Learndash site.
9
+ %p Enrolling a user here will enroll them on the LearnDash site.
10
10
  %p Alternately, if this course is available for registration, the enrollment will be created upon registration purchase.
11
11
 
12
12
  - datatable = Admin::EffectiveLearndashEnrollmentsDatatable.new(learndash_course: learndash_course)
@@ -1,10 +1,10 @@
1
- = card('Learndash Course') do
1
+ = card('LearnDash Course') do
2
2
  %p= learndash_course.title
3
3
  %p= link_to(learndash_course.link, learndash_course.link, target: '_blank')
4
4
 
5
- %p= link_to "Learndash LMS Course Admin", EffectiveLearndash.learndash_url.chomp('/') + "/wp-admin/post.php?post=#{learndash_course.course_id}}&action=edit", target: '_blank'
5
+ %p= link_to "LearnDash LMS Course Admin", EffectiveLearndash.learndash_url.chomp('/') + "/wp-admin/post.php?post=#{learndash_course.course_id}}&action=edit", target: '_blank'
6
6
 
7
- %h3 Learndash User Enrollments
7
+ %h3 LearnDash User Enrollments
8
8
 
9
9
  %p Click the New button from the below table to enroll a user into this course.
10
10
 
@@ -1,5 +1,5 @@
1
1
  - if owner.learndash_user.blank?
2
- %p #{owner} does not yet have an account on Learndash.
2
+ %p #{owner} does not yet have an account on LearnDash.
3
3
 
4
4
  - if owner.learndash_user.present?
5
5
  = render('admin/learndash_users/learndash_user', learndash_user: owner.learndash_user)
@@ -1,6 +1,6 @@
1
1
  = effective_form_with(model: [:admin, learndash_user], engine: true) do |f|
2
2
 
3
3
  = f.select :owner, {'Owners' => current_user.class.sorted }, polymorphic: true,
4
- hint: 'Create a Learndash user account for this website user'
4
+ hint: 'Create a LearnDash account for this user'
5
5
 
6
6
  = f.submit
@@ -1,19 +1,19 @@
1
- = card('Learndash User') do
1
+ = card('LearnDash') do
2
2
  %p
3
3
  = link_to(learndash_user.owner, "/admin/users/#{learndash_user.owner.to_param}/edit")
4
- has an existing account on Learndash.
4
+ has an existing account on LearnDash.
5
5
 
6
6
  %ul
7
7
  %li Email: #{learndash_user.email}
8
8
  %li Username: #{learndash_user.username}
9
9
  %li Password: #{learndash_user.password}
10
10
 
11
- %p= link_to "Learndash LMS User Admin", EffectiveLearndash.learndash_url.chomp('/') + "/wp-admin/user-edit.php?user_id=#{learndash_user.user_id}", target: '_blank'
11
+ %p= link_to "LearnDash LMS User Admin", EffectiveLearndash.learndash_url.chomp('/') + "/wp-admin/user-edit.php?user_id=#{learndash_user.user_id}", target: '_blank'
12
12
 
13
13
  %p
14
14
  %small Last refreshed #{time_ago_in_words(learndash_user.last_synced_at)} ago.
15
15
 
16
- %h3 Learndash Course Enrollments
16
+ %h3 LearnDash Course Enrollments
17
17
 
18
18
  %p Click the New button from the below table to manually enroll this user into a new course.
19
19
 
@@ -2,19 +2,23 @@
2
2
  %table.table.table-sm
3
3
  %tbody
4
4
  %tr
5
- %th.border-0 Learndash Course
5
+ %th.border-0 Course
6
6
  %td.border-0
7
- %p= link_to(course_registration.course, EffectiveLearndash.learndash_url, target: '_blank')
7
+ %p
8
+ %strong=course_registration.course
8
9
 
9
- %p Please sign into Learndash with the following credentials:
10
10
  - learndash_user = course_registration.learndash_owner.learndash_user
11
+ %p Your course account credentials are:
11
12
 
12
13
  %ul
13
- %li Email: #{learndash_user.email}
14
- %li Username: #{learndash_user.username}
15
- %li Password: #{learndash_user.password}
14
+ %li
15
+ %strong Username:
16
+ #{learndash_user.username}
17
+ %li
18
+ %strong Password:
19
+ #{learndash_user.password}
16
20
 
17
- %p= link_to('Learndash LMS', EffectiveLearndash.learndash_url, target: '_blank')
21
+ %p= link_to('Sign in to your course account', EffectiveLearndash.learndash_url, target: '_blank', class: 'btn btn-primary mb-2')
18
22
 
19
23
  - if request.path.start_with?('/admin')
20
24
  %tr
@@ -2,9 +2,8 @@
2
2
  = render 'effective/course_registrations/content', resource: resource
3
3
 
4
4
  = card('Course') do
5
- = render('effective/learndash_courses/learndash_course', learndash_course: resource.learndash_course)
6
-
7
- %p You qualify for #{resource.member_pricing? ? 'member' : 'regular'} pricing.
5
+ %p= resource.learndash_course
6
+ %p= price_to_currency(resource.registration_price)
8
7
 
9
8
  = effective_form_with(model: resource, url: wizard_path(step), method: :put) do |f|
10
9
  = f.hidden_field :id
@@ -13,12 +13,13 @@
13
13
  .alert.alert-warning
14
14
  You are already enrolled in #{link_to(resource.course, EffectiveLearndash.learndash_url, target: '_blank')}.
15
15
 
16
- = effective_form_with(model: resource, url: wizard_path(step), method: :put) do |f|
17
- = f.hidden_field :id
16
+ - if existing.blank?
17
+ = effective_form_with(model: resource, url: wizard_path(step), method: :put) do |f|
18
+ = f.hidden_field :id
18
19
 
19
- = f.hidden_field :learndash_course_id
20
+ = f.hidden_field :learndash_course_id
20
21
 
21
- = f.hidden_field :owner_type
22
- = f.hidden_field :owner_id
22
+ = f.hidden_field :owner_type
23
+ = f.hidden_field :owner_id
23
24
 
24
- = f.save 'Save and Continue'
25
+ = f.save 'Save and Continue'
@@ -10,7 +10,6 @@
10
10
  = link_to "Return to Dashboard", root_path, class: 'btn btn-lg btn-primary mb-4'
11
11
 
12
12
  = render 'effective/course_registrations/summary', course_registration: resource
13
- = render 'effective/course_registrations/course_registration', course_registration: resource
14
13
  = render 'effective/course_registrations/orders', course_registration: resource
15
14
 
16
15
  = link_to "Return to Dashboard", root_path, class: 'btn btn-lg btn-primary'
@@ -1,31 +1,29 @@
1
1
  - learndash_user = current_user.try(:learndash_user)
2
2
  - authorized = learndash_user && EffectiveResources.authorized?(self, :show, learndash_user)
3
3
 
4
- %h2 Learndash Courses
4
+ %h2 Courses
5
5
 
6
6
  - if learndash_user.blank?
7
- %p You do not have a Learndash account.
8
-
9
- - if learndash_user.present?
10
- %p
11
- = succeed('.') do
12
- You have an existing account on
13
- = link_to('Learndash', EffectiveLearndash.learndash_url, target: '_blank')
7
+ %p You do not have an account to access courses. When you are enrolled in a course, your account credentials will be displayed here.
14
8
 
15
9
  - if learndash_user.present? && authorized
16
10
  - learndash_user.refresh!
17
11
 
18
- %p Please sign into Learndash with the following credentials:
12
+ %p Your course account credentials are:
19
13
 
20
14
  %ul
21
- %li Email: #{learndash_user.email}
22
- %li Username: #{learndash_user.username}
23
- %li Password: #{learndash_user.password}
15
+ %li
16
+ %strong Username:
17
+ #{learndash_user.username}
18
+ %li
19
+ %strong Password:
20
+ #{learndash_user.password}
24
21
 
25
- - if learndash_user.learndash_enrollments.present?
26
- %p You are enrolled in #{pluralize(learndash_user.learndash_enrollments.length, 'course')}.
22
+ %p= link_to('Sign in to your course account', EffectiveLearndash.learndash_url, target: '_blank', class: 'btn btn-primary')
27
23
 
24
+ - if learndash_user.learndash_enrollments.present?
28
25
  - datatable = EffectiveResources.best('EffectiveLearndashEnrollmentsDatatable').new(self)
29
26
  = render_datatable(datatable, simple: true)
27
+
30
28
  - else
31
- You are not enrolled in any Learndash courses.
29
+ %p You are not enrolled in any courses.
@@ -4,7 +4,7 @@
4
4
  %th Regular Price
5
5
  %td= price_to_currency(learndash_course.regular_price)
6
6
  %tr
7
- %th Member Price
7
+ %th Discounted Price
8
8
  %td= price_to_currency(learndash_course.member_price)
9
9
 
10
10
  - if learndash_course.body.present?
data/config/routes.rb CHANGED
@@ -7,7 +7,7 @@ end
7
7
  EffectiveLearndash::Engine.routes.draw do
8
8
  # Public routes
9
9
  scope module: 'effective' do
10
- resources :learndash_courses, only: [:index, :show] do
10
+ resources :learndash_courses, only: [:index] do
11
11
  resources :course_registrations, only: [:new, :show, :destroy] do
12
12
  resources :build, controller: :course_registrations, only: [:show, :update]
13
13
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveLearndash
2
- VERSION = '0.1.4'.freeze
2
+ VERSION = '0.1.7'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_learndash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-31 00:00:00.000000000 Z
11
+ date: 2022-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -164,7 +164,7 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
- description: Create Wordpress users and read Learndash course progress
167
+ description: Create Wordpress users and read LearnDash course progress
168
168
  email:
169
169
  - info@codeandeffect.com
170
170
  executables: []
@@ -259,5 +259,5 @@ requirements: []
259
259
  rubygems_version: 3.1.2
260
260
  signing_key:
261
261
  specification_version: 4
262
- summary: Create Wordpress users and read Learndash course progress
262
+ summary: Create Wordpress users and read LearnDash course progress
263
263
  test_files: []