options = $options;
$this->settings = $settings;
$this->isSwitchingVersions = false;
}
// static, as called also in AcfGroup
public static function isAcfProPluginAvailable(): bool
{
return class_exists('acf_pro');
}
public static function getThemeTextDomain(): string
{
return (string)wp_get_theme()->get('TextDomain');
}
public static function getLabelTranslation(string $label, string $textDomain = ''): string
{
$textDomain = $textDomain ?: self::getThemeTextDomain();
// escape quotes to keep compatibility with the generated translation file
// (quotes there escaped to prevent breaking the PHP string)
$label = str_replace("'", "'", $label);
$label = str_replace('"', """, $label);
$translation = __($label, $textDomain);
$translation = str_replace("'", "'", $translation);
$translation = str_replace(""", '"', $translation);
return $translation;
}
protected function amendProFieldLabelAndInstruction(array $field): array
{
$isProField = key_exists('a-pro', $field) &&
$this->isProFieldLocked();
$isAcfProField = !$this->isAcfPluginAvailable(true) &&
key_exists('a-acf-pro', $field);
if (!$isProField &&
!$isAcfProField) {
return $field;
}
$type = $field['type'] ?? '';
$field['label'] = $field['label'] ?? '';
$field['instructions'] = $field['instructions'] ?? '';
if ($isProField) {
$field['label'] = $field['label'] . ' (Pro)';
if ('tab' !== $type) {
$label = !$this->isProVersion() ?
__('Upgrade to Pro', 'acf-views') :
__('Activate your license', 'acf-views');
$link = !$this->isProVersion() ?
Plugin::PRO_VERSION_URL :
$this->getAdminUrl(Dashboard::PAGE_PRO);
$field['instructions'] = sprintf(
'%s %s %s',
$link,
$label,
__('to unlock.', 'acf-views'),
"
" . $field['instructions']
);
}
}
if ($isAcfProField) {
$field['instructions'] = sprintf(
'(%s %s) %s',
'https://www.advancedcustomfields.com/pro/',
__('ACF Pro', 'acf-views'),
__('version is required for this feature', 'acf-views'),
$field['instructions']
);
}
return $field;
}
protected function addDeprecatedFieldClass(array $field): array
{
if (!key_exists('a-deprecated', $field)) {
return $field;
}
if (!key_exists('wrapper', $field)) {
$field['wrapper'] = [];
}
if (!key_exists('class', $field['wrapper'])) {
$field['wrapper']['class'] = '';
}
$field['wrapper']['class'] .= ' acf-field--deprecated';
return $field;
}
public function isProFieldLocked(): bool
{
return !$this->isProVersion() ||
!$this->settings->isActiveLicense();
}
public function getName(): string
{
return __('Advanced Views Lite', 'acf-views');
}
public function getSlug(): string
{
return $this->slug;
}
public function getShortSlug(): string
{
return $this->shortSlug;
}
public function getVersion(): string
{
// return strval(time());
return $this->version;
}
public function isProVersion(): bool
{
return $this->isProVersion;
}
public function getAssetsUrl(string $file): string
{
return plugin_dir_url(__FILE__) . 'Assets/' . $file;
}
public function getAcfProAssetsUrl(string $file): string
{
return plugin_dir_url(__FILE__) . 'AcfPro/assets/' . $file;
}
public function isAcfPluginAvailable(bool $isProOnly = false): bool
{
// don't use 'is_plugin_active()' as the function available lately
return static::isAcfProPluginAvailable() ||
(!$isProOnly && class_exists('ACF'));
}
public function showWarningAboutInactiveAcfPlugin(): void
{
if ($this->isAcfPluginAvailable()) {
return;
}
$acfPluginInstallLink = get_admin_url(null, static::ACF_INSTALL_URL);
$acfFree = 'https://wordpress.org/plugins/advanced-custom-fields/';
$acfPro = 'https://www.advancedcustomfields.com/pro/';
echo sprintf(
'
%s
%s %s
%s
' . '