Dashboard'; $links[] = $settings_link; return $links; } function hide_submenu_entries($submenu_file) { global $plugin_page; $hidden_submenus = array( AFFILILABS_SLUG . "-product-edit" => true, AFFILILABS_SLUG . "-marketplace-edit" => true, AFFILILABS_SLUG . "-criteria-edit" => true, AFFILILABS_SLUG . "-list-edit" => true, AFFILILABS_SLUG . "-template-editor" => true, AFFILILABS_SLUG . "-product-category-edit" => true, ); // highlight another submenu if ( $plugin_page && isset( $hidden_submenus[ $plugin_page ] ) ) { switch ($plugin_page) { case AFFILILABS_SLUG . "-product-edit": $submenu_file = AFFILILABS_SLUG . "-products"; break; case AFFILILABS_SLUG . "-marketplace-edit": $submenu_file = AFFILILABS_SLUG . "-marketplaces"; break; // break; case AFFILILABS_SLUG . "-criteria-edit": $submenu_file = AFFILILABS_SLUG . "-criteria"; break; case AFFILILABS_SLUG . "-list-edit": $submenu_file = AFFILILABS_SLUG . "-lists"; break; case AFFILILABS_SLUG . "-template-editor": $submenu_file = AFFILILABS_SLUG . "-templates"; break; case AFFILILABS_SLUG . "-product-category-edit": $submenu_file = AFFILILABS_SLUG . "-product-categories"; break; } } foreach ( $hidden_submenus as $submenu => $_ ) { remove_submenu_page(AFFILILABS_SLUG , $submenu ); } return $submenu_file; } function highlight_parent_menu($parent_file) { global $current_screen, $pagenow, $submenu_file; $is_current_page_product_categories = ( $pagenow == 'edit-tags.php' && $current_screen->post_type == AFFILILABS_CPT_PRODUCT && $current_screen->taxonomy == AFFILILABS_TAXONOMY_PRODUCT_CATEGORY ); if ($is_current_page_product_categories) { $parent_file = AFFILILABS_CLASSIC_SLUG; $submenu_file = "edit-tags.php?taxonomy=" . AFFILILABS_TAXONOMY_PRODUCT_CATEGORY . "&post_type=" . AFFILILABS_CPT_PRODUCT; } return $parent_file; } function enqueue_admin_scripts() { wp_enqueue_style('affililabs-common', AFFILILABS_COMMON_BASE_CSS_URL, array(), AFFILILABS_VERSION); } function enqueue_frontend_scripts() { if ( is_singular( AFFILILABS_CPT_PRODUCT ) ) { wp_enqueue_style( 'affililabs-single-product', AFFILILABS_SINGLE_PRODUCT_TEMPLATE_CSS_URL, array(), AFFILILABS_VERSION ); // Logic to add inline styles/scripts from custom template affl_import(AFFILILABS_SERVICE_OPTIMIZEPRESS_FILE); if (class_exists('Affililabs_Optimizepress_Integration')) { $integration = new Affililabs_Optimizepress_Integration(); $op3_present = $integration->is_op3_present(); $template_enabled = AFFLSettingsService::get_enable_custom_template(); if (!$op3_present && $template_enabled) { $product_id = get_the_ID(); $template_id = get_post_meta($product_id, AFFILILABS_META_KEY_APPLIED_PRODUCT_TEMPLATE_ID, true); } } } wp_enqueue_style( 'affl-product-fields', AFFILILABS_SHORTCODE_PRODUCT_FIELDS_CSS_URL, array(), AFFILILABS_VERSION ); } function render_dashboard() { affl_import(AFFILILABS_DASHBOARD_FILE); } function render_marketplaces() { affl_import(AFFILILABS_MARKETPLACES_FILE); } function render_marketplace_edit() { affl_import(AFFILILABS_MARKETPLACE_EDIT_FILE); } function render_product_edit() { affl_import(AFFILILABS_PRODUCTS_EDIT_FILE); } function render_products() { affl_import(AFFILILABS_PRODUCTS_FILE); } function render_product_categories() { affl_import(AFFILILABS_PRODUCT_CATEGORIES_FILE); } function render_product_category_edit() { affl_import(AFFILILABS_PRODUCT_CATEGORY_EDIT_FILE); } function render_criteria() { affl_import(AFFILILABS_CRITERIA_FILE); } function render_criteria_edit() { affl_import(AFFILILABS_CRITERIA_EDIT_FILE); } function render_lists() { affl_import(AFFILILABS_LISTS_FILE); } function render_list_edit() { affl_import(AFFILILABS_LIST_EDIT_FILE); } function render_templates() { affl_import(AFFILILABS_TEMPLATES_FILE); } function render_template_editor() { affl_import(AFFILILABS_TEMPLATE_EDITOR_FILE); } function render_about_us() { affl_import(AFFILILABS_ABOUT_US_FILE); } function render_classic_links() { affl_import(AFFILILABS_CLASSIC_LINKS_FILE); } function render_settings() { affl_import(AFFILILABS_SETTINGS_FILE); } function render_logs_page() { affl_import(AFFILILABS_LOG_PAGE_FILE); } public function inject_single_product_template_content( $content ) { if ( is_singular( AFFILILABS_CPT_PRODUCT ) && in_the_loop() && is_main_query() ) { $integration = new Affililabs_Optimizepress_Integration(); $op3_present = $integration->is_op3_present(); $template_enabled = AFFLSettingsService::get_enable_custom_template(); if (!$op3_present && $template_enabled) { $product_id = get_the_ID(); $template_id = get_post_meta($product_id, AFFILILABS_META_KEY_APPLIED_PRODUCT_TEMPLATE_ID, true); if ( $template_id ) { $template = get_post($template_id); if ($template && $template->post_type === AFFILILABS_CPT_TEMPLATE) { $template_modules = get_post_meta($template_id, AFFILILABS_META_KEY_TEMPLATE_DATA, true); $output_html = ''; if (!empty($template_modules) && is_array($template_modules)) { foreach ($template_modules as $module) { $shortcode_output = do_shortcode('[affl_' . $module . ' id="' . $product_id . '"]'); if (!empty(trim($shortcode_output))) { $class_name = 'affl_' . str_replace('_', '-', $module); // Injecting the shortcode output into a div with a class for styling // The actual HTML structure will depend on how each shortcode is designed to render $output_html .= '
' . $shortcode_output . '
'; } } } $allowed_html = affl_get_allowed_html_tags(); return wp_kses($output_html, $allowed_html); } } } } return $content; } public function redirect_to_custom_product_template() { if (is_singular(AFFILILABS_CPT_PRODUCT)) { $enable_custom = AFFLSettingsService::get_enable_custom_template(); $enable_premium = AFFLSettingsService::get_enable_premium_template(); if (!$enable_custom && !$enable_premium) { return; } $product_id = get_the_ID(); $template_id = get_post_meta($product_id, AFFILILABS_META_KEY_APPLIED_PRODUCT_TEMPLATE_ID, true); // If premium view is enabled, we ignore the assigned template ID and use the absolute template // OR if no template is applied but custom template is enabled generally. if ($enable_premium || (!$template_id && $enable_custom)) { $new_template = AFFILILABS_SINGLE_PRODUCT_TEMPLATE_FILE; if (file_exists($new_template)) { include($new_template); exit(); } } } } public function redirect_product_category_taxonomy_to_category_page_cpt() { if (is_admin() || !is_tax(AFFILILABS_TAXONOMY_PRODUCT_CATEGORY)) { return; } // Keep taxonomy URLs active when the All Categories Page option is enabled. if (intval(AFFLSettingsService::get_enable_all_categories_page()) === 1) { return; } $term = get_queried_object(); if (!$term || is_wp_error($term) || !($term instanceof WP_Term)) { return; } $target_url = ''; if (class_exists('AffiliLabsCategoryPageCPT')) { $target_url = AffiliLabsCategoryPageCPT::get_permalink_for_term(intval($term->term_id), true); } if (empty($target_url)) { return; } $request_uri = isset($_SERVER['REQUEST_URI']) ? esc_url_raw(wp_unslash($_SERVER['REQUEST_URI'])) : ''; $current_path = trim((string) wp_parse_url($request_uri, PHP_URL_PATH), '/'); $target_path = trim((string) wp_parse_url($target_url, PHP_URL_PATH), '/'); if (!empty($current_path) && !empty($target_path) && $current_path === $target_path) { return; } wp_safe_redirect($target_url, 301); exit(); } public function template_include_category_page($template) { if (is_tax(AFFILILABS_TAXONOMY_PRODUCT_CATEGORY)) { $term = get_queried_object(); if (!$term || is_wp_error($term)) { return $template; } $term_id = intval($term->term_id); $posts = get_posts(array( 'post_type' => AFFILILABS_CPT_CATEGORY_PAGE, 'meta_key' => AFFILILABS_META_KEY_CATEGORY_PAGE_TERM, 'meta_value' => $term_id, 'post_status' => 'publish', 'posts_per_page' => 1, )); if (!empty($posts) && $posts[0]) { global $post; $post = $posts[0]; setup_postdata($post); $file = AFFILILABS_CATEGORY_PAGE_TEMPLATE_FILE; if (file_exists($file)) { include($file); exit(); } } } return $template; } } }