🔄', esc_attr( $handle ), esc_attr( $nonce ), esc_attr__( 'Refresh Batch Requests', 'ai-content-by-parallax' ) ); } /** * Map the current table item type to the correct AJAX refresh nonce action. * * @return string */ protected function get_refresh_nonce_action(): string { $item_type = property_exists( $this, 'item_type' ) ? (string) $this->item_type : ''; if ( 'category' === $item_type ) { return 'ai_content_by_parallax_ajax_refresh_batreqs_cats'; } // Default to product refresh nonce. return 'ai_content_by_parallax_ajax_refresh_batreqs_prods'; } /** * Output an "optimize all" link styled as a button. * * @param string $url Destination URL. */ protected function get_optimize_all_button( $url ) { echo wp_kses_post( self::display_action_button_link( /* translators: %s: item type (e.g., products, categories) */ sprintf( __( 'Optimize All %s Items', 'ai-content-by-parallax' ), ucfirst( $this->item_type ) ), $url, array( 'id' => 'optimize-all', 'style' => 'margin-left: 10px;', 'data-nonce' => wp_create_nonce( 'ai_content_by_parallax_ajax_optimize_all' ), 'data-item-type' => $this->item_type, 'data-credits-required' => '0', 'data-eligible-count' => '0', ), 'button-primary' ) ); echo ' '; } /** * Render a redirecting refresh button. * * @return string */ protected function get_redirect_refresh_button() { return sprintf( ' ', esc_url( add_query_arg( 'ai_content_by_parallax_refresh', '1' ) ) ); } /** * Build an HTML link styled as a button. * * @param string $name Button text. * @param string $url Target URL. * @param array $attr Additional attributes. * @param string $classes Button CSS classes. * @return string */ protected static function display_action_button_link( $name, $url, $attr = array(), $classes = 'button-small' ): string { return sprintf( '%s', esc_attr( $classes ), esc_url( $url ), self::get_attributes_string( $attr ), esc_html( $name ) ); } /** * Convert an associative array to an HTML attribute string. * * @param array $attributes Key/value attribute pairs. * @return string */ protected static function get_attributes_string( $attributes ) { $attr_strings = array(); foreach ( $attributes as $key => $value ) { $attr_strings[] = sprintf( '%s="%s"', esc_attr( $key ), esc_attr( $value ) ); } return implode( ' ', $attr_strings ); } /** * Retrieve the table title. * * @return string */ protected function get_table_title() { return $this->table_title; } /** * Render left-aligned table actions. */ protected function display_table_actions_left(): void { echo '
'; $this->render_batch_request_select(); echo '
'; } /** * Render right-aligned table actions. */ protected function display_table_actions_right(): void { echo '
'; $this->show_action_buttons(); if ( $this->show_refresh_button ) { echo wp_kses_post( sprintf( '', esc_url( add_query_arg( array( 'ai_content_by_parallax_refresh' => '1' ) ) ) ) ); } if ( $this->show_refresh_button_ajax ) { echo wp_kses_post( $this->get_ajax_refresh_button( $this->get_refresh_nonce_action(), 'wc-parallax-refresh-' . $this->item_type . '-batch-requests' ) ); } echo '
'; } /** * Output the table title heading. */ public function display_title() { echo '

' . esc_html( $this->get_table_title() ) . '

'; } }