/home/vianto5/heredit.mx/wp-content/plugins/wpforms/src/Pro/Admin/Pages
Edit: /home/vianto5/heredit.mx/wp-content/plugins/wpforms/src/Pro/Admin/Pages/Addons.php (13648B)
allow_load() || $is_loaded ) {
return;
}
$this->can_install = wpforms_can_install( 'addon' );
$this->license_type = wpforms_get_license_type();
$this->init_addons();
$this->hooks();
$is_loaded = true;
}
/**
* Hooks.
*
* @since 1.6.7
*/
public function hooks() {
add_action( 'admin_enqueue_scripts', [ $this, 'enqueues' ] );
add_action( 'admin_notices', [ $this, 'notices' ] );
add_action( 'wpforms_admin_page', [ $this, 'output' ] );
}
/**
* Init addons data.
*
* @since 1.6.7
*/
public function init_addons() {
$this->refresh = ! empty( $_GET['wpforms_refresh_addons'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$this->addons = wpforms()->obj( 'addons' )->get_all( $this->refresh );
}
/**
* Enqueue assets for the addons page.
*
* @since 1.6.7
*/
public function enqueues() {
// JavaScript.
wp_enqueue_script(
'listjs',
WPFORMS_PLUGIN_URL . 'assets/lib/list.min.js',
[ 'jquery' ],
'1.5.0',
false
);
}
/**
* Build the output for the plugin addons page.
*
* @since 1.6.7
*/
public function output() {
// The last attempt to obtain the addons data.
if ( empty( $this->addons ) ) {
$this->init_addons();
}
?>
addons ) ) {
echo '
';
return;
}
$installed_addons = $this->get_addons_grid( 'activated' );
$all_addons = $this->get_addons_grid( 'all' );
?>
obj( 'license' )->get_errors();
if ( empty( $this->addons ) ) {
Notice::error( esc_html__( 'There was an issue retrieving Addons for this site. Please click on the button above to refresh.', 'wpforms' ) );
return;
}
if ( ! empty( $errors ) ) {
Notice::error( esc_html__( 'In order to get access to Addons, you need to resolve your license key errors.', 'wpforms' ) );
return;
}
if ( $this->refresh ) {
Notice::success( esc_html__( 'Addons have successfully been refreshed.', 'wpforms' ) );
}
}
/**
* Render grid of addons.
*
* @since 1.6.7
*
* @param string $section Section name.
*/
public function get_addons_grid( string $section ) {
$addons = $this->get_prepared_addons();
$addons = $addons[ $section ] ?? [];
ob_start();
foreach ( $addons as $addon ) {
$this->print_addon( $addon );
}
return ob_get_clean();
}
/**
* Get prepared addons.
*
* @since 1.8.9
*
* @return array
*/
private function get_prepared_addons(): array {
$prepared_addons = [];
foreach ( $this->addons as $addon ) {
$addon = (array) $addon;
$addon = wpforms()->obj( 'addons' )->get_addon( $addon['slug'] );
// Prepare activated addons.
if ( $this->should_display_addon( $addon, 'activated' ) ) {
$prepared_addons['activated'][] = $addon;
}
// Prepare all addons. Not including activated addons.
if ( $this->should_display_addon( $addon, 'all' ) && ! in_array( $addon, $prepared_addons['activated'] ?? [], true ) ) {
$prepared_addons['all'][] = $addon;
}
}
// Sort activated addons by title.
if ( ! empty( $prepared_addons['activated'] ) ) {
$prepared_addons['activated'] = wp_list_sort( $prepared_addons['activated'], 'title' );
}
return $prepared_addons;
}
/**
* Determine if addon should be displayed.
*
* @since 1.8.6
*
* @param array $addon Addon information.
* @param string $section Section name.
*/
private function should_display_addon( array $addon, string $section ): bool {
$should_display = false;
if ( $section === 'activated' ) {
$allowed_statuses = [ 'active', 'incompatible' ];
$current_license_type = wpforms_get_license_type();
$should_display = in_array( $addon['status'], $allowed_statuses, true ) && in_array( $current_license_type, $addon['license'], true );
} elseif ( $section === 'all' ) {
$allowed_statuses = [ 'active', 'incompatible', 'installed', 'missing' ];
$should_display = in_array( $addon['status'], $allowed_statuses, true );
}
return $should_display;
}
/**
* Print addon.
*
* @since 1.6.7
*
* @param array $addon Addon information.
*/
private function print_addon( $addon ) {
$image = ! empty( $addon['icon'] ) ? $addon['icon'] : 'sullie.png';
$url = add_query_arg(
[
'utm_source' => 'WordPress',
'utm_campaign' => 'plugin',
'utm_medium' => 'addons',
'utm_content' => $addon['title'],
],
! empty( $addon['status'] ) && in_array( $addon['status'], [ 'active', 'incompatible' ], true ) && $addon['plugin_allow'] ? $addon['doc_url'] : $addon['page_url']
);
echo wpforms_render( // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
'admin/addons-item',
[
'addon' => $addon,
'image' => WPFORMS_PLUGIN_URL . 'assets/images/' . $image,
'url' => $url,
'button' => $this->get_addon_button_html( $addon ),
'has_settings_link' => $this->has_settings_link( $addon['slug'] ),
'settings_url' => $this->get_settings_link( $addon['slug'] ),
'has_cap' => current_user_can( 'manage_options' ),
],
true
);
}
/**
* Get addon button HTML.
*
* @since 1.6.7
*
* @param array $addon Prepared addon data.
*
* @return string
*/
private function get_addon_button_html( $addon ) {
if ( $addon['action'] === 'upgrade' || $addon['action'] === 'license' || ! $addon['plugin_allow'] ) {
return sprintf(
'