prefix . 'accredible_mapping'; $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE $table_name ( id mediumint(9) NOT NULL AUTO_INCREMENT, course_id mediumint(9) NOT NULL, group_id mediumint(9) NOT NULL, PRIMARY KEY (id) ) $charset_collate;"; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); dbDelta( $sql ); add_option( 'accredible_db_version', $accredible_db_version ); } /** * Add the settings link to the plugins page * @param type $links * @return type */ public function plugin_settings_link($links) { $settings_link = 'Settings'; array_unshift($links, $settings_link); return $links; } /** * Get an array of credentials for a particular email address * @param String $email * @return Array $credentials */ public static function get_credentials_for_email($email){ $api = new Api(get_option('api_key')); $credentials = $api->get_credentials(null, $email); return $credentials; } /** * Create a credential * @param String $name * @param String $email * @param int $group_id * @return mixed $response */ public static function create_credential($name, $email, $group_id){ $api = new Api(get_option('api_key')); $response = $api->create_credential($name, $email, $group_id); return $response; } /** * Get all credential groups * @return Array $groups */ public static function get_groups(){ $api = new Api(get_option('api_key')); $response = $api->get_groups(1000, 1); return $response->groups; } /** * Create a group on Accredible * @return mixed $response */ public static function create_group($name, $course_name, $course_description, $course_link){ $api = new Api(get_option('api_key')); $response = $api->create_group($name, $course_name, $course_description, $course_link); return $response->group; } /** * Update a group on Accredible * @param int $id * @param String $course_name * @param String $course_description * @param String $course_link * @return mixed $response */ public static function update_group($id, $course_name, $course_description, $course_link){ $api = new Api(get_option('api_key')); $response = $api->update_group($id, $course_name, $course_description, $course_link); return $response->group; } /** * Register the admin menu item * @return null */ public function register_certificates_admin_menu_page(){ add_menu_page( 'Certificates & Badges', 'Certificates & Badges', 'list_users', 'accredible-certificates/certificates-admin.php', '', 'dashicons-tablet', 40 ); } /** * Load the admin styles * @return type */ public static function acc_load_plugin_css() { wp_register_style( 'accredible-admin-style', plugins_url( '/css/style.css', __FILE__ ) ); wp_enqueue_style('accredible-admin-style'); } /** * Should we show the issuer an option to auto create credentials? * @return boolean */ public static function auto_sync_available(){ $theme = wp_get_theme(); // gets the current theme if ('Academy' == $theme->name || 'Academy' == $theme->parent_theme) { return true; } else { return false; } } /** * Function called hourly to sync with Accredible * @return null */ public static function sync_with_accredible(){ if(get_option('automatically_issue_certificates') == 1){ Accredible_Acadmey_Theme::sync_with_accredible(); } } /** * Send batch requests via the ACMS API * @param Array $requests * @return mixed $response */ public static function batch_requests($requests){ $api = new Api(get_option('api_key')); for ($i=0; $i < count($requests); $i++) { $requests[$i]['url'] = "v1/" . $requests[$i]['url']; } $response = $api->send_batch_requests($requests); return $response; } // Deprecated below here /* * Get existing certificates for a course */ public static function certificates($course_id) { $client = new GuzzleHttp\Client(); $params = array( 'headers' => array( 'Authorization' => 'Token token="'.get_option('api_key').'"' )); $res = $client->get('https://api.accredible.com/v1/credentials?achievement_id=' . $course_id . '&full_view=true', $params); $result = json_decode($res->getBody()); return $result; } public static function hasCertificate($course_id, $user_id){ $user = get_user_by("id", $user_id); $all_certificates = Accredible_Certificate::certificates($course_id); $all_certificates = $all_certificates->credentials; $cert_exit = False; if(is_array($all_certificates)){ foreach ($all_certificates as $key => $cert) { if($cert->recipient->email == $user->user_email){ $cert_exit = True; $cert_id = $cert->id; $approve = $cert->approve; if($approve){ return $cert_id; }else{ return $approve; } } } } return $cert_exit; } } // END class accredible_certificates } // END if(!class_exists('accredible_certificates')) if(class_exists('Accredible_Certificate')) { // Installation and uninstallation hooks register_activation_hook(__FILE__, array('Accredible_Certificate', 'activate')); register_deactivation_hook(__FILE__, array('Accredible_Certificate', 'deactivate')); // instantiate the plugin class $accredible_certificate = new Accredible_Certificate(); }