celtic-project / wordpress-lti-platform

Plugin to enable WordPress to act as an LTI Platform
GNU General Public License v3.0
2 stars 1 forks source link

Add URL Only Output Option to Shortcode in WordPress LTI Platform #7

Open abdolnabi opened 1 month ago

abdolnabi commented 1 month ago

Issue Description:

In the Celtic project under the wordpress-lti-platform, the current shortcode implementation for displaying LTI tool links and titles ([lti-platform tool=saltire id=iofkljfg target='']) only supports a limited set of target options: "New window", "popup", "iframe", and "embed". There is a common need, especially when integrating with custom elements, to use only the URL of the LTI tools without embedding or opening them in new windows.

Feature Request:

It would be highly beneficial to add an "URL only" output option to the shortcode. This feature would allow developers to retrieve just the URL of an LTI tool, enabling more flexible integration possibilities, such as linking directly from custom buttons or other UI elements without altering the behavior dictated by the target attribute.

Potential Benefits:

Example Use Case:

A developer wants to create a custom button on their site that links directly to an LTI tool without opening it within an iframe or a new window. Specifically, using a WordPress page builder, the developer plans to incorporate custom elements or buttons that require direct URLs to LTI tools for seamless integration. Currently, this is not possible with the existing shortcode options which limit output to embedding methods like iframe or popup windows. The addition of a "URL only" option would enable more streamlined and custom integrations within WordPress environments.

spvickers commented 1 month ago

Thanks for your contribution. As I understand it, what you are looking for is an option which allows a shortcode to be added which is replaced only by the URL to open the tool, and omits any surrounding HTML to create a hyperlink within the WordPress page. If that is correct, then I would not consider this to be a target option which is part of the LTI spec. It seems to me that you merely need an attribute which renders the shortcode as a simple URL. For example, do you think something like the following would solve your issue?

[lti-platform tool=saltire id=iofkljfg urlonly]

which would be replaced with a URL like:

https://my.wordpress.site/?lti-platform&post=[x]&id=[id]

where [x] is the ID of the post containing the shortcode and [id] is the ID of the shortcode link. This link would generate an launch message to the LTI tool (with the setting for the presentation_document_target being included in the message). This assumes that the location where the LTI tool is opened is actually controlled by the HTML code in which the shortcode is embedded, rather than this plugin, so it is possible that the parameter included in the LTI message may not accurately reflect the actual location of the tool. It would rely on the tool or shortcode being consistently configured.

abdolnabi commented 1 month ago

Thanks for the explanation, my requirement is to find a url of the lti course’s (my lti tools) which is working on any page from anywhere, just imagine this scenario, I have some blog posts with this course’s shortcode in custom parameters, and I need to display blog posts on the blog page with the link to the course as a button below each blog post fetching their link from the shortcode stored as a custom parameter, when it is fetching the shortcode the page id and shortcode id is not aligned to the blog page and only works on that specific blog post. Now I’m trying to find a way to make the course urls working on everywhere not only on the main blog post the shortcode defined on it.

abdolnabi commented 1 month ago

Also I tried the shortcode the way you mentioned above like [lti-platform tool=saltire id=iofkljfg urlonly]but it will replace the shortcode with an href tag like below:

`<a href="https://my.wordpress.site?lti-platform&post=[x]&id=[id]" title="Launch [tool_name] tool" target="_blank">[tool_name]</a>`
spvickers commented 1 month ago

Sorry if I was not clear. My previous response was merely trying to outline a proposed solution to meet your needs; it was not intended to describe an existing solution. Do you think my proposal is suitable?

spvickers commented 1 month ago

Some questions about your response:

my requirement is to find a url of the lti course’s (my lti tools)

What do you mean by an LTI course? Does this relate to a page within an LTI tool?

which is working on any page from anywhere

What types of page are you referring to here? More than just those stored in the WordPress posts table?

this course’s shortcode in custom parameters

Are you referring to LTI custom parameters, or a WordPress element?

abdolnabi commented 4 weeks ago

Thanks very much for your clarifications and detailed questions, please find my responses below: 1. My requirement is to find a URL of the LTI course’s (my LTI tools)

