Title: calling class with data
Last modified: September 25, 2019

---

# calling class with data

 *  [ukndoit](https://wordpress.org/support/users/ukndoit/)
 * (@ukndoit)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/calling-class-with-data/)
 * I am trying to figure out how to use PHP to call a function that is in a class
   in a file in a plugin… (S2Member-Pro) in this file: /wp-content/plugins/s2member/
   src/includes/classes/register-access.inc.php
 * Here is the file data, in part:
 *     ```
       if(!defined('WPINC')) // MUST have WordPress.
       	exit('Do not access this file directly.');
   
       if(!class_exists('c_ws_plugin__s2member_register_access'))
       {
       	/**
       	 * Registration Access Links.
       	 *
       	 * @package s2Member\Registrations
       	 * @since 3.5
       	 */
       	class c_ws_plugin__s2member_register_access
       	{
       		/**
       		 * Generates Registration Access Links.
       		 *
       		 * @package s2Member\Registrations
       		 * @since 3.5
       		 *
       		 * @param string     $subscr_gateway Payment Gateway associated with a Customer.
       		 * @param string     $subscr_id Unique Subscr. ID associated with Payment Gateway; associated with a Customer.
       		 * @param string     $custom Custom String value *(as supplied in Shortcode)*; must start with installation domain name.
       		 * @param int|string $item_number An s2Member-generated <code>item_number</code> *( i.e., <code>1</code> for Level 1, or <code>level|ccaps|fixed-term</code>, or <code>sp|ids|expiration</code> )*.
       		 * @param bool       $shrink Optional. Defaults to true. If false, the raw registration link will NOT be reduced in size through the tinyURL API.
       		 *
       		 * @return string|bool A Registration Access Link on success, else false on failure.
       		 */
       		public static function register_link_gen($subscr_gateway = '', $subscr_id = '', $custom = '', $item_number = '', $shrink = TRUE)
       		{
       			foreach(array_keys(get_defined_vars()) as $__v) $__refs[$__v] =& $$__v;
       			do_action('ws_plugin__s2member_before_register_link_gen', get_defined_vars());
       			unset($__refs, $__v);
   
       			if($subscr_gateway && is_string($subscr_gateway) && $subscr_id && is_string($subscr_id) && $custom && is_string($custom) && $item_number && (is_string($item_number) || is_numeric($item_number)))
       			{
       				$register = c_ws_plugin__s2member_utils_encryption::encrypt('subscr_gateway_subscr_id_custom_item_number_time:.:|:.:'.$subscr_gateway.':.:|:.:'.$subscr_id.':.:|:.:'.$custom.':.:|:.:'.$item_number.':.:|:.:'.strtotime('now'));
   
       				$register_link = home_url('/?s2member_register='.urlencode($register)); // Generate long URL/link.
   
       				if($shrink && ($shorter_url = c_ws_plugin__s2member_utils_urls::shorten($register_link)))
       				{
       					$domain_tag    = (strpos($shorter_url, $_SERVER['HTTP_HOST'])) ? '' : '#'.$_SERVER['HTTP_HOST']; // Personalize the link with the site's domain name if it's not already there.
       					$register_link = $shorter_url.$domain_tag;
       				}
       			}
       			return apply_filters('ws_plugin__s2member_register_link_gen', ((!empty($register_link)) ? $register_link : FALSE), get_defined_vars());
       		}
       ```
   
 * I have this data:
 *     ```
       $subscr_gateway
       $subscr_id
       $custom // Custom String value *(as supplied in Shortcode)*; must start with installation domain name.
       $item_number // An s2Member-generated <code>item_number</code> *( i.e., <code>1</code> for Level 1, or <code>level|ccaps|fixed-term</code>, or <code>sp|ids|expiration</code> )*.
       $shrink // false...
       ```
   
 * So I have those set.
 * How would I call the above in wordpress via php?
 * to have it return a valid link?
    I’m self taught, so have never learned anything
   about programming with classes and advanced programming… and have never programmed
   anything with them.
 * I’d appreciate advice on how to use PHP to call one of those classes with my 
   data I have… passed to it.
 * -Rich

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Joy](https://wordpress.org/support/users/joyously/)
 * (@joyously)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/calling-class-with-data/#post-11968894)
 * See that last line of the function?
    `return apply_filters('ws_plugin__s2member_register_link_gen',((!
   empty($register_link)) ? $register_link : FALSE), get_defined_vars());`
 * It is the way you can affect the data and your code can be very small. For filters,
   you can only modify the first parameter that is passed to the filter. Any other
   parameters are passed for context, but can’t be changed.
 *     ```
       add_filter( 'ws_plugin__s2member_register_link_gen', 'my_own_s2member_register_link_gen' );
       function my_own_s2member_register_link_gen ( $register_link, $defined_vars ) {
         // get your data out of $defined_vars  (gateway, id, number, etc.)
         // build the link or modify the $register_link passed in
         return $register_link;
       }
       ```
   
 * Your function will be called when the plugin function calls `apply_filters`.
 *  [mrtom414](https://wordpress.org/support/users/mrtom414/)
 * (@mrtom414)
 * [6 years, 8 months ago](https://wordpress.org/support/topic/calling-class-with-data/#post-11968899)
 * did you create an instance of the class. myinstant = new definedClass
 * then you can access the members of the object.
    myinstant->classMethod
 * Try looking at object oriented php

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘calling class with data’ is closed to new replies.

## Tags

 * [classes](https://wordpress.org/support/topic-tag/classes/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 3 participants
 * Last reply from: [mrtom414](https://wordpress.org/support/users/mrtom414/)
 * Last activity: [6 years, 8 months ago](https://wordpress.org/support/topic/calling-class-with-data/#post-11968899)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
