HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.30
System: Linux iZj6c1151k3ad370bosnmsZ 3.10.0-1160.76.1.el7.x86_64 #1 SMP Wed Aug 10 16:21:17 UTC 2022 x86_64
User: root (0)
PHP: 7.4.30
Disabled: NONE
Upload Files
File: /var/www/html/sparkle/wp-content/plugins/flexible-product-fields/src/Product/FieldsConfig.php
<?php

namespace WPDesk\FPF\Free\Product;

use VendorFPF\WPDesk\PluginBuilder\Plugin\Hookable;
use VendorFPF\WPDesk\PluginBuilder\Plugin\HookablePluginDependant;
use VendorFPF\WPDesk\PluginBuilder\Plugin\PluginAccess;
use VendorFPF\WPDesk\View\Renderer\SimplePhpRenderer;
use VendorFPF\WPDesk\View\Resolver\DirResolver;

/**
 * Supports feature "Save product config" for Administrator.
 */
class FieldsConfig implements Hookable, HookablePluginDependant {

	use PluginAccess;

	/**
	 * Class object for template rendering.
	 *
	 * @var SimplePhpRenderer
	 */
	private $renderer;

	public function __construct() {
		$this->set_renderer();
	}

	/**
	 * Init class for template rendering.
	 */
	private function set_renderer() {
		$this->renderer = new SimplePhpRenderer( new DirResolver( dirname( dirname( __DIR__ ) ) . '/templates' ) );
	}

	/**
	 * {@inheritdoc}
	 */
	public function hooks() {
		add_filter( 'woocommerce_before_add_to_cart_button', [ $this, 'show_save_config_button' ], 20 );
	}

	/**
	 * Displays button for generating URL with product config.
	 *
	 * @internal
	 */
	public function show_save_config_button() {
		if ( ! current_user_can( 'manage_options' ) ) {
			return;
		}

		echo $this->renderer->render( 'config/button-save' ); // phpcs:ignore
	}
}