Response: An LTI course in this context refers to a specific educational resource or set of activities from OpenLearning, which is integrated into our WordPress site using the LTI 1.3 standard. The URL of the LTI course is essentially the target URL provided by OpenLearning that allows for LTI-based connections. This URL is used to launch the LTI tool from WordPress and typically contains the endpoint that handles LTI launch requests within the OpenLearning platform.

2. What do you mean by an LTI course? Does this relate to a page within an LTI tool?

Response: Yes, by an LTI course, I am referring to an OpenLearning course that is integrated into our WordPress site via an LTI tool. It does not directly relate to a traditional web page but to a course hosted on OpenLearning, which is made accessible within our WordPress environment through LTI integration. The courses are represented as external content embedded or linked from our WordPress posts, enabling direct interaction with OpenLearning’s LTI-compliant content.

3. Which is working on any page from anywhere. What types of page are you referring to here? More than just those stored in the WordPress posts table?

Response: The phrase “working on any page from anywhere” refers to the flexibility of placing LTI tool links or buttons on various parts of our WordPress site, not limited to the individual course posts. While each course has its own dedicated post, we also have a centralized course list page that aggregates these courses. The LTI links or start course buttons can be included on this list page, other posts, pages, or even widgets throughout the site, facilitating access to the LTI courses from various navigational points within the WordPress environment.

4. This course’s shortcode in custom parameters. Are you referring to LTI custom parameters, or a WordPress element?

Response: In this context, the reference to “shortcode in custom parameters” pertains to a WordPress element — specifically, a shortcode that we use to embed or link to the LTI course. This shortcode is designed to utilize custom parameters that are stored within each course’s WordPress post as metadata. These parameters might include identifiers, keys, or other course-specific data that configure the LTI link to launch the corresponding course in OpenLearning. The shortcode facilitates the dynamic generation of these links based on the metadata stored in each course’s post, ensuring that the correct course is launched via the LTI integration.

spvickers commented 4 weeks ago

Thanks for the further details. Some follow-up questions:

  1. I am still not clear on whether any of the pages on which you wish to place a shortcode are not stored within the posts table. For example, is your "centralized course list page" a bespoke PHP/HTML page? (I have no experience of support for shortcodes outside a WordPrress page/post.)
  2. The LTI launch message needs to contain some specific values to identify the destination within the LTI tool (OpenLearning). If these values are saved as metadata within the WordPress page for the course, how would they be found by a link on the centralized course list page, for example?
  3. I assume the course-specific values are to be passed to the LTI tool (OpenLearning) as LTI custom parameters in the LTI message; or are they to be passed as query parameters on the LTI launch URL?
  4. Is there any reason why the course-specific values cannot be specified within the shortcode rather than as metadata in the course's post?
abdolnabi commented 3 weeks ago

Here's your response formatted in Markdown:


Apologies for the delayed response, and thank you for your patience. I’ve reviewed our setup and would like to clarify the following points regarding the implementation of the LTI launch and shortcode integration:

  1. Page Storage:

    • All pages where I wish to place a shortcode are indeed stored within the WordPress posts table. This should simplify integration as they are standard WordPress posts.
  2. LTI Launch Metadata:

    • I intend to store an LTI shortcode that contains the URL of the LTI tool as an attribute of the posts. This will allow me to easily use these URLs in buttons that launch the courses on OpenLearning.
  3. Passing Course-Specific Values:

    • I am currently passing the class_id attribute to OpenLearning as part of the custom parameters in the LTI tool. This method aligns with our need to specify certain course details directly within the launch parameters.
  4. Design and Usability:

    • The reason for having the link to each course outside of the post content is due to our design scenario. We plan to use a page builder to loop over course posts and render certain attributes on the course list page based on each course/post. This approach is more manageable and flexible for our needs than embedding everything directly inside the post content.

I hope this clarifies our approach and the requirements. I look forward to your guidance on how we can best implement these functionalities within the current framework of the plugin.

Thank you for your support.


spvickers commented 3 weeks ago

Thanks for the clarifications. It sounds like there is no need to include metadata from the WordPress page in the LTI message, so your original request of merely being able to render the shortcode as just the URL needed to launch the LTI tool so that it can be included in bespoke HTML is sufficient for your needs. So my original proposal to add an attribute to the shortcode of something like urlonly would support this requirement.

