Esempio n. 1
0
 /**
  * initialize
  */
 public function initialize()
 {
     $screen = get_current_screen();
     $contact_data_post_types = MW_WP_Form_Contact_Data_Setting::get_posts();
     if ($screen->base === 'post' && !in_array($screen->id, $contact_data_post_types)) {
         exit;
     }
     if ($screen->base === 'post' && in_array($screen->id, $contact_data_post_types)) {
         $_args = apply_filters('mwform_get_inquiry_data_args-' . $screen->post_type, array());
         if (!empty($_args) && is_array($_args)) {
             $args = array('post_type' => $screen->post_type, 'post_status' => 'publish', 'posts_per_page' => 1, 'p' => $_GET['post']);
             $args = array_merge($_args, $args);
             $permit_posts = get_posts($args);
             if (empty($permit_posts)) {
                 exit;
             }
         }
     }
     $Contact_Data = new MW_WP_Form_Contact_Data();
     add_action('add_meta_boxes', array($this, 'add_meta_boxes'));
     add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
     add_action('admin_print_styles', array($this, 'admin_print_styles'));
     add_action('edit_form_top', array($this, 'edit_form_top'));
     add_action('save_post', array($Contact_Data, 'save_post'));
 }
Esempio n. 2
0
 /**
  * initialize
  */
 public function initialize()
 {
     $contact_data_post_types = MW_WP_Form_Contact_Data_Setting::get_posts();
     if (!in_array($this->formkey, $contact_data_post_types)) {
         exit;
     }
     add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
 }
 /**
  * @backupStaticAttributes enabled
  * @group get_posts
  */
 public function test_mwform_get_posts_投稿タイプを一つ消す()
 {
     add_filter('mwform_contact_data_post_types', function ($post_types) {
         unset($post_types[0]);
         return $post_types;
     });
     $post_types = MW_WP_Form_Contact_Data_Setting::get_posts();
     $this->assertEquals(4, count($post_types));
 }
 public function index()
 {
     $contact_data_post_types = MW_WP_Form_Contact_Data_Setting::get_posts();
     $form_list = array();
     foreach ($contact_data_post_types as $post_type) {
         $post_type_object = get_post_type_object($post_type);
         $form_list[$post_type] = array('title' => $post_type_object->labels->singular_name, 'count' => $this->get_count($post_type), 'modified_datetime' => $this->get_modified_datetime($post_type), 'created_datetime' => $this->get_created_datetime($post_type));
     }
     $this->assign('form_list', $form_list);
     $this->render('stores-inquiry-data-form-list/index');
 }
Esempio n. 5
0
 /**
  * 各画面のコントローラーの呼び出し
  *
  * @param WP_Screen $screen
  */
 public function current_screen($screen)
 {
     $contact_data_post_types = MW_WP_Form_Contact_Data_Setting::get_posts();
     if ($screen->id === MWF_Config::NAME) {
         $validation_rules = $this->get_validation_rules();
         $Controller = new MW_WP_Form_Admin_Controller($validation_rules);
         $Controller->initialize();
     } elseif ($screen->id === 'edit-' . MWF_Config::NAME) {
         $Controller = new MW_WP_Form_Admin_List_Controller();
         $Controller->initialize();
     } elseif (MWF_Functions::is_contact_data_post_type($screen->id)) {
         $Controller = new MW_WP_Form_Contact_Data_Controller();
         $Controller->initialize();
     } elseif (preg_match('/^edit-' . MWF_Config::DBDATA . '\\d+$/', $screen->id)) {
         $Controller = new MW_WP_Form_Contact_Data_List_Controller();
         $Controller->initialize();
     } elseif ($screen->id === MWF_Config::NAME . '_page_' . MWF_Config::NAME . '-chart') {
         $Controller = new MW_WP_Form_Chart_Controller();
         $Controller->initialize();
     }
 }
