TEXT   31

Appsero - Client

Guest on 22nd August 2022 01:24:04 AM

  1. # Appsero - Client
  2.  
  3. - [Installation](#installation)
  4. - [Insights](#insights)
  5. - [Dynamic Usage](#dynamic-usage)
  6.  
  7.  
  8. ## Installation
  9.  
  10. You can install AppSero Client in two ways, via composer and manually.
  11.  
  12. ### 1. Composer Installation
  13.  
  14. Add dependency in your project (theme/plugin):
  15.  
  16. ```
  17. composer require appsero/client
  18. ```
  19.  
  20. Now add `autoload.php` in your file if you haven't done already.
  21.  
  22. ```php
  23. require __DIR__ . '/vendor/autoload.php';
  24. ```
  25.  
  26. ### 2. Manual Installation
  27.  
  28. Clone the repository in your project.
  29.  
  30. ```
  31. cd /path/to/your/project/folder
  32. git clone https://github.com/AppSero/client.git appsero
  33. ```
  34.  
  35. Now include the dependencies in your plugin/theme.
  36.  
  37. ```php
  38. require __DIR__ . '/appsero/src/Client.php';
  39. ```
  40.  
  41. ## Insights
  42.  
  43. AppSero can be used in both themes and plugins.
  44.  
  45. The `Appsero\Client` class has *three* parameters:
  46.  
  47. ```php
  48. $client = new Appsero\Client( $hash, $name, $file );
  49. ```
  50.  
  51. - **hash** (*string*, *required*) - The unique identifier for a plugin or theme.
  52. - **name** (*string*, *required*) - The name of the plugin or theme.
  53. - **file** (*string*, *required*) - The **main file** path of the plugin. For theme, path to `functions.php`
  54.  
  55. ### Usage Example
  56.  
  57. Please refer to the **installation** step before start using the class.
  58.  
  59. You can obtain the **hash** for your plugin for the [Appsero Dashboard](https://dashboard.appsero.com). The 3rd parameter **must** have to be the main file of the plugin.
  60.  
  61. ```php
  62. /**
  63.  * Initialize the tracker
  64.  *
  65.  * @return void
  66.  */
  67. function appsero_init_tracker_appsero_test() {
  68.  
  69.     if ( ! class_exists( 'Appsero\Client' ) ) {
  70.         require_once __DIR__ . '/appsero/src/Client.php';
  71.     }
  72.  
  73.     $client = new Appsero\Client( 'a4a8da5b-b419-4656-98e9-4a42e9044891', 'Akismet', __FILE__ );
  74.  
  75.     // Active insights
  76.     $client->insights()->init();
  77.  
  78.     // Active automatic updater
  79.     $client->updater();
  80.  
  81.     // Active license page and checker
  82.     $args = array(
  83.         'type'       => 'options',
  84.         'menu_title' => 'Akismet',
  85.         'page_title' => 'Akismet License Settings',
  86.         'menu_slug'  => 'akismet_settings',
  87.     );
  88.     $client->license()->add_settings_page( $args );
  89. }
  90.  
  91. appsero_init_tracker_appsero_test();
  92. ```
  93.  
  94. Make sure you call this function directly, never use any action hook to call this function.
  95.  
  96. > For plugins example code that needs to be used on your main plugin file.
  97. > For themes example code that needs to be used on your themes `functions.php` file.
  98.  
  99. ## More Usage
  100.  
  101. ```php
  102. $client = new Appsero\Client( 'a4a8da5b-b419-4656-98e9-4a42e9044892', 'Twenty Twelve', __FILE__ );
  103. ```
  104.  
  105. #### 1. Hiding the notice
  106.  
  107. Sometimes you wouldn't want to show the notice, or want to customize the notice message. You can do that as well.
  108.  
  109. ```php
  110. $client->insights()
  111.        ->hide_notice()
  112.        ->init();
  113. ```
  114.  
  115. #### 2. Customizing the notice message
  116.  
  117. ```php
  118. $client->insights()
  119.        ->notice( 'My Custom Notice Message' )
  120.        ->init();
  121. ```
  122.  
  123. #### 3. Adding extra data
  124.  
  125. You can add extra metadata from your theme or plugin. In that case, the **keys** has to be whitelisted from the Appsero dashboard.
  126. `add_extra` method also support callback as parameter, If you need database call then callback is best for you.
  127.  
  128. ```php
  129. $metadata = array(
  130.     'key'     => 'value',
  131.     'another' => 'another_value'
  132. );
  133. $client->insights()
  134.        ->add_extra( $metadata )
  135.        ->init();
  136. ```
  137.  
  138. Or if you want to run a query then pass callback, we will call the function when it is necessary.
  139.  
  140. ```php
  141. $metadata = function () {
  142.     $total_posts = wp_count_posts();
  143.  
  144.     return array(
  145.         'total_posts' => $total_posts,
  146.         'another'     => 'another_value'
  147.     );
  148. };
  149. $client->insights()
  150.        ->add_extra( $metadata )
  151.        ->init();
  152. ```
  153.  
  154. #### 4. Set textdomain
  155.  
  156. You may set your own textdomain to translate text.
  157.  
  158. ```php
  159. $client->set_textdomain( 'your-project-textdomain' );
  160. ```
  161.  
  162. ---
  163.  
  164. ### Check License Validity
  165.  
  166. Check your plugin/theme is using with valid license or not, First create a global variable of `License` object then use it anywhere in your code.
  167. If you are using it outside of same function make sure you global the variable before using the condition.
  168.  
  169. ```php
  170. $client = new Appsero\Client( 'a4a8da5b-b419-4656-98e9-4a42e9044892', 'Twenty Twelve', __FILE__ );
  171.  
  172. $args = array(
  173.     'type'        => 'submenu',
  174.     'menu_title'  => 'Twenty Twelve License',
  175.     'page_title'  => 'Twenty Twelve License Settings',
  176.     'menu_slug'   => 'twenty_twelve_settings',
  177.     'parent_slug' => 'themes.php',
  178. );
  179.  
  180. global $twenty_twelve_license;
  181. $twenty_twelve_license = $client->license();
  182. $twenty_twelve_license->add_settings_page( $args );
  183.  
  184. if ( $twenty_twelve_license->is_valid()  ) {
  185.     // Your special code here
  186. }
  187.  
  188. Or check by pricing plan title
  189.  
  190. if ( $twenty_twelve_license->is_valid_by( 'title', 'Business' ) ) {
  191.     // Your special code here
  192. }
  193.  
  194. // Set custom options key for storing the license info
  195. $twenty_twelve_license->set_option_key( 'my_plugin_license' );
  196. ```
  197.  
  198. ### Use your own license form
  199.  
  200. You can easily manage license by creating a form using HTTP request. Call `license_form_submit` method from License object.
  201.  
  202. ```php
  203. global $twenty_twelve_license; // License object
  204. $twenty_twelve_license->license_form_submit([
  205.     '_nonce'      => wp_create_nonce( 'Twenty Twelve' ), // create a nonce with name
  206.     '_action'     => 'active', // active, deactive
  207.     'license_key' => 'random-license-key', // no need to provide if you want to deactive
  208. ]);
  209. if ( ! $twenty_twelve_license->error ) {
  210.     // license activated
  211.     $twenty_twelve_license->success; // Success message is here
  212. } else {
  213.     $twenty_twelve_license->error; // has error message here
  214. }
  215. ```
  216.  
  217. ### Set Custom Deactivation Reasons
  218.  
  219. First set your deactivation reasons in Appsero dashboard then map them in your plugin/theme using filter hook.
  220.  
  221. - **id** is the deactivation slug
  222. - **text** is the deactivation title
  223. - **placeholder** will show on textarea field
  224. - **icon** You can set SVG icon with 23x23 size
  225.  
  226. ```php
  227. add_filter( 'appsero_custom_deactivation_reasons', function () {
  228.     return [
  229.         [
  230.             'id'          => 'looks-buggy',
  231.             'text'        => 'Looks buggy',
  232.             'placeholder' => 'Can you please tell which feature looks buggy?',
  233.             'icon'        => '',
  234.         ],
  235.         [
  236.             'id'          => 'bad-ui',
  237.             'text'        => 'Bad UI',
  238.             'placeholder' => 'Could you tell us a bit more?',
  239.             'icon'        => '',
  240.         ],
  241.     ];
  242. } );
  243. ```
  244.  
  245. ## Credits
  246.  
  247. Created and maintained by [Appsero](https://appsero.com).

Raw Paste


Login or Register to edit or fork this paste. It's free.