コード例 #1
0
 function add_new_api_key()
 {
     global $user_id, $post;
     if (isset($_POST['add_new_api_key'])) {
         $metas = array();
         $post_field_types = tc_post_fields();
         foreach ($_POST as $field_name => $field_value) {
             if (preg_match('/_post_title/', $field_name)) {
                 $title = $field_value;
             }
             if (preg_match('/_post_excerpt/', $field_name)) {
                 $excerpt = $field_value;
             }
             if (preg_match('/_post_content/', $field_name)) {
                 $content = $field_value;
             }
             if (preg_match('/_post_meta/', $field_name)) {
                 $metas[str_replace('_post_meta', '', $field_name)] = $field_value;
             }
             do_action('tc_after_api_key_post_field_type_check');
         }
         $metas = apply_filters('tc_api_keys_metas', $metas);
         $arg = array('post_author' => $user_id, 'post_excerpt' => isset($excerpt) ? $excerpt : '', 'post_content' => isset($content) ? $content : '', 'post_status' => 'publish', 'post_title' => isset($title) ? $title : '', 'post_type' => 'tc_api_keys');
         if (isset($_POST['post_id'])) {
             $arg['ID'] = $_POST['post_id'];
             //for edit
         }
         $post_id = @wp_insert_post($arg, true);
         //Update post meta
         if ($post_id !== 0) {
             if (isset($metas)) {
                 foreach ($metas as $key => $value) {
                     update_post_meta($post_id, $key, $value);
                 }
             }
         }
         return $post_id;
     }
 }
コード例 #2
0
function tc_is_post_field($post_field = '')
{
    if (in_array($post_field, tc_post_fields())) {
        return true;
    } else {
        return false;
    }
}