コード例 #1
0
ファイル: get-custom.php プロジェクト: hunk/Magic-Fields
function purge_cache_dir($dir)
{
    foreach (glob($dir) as $file) {
        if (is_dir($file)) {
            purge_cache_dir("{$file}/*");
            rmdir($file);
        } else {
            unlink($file);
        }
    }
}
コード例 #2
0
ファイル: RCCWP_Post.php プロジェクト: hunk/Magic-Fields
 /**
  * Save all custom field values meta values for the post, this function assumes that 
  * $_POST['rc_cwp_meta_keys'] contains the names of the fields, while $_POST[{FIELD_NAME}]
  * contains the value of the field named {FIELD_NAME}
  *
  * @param integer $postId
  * @return void
  */
 function SetMetaValues($postId)
 {
     global $wpdb;
     $customWritePanelId = $_POST['rc-cwp-custom-write-panel-id'];
     //delete file
     if (!empty($_POST['magicfields_remove_files'])) {
         $files = preg_split('/\\|\\|\\|/', $_POST['magicfields_remove_files']);
         foreach ($files as $file) {
             do_action('mf_before_delete_file', $file);
             @unlink(MF_FILES_PATH . $file);
         }
     }
     if (empty($_POST['magicfields'])) {
         return true;
     }
     $customfields = $_POST['magicfields'];
     if ($the_post = wp_is_post_revision($postId)) {
         $postId = $the_post;
     }
     if (!empty($customWritePanelId)) {
         // --- Delete old values
         foreach ($customfields as $name => $field) {
             delete_post_meta($postId, $name);
         }
         $wpdb->delete(MF_TABLE_POST_META, array('post_id' => $postId), array('%d'));
         //Creating the new values
         //Iterating the custom fields
         foreach ($customfields as $name => $groups) {
             $groups_index = 1;
             //Iterating the groups
             foreach ($groups as $group_id => $fields) {
                 $index = 1;
                 //Iterating the  duplicates
                 foreach ($fields as $value) {
                     // Adding field value meta data
                     add_post_meta($postId, $name, $value);
                     $fieldMetaID = $wpdb->insert_id;
                     $wpdb->insert(MF_TABLE_POST_META, array('id' => $fieldMetaID, 'field_name' => $name, 'group_count' => $groups_index, 'field_count' => $index, 'post_id' => $postId, 'order_id' => $groups_index), array('%d', '%s', '%d', '%d', '%d', '%d'));
                     //pre save value
                     do_action('mf_presave', $fieldMetaID, $name, $groups_index, $index, $postId, $value, $customWritePanelId);
                     $index++;
                 }
                 $groups_index++;
             }
         }
         if (MF_GET_CACHE_IS_ON) {
             purge_cache_dir(MF_GET_CACHE_DIR . $postId);
         }
     }
 }
コード例 #3
0
ファイル: RCCWP_Post.php プロジェクト: ahsaeldin/projects
 /**
  * Save all custom field values meta values for the post, this function assumes that 
  * $_POST['rc_cwp_meta_keys'] contains the names of the fields, while $_POST[{FIELD_NAME}]
  * contains the value of the field named {FIELD_NAME}
  *
  * @param integer $postId
  * @return void
  */
 function SetMetaValues($postId)
 {
     global $wpdb;
     $customWritePanelId = $_POST['rc-cwp-custom-write-panel-id'];
     //delete file
     if (!empty($_POST['magicfields_remove_files'])) {
         $files = preg_split('/\\|\\|\\|/', $_POST['magicfields_remove_files']);
         foreach ($files as $file) {
             do_action('mf_before_delete_file', $file);
             @unlink(MF_FILES_PATH . $file);
         }
     }
     if (empty($_POST['magicfields'])) {
         return true;
     }
     $customfields = $_POST['magicfields'];
     if ($the_post = wp_is_post_revision($postId)) {
         $postId = $the_post;
     }
     if (!empty($customWritePanelId)) {
         // --- Delete old values
         foreach ($customfields as $name => $field) {
             delete_post_meta($postId, $name);
         }
         $wpdb->query("DELETE FROM " . MF_TABLE_POST_META . " WHERE post_id={$postId}");
         //Creating the new values
         //Iterating the custom fields
         foreach ($customfields as $name => $groups) {
             $groups_index = 1;
             //Iterating the groups
             foreach ($groups as $group_id => $fields) {
                 $index = 1;
                 //Iterating the  duplicates
                 foreach ($fields as $value) {
                     // Adding field value meta data
                     add_post_meta($postId, $name, $value);
                     $fieldMetaID = $wpdb->insert_id;
                     // Adding  the referencie in the magic fields post meta table
                     $wpdb->query("INSERT INTO " . MF_TABLE_POST_META . " (id, field_name, group_count, field_count, post_id,order_id) " . " VALUES ({$fieldMetaID}, '{$name}',{$groups_index},{$index},{$postId},{$groups_index})");
                     //pre save value
                     do_action('mf_presave', $fieldMetaID, $name, $groups_index, $index, $postId, $value, $customWritePanelId);
                     $index++;
                 }
                 $groups_index++;
             }
         }
         if (MF_GET_CACHE_IS_ON) {
             purge_cache_dir(MF_GET_CACHE_DIR . $postId);
         }
     }
 }