/** * @group get_forms_using_database */ public function test_get_forms_using_database() { $forms = array(); $_forms = $this->Admin->get_forms(); foreach ($_forms as $form) { $Setting = new MW_WP_Form_Setting($form->ID); if (!$Setting->get('usedb')) { continue; } $forms[] = $form; } $forms_using_database = $this->Admin->get_forms_using_database(); $this->assertEquals(1, count($forms_using_database)); $this->assertEquals(count($forms), count($forms_using_database)); }
/** * アンインストールした時の処理 */ public static function uninstall() { $plugin_dir_path = plugin_dir_path(__FILE__); include_once $plugin_dir_path . 'classes/models/class.admin.php'; $Admin = new MW_WP_Form_Admin(); $forms = $Admin->get_forms(); $data_post_ids = array(); foreach ($forms as $form) { $data_post_ids[] = $form->ID; wp_delete_post($form->ID, true); } foreach ($data_post_ids as $data_post_id) { delete_option(MWF_Config::NAME . '-chart-' . $data_post_id); $data_posts = get_posts(array('post_type' => MWF_Functions::get_contact_data_post_type_from_form_id($data_post_id), 'posts_per_page' => -1)); if (empty($data_posts)) { continue; } foreach ($data_posts as $data_post) { wp_delete_post($data_post->ID, true); } } include_once plugin_dir_path(__FILE__) . 'classes/models/class.file.php'; $File = new MW_WP_Form_File(); $File->remove_temp_dir(); delete_option(MWF_Config::NAME); }
/** * データベースに保存に設定されているフォーム(投稿)を取得 * * @return array */ public static function get_posts() { if (self::$contact_data_post_types !== null) { return self::$contact_data_post_types; } $contact_data_post_types = array(); $Admin = new MW_WP_Form_Admin(); $forms = $Admin->get_forms_using_database(); foreach ($forms as $form) { $post_type = MWF_Functions::get_contact_data_post_type_from_form_id($form->ID); $contact_data_post_types[] = $post_type; } $raw_post_types = $contact_data_post_types; $new_post_types = array(); $contact_data_post_types = apply_filters('mwform_contact_data_post_types', $contact_data_post_types); // もともとの配列に含まれていない値は削除する foreach ($contact_data_post_types as $post_type) { if (in_array($post_type, $raw_post_types)) { $new_post_types[] = $post_type; } } self::$contact_data_post_types = $new_post_types; return self::$contact_data_post_types; }