meets_minimum_requirements();
if ( ! $meets_requirements['meets_requirements'] ) {
return;
}
add_filter( 'gravityflow_menu_items', array( $this, 'menu_items' ) );
add_filter( 'gravityflow_toolbar_menu_items', array( $this, 'toolbar_menu_items' ) );
}
/**
* If the extensions minimum requirements are met add the admin hooks.
*/
public function init_admin() {
parent::init_admin();
$meets_requirements = $this->meets_minimum_requirements();
if ( ! $meets_requirements['meets_requirements'] ) {
return;
}
add_filter( 'gravityflow_settings_menu_tabs', array( $this, 'app_settings_tabs' ) );
add_filter( 'plugin_action_links', array( $this, 'plugin_settings_link' ), 10, 2 );
// Members 2.0+ Integration.
if ( function_exists( 'members_register_cap_group' ) ) {
remove_filter( 'members_get_capabilities', array( $this, 'members_get_capabilities' ) );
add_filter( 'gravityflow_members_capabilities', array( $this, 'get_members_capabilities' ) );
}
}
/**
* Add the extension capabilities to the Gravity Flow group in Members.
*
* Override to provide human readable labels.
*
* @since 1.8.1-dev
*
* @param array $caps The capabilities and their human readable labels.
*
* @return array
*/
public function get_members_capabilities( $caps ) {
foreach ( $this->_capabilities as $capability ) {
$caps[ $capability ] = $capability;
}
return $caps;
}
/**
* Add a tab to the app settings page for this extension.
*
* @param array $settings_tabs The app settings tabs.
*
* @return array
*/
public function app_settings_tabs( $settings_tabs ) {
$settings_tabs[] = array(
'name' => $this->_slug,
'label' => $this->get_short_title(),
'callback' => array( $this, 'app_settings_tab' ),
);
return $settings_tabs;
}
/**
* The callback for this extensions app settings tab.
*/
public function app_settings_tab() {
require_once( GFCommon::get_base_path() . '/tooltips.php' );
$icon = $this->app_settings_icon();
if ( empty( $icon ) ) {
$icon = '';
}
?>
app_settings_title() ?>
maybe_uninstall() ) {
?>
maybe_save_app_settings();
// Reads main add-on settings.
$settings = $this->get_app_settings();
$this->set_settings( $settings );
// Reading add-on fields.
$sections = $this->app_settings_fields();
GFCommon::display_admin_message();
// Rendering settings based on fields and current settings.
$this->render_settings( $sections );
$this->render_uninstall();
}
}
/**
* Override this function to customize the markup for the uninstall section on the plugin settings page
*/
public function render_uninstall() {
?>
$this->get_short_title(),
'fields' => array(
array(
'name' => 'license_key',
'label' => esc_html__( 'License Key', 'gravityflow' ),
'type' => 'text',
'validation_callback' => array( $this, 'license_validation' ),
'feedback_callback' => array( $this, 'license_feedback' ),
'error_message' => __( 'Invalid license', 'gravityflow' ),
'class' => 'large',
'default_value' => '',
),
),
),
);
}
/**
* Return the saved settings.
*
* @return mixed
*/
public function get_app_settings() {
return parent::get_app_settings();
}
/**
* Validate the license key setting.
*
* @param string $value The field value; the license key.
* @param array $field The field properties.
*
* @return bool|null
*/
public function license_feedback( $value, $field ) {
if ( empty( $value ) ) {
return null;
}
$license_data = $this->check_license( $value );
$valid = null;
if ( empty( $license_data ) || $license_data->license == 'invalid' ) {
$valid = false;
} elseif ( $license_data->license == 'valid' ) {
$valid = true;
}
return $valid;
}
/**
* Retrieve the license data.
*
* @param string $value The license key for this extension.
*
* @return array|mixed|object
*/
public function check_license( $value ) {
$response = gravity_flow()->perform_edd_license_request( 'check_license', $value, $this->edd_item_name );
return json_decode( wp_remote_retrieve_body( $response ) );
}
/**
* Deactivate the old license key and active the new license key.
*
* @param array $field The field properties.
* @param string $field_setting The field value; the license key.
*/
public function license_validation( $field, $field_setting ) {
$old_license = $this->get_app_setting( 'license_key' );
if ( $old_license && $field_setting != $old_license ) {
$response = gravity_flow()->perform_edd_license_request( 'deactivate_license', $old_license, $this->edd_item_name );
$this->log_debug( __METHOD__ . '(): response: ' . print_r( $response, 1 ) );
}
if ( empty( $field_setting ) ) {
return;
}
$this->activate_license( $field_setting );
}
/**
* Activate the license key.
*
* @param string $license_key The license key for this extension.
*
* @return array|mixed|object
*/
public function activate_license( $license_key ) {
$response = gravity_flow()->perform_edd_license_request( 'activate_license', $license_key, $this->edd_item_name );
// Force plugins page to refresh the update info.
set_site_transient( 'update_plugins', null );
$cache_key = md5( 'edd_plugin_' . sanitize_key( $this->_path ) . '_version_info' );
delete_transient( $cache_key );
return json_decode( wp_remote_retrieve_body( $response ) );
}
/**
* Override to add menu items to the Gravity Flow app menu.
*
* @param array $menu_items The app menu items.
*
* @return array
*/
public function menu_items( $menu_items ) {
return $menu_items;
}
/**
* Override to add menu items to the Gravity Flow toolbar.
*
* @param array $menu_items The toolbar menu items.
*
* @return array
*/
public function toolbar_menu_items( $menu_items ) {
return $menu_items;
}
/**
* Prevent the failed requirements page being added to the Forms > Settings area.
* Add the settings link to the installed plugins page.
*
* @since 1.7.1-dev
*/
public function failed_requirements_init() {
$failed_requirements = $this->meets_minimum_requirements();
// Prepare errors list.
$errors = '';
foreach ( $failed_requirements['errors'] as $error ) {
$errors .= sprintf( '%s', esc_html( $error ) );
}
// Prepare error message.
$error_message = sprintf(
'%s
%s%s
',
sprintf( esc_html__( '%s is not able to run because your WordPress environment has not met the minimum requirements.', 'gravityflow' ), $this->_title ),
sprintf( esc_html__( 'Please resolve the following issues to use %s:', 'gravityflow' ), $this->get_short_title() ),
$errors
);
// Add error message.
GFCommon::add_error_message( $error_message );
}
/**
* Determine if the add-ons minimum requirements have been met with Gravity Forms 2.2+.
*
* @since 1.8.1-dev
*
* @return array
*/
public function meets_minimum_requirements() {
if ( $this->is_gravityforms_supported( '2.2' ) ) {
return parent::meets_minimum_requirements();
}
return array( 'meets_requirements' => true, 'errors' => array() );
}
/**
* Add the settings link for the extension to the installed plugins page.
*
* @param array $links An array of plugin action links.
* @param string $file Path to the plugin file relative to the plugins directory.
*
* @since 1.7.1-dev
*
* @return array
*/
public function plugin_settings_link( $links, $file ) {
if ( $file != $this->_path ) {
return $links;
}
array_unshift( $links, '' . esc_html__( 'Settings', 'gravityflow' ) . '' );
return $links;
}
}