0, 'number' => '', 'text' => '', 'class' => 'easy-invoice-url', 'target' => '_blank' ], $atts, 'easy_invoice_url'); // Get invoice by ID or number $invoice = null; if (!empty($atts['id'])) { $invoice = \EasyInvoice\Providers\InvoiceServiceProvider::getInvoiceRepository()->find($atts['id']); } elseif (!empty($atts['number'])) { $invoice = \EasyInvoice\Providers\InvoiceServiceProvider::getInvoiceRepository()->findByNumber($atts['number']); } if (!$invoice) { return '' . __('Invoice not found', 'easy-invoice') . ''; } $url = get_permalink($invoice->getId()); // Only use secure link if enabled in settings and available $secure_links_enabled = get_option('easy_invoice_pro_enable_secure_links', 'no') === 'yes'; if ($secure_links_enabled && class_exists('\EasyInvoicePro\Addons\SecureLinks\Controllers\PermalinkController')) { $secure_url = \EasyInvoicePro\Addons\SecureLinks\Controllers\PermalinkController::getInvoiceSecureLinkUrl($invoice->getId()); if ($secure_url) { $url = $secure_url; } } $text = !empty($atts['text']) ? $atts['text'] : $invoice->getNumber(); $class = esc_attr($atts['class']); $target = esc_attr($atts['target']); return sprintf( '%s', esc_url($url), $class, $target, esc_html($text) ); } /** * Render quote URL shortcode * * @param array $atts Shortcode attributes * @return string Rendered shortcode */ public function renderQuoteUrl($atts) { $atts = shortcode_atts([ 'id' => 0, 'number' => '', 'text' => '', 'class' => 'easy-quote-url', 'target' => '_blank' ], $atts, 'easy_quote_url'); // Get quote by ID or number $quote = null; if (!empty($atts['id'])) { $quote = \EasyInvoice\Providers\QuoteServiceProvider::getQuoteRepository()->find($atts['id']); } elseif (!empty($atts['number'])) { $quote = \EasyInvoice\Providers\QuoteServiceProvider::getQuoteRepository()->findByNumber($atts['number']); } if (!$quote) { return '' . __('Quote not found', 'easy-invoice') . ''; } $url = get_permalink($quote->getId()); $secure_links_enabled = get_option('easy_invoice_pro_enable_secure_links', 'no') === 'yes'; if ($secure_links_enabled && class_exists('\EasyInvoicePro\Addons\SecureLinks\Controllers\PermalinkController')) { $secure_url = \EasyInvoicePro\Addons\SecureLinks\Controllers\PermalinkController::getQuoteSecureLinkUrl($quote->getId()); if ($secure_url) { $url = $secure_url; } } $text = !empty($atts['text']) ? $atts['text'] : $quote->getNumber(); $class = esc_attr($atts['class']); $target = esc_attr($atts['target']); return sprintf( '%s', esc_url($url), $class, $target, esc_html($text) ); } /** * Add shortcode help to the help tab */ public function addShortcodeHelp() { $screen = get_current_screen(); if ($screen && ($screen->id === 'easy-invoice_page_easy-invoice-settings' || $screen->id === 'edit-easy_invoice')) { $screen->add_help_tab([ 'id' => 'easy-invoice-shortcodes', 'title' => __('Shortcodes', 'easy-invoice'), 'content' => $this->getShortcodeHelpContent() ]); } } /** * Get shortcode help content * * @return string Help content */ private function getShortcodeHelpContent() { $content = '
[easy_invoice_url]' . __('Displays a link to an invoice.', 'easy-invoice') . '
'; $content .= 'id - ' . __('Invoice ID (required if number is not provided)', 'easy-invoice') . 'number - ' . __('Invoice number (required if id is not provided)', 'easy-invoice') . 'text - ' . __('Link text (default: invoice number)', 'easy-invoice') . 'class - ' . __('CSS class for the link (default: easy-invoice-url)', 'easy-invoice') . 'target - ' . __('Link target (default: _blank)', 'easy-invoice') . '[easy_invoice_url id="123" text="View Invoice"]';
$content .= '[easy_invoice_url number="INV-001" text="Click here to view"]';
$content .= '[easy_quote_url]' . __('Displays a link to a quote.', 'easy-invoice') . '
'; $content .= 'id - ' . __('Quote ID (required if number is not provided)', 'easy-invoice') . 'number - ' . __('Quote number (required if id is not provided)', 'easy-invoice') . 'text - ' . __('Link text (default: quote number)', 'easy-invoice') . 'class - ' . __('CSS class for the link (default: easy-quote-url)', 'easy-invoice') . 'target - ' . __('Link target (default: _blank)', 'easy-invoice') . '[easy_quote_url id="456" text="View Quote"]';
$content .= '[easy_quote_url number="QT-001" text="Click here to view"]';
return $content;
}
}