src/Plugin.php
/**
     * Main function
     * This will run when accessing the page "moloni" and the routing shoud be done here with and $_GET['action']
     */
Main function
This will run when accessing the page "moloni" and the routing shoud be done here with and $_GET['action']
Main function This will run when accessing the page " moloni " and the routing shoud be done here with and $_GET [ ' action ' ]
public function run()
    {
        try {
            if (Start::login()) {
                $action = isset($_REQUEST['action']) ? sanitize_text_field($_REQUEST['action']) : '';
                switch ($action) {
                    case 'remInvoice':
                        $this->removeOrder((int)$_GET['id']);
                        break;
                    case 'remInvoiceAll':
                        $this->removeOrdersAll();
                        break;
                    case 'genInvoice':
                        $orderId = (int)$_REQUEST['id'];
                        $document = $this->createDocument($orderId);
                        break;
                    case 'syncStocks':
                        $this->syncStocks();
                        break;
                    case 'remLogs':
                        Log::removeLogs();
                        add_settings_error('moloni', 'moloni-rem-logs', __('A limpeza de logs foi concluída.'), 'updated');
                        break;
                    case 'getInvoice':
                        $document = false;
                        $documentId = (int)$_REQUEST['id'];
                        if ($documentId > 0) {
                            $document = Documents::showDocument($documentId);
                        }
                        if (!$document) {
                            add_settings_error('moloni', 'moloni-document-not-found', __('Documento não encontrado'));
                        }
                        break;
                    case 'downloadDocument':
                        $documentId = (int)$_REQUEST['id'];
                        if ($documentId > 0) {
                            Documents::downloadDocument($documentId);
                            exit;
                        }
                        break;
                }
                if (!wp_doing_ajax()) {
                    include MOLONI_TEMPLATE_DIR . 'MainContainer.php';
                }
            }
        } catch (Error $error) {
            $error->showError();
        }
    }
public function run ( ) { try { if ( Start :: login ( ) ) { $ action = isset ( $ _REQUEST [ 'action' ] ) ? sanitize_text_field ( $ _REQUEST [ 'action' ] ) : '' ; switch ( $ action ) { case 'remInvoice' : $ this -> removeOrder ( ( int ) $ _GET [ 'id' ] ) ; break ; case 'remInvoiceAll' : $ this -> removeOrdersAll ( ) ; break ; case 'genInvoice' : $ orderId = ( int ) $ _REQUEST [ 'id' ] ; $ document = $ this -> createDocument ( $ orderId ) ; break ; case 'syncStocks' : $ this -> syncStocks ( ) ; break ; case 'remLogs' : Log :: removeLogs ( ) ; add_settings_error ( 'moloni' , 'moloni-rem-logs' , __ ( 'A limpeza de logs foi concluída.') , updated') ; break ; case 'getInvoice' : $ document = false ; $ documentId = ( int ) $ _REQUEST [ 'id' ] ; if ( $ documentId > 0 ) { $ document = Documents :: showDocument ( $ documentId ) ; } if ( ! $ document ) { add_settings_error ( 'moloni' , 'moloni-document-not-found' , __ ( 'Documento não encontrado') ) ; } break ; case 'downloadDocument' : $ documentId = ( int ) $ _REQUEST [ 'id' ] ; if ( $ documentId > 0 ) { Documents :: downloadDocument ( $ documentId ) ; exit ; } break ; } if ( ! wp_doing_ajax ( ) ) { include MOLONI_TEMPLATE_DIR . 'MainContainer.php' ; } } } catch ( Error $ error ) { $ error -> showError ( ) ; } }
Main function
 This will run when accessing the page "moloni" and the routing shoud be done here with and $_GET['action']
Main function This will run when accessing the page " moloni " and the routing shoud be done here with and $_GET [ ' action ' ]
/** If the user is not logged in show the login form */ /** @var Documents $document intended */