spvickers commented 2 weeks ago

To address your issue, my proposal is to add a new optional attribute to the shortcode named "output". The attribute can have a value of "url", "title", "width" or "height". When present the shortcode will be replaced with just the value of the specified item with no additional HTML. Any double quotes will be replaced with """ to allow the value to be included within an HTML tag. Does that sound like it will address your needs?

abdolnabi commented 2 weeks ago

I’m not sure if I get it correctly, can you give an example of the shortcode output with those attributes you’ve mentioned earlier?

spvickers commented 2 weeks ago

Sure. Updating my example from above, the shortcode would be:

[lti-platform tool=saltire id=iofkljfg output=url][/lti-platform]

which would render as:

https://my.wordpress.site/?lti-platform&post=[x]&id=[id]

where [x] is the ID of the post containing the shortcode and [id] is the ID of the shortcode link.

A shortcode of:

[lti-platform tool=saltire output=title][/lti-platform]

would render as:

Launch saltire tool

Note that the id attribute is not required when the output attribute is not set to url. The following shortcode would render a title of "Launch LTI tool" but is rather redundant as it could just be replaced with the value itself:

[lti-platform tool=saltire title="Launch LTI tool" output=title][/lti-platform]

A shortcode of:

[lti-platform tool=saltire output=width][/lti-platform]

would render as:

750

assuming this is the width specified in the tool's configuration.

spvickers commented 5 days ago

NB previous comment has been edited to add closing shortcode tags.

abdolnabi commented 4 days ago

Given our ongoing discussion, the solution seems viable. However, I'm curious about a couple of scenarios concerning the WordPress page context, particularly for a specific post type like 'portfolios' which uses the posts table but doesn't support Gutenberg—only the classic editor is available.

These questions aim to ensure clarity on how the shortcodes interact with different editors and across various display contexts. Looking forward to your insights on this.

spvickers commented 4 days ago

I have not tried adding the LTI Platform shortcodes to portfolio pages, but since they can be typed manually (as in my examples above), I see no reason why they should not work, assuming that WordPress parses these pages for shortcodes when displaying them. Each shortcode to launch a tool must have a unique value for its id attribute, so displaying multiple links from multiple pages should work. Perhaps you can try it out with the existing shortcode functionality to add LTI tool launch links and see if it does?

abdolnabi commented 3 days ago

That's a fantastic discovery! Utilizing custom parameters within the shortcode to pass the page_id and differentiate LTI tools for specific courses sounds like an effective solution. Here’s how I implemented it based on your insight:

[lti-platform tool="xxx" id="xxyzxx" custom="page_id=xxyyzz; class_id=6668...367845"]

This approach enables the use of a single LTI tool across multiple courses by specifying unique class_idsfor each, ensuring the correct course context is maintained when navigating from the general course link to the specific course page on the LTI platform.

abdolnabi commented 3 days ago

It seems we might be encountering a specific challenge with how the shortcode interacts with custom fields. When the shortcode is embedded in a custom field of WordPress posts rather than directly in the post content, it appears that the shortcode does not function properly when called from a list on another page, resulting in the "No LTI tools found." message.

spvickers commented 3 days ago

Two comments on your last two messafes:

  1. The id value should not need to be repeated as a custom parameter as it is used as the LTI resource_link_id parameter which is one of the few required parameters in an LTI launch message.
  2. The plugin has not been designed to have its shortcodes entered outside of a page content - have you experienced other shortcodes being used elsewhere in WordPress?
spvickers commented 3 days ago

Just to make sure I am understanding your requirements correctly:

  1. You are wanting to have a link (e.g. a button) on a page (whose contents are stored in the wp_posts table) which will launch an LTI tool.
  2. You wish to be able to place the shortcode which helps to achieve this within the custom fields of the page, rather than within the body of the page.
  3. A script (e.g. a theme) will extract the value of this custom field when the page is rendered.

Does this sound correct? If so, are you able to provide an example of the value(s) which might be entered in a page's custom field(s) and the HTML which your script might render from it/them?