Home Developers

Developers

Juliana Dias
By Juliana Dias
6 articles

Code Snippets for v2

Basically, code snippets for WordPress are used to do certain actions that might otherwise require a dedicated smaller plugin. Such code snippets are placed in one of the WordPress core or theme files (generally the functions.php file of your theme) or they can be used as a MU plugin. In this article we will show you three code snippets that can be used with WP Ultimo v2: - Changing the position of the Account menu item - How to check if the user is under a given plan and/or has an active subscription - Fixing CORS issues with Font -Icons in mapped domains Changing the position of the Account menu item To change the position of the Account menu item on your client’s Dashboard, just add the following code snippet to the functions.php of your main site’s active theme. You can also put the snippet inside one of you mu-plugins or custom plugins. add_filter('wu_my_account_menu_position', function() { return 10; // Tweak this value to place the menu in the desired position. How to check if the user is under a given plan and/or has an active subscription As a network admin, you may need to create custom functions that will perform basic actions or make a service/feature available to a selected group of subscribers or end-users, based on the status of their subscription and the plan they are subscribed under. These WP Ultimo native functions will help you with that. To check if the user is a member of a given plan, you can use the function: wu_has_plan($user_id, $plan_id) To check if the subscription is active, you can use the function: wu_is_active_subscriber($user_id) Below is an example snippet that checks whether the current user is under a specific plan (Plan ID 50) and if the user subscription is active. $user_id = get_current_user_id();$plan_id = 50;if (wu_has_plan($user_id, $plan_id) && wu_is_active_subscriber($user_id)) { // USER IS MEMBER OF PLAN AND HIS SUBSCRIPTION IS ACTIVE, DO STUFF} else { // USER IS NOT A MEMBER OF PLAN -- OR -- HIS SUBSCRIPTION IS NOT ACTIVE, DO OTHER STUFF} // end if; Note that wu_has_plan requires a "Plan ID" in order for it to function. To get the ID of a plan, you can go to WP Ultimo > Products. The ID of each product will be shown on the right of the table. Note that users can only be subscribed to a Plan, not a Package or Service, as they are only add-ons for a Plan. Fixing CORS issues with Font-Icons in mapped domains After mapping a domain to a sub-site you might find out that the site is having trouble loading custom fonts. That’s caused by a cross-origin block on your server settings. Since font files are almost always loaded directly from CSS, our domain mapping plugin is not able to rewrite the URLs to use the mapped domain instead of the original one, so in order to fix the issue, you’ll need to amend your server configuration files. Below are code snippets to fix the issue for Apache and NGINX. These changes require advanced knowledge of server configuration files (.htaccess files and NGINX config files). If you are not comfortable with making those changes yourself, send this page to your hosting provider support agents when requiring assistance. Apache On your .htaccess file, add: <FilesMatch “.(ttf|ttc|otf|eot|woff|font.css|css)$”> Header set Access-Control-Allow-Origin “*” NGINX On your server config file (the location varies from server to server), add: location ~ .(ttf|ttc|otf|eot|woff|font.css|css)$ { add_header Access-Control-Allow-Origin “*”;}

Last updated on Oct 11, 2023

The WP Ultimo Register API endpoint

In this tutorial, you will learn how to use the WP Ultimo /register API endpoint to create the entire onboarding process for a new customer in your network and how to do that with Zapier. The endpoint uses the POST method and is called by the URL https://yoursite.com/wp-json/wu/v2/register. In this call, 4 processes will be executed within your network: - A new WordPress user or its identification through the user ID will be created. - A new Customer in WP Ultimo or its identification through the customer ID will be created. - A new site on the WordPress network will be created. - In the end, a new Membership in WP Ultimo will be created. For this process, you will need your API credentials. To get them, go to your network admin panel, navigate to WP Ultimo > Settings > API & Webhooks, and look for the API Settings section. Select the Enable API and get your API credentials. Now, let's explore the endpoint and then create a registration action in Zapier. Endpoint body parameters Let's have an overview of the minimum information we need to send to the endpoint. At the end of this article, you'll find the full call. Customer This is the information that is necessary for the process of creating the User and the WP Ultimo Customer: "customer_id" : integer It is possible to send the customer ID created in your network. If not submitted, the information below will be used to create a new customer and a new WordPress user. The user ID can also be sent in the same manner as the customer ID. "customer" : { "user_id" : integer "username" : "string", "password" : "string", "email" : "string", }, Membership The only information we need inside this object is Membership Status. "membership" { "status" : "string", // one of "pending", "active", "trialing", "expired", "on-hold", "canceled" }, Products Products are given an array with 1 or more product ID from your network. Beware, this endpoint does not create products. Check WP Ultimo's documentation to better understand the product creation endpoint. "products" : [1,2], Payment As with Membership, we only need the status. "payment" { "status" : "string", // one of "pending", "completed", "refunded", "partially-refunded", "partially-paid", "failed", "canceled" }, Site And to close the body we need the site's URL and Title, both inside the Site object. "site" : { "site_url" : "string", "site_title" : "string" } The return of the register endpoint will be an array with the newly created membership information. Creating an action in Zapier With the introduction of this new and more robust account creation endpoint you will also access a new action in Zapier. Do you know how to use and enjoy everything that the new version of Zapier offers? Learn more here. (link?) Creating an action To better illustrate how to use the registration endpoint with Zapier, let's create an integration with Google Forms. Every time this form is filled out and the information is saved in the form's answer sheet, a new membership will be created in the WP Ultimo network. In Google Forms, make a form with the minimum fields necessary to create a new membership in the network. Now in Zapier, make a new Zap and connect the created form in Google through the spreadsheet where the data is saved. Done! The Google Forms form is connected with Zapier and ready to be integrated with the network. Now let's move on to the Action that will result from the Trigger that Google Forms triggers every time it's filled. Locate the new WP Ultimo app and select it. For this kind of Zap choose the Register option. After this first step, choose the account that will be connected with this Zap. This is the most sensitive part of the whole process. We need to match the fields that came from Google Forms with the minimum fields necessary for the register endpoint, as shown in the previous section of this article. In this example, we only need to configure the username, email, password, name and URL of the website. The rest is left pre-determined so that all memberships generated on this Google Forms follow the same product and status pattern. With the information set up, proceed to the final test. On the last screen you can see all the fields that will be sent to the endpoint, their respective information and the fields that will be sent empty. Test your new Zap and it should complete successfully. If any error occurs, check all fields and if they are being sent correctly. As there is a lot of information, some things can go unnoticed. Complete endpoint parameters Here is the complete call and all the possibilities of fields that can be sent. "customer_id" : integer, "customer" : { "user_id" : integer "username" : "string", "password" : "string", "email" : "string", }, "membership" : { "status" : "string", // one of "pending", "active", "trialing", "expired", "on-hold", "cancelled" "date_expiration" : "string", "date_trial_end" : "string", "date_activated" : "string", "date_renewed" : "string", "date_cancellation" : "string", "date_payment_plan_completed": "string", }, "products" : [1,2], "duration" : "string", "duration_unit" : "string", "discount_code" : "string", "auto_renew" : "boolean", "country" : "string", "currency" : "string", "payment" { "status" : "string", // one of "pending", "completed", "refunded", "partially-refunded", "partially-paid", "failed", "cancelled" }, "payment_method" : { "gateway" : "string", "gateway_customer_id" : "string", "gateway_subscription_id" : "string", "gateway_payment_id" : "string", }, "site" : { "site_url" : "string", "site_title" : "string", "publish" : "boolean", "template_id" : "string", }

Last updated on Oct 11, 2023

How to use WP Ultimo snippets on our GitHub repository

There are code snippets available in GitHub repository that are frequently requested by WP Ultimo users who wish to add small functionalities like adding Google Analytics script on sign-up pages or hiding a meta box from the admin dashboard. This article will show you how to use or more specifically where to place these codes. You can find the snippets on the link below. https://github.com/next-press/wp-ultimo-snippets/ There are 2 ways for you to add the code 1. On your theme's functions.php file. 2. Must-Use Plugins (mu-plugins) How to add the snippet on your theme's functions.php file. 1. Log into your WordPress Network admin dashboard and go to Themes >Theme Editor (See screenshot below). 2. On the "Edit Themes" page, make sure that you have your active theme selected on the dropdown field located on the upper right-hand side of your screen (#3 on the screenshot below). 3. Click the functions.php file under the "Theme Files" section to load the file. Scroll down at the bottom and paste the WP Ultimo snippet you got from GitHub repository. How to create Must-Use Plugins (mu-plugins) WordPress has a feature that allows you to load custom functionality called "Must-Use Plugins", or "mu-plugins" for short. These special mu-plugins are loaded before all other regular plugins, and they can’t be deactivated. In a multisite network, the code in these mu-plugins will be loaded on all the sites in your installation. 1. Use FTP or SSH to access the filesystem of your WordPress install. 2. Inside the wp-content directory of your WordPress install, create a new directory named: mu-plugins. 3. Create a new PHP file on your computer named wu-snippet.php using Notepad or any code editor. 4. Place the WP Ultimo code snippet you got GitHub repository into the file and save it. You can also add this code on top of the code snippet to label your mu plugin.

Last updated on Oct 11, 2023