documents['\WPO\WC\PDF_Invoices\Documents\Invoice'] = include( 'documents/class-wcpdf-invoice.php' ); $this->documents['\WPO\WC\PDF_Invoices\Documents\Packing_Slip'] = include( 'documents/class-wcpdf-packing-slip.php' ); // Allow plugins to add their own documents $this->documents = apply_filters( 'wpo_wcpdf_document_classes', $this->documents ); } /** * Return the document classes - used in admin to load settings. * * @return array */ public function get_documents( $filter = 'enabled' ) { if ( empty($this->documents) ) { $this->init(); } if ( $filter == 'enabled' ) { $documents = array(); foreach ($this->documents as $class_name => $document) { if ( is_callable( array( $document, 'is_enabled' ) ) && $document->is_enabled() ) { $documents[$class_name] = $document; } } return $documents; } else { // return all documents return $this->documents; } } public function get_document( $document_type, $order ) { foreach ( $this->get_documents('all') as $class_name => $document) { if ( $document->get_type() == $document_type && class_exists( $class_name ) ) { return new $class_name( $order ); } } // document not known, inject into legacy document $document = include( WPO_WCPDF()->plugin_path() . '/includes/legacy/class-wcpdf-legacy-document.php' ); // set document properties, which will trigger parent construct and load data correctly $document->set_props( array( 'type' => $document_type, 'title' => '', 'order' => $order, ) ); return $document; } } endif; // class_exists return new Documents();