lifterlms icon indicating copy to clipboard operation
lifterlms copied to clipboard

Custom Merge Codes Don't Render in Certificates

Open nrherron92 opened this issue 2 years ago • 1 comments

Reproduction Steps

  • Add our snippet for custom merge codes here: https://github.com/gocodebox/snippets/blob/trunk/lifterlms/llms-cert-custom-merge-example.php
  • Add the new custom merge code to a certificate template
  • Save the template
  • Award the certificate

Expected Behavior

  • The certificate should render the new custom merge code

Actual Behavior

  • Instead the merge code just show up as plain text
  • Users earn a certificate
  • it gets the certificate template content, process the merge codes -> save it into the earned certificate content
  • then it fires the hook from the custom code snippet
  • and again gets the certificate template content, process the merge codes -> save it into the earned certificate content

Error Messages / Logs

  • Include any relevant error messages or log files
<!-- Paste error logs / backtraces below this line -->

System and Environment Information

System Report
Wordpress
-------------------------------------------

Home Url: https://natalie-test-site.myliftersite.com
Site Url: https://natalie-test-site.myliftersite.com
Login Url: https://natalie-test-site.myliftersite.com/wp-login.php
Version: 6.0
Debug Mode: No
Debug Log: No
Debug Display: Yes
Locale: en_US
Multisite: No
Page For Posts: Not Set
Page On Front: Homepage (#1398) [https://natalie-test-site.myliftersite.com/]
Permalink Structure: /%postname%/
Show On Front: page
Wp Cron: Yes


Settings
-------------------------------------------

Version: 6.7.0
Db Version: 6.7.0
Course Catalog: Course Catalog (#35) [https://natalie-test-site.myliftersite.com/courses/]
Membership Catalog: Membership Catalog (#36) [https://natalie-test-site.myliftersite.com/memberships/]
Student Dashboard: Dashboard (#38) [https://natalie-test-site.myliftersite.com/dashboard/]
Checkout Page: Checkout (#715) [https://natalie-test-site.myliftersite.com/checkout/]
Course Catalog Per Page: 9
Course Catalog Sorting: menu_order,ASC
Membership Catalog Per Page: 9
Membership Catalog Sorting: menu_order
Site Membership: Not Set
Courses Endpoint: my-courses
Edit Endpoint: edit-account
Lost Password Endpoint: lost-password
Vouchers Endpoint: redeem-voucher
Autogenerate Username: no
Password Strength Meter: no
Minimum Password Strength: 
Terms Required: yes
Terms Page: Activate (#443) [https://natalie-test-site.myliftersite.com/activate/]
Checkout Names: 
Checkout Address: 
Checkout Phone: 
Checkout Email Confirmation: no
Open Registration: yes
Registration Names: 
Registration Address: 
Registration Phone: 
Registration Voucher: 
Registration Email Confirmation: no
Account Names: 
Account Address: 
Account Phone: 
Account Email Confirmation: no
Confirmation Endpoint: confirm-payment
Force Ssl Checkout: no
Country: CA
Currency: CAD
Currency Position: left
Thousand Separator: ,
Decimal Separator: .
Decimals: 2
Trim Zero Decimals: no
Recurring Payments: yes
Email From Address: [email protected]
Email From Name: A LifterLMS Sandbox
Email Footer Text: 
Email Header Image: 
Cert Bg Width: 1123
Cert Bg Height: 794
Cert Legacy Compat: no


Constants
-------------------------------------------

LLMS_REMOVE_ALL_DATA: undefined
LLMS_REST_DISABLE: undefined
LLMS_SITE_FEATURE_RECURRING_PAYMENTS: undefined
LLMS_SITE_IS_CLONE: undefined


Gateways
-------------------------------------------

Manual: Enabled
Manual Logging: no
Manual Order: 1


Server
-------------------------------------------

Mysql Version: 5.7.38
Php Curl: Yes
Php Default Timezone: UTC
Php Fsockopen: Yes
Php Max Input Vars: 5000
Php Max Upload Size: 512 MB
Php Memory Limit: 256M
Php Post Max Size: 1024M
Php Soap: Yes
Php Suhosin: No
Php Time Limt: 30
Php Version: 8.0.20
Software: Apache/2.4.54 (Unix) OpenSSL/1.1.1
Wp Memory Limit: 256M


Browser
-------------------------------------------

HTTP USER AGENT: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36


Theme
-------------------------------------------

Name: Astra
Version: 3.8.5
Themeuri: https://wpastra.com/
Authoruri: https://wpastra.com/about/?utm_source=theme_preview&utm_medium=author_link&utm_campaign=astra_theme
Template: 
Child Theme: No
Llms Support: Yes


Plugins
-------------------------------------------

Code Snippets: 3.1.1
LifterLMS: 6.7.0
LifterLMS Custom Fields: 2.0.2
User Switching: 1.6.0

Integrations
-------------------------------------------

BbPress: No
BuddyPress: No


Template Overrides
-------------------------------------------


This issue has be recreated:

  • [x] Locally
  • [x] On a staging site
  • [ ] On a production website
  • [x] With only LifterLMS and a default theme

Browser, Device, and Operating System Information

  • Browser name and version
  • Operating System name and version
  • Device name and version (if applicable)

nrherron92 avatar Jul 07 '22 16:07 nrherron92

Thanks for reporting this @nrherron92 so the problem here is that, when a certificate is awarded, we apparently save its content twice: As you said:

  • Users earn a certificate
  • it gets the certificate template content, process the merge codes -> save it into the earned certificate content
  • then we do something else, like firing that hook from the custom code snippet
  • then again we get the certificate template content, process the merge codes -> save it into the earned certificate content overriding the previous content.

In any case, customers who wishes to add custom merge codes to the certificates, can use this filter: https://github.com/gocodebox/lifterlms/blob/e1f7f1b45a9900c25db7bf4ce9e599b011f39ce1/includes/models/model.llms.user.certificate.php#L494

eri-trabiccolo avatar Jul 07 '22 16:07 eri-trabiccolo