plugin_name = $plugin_name;
add_action('admin_menu', array($this, 'addPluginAdminMenu'), 9);
add_action('admin_init', [$this, 'register_settings_fields']);
add_filter('plugin_action_links_ar-model-viewer/ar-model-viewer.php', array($this, 'add_plugin_action_link'));
}
public static function is_premium_plan()
{
return self::PLUGIN_PLAN === 'premium';
}
public function addPluginAdminMenu()
{
add_submenu_page('options-general.php', 'AR Model Configurator Settings', 'AR Model Configurator', 'administrator', $this->plugin_name . '-settings', array($this, 'display_settings'));
}
public function add_plugin_action_link($links)
{
$url = esc_url(add_query_arg(
'page',
$this->plugin_name . '-settings',
get_admin_url() . 'admin.php'
));
// Create the link.
$settings_link = "" . __('Settings') . ' ';
// Adds the link to the end of the array.
array_push(
$links,
$settings_link
);
return $links;
}
public function display_settings()
{
echo '
AR Model Viewer ';
echo '';
$this->showInstalledProducts();
echo ' ';
$this->getFeedback();
}
public function register_settings_fields()
{
add_settings_section(
'ar_model_viewer_product_section',
__('', 'my-textdomain'),
function () {
$this->getSettingsHeader();
},
$this->plugin_name
);
add_settings_field(
'ar_model_viewer_option_' . self::PRODUCT_BTN_TEXT_KEY,
'Product Button Text',
function () {
echo ' ';
},
$this->plugin_name,
'ar_model_viewer_product_section'
);
add_settings_field(
'ar_model_viewer_option_' . self::AUTO_PLAY_ANIMATION,
'Autoplay Animation',
function () {
$auto_play_animation = $this->autoPlayAnimation() ? 'checked' : '';
echo ' ';
},
$this->plugin_name,
'ar_model_viewer_product_section'
);
if (self::is_premium_plan()) {
add_settings_field(
'ar_model_viewer_option_' . self::REMOVE_BRAND_KEY,
'Remove Branding',
function () {
$remove_brand_key_checked = $this->removeBrandKey() ? 'checked' : '';
echo ' ';
},
$this->plugin_name,
'ar_model_viewer_product_section'
);
add_settings_field(
'ar_model_viewer_option_' . self::REMOVE_DESKTOP_MODAL,
'Remove Desktop Modal',
function () {
$remove_desktop_modal_checked = $this->removeDesktopModal() ? 'checked' : '';
echo ' ';
},
$this->plugin_name,
'ar_model_viewer_product_section'
);
add_settings_field(
'ar_model_viewer_option_' . self::DESKTOP_MODAL_DESCRIPTION,
'Desktop Modal Description',
function () {
$description = $this->getDesktopModalDescription();
echo '';
},
$this->plugin_name,
'ar_model_viewer_product_section'
);
}
register_setting($this->plugin_name, self::AR_MODEL_VIEWER_SETTINGS);
}
public function getProductButtonText()
{
$options = self::getOptions();
$options = $this->getOptions();
return $options[self::PRODUCT_BTN_TEXT_KEY];
}
public function autoPlayAnimation()
{
$options = self::getOptions();
$value = $options[self::AUTO_PLAY_ANIMATION];
return !empty($value);
}
public function getDesktopModalDescription()
{
$options = self::getOptions();
return $options[self::DESKTOP_MODAL_DESCRIPTION];
}
public function removeBrandKey()
{
$options = self::getOptions();
$value = $options[self::REMOVE_BRAND_KEY];
return !empty($value);
}
public function removeDesktopModal()
{
$options = self::getOptions();
$value = $options[self::REMOVE_DESKTOP_MODAL];
return !empty($value);
}
public static function getOptions()
{
$defaultOptions = array(
self::PRODUCT_BTN_TEXT_KEY => "View In AR",
self::AUTO_PLAY_ANIMATION => '',
self::REMOVE_BRAND_KEY => '',
self::REMOVE_DESKTOP_MODAL => '',
self::DESKTOP_MODAL_DESCRIPTION => 'View this page on your mobile device to experience AR'
);
$options = get_option(self::AR_MODEL_VIEWER_SETTINGS);
if (empty($options)) {
$options = [];
}
$rs = array_merge($defaultOptions, $options);
return $rs;
}
public static function get3DProducts()
{
$post_ids = get_option(self::INSTALLED_3D_PRODUCTS, []);
if (is_array($post_ids)) {
return $post_ids;
}
return [];
}
private function showInstalledProducts()
{
if (self::PLUGIN_PLAN != 'pro') {
return;
}
$html = "List of Products with 3D Models ";
$products = self::get3DProducts();
if (empty($products)) {
$html .= 'No Products Found ';
} else {
$links = array_map(fn ($item) => '' . get_the_title($item) . ' ', $products);
$html .= implode(' | ', $links);
}
echo $html;
echo ' ';
}
private function getFeedback()
{
$feedbackHTML = '
We are always looking for ways to improve & would love to have a any valuable feedback from our customers. Please contact us to submit any query/feedback.
Contact Us
';
echo $feedbackHTML;
}
private function getSettingsHeader()
{
$headerHTML = '';
echo $headerHTML;
}
}