EasyDigitalDownloads
3 years ago
Elementor
2 years ago
Integrations
3 years ago
MemberPress
2 years ago
Plugins
2 years ago
Promos
3 years ago
Rules
2 years ago
Shortcodes
2 years ago
WPForms
1 year ago
WooCommerce
1 year ago
Actions.php
1 year ago
Ajax.php
4 years ago
Api.php
1 year ago
ApiAuth.php
4 years ago
ApiKey.php
1 year ago
AssetLoader.php
5 years ago
BaseRestApi.php
3 years ago
Blocks.php
1 year ago
ClassicEditor.php
3 years ago
ConstantContact.php
1 year ago
Debug.php
1 year ago
EasyDigitalDownloads.php
1 year ago
Elementor.php
3 years ago
Inserter.php
3 years ago
InstallSkin.php
5 years ago
InstallSkinCompat.php
5 years ago
MailPoet.php
1 year ago
MemberPress.php
2 years ago
Menu.php
1 year ago
Notifications.php
1 year ago
OmuApi.php
4 years ago
Output.php
1 year ago
Pages.php
1 year ago
Partners.php
1 year ago
Plugins.php
2 years ago
Promos.php
3 years ago
Refresh.php
1 year ago
RestApi.php
1 year ago
RevenueAttribution.php
4 years ago
Review.php
4 years ago
Rules.php
1 year ago
Save.php
2 years ago
Shortcode.php
4 years ago
Sites.php
1 year ago
Support.php
1 year ago
Type.php
3 years ago
Urls.php
1 year ago
Utils.php
1 year ago
Validate.php
2 years ago
WPForms.php
2 years ago
Welcome.php
4 years ago
Widget.php
4 years ago
WooCommerce.php
1 year ago
Wordfence.php
3 years ago
WpErrorException.php
5 years ago
WPForms.php
141 lines
| 1 | <?php |
| 2 | /** |
| 3 | * WPForms class. |
| 4 | * |
| 5 | * @since 2.9.0 |
| 6 | * |
| 7 | * @package OMAPI |
| 8 | * @author Eduardo Nakatsuka |
| 9 | */ |
| 10 | |
| 11 | // Exit if accessed directly. |
| 12 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | exit; |
| 14 | } |
| 15 | |
| 16 | /** |
| 17 | * The WPForms class. |
| 18 | * |
| 19 | * @since 2.9.0 |
| 20 | */ |
| 21 | class OMAPI_WPForms extends OMAPI_Integrations_Base { |
| 22 | |
| 23 | /** |
| 24 | * The OMAPI_WPForms_RestApi instance. |
| 25 | * |
| 26 | * @since 2.13.0 |
| 27 | * |
| 28 | * @var null|OMAPI_WPForms_RestApi |
| 29 | */ |
| 30 | public $rest = null; |
| 31 | |
| 32 | /** |
| 33 | * Holds the instance of OMAPI_WPForms_Save. |
| 34 | * |
| 35 | * @var null|OMAPI_WPForms_Save |
| 36 | */ |
| 37 | public $save = null; |
| 38 | |
| 39 | /** |
| 40 | * Primary class constructor. |
| 41 | * |
| 42 | * @since 2.9.0 |
| 43 | */ |
| 44 | public function __construct() { |
| 45 | parent::__construct(); |
| 46 | $this->save = new OMAPI_WPForms_Save(); |
| 47 | |
| 48 | add_action( 'optin_monster_api_rest_register_routes', array( $this, 'maybe_init_rest_routes' ) ); |
| 49 | |
| 50 | // When WPForms is activated, connect it. |
| 51 | add_action( 'activate_wpforms-lite/wpforms.php', array( $this->save, 'connect' ) ); |
| 52 | add_action( 'activate_wpforms/wpforms.php', array( $this->save, 'connect' ) ); |
| 53 | |
| 54 | // When WPForms is deactivated, disconnect. |
| 55 | add_action( 'deactivate_wpforms-lite/wpforms.php', array( $this->save, 'disconnect' ) ); |
| 56 | add_action( 'deactivate_wpforms/wpforms.php', array( $this->save, 'disconnect' ) ); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Check if the WPForms plugin is active. |
| 61 | * |
| 62 | * @since 2.9.0 |
| 63 | * |
| 64 | * @return bool |
| 65 | */ |
| 66 | public static function is_active() { |
| 67 | return class_exists( 'WPForms', true ); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Get WPForms forms array containing label and value. |
| 72 | * |
| 73 | * @since 2.9.0 |
| 74 | * |
| 75 | * @return array |
| 76 | */ |
| 77 | public function get_forms_array() { |
| 78 | $forms = $this->get_forms(); |
| 79 | $result = array(); |
| 80 | |
| 81 | if ( empty( $forms ) || ! is_array( $forms ) ) { |
| 82 | return $result; |
| 83 | } |
| 84 | |
| 85 | foreach ( $forms as $form ) { |
| 86 | $result[] = array( |
| 87 | 'value' => $form->ID, |
| 88 | 'label' => $form->post_title, |
| 89 | ); |
| 90 | } |
| 91 | |
| 92 | return $result; |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * Get forms from WPForms plugin. |
| 97 | * |
| 98 | * @since 2.9.0 |
| 99 | * |
| 100 | * @return array All the forms in WPForms plugin. |
| 101 | */ |
| 102 | public function get_forms() { |
| 103 | if ( ! function_exists( 'wpforms' ) ) { |
| 104 | return array(); |
| 105 | } |
| 106 | |
| 107 | return wpforms()->form->get( '', array( 'order' => 'DESC' ) ); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Get the currently installed WPForms version. |
| 112 | * |
| 113 | * @since 2.9.0 |
| 114 | * |
| 115 | * @return string The WPForms version. |
| 116 | */ |
| 117 | public static function version() { |
| 118 | if ( ! function_exists( 'wpforms' ) ) { |
| 119 | return '0.0.0'; |
| 120 | } |
| 121 | |
| 122 | $version = wpforms()->version; |
| 123 | |
| 124 | return $version ? $version : '0.0.0'; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Initiate our REST routes for EDD if EDD active. |
| 129 | * |
| 130 | * @since 2.13.0 |
| 131 | * |
| 132 | * @return void |
| 133 | */ |
| 134 | public function maybe_init_rest_routes() { |
| 135 | if ( self::is_active() ) { |
| 136 | $this->rest = new OMAPI_WPForms_RestApi( $this ); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | } |
| 141 |