Esempio n. 6
0
 /**
  * CSVの各行を生成
  *
  * @param array $posts
  * @param array $headings
  * @return array
  */
 protected function get_rows(array $posts, array $headings)
 {
     global $post;
     $rows = array();
     foreach ($posts as $post) {
         setup_postdata($post);
         $columns = array();
         foreach ($headings as $key => $value) {
             $Contact_Data_Setting = new MW_WP_Form_Contact_Data_Setting($post->ID);
             $response_statuses = $Contact_Data_Setting->get_response_statuses();
             $column = '';
             if ($value === __('Response Status', MWF_Config::DOMAIN)) {
                 $response_status = $Contact_Data_Setting->get('response_status');
                 $column = $response_statuses[$response_status];
             } elseif ($value === __('Memo', MWF_Config::DOMAIN)) {
                 $column = $Contact_Data_Setting->get('memo');
             } elseif ($value === MWF_Functions::get_tracking_number_title($this->post_type)) {
                 $column = get_post_meta(get_the_ID(), MWF_Config::TRACKINGNUMBER, true);
             } elseif (isset($post->{$value})) {
                 $post_meta = $post->{$value};
                 if ($Contact_Data_Setting->is_upload_file_key($post, $value)) {
                     // 過去バージョンでの不具合でメタデータが空になっていることがあるのでその場合は代替処理
                     if ($post_meta === '') {
                         $post_meta = MWF_Functions::get_multimedia_id__fallback($post, $value);
                     }
                     $column = wp_get_attachment_url($post_meta);
                 } else {
                     $column = $post_meta ? $post_meta : '';
                 }
             }
             $columns[$key] = $column;
         }
         $rows[] = $columns;
     }
     wp_reset_postdata();
     return $rows;
 }
 /**
  * 各カラムのデータを出力
  *
  * @param string $column カラム名
  * @param int $post_id
  */
 public function add_form_columns($column, $post_id)
 {
     $post = get_post($post_id);
     $post_custom_keys = get_post_custom_keys($post_id);
     $Contact_Data_Setting = new MW_WP_Form_Contact_Data_Setting($post_id);
     if ($column === 'post_date') {
         $value = esc_html($post->post_date);
     } elseif ($column === 'response_status') {
         $response_statuses = $Contact_Data_Setting->get_response_statuses();
         $response_status = $Contact_Data_Setting->get('response_status');
         $value = $response_statuses[$response_status];
     } elseif (is_array($post_custom_keys) && in_array($column, $post_custom_keys)) {
         $post_meta = get_post_meta($post_id, $column, true);
         if ($Contact_Data_Setting->is_upload_file_key($post, $column)) {
             // 過去バージョンでの不具合でメタデータが空になっていることがあるのでその場合は代替処理
             if ($post_meta === '') {
                 $post_meta = MWF_Functions::get_multimedia_id__fallback($post, $column);
             }
             $value = MWF_Functions::get_multimedia_data($post_meta);
         } elseif ($post_meta) {
             $value = esc_html($post_meta);
         } else {
             $value = ' ';
         }
     } else {
         $value = ' ';
     }
     $this->assign('column', $value);
     $this->render('contact-data-list/column');
 }
Esempio n. 8
0
 /**
  * 添付データのIDを返す
  * 過去バージョンでの不具合でアップロードファイルを示すメタデータが空になっていることがあるのでその場合の代替処理
  *
  * @param WP_Post $post
  * @param int $meta_key
  * @return int
  */
 public static function get_multimedia_id__fallback($post, $meta_key)
 {
     $Contact_Data_Setting = new MW_WP_Form_Contact_Data_Setting($post->ID);
     $key = $Contact_Data_Setting->get_key_in_upload_file_keys($post, $meta_key);
     $attachments = get_posts(array('post_type' => 'attachment', 'post_parent' => $post->ID, 'posts_per_page' => 1, 'offset' => $key));
     if (isset($attachments[0])) {
         return $attachments[0]->ID;
     }
 }
 /**
  * データベースに保存に設定されているフォーム(投稿)を取得
  *
  * @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;
 }