errorMsg = "Apollo error"; $this->successMsg = "Apollo success"; // check if user admin if ( !current_user_can('administrator') && !current_user_can('editor') ) { return; } $wp_upload_dir = wp_upload_dir(); add_filter( 'plugin_action_links_' . plugin_basename( APOLLO_FILE ), array($this,'add_action_links') ); Apollo_Main_Settings::init_hooks(); add_action( 'add_meta_boxes', array( $this, 'add_apollo_boxes' ) ); add_filter( 'plugin_row_meta', array( $this, 'add_plugin_row_meta' ), 10, 2 ); add_action( 'admin_init', array( $this, 'admin_pdf_callback' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'my_admin_scripts' ) ); } public function my_admin_scripts() { //css wp_register_style( 'apollo_settings_css', APOLLO_URL . '/admin/css/custom.css'); wp_enqueue_style('apollo_settings_css'); //js wp_register_script( 'apollo_settings_js', APOLLO_URL . '/admin/js/custom.js' ); wp_enqueue_script( 'apollo_settings_js' ); } public function admin_pdf_callback() { $action = isset($_GET['apollo_action']) ? sanitize_key($_GET['apollo_action']) : ''; $order_id = isset($_GET['post']) ? intval( $_GET['post'] ): 0; $type = isset($_GET['apollo_type']) ? sanitize_key($_GET['apollo_type']) : 'invoice'; $apollo_document_id = isset($_GET['apollo_document_id']) ? sanitize_key($_GET['apollo_document_id']) : false; $apollo_document_number = isset($_GET['apollo_document_number']) ? sanitize_key($_GET['apollo_document_number']) : false; if ($action === 'create') { $nonce = sanitize_key( $_GET['nonce'] ); if ( ! wp_verify_nonce( $nonce, $action ) ) { wp_die( 'Invalid request.' ); } $callback = Apollo_invoice::create($order_id, $type); if (isset($callback['error'])) { $this->errorMsg = $callback['error']; add_action( 'admin_notices', array( $this, 'apollo_error_notice' )); } else if (!isset($callback['exsists'])) { $this->successMsg = "Successfully created Apollo $type."; add_action( 'admin_notices', array( $this, 'apollo_success_notice' )); } } else if ($action === 'pdf' && $apollo_document_id) { $nonce = sanitize_key( $_GET['nonce'] ); if ( ! wp_verify_nonce( $nonce, $action ) ) { wp_die( 'Invalid request.' ); } Apollo_invoice::viewPdf($apollo_document_id, $apollo_document_number, $type); } } function apollo_error_notice() { ?>
= $this->errorMsg ?>
= $this->successMsg ?>
| %s | ', __( 'Number:', 'apollo-invoices' ) ); printf( '%s | ', $invoice['number'] ); printf( '
| %2$s | ', __( 'You can read about sending inovices in Apollo settings, under Mailing Options', 'apollo-invoices' ), __( 'Sent:', 'apollo-invoices' ) ); printf( '%s | ', (bool) $invoice['sent'] ? __( 'Yes', 'apollo-invoices' ) : __( 'No', 'apollo-invoices' ) ); printf( '
'; $org_id = get_option('apollo_general_settings')['apollo_organization-id']; $view_url = "https://getapollo.io/app/$org_id/documents/view/".$invoice['id']; printf( 'View invoice', $view_url); $download_pdf_url = wp_nonce_url(add_query_arg( array( 'post' => $order->ID, 'action' => 'edit', 'apollo_action' => 'pdf', 'apollo_document_id' => $invoice['id'], 'apollo_document_number' => $invoice['number'], 'apollo_type' => 'invoice' ), admin_url( 'post.php' )), 'pdf', 'nonce'); printf( 'View PDF', $download_pdf_url); echo '
'; } } public function display_apollo_estimate_box( $order ) { $estimate = Apollo_invoice::getEstimate( $order->ID ); if ( !$estimate ) { $url = wp_nonce_url(add_query_arg( array( 'post' => $order->ID, 'action' => 'edit', 'apollo_action' => 'create', 'apollo_type' => 'estimate' ), admin_url( 'post.php' )), 'create', 'nonce' ); printf( 'Create', $url); } else { echo "| %s | ', __( 'Number:', 'apollo-invoices' ) ); printf( '%s | ', $estimate['number'] ); printf( '
| %2$s | ', __( 'You can read about sending estimates in Apollo settings, under Mailing Options', 'apollo-invoices' ), __( 'Sent:', 'apollo-invoices' ) ); printf( '%s | ', (bool) $estimate['sent'] ? __( 'Yes', 'apollo-invoices' ) : __( 'No', 'apollo-invoices' ) ); printf( '
'; $org_id = get_option('apollo_general_settings')['apollo_organization-id']; $view_url = "https://getapollo.io/app/$org_id/documents/view/".$estimate['id']; printf( 'View estimate', $view_url); $download_pdf_url = wp_nonce_url(add_query_arg( array( 'post' => $order->ID, 'action' => 'edit', 'apollo_action' => 'pdf', 'apollo_document_id' => $estimate['id'], 'apollo_document_number' => $estimate['number'], 'apollo_type' => 'estimate' ), admin_url( 'post.php' )), 'pdf', 'nonce' ); printf( 'View PDF', $download_pdf_url); echo '
'; } } public static function add_plugin_row_meta( $links, $file ) { if ( plugin_basename( APOLLO_FILE ) === $file ) { $url = 'https://getapollo.io'; $title = __( 'Visit Apollo', 'apollo-invoices' ); $links[] = sprintf( '%2$s', $url, $title ); } return $links; } } }