/** * @param int $original_post_id * @param string $lang * @param bool $duplicate sets whether missing terms should be created by duplicating the original term */ private function synchronize_terms($original_post_id, $lang, $duplicate) { global $wpml_post_translations; $wpml_post_translations->reload(); $translated_post_id = $wpml_post_translations->element_id_in($original_post_id, $lang); if ((bool) $translated_post_id === true) { $taxonomies = get_post_taxonomies($original_post_id); foreach ($taxonomies as $tax) { $terms_on_original = wp_get_object_terms($original_post_id, $tax); if (!$this->sitepress->is_translated_taxonomy($tax)) { if ($this->sitepress->get_setting('sync_post_taxonomies')) { // Taxonomy is not translated so we can just copy from the original foreach ($terms_on_original as $key => $term) { $terms_on_original[$key] = $term->term_id; } wp_set_object_terms($translated_post_id, $terms_on_original, $tax); } } else { /** @var int[] $translated_terms translated term_ids */ $translated_terms = $this->get_translated_term_ids($terms_on_original, $lang, $tax, $duplicate); wp_set_object_terms($translated_post_id, $translated_terms, $tax); } } } clean_object_term_cache($original_post_id, get_post_type($original_post_id)); }
/** * WP Cron even for purging object cache in batches */ function cron_action($tt_id, $taxonomy) { global $wpdb; $objects = $wpdb->get_col($wpdb->prepare("SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id = %d", $tt_id)); $tax_object = get_taxonomy($taxonomy); foreach ($tax_object->object_type as $object_type) { clean_object_term_cache($objects, $object_type); } }
/** * @param int $original_post_id * @param string $lang * @param bool $duplicate sets whether missing terms should be created by duplicating the original term */ private function synchronize_terms($original_post_id, $lang, $duplicate) { global $wpml_post_translations; $wpml_post_translations->reload(); $translated_post_id = $wpml_post_translations->element_id_in($original_post_id, $lang); if ((bool) $translated_post_id === true) { $taxonomies = get_post_taxonomies($original_post_id); foreach ($taxonomies as $tax) { $terms_on_original = wp_get_object_terms($original_post_id, $tax); /** @var int[] $translated_terms translated term_ids */ $translated_terms = $this->get_translated_term_ids($terms_on_original, $lang, $tax, $duplicate); wp_set_object_terms($translated_post_id, $translated_terms, $tax); } } clean_object_term_cache($original_post_id, get_post_type($original_post_id)); }
/** * Save taxonomy terms for a specific user * * @since 0.1.0 * * @param int $user_id * @param string $taxonomy * @param array $terms * @param boolean $bulk * * @return boolean */ function wp_set_terms_for_user($user_id, $taxonomy, $terms = array(), $bulk = false) { // Get the taxonomy $tax = get_taxonomy($taxonomy); // Make sure the current user can edit the user and assign terms before proceeding. if (!current_user_can('edit_user', $user_id) && current_user_can($tax->cap->assign_terms)) { return false; } if (empty($terms) && empty($bulk)) { $terms = isset($_POST[$taxonomy]) ? $_POST[$taxonomy] : null; } // Delete all user terms if (is_null($terms) || empty($terms)) { wp_delete_object_term_relationships($user_id, $taxonomy); // Set the terms } else { $_terms = array_map('sanitize_key', $terms); // Sets the terms for the user wp_set_object_terms($user_id, $_terms, $taxonomy, false); } clean_object_term_cache($user_id, $taxonomy); }
public function save_user_rank_terms($user_id) { $tax = get_taxonomy('rank'); /* Make sure the current user can edit the user and assign terms before proceeding. */ if (!current_user_can('edit_user', $user_id) && current_user_can($tax->cap->assign_terms)) { return false; } $term = esc_attr($_POST['rank']); /* Sets the terms (we're just using a single term) for the user. */ wp_set_object_terms($user_id, array($term), 'rank', false); clean_object_term_cache($user_id, 'rank'); }
function wppb_front_end_register($atts) { ob_start(); global $current_user; global $wp_roles; global $wpdb; global $error; global $wppb_shortcode_on_front; //get required and shown fields $wppb_defaultOptions = get_option('wppb_default_settings'); //get "login with" setting $wppb_generalSettings = get_option('wppb_general_settings'); $wppb_shortcode_on_front = true; $agreed = true; $new_user = '******'; $multisite_message = false; $registerFilterArray = array(); $registerFilterArray2 = array(); $uploadExt = array(); $extraFieldsErrorHolder = array(); //we will use this array to store the ID's of the extra-fields left uncompleted get_currentuserinfo(); /* variables used to verify if all required fields were submitted*/ $firstnameComplete = 'yes'; $lastnameComplete = 'yes'; $nicknameComplete = 'yes'; $websiteComplete = 'yes'; $aimComplete = 'yes'; $yahooComplete = 'yes'; $jabberComplete = 'yes'; $bioComplete = 'yes'; /* END variables used to verify if all required fields were submitted*/ /* Check if users can register. */ $registration = get_option('users_can_register'); $registration = apply_filters('wppb_register_setting_override', $registration); //fallback if the file was largen then post_max_size, case in which no errors can be saved in $_FILES[fileName]['error'] if (empty($_FILES) && empty($_POST) && isset($_SERVER['REQUEST_METHOD']) && strtolower($_SERVER['REQUEST_METHOD']) == 'post') { $registerFilterArray['noPostError'] = '<p class="error">' . sprintf(__('The information size you were trying to submit was larger than %1$sb!<br/>This is usually caused by a large file(s) trying to be uploaded.<br/>Since it was also larger than %2$sb no additional information is available.<br/>The user was NOT created!', 'profilebuilder'), WPPB_SERVER_MAX_UPLOAD_SIZE_MEGA, WPPB_SERVER_MAX_POST_SIZE_MEGA) . '</p>'; echo $registerFilterArray['noPostError'] = apply_filters('wppb_register_no_post_error_message', $registerFilterArray['noPostError'], WPPB_SERVER_MAX_UPLOAD_SIZE_MEGA, WPPB_SERVER_MAX_POST_SIZE_MEGA); } /* If user registered, input info. */ if ('POST' == $_SERVER['REQUEST_METHOD'] && !empty($_POST['action']) && $_POST['action'] == 'adduser' && wp_verify_nonce($_POST['register_nonce_field'], 'verify_true_registration') && $_POST['formName'] == 'register') { //global $wp_roles; //get value sent in the shortcode as parameter, use default if not set $default_role = get_option('default_role'); extract(shortcode_atts(array('role' => $default_role), $atts)); //check if the specified role exists in the database, else fall back to the "safe-zone" $aprovedRole = $role == $default_role || get_role($role) ? $role : $default_role; /* preset the values in case some are not submitted */ $user_pass = ''; if (isset($_POST['passw1'])) { $user_pass = esc_attr($_POST['passw1']); } $email = ''; if (isset($_POST['email'])) { $email = trim($_POST['email']); } if (isset($wppb_generalSettings['loginWith']) && $wppb_generalSettings['loginWith'] == 'email') { $user_name = wppb_generate_random_username($email); } else { $user_name = ''; if (isset($_POST['user_name'])) { $user_name = trim($_POST['user_name']); } } $first_name = ''; if (isset($_POST['first_name'])) { $first_name = trim($_POST['first_name']); } $last_name = ''; if (isset($_POST['last_name'])) { $last_name = trim($_POST['last_name']); } $nickname = ''; if (isset($_POST['nickname'])) { //the field is filled by the user upon registration $nickname = trim($_POST['nickname']); } elseif (isset($wppb_generalSettings['loginWith']) && $wppb_generalSettings['loginWith'] == 'email') { //in case the nickname field is hidden, and the login with email is active $nickname = $email; } else { //in case the nickname field is hidden, but login is done with username $nickname = $user_name; } $website = ''; if (isset($_POST['website'])) { $website = trim($_POST['website']); } $aim = ''; if (isset($_POST['aim'])) { $aim = trim($_POST['aim']); } $yim = ''; if (isset($_POST['yim'])) { $yim = trim($_POST['yim']); } $jabber = ''; if (isset($_POST['jabber'])) { $jabber = trim($_POST['jabber']); } $description = ''; if (isset($_POST['description'])) { $description = trim($_POST['description']); } /* use filters to modify (if needed) the posted data before creating the user-data */ $user_pass = apply_filters('wppb_register_posted_password', $user_pass); $user_name = apply_filters('wppb_register_posted_username', $user_name); $first_name = apply_filters('wppb_register_posted_first_name', $first_name); $last_name = apply_filters('wppb_register_posted_last_name', $last_name); $nickname = apply_filters('wppb_register_posted_nickname', $nickname); $email = apply_filters('wppb_register_posted_email', $email); $website = apply_filters('wppb_register_posted_website', $website); $aim = apply_filters('wppb_register_posted_aim', $aim); $yim = apply_filters('wppb_register_posted_yahoo', $yim); $jabber = apply_filters('wppb_register_posted_jabber', $jabber); $description = apply_filters('wppb_register_posted_bio', $description); /* END use filters to modify (if needed) the posted data before creating the user-data */ $userdata = array('user_pass' => $user_pass, 'user_login' => esc_attr($user_name), 'first_name' => esc_attr($first_name), 'last_name' => esc_attr($last_name), 'nickname' => esc_attr($nickname), 'user_email' => esc_attr($email), 'user_url' => esc_attr($website), 'aim' => esc_attr($aim), 'yim' => esc_attr($yim), 'jabber' => esc_attr($jabber), 'description' => esc_attr($description), 'role' => $aprovedRole); $userdata = apply_filters('wppb_register_userdata', $userdata); //check if the user agreed to the terms and conditions (if it was set) $wppb_premium = WPPB_PLUGIN_DIR . '/premium/functions/'; if (file_exists($wppb_premium . 'extra.fields.php')) { $wppbFetchArray = get_option('wppb_custom_fields'); foreach ($wppbFetchArray as $key => $value) { switch ($value['item_type']) { case "agreeToTerms": $agreed = false; if (isset($_POST[$value['item_type'] . $value['id']]) && $_POST[$value['item_type'] . $value['id']] == 'agree') { $agreed = true; } break; } // add filters for all the custom fields $_POST[$value['item_type'] . $value['id']] = apply_filters('wppb_register_' . $value['item_type'] . $value['id'] . '_general_filter', $_POST[$value['item_type'] . $value['id']]); } } $registerFilterArray['extraError'] = ''; //this is for creating extra error message and bypassing registration $registerFilterArray['extraError'] = apply_filters('wppb_register_extra_error', $registerFilterArray['extraError']); /* check if all the required fields were completed */ if ($wppb_defaultOptions['firstname'] == 'show') { if ($wppb_defaultOptions['firstnameRequired'] == 'yes' && trim($_POST['first_name']) == '') { $firstnameComplete = 'no'; } } if ($wppb_defaultOptions['lastname'] == 'show') { if ($wppb_defaultOptions['lastnameRequired'] == 'yes' && trim($_POST['last_name']) == '') { $lastnameComplete = 'no'; } } if ($wppb_defaultOptions['nickname'] == 'show') { if ($wppb_defaultOptions['nicknameRequired'] == 'yes' && trim($_POST['nickname']) == '') { $nicknameComplete = 'no'; } } if ($wppb_defaultOptions['website'] == 'show') { if ($wppb_defaultOptions['websiteRequired'] == 'yes' && trim($_POST['website']) == '') { $websiteComplete = 'no'; } } if ($wppb_defaultOptions['aim'] == 'show') { if ($wppb_defaultOptions['aimRequired'] == 'yes' && trim($_POST['aim']) == '') { $aimComplete = 'no'; } } if ($wppb_defaultOptions['yahoo'] == 'show') { if ($wppb_defaultOptions['yahooRequired'] == 'yes' && trim($_POST['yahoo']) == '') { $yahooComplete = 'no'; } } if ($wppb_defaultOptions['jabber'] == 'show') { if ($wppb_defaultOptions['jabberRequired'] == 'yes' && trim($_POST['jabber']) == '') { $jabberComplete = 'no'; } } if ($wppb_defaultOptions['bio'] == 'show') { if ($wppb_defaultOptions['bioRequired'] == 'yes' && trim($_POST['description']) == '') { $bioComplete = 'no'; } } // check the extra fields also $wppb_premium = WPPB_PLUGIN_DIR . '/premium/functions/'; if (file_exists($wppb_premium . 'extra.fields.php')) { $wppbFetchArray = get_option('wppb_custom_fields'); foreach ($wppbFetchArray as $key => $value) { switch ($value['item_type']) { case "input": $_POST[$value['item_type'] . $value['id']] = apply_filters('wppb_register_input_custom_field_' . $value['id'], $_POST[$value['item_type'] . $value['id']]); if (isset($value['item_required'])) { if ($value['item_required'] == 'yes') { if (trim($_POST[$value['item_type'] . $value['id']]) == '') { array_push($extraFieldsErrorHolder, $value['id']); } } } break; case "checkbox": $checkboxOption = ''; $value['item_options'] = wppb_icl_t('plugin profile-builder-pro', 'custom_field_' . $id . '_options_translation', $value['item_options']); $checkboxValue = explode(',', $value['item_options']); foreach ($checkboxValue as $thisValue) { $thisValue = str_replace(' ', '#@space@#', $thisValue); //we need to escape the space-codification we sent earlier in the post if (isset($_POST[$thisValue . $value['id']])) { $localValue = str_replace('#@space@#', ' ', $_POST[$thisValue . $value['id']]); $checkboxOption = $checkboxOption . $localValue . ','; } } if (isset($value['item_required'])) { if ($value['item_required'] == 'yes') { if (trim($checkboxOption) == '') { array_push($extraFieldsErrorHolder, $value['id']); } } } break; case "radio": if (isset($value['item_required'])) { if ($value['item_required'] == 'yes') { if (trim($_POST[$value['item_type'] . $value['id']]) == '') { array_push($extraFieldsErrorHolder, $value['id']); } } } break; case "select": if (isset($value['item_required'])) { if ($value['item_required'] == 'yes') { if (trim($_POST[$value['item_type'] . $value['id']]) == '') { array_push($extraFieldsErrorHolder, $value['id']); } } } break; case "countrySelect": if (isset($value['item_required'])) { if ($value['item_required'] == 'yes') { if (trim($_POST[$value['item_type'] . $value['id']]) == '') { array_push($extraFieldsErrorHolder, $value['id']); } } } break; case "timeZone": if (isset($value['item_required'])) { if ($value['item_required'] == 'yes') { if (trim($_POST[$value['item_type'] . $value['id']]) == '') { array_push($extraFieldsErrorHolder, $value['id']); } } } break; case "datepicker": if (isset($value['item_required'])) { if ($value['item_required'] == 'yes') { if (trim($_POST[$value['item_type'] . $value['id']]) == '') { array_push($extraFieldsErrorHolder, $value['id']); } } } break; case "textarea": if (isset($value['item_required'])) { if ($value['item_required'] == 'yes') { if (trim($_POST[$value['item_type'] . $value['id']]) == '') { array_push($extraFieldsErrorHolder, $value['id']); } } } break; case "upload": $uploadedfile = $value['item_type'] . $value['id']; if (basename($_FILES[$uploadedfile]['name']) == '') { if (isset($value['item_required'])) { if ($value['item_required'] == 'yes') { array_push($extraFieldsErrorHolder, $value['id']); } } } elseif (basename($_FILES[$uploadedfile]['name']) != '') { //get allowed file types if ($value['item_options'] != NULL || $value['item_options'] != '') { $allFiles = false; $extensions = explode(',', $value['item_options']); foreach ($extensions as $key2 => $value2) { $extensions[$key2] = trim($value2); } } else { $allFiles = true; } $thisFileExtStart = strrpos($_FILES[$uploadedfile]['name'], '.'); $thisFileExt = substr($_FILES[$uploadedfile]['name'], $thisFileExtStart); if ($allFiles == false && !in_array($thisFileExt, $extensions)) { array_push($uploadExt, basename($_FILES[$uploadedfile]['name'])); $allowedExtensions = ''; (int) ($nrOfExt = count($extensions) - 2); foreach ($extensions as $key2 => $value2) { $allowedExtensions .= $value2; if ($key2 <= $nrOfExt) { $allowedExtensions .= ', '; } } } } break; case "avatar": $uploadedfile = $value['item_type'] . $value['id']; if (basename($_FILES[$uploadedfile]['name']) == '') { if ($_FILES[$uploadedfile]['type'] != 'image/jpeg' || $_FILES[$uploadedfile]['type'] != 'image/jpg' || $_FILES[$uploadedfile]['type'] != 'image/png' || $_FILES[$uploadedfile]['type'] != 'image/bmp' || $_FILES[$uploadedfile]['type'] != 'image/pjpeg' || $_FILES[$uploadedfile]['type'] != 'image/x-png') { if (isset($value['item_required'])) { if ($value['item_required'] == 'yes') { array_push($extraFieldsErrorHolder, $value['id']); } } } } break; case "agreeToTerms": if (isset($value['item_required'])) { if ($value['item_required'] == 'yes') { if ($_POST[$value['item_type'] . $value['id']] == NULL) { array_push($extraFieldsErrorHolder, $value['id']); } } } break; } } } /* END check if all the required fields were completed */ if ($registerFilterArray['extraError'] != '') { $error = $registerFilterArray['extraError']; } elseif (!$userdata['user_login']) { if (isset($wppb_generalSettings['loginWith']) && $wppb_generalSettings['loginWith'] == 'email') { } else { $error = apply_filters('wppb_register_userlogin_error1', __('A username is required for registration.', 'profilebuilder')); } } elseif (username_exists($userdata['user_login'])) { if (isset($wppb_generalSettings['loginWith']) && $wppb_generalSettings['loginWith'] == 'email') { } else { $error = apply_filters('wppb_register_userlogin_error2', __('Sorry, that username already exists!', 'profilebuilder')); } } elseif (!is_email($userdata['user_email'], true)) { $error = apply_filters('wppb_register_useremail_error1', __('You must enter a valid email address.', 'profilebuilder')); } elseif (email_exists($userdata['user_email'])) { $error = apply_filters('wppb_register_useremail_error2', __('Sorry, that email address is already used!', 'profilebuilder')); } elseif (empty($_POST['passw1']) || empty($_POST['passw2']) || $_POST['passw1'] != $_POST['passw2']) { if (empty($_POST['passw1']) || empty($_POST['passw2'])) { //verify if the user has completed both password fields $error = apply_filters('wppb_register_userpass_error1', __('You didn\'t complete one of the password-fields!', 'profilebuilder')); } elseif ($_POST['passw1'] != $_POST['passw2']) { //verify if the the password and the retyped password are a match $error = apply_filters('wppb_register_userpass_error2', __('The entered passwords don\'t match!', 'profilebuilder')); } } elseif (count($uploadExt) > 0) { $error = '<p class="semi-saved">' . __('There was an error while trying to upload the following attachment(s)', 'profilebuilder') . ': <span class="error">'; foreach ($uploadExt as $key5 => $name5) { $lastOne++; $error .= $name5; if (count($uploadExt) - $lastOne > 0) { $error .= ';<span style="padding-left:10px"></span>'; } } $error .= '</span><br/>' . __('Only files with the following extension(s) can be uploaded:', 'profilebuilder') . ' <span class="error">' . $allowedExtensions . '</span><br/><span class="error">' . __('The account was NOT created!', 'profilebuilder') . '</span> </p>'; } elseif ($agreed == false) { $error = __('You must agree to the terms and conditions before registering!', 'profilebuilder'); } elseif ($firstnameComplete == 'no' || $lastnameComplete == 'no' || $nicknameComplete == 'no' || $websiteComplete == 'no' || $aimComplete == 'no' || $yahooComplete == 'no' || $jabberComplete == 'no' || $bioComplete == 'no' || !empty($extraFieldsErrorHolder)) { $error = __('The account was NOT created!', 'profilebuilder') . '<br/>' . __('(Several required fields were left uncompleted)', 'profilebuilder'); } else { $registered_name = $_POST['user_name']; //register the user normally if it is not a multi-site installation if (!is_multisite()) { $wppb_generalSettings = get_option('wppb_general_settings'); if ($wppb_generalSettings['emailConfirmation'] == 'yes') { $foundError = false; if (is_multisite()) { $userSignup = $wpdb->get_results("SELECT * FROM {$wpdb->signups} WHERE user_login='******'user_login'] . "' OR user_email='" . $userdata['user_email'] . "'"); } else { $userSignup = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "signups WHERE user_login='******'user_login'] . "' OR user_email='" . $userdata['user_email'] . "'"); } if (trim($userSignup[0]->user_login) == $userdata['user_login']) { $foundError = true; $error = __('This username is already reserved to be used soon.', 'profilebuilder') . '<br/>' . __('Please try a different one!', 'profilebuilder'); } elseif (trim($userSignup[0]->user_email) == $userdata['user_email']) { $foundError = true; $error = __('This email address is already reserved to be used soon.', 'profilebuilder') . '<br/>' . __('Please try a different one!', 'profilebuilder'); } if ($foundError) { } else { $new_user = '******'; $multisite_message = true; $meta = array('user_pass' => base64_encode($userdata['user_pass']), 'first_name' => $userdata['first_name'], 'last_name' => $userdata['last_name'], 'nickname' => $userdata['nickname'], 'user_url' => $userdata['user_url'], 'aim' => $userdata['aim'], 'yim' => $userdata['yim'], 'jabber' => $userdata['jabber'], 'description' => $userdata['description'], 'role' => $userdata['role']); $meta = wppb_add_custom_field_values($_POST, $meta); wppb_signup_user($userdata['user_login'], $userdata['user_email'], $meta); } } else { $new_user = wp_insert_user($userdata); /* add the extra profile information */ $wppb_premium = WPPB_PLUGIN_DIR . '/premium/functions/'; if (file_exists($wppb_premium . 'extra.fields.php')) { $wppbFetchArray = get_option('wppb_custom_fields'); foreach ($wppbFetchArray as $key => $value) { switch ($value['item_type']) { case "input": add_user_meta($new_user, $value['item_metaName'], esc_attr($_POST[$value['item_type'] . $value['id']])); break; case "hiddenInput": add_user_meta($new_user, $value['item_metaName'], esc_attr($_POST[$value['item_type'] . $value['id']])); break; case "checkbox": $checkboxOption = ''; $value['item_options'] = wppb_icl_t('plugin profile-builder-pro', 'custom_field_' . $id . '_options_translation', $value['item_options']); $checkboxValue = explode(',', $value['item_options']); foreach ($checkboxValue as $thisValue) { $thisValue = str_replace(' ', '#@space@#', $thisValue); //we need to escape the space-codification we sent earlier in the post if (isset($_POST[$thisValue . $value['id']])) { $localValue = str_replace('#@space@#', ' ', $_POST[$thisValue . $value['id']]); $checkboxOption = $checkboxOption . $localValue . ','; } } add_user_meta($new_user, $value['item_metaName'], $checkboxOption); break; case "radio": add_user_meta($new_user, $value['item_metaName'], $_POST[$value['item_type'] . $value['id']]); break; case "select": add_user_meta($new_user, $value['item_metaName'], $_POST[$value['item_type'] . $value['id']]); break; case "countrySelect": update_user_meta($new_user, $value['item_metaName'], $_POST[$value['item_type'] . $value['id']]); break; case "timeZone": update_user_meta($new_user, $value['item_metaName'], $_POST[$value['item_type'] . $value['id']]); break; case "datepicker": update_user_meta($new_user, $value['item_metaName'], $_POST[$value['item_type'] . $value['id']]); break; case "textarea": add_user_meta($new_user, $value['item_metaName'], esc_attr($_POST[$value['item_type'] . $value['id']])); break; case "upload": $uploadedfile = $value['item_type'] . $value['id']; //first we need to verify if we don't try to upload a 0b or 0 length file if (basename($_FILES[$uploadedfile]['name']) != '') { //second we need to verify if the uploaded file size is less then the set file size in php.ini if ($_FILES[$uploadedfile]['size'] < WPPB_SERVER_MAX_UPLOAD_SIZE_BYTE && $_FILES[$uploadedfile]['size'] != 0) { //we need to prepare the basename of the file, so that ' becomes ` as ' gives an error $fileName = basename($_FILES[$uploadedfile]['name']); $finalFileName = ''; for ($i = 0; $i < strlen($fileName); $i++) { if ($fileName[$i] == "'") { $finalFileName .= '`'; } else { $finalFileName .= $fileName[$i]; } } //create the target path for uploading $wpUploadPath = wp_upload_dir(); // Array of key => value pairs $target_path = $wpUploadPath['basedir'] . "/profile_builder/attachments/"; $target_path = $target_path . 'userID_' . $new_user . '_attachment_' . $finalFileName; if (move_uploaded_file($_FILES[$uploadedfile]['tmp_name'], $target_path)) { //$upFile = get_bloginfo('home').'/'.$target_path; $upFile = $wpUploadPath['baseurl'] . '/profile_builder/attachments/userID_' . $new_user . '_attachment_' . $finalFileName; add_user_meta($new_user, $value['item_metaName'], $upFile); $pictureUpload = 'yes'; } } } break; case "avatar": $uploadedfile = $value['item_type'] . $value['id']; $wpUploadPath = wp_upload_dir(); // Array of key => value pairs $target_path_original = $wpUploadPath['basedir'] . "/profile_builder/avatars/"; $fileName = $_FILES[$uploadedfile]['name']; $finalFileName = ''; for ($i = 0; $i < strlen($fileName); $i++) { if ($fileName[$i] == "'") { $finalFileName .= '`'; } elseif ($fileName[$i] == ' ') { $finalFileName .= '_'; } else { $finalFileName .= $fileName[$i]; } } $fileName = $finalFileName; $target_path = $target_path_original . 'userID_' . $new_user . '_originalAvatar_' . $fileName; /* when trying to upload file, be sure it's one of the accepted image file-types */ if (($_FILES[$uploadedfile]['type'] == 'image/jpeg' || $_FILES[$uploadedfile]['type'] == 'image/jpg' || $_FILES[$uploadedfile]['type'] == 'image/png' || $_FILES[$uploadedfile]['type'] == 'image/bmp' || $_FILES[$uploadedfile]['type'] == 'image/pjpeg' || $_FILES[$uploadedfile]['type'] == 'image/x-png') && ($_FILES[$uploadedfile]['size'] < WPPB_SERVER_MAX_UPLOAD_SIZE_BYTE && $_FILES[$uploadedfile]['size'] != 0)) { $wp_filetype = wp_check_filetype(basename($_FILES[$uploadedfile]['name']), null); $attachment = array('post_mime_type' => $wp_filetype['type'], 'post_title' => $fileName, 'post_content' => '', 'post_status' => 'inherit'); $attach_id = wp_insert_attachment($attachment, $target_path); $upFile = image_downsize($attach_id, 'thumbnail'); $upFile = $upFile[0]; //if file upload succeded if (move_uploaded_file($_FILES[$uploadedfile]['tmp_name'], $target_path)) { add_user_meta($new_user, $value['item_metaName'], $upFile); wppb_resize_avatar($new_user); $avatarUpload = 'yes'; } else { $avatarUpload = 'no'; } } if ($_FILES[$uploadedfile]['type'] == '') { $avatarUpload = 'yes'; } break; } } } // if admin approval is activated, then block the user untill he gets approved $wppb_generalSettings = get_option('wppb_general_settings', 'not_found'); if ($wppb_generalSettings != 'not_found') { if ($wppb_generalSettings['adminApproval'] == 'yes') { wp_set_object_terms($new_user, array('unapproved'), 'user_status', false); clean_object_term_cache($new_user, 'user_status'); } } // send an email to the admin, and - if selected - to the user also. $bloginfo = get_bloginfo('name'); $sentEmailStatus = wppb_notify_user_registration_email($bloginfo, esc_attr($_POST['user_name']), esc_attr($_POST['email']), $_POST['send_credentials_via_email'], $_POST['passw1'], $wppb_generalSettings['adminApproval']); } } elseif (is_multisite()) { //validate username and email $validationRes = wpmu_validate_user_signup($userdata['user_login'], $userdata['user_email']); $error = apply_filters('wppb_register_wpmu_registration_error', $validationRes['errors']->get_error_message()); if (trim($error) != '') { } else { $new_user = '******'; $multisite_message = true; $meta = array('user_pass' => base64_encode($userdata['user_pass']), 'first_name' => $userdata['first_name'], 'last_name' => $userdata['last_name'], 'nickname' => $userdata['nickname'], 'user_url' => $userdata['user_url'], 'aim' => $userdata['aim'], 'yim' => $userdata['yim'], 'jabber' => $userdata['jabber'], 'description' => $userdata['description'], 'role' => $userdata['role']); $meta = wppb_add_custom_field_values($_POST, $meta); wppb_signup_user($userdata['user_login'], $userdata['user_email'], $meta); } } } } ?> <div class="wppb_holder" id="wppb_register"> <?php if (is_user_logged_in() && !current_user_can('create_users')) { global $user_ID; $login = get_userdata($user_ID); if ($login->display_name == '') { $login->display_name = $login->user_login; } $registerFilterArray['loginLogoutError'] = ' <p class="log-in-out alert">' . __('You are logged in as', 'profilebuilder') . ' <a href="' . get_author_posts_url($login->ID) . '" title="' . $login->display_name . '">' . $login->display_name . '</a>. ' . __('You don\'t need another account.', 'profilebuilder') . ' <a href="' . wp_logout_url(get_permalink()) . '" title="' . __('Log out of this account.', 'profilebuilder') . '">' . __('Logout', 'profilebuilder') . ' »</a></p><!-- .log-in-out .alert -->'; $registerFilterArray['loginLogoutError'] = apply_filters('wppb_register_have_account_alert', $registerFilterArray['loginLogoutError'], $login->ID); echo $registerFilterArray['loginLogoutError']; } elseif ($new_user != 'no') { if (current_user_can('create_users')) { if ($multisite_message) { $registerFilterArray['wpmuRegistrationMessage1'] = '<p class="success">' . sprintf(__('An email has been sent to %1$s with information on how to activate his/her account.', 'profilebuilder'), $userdata['user_email']) . '</p><!-- .success -->'; echo $registerFilterArray['registrationMessage1'] = apply_filters('wppb_wpmu_register_account_created1', $registerFilterArray['wpmuRegistrationMessage1'], $registered_name, $userdata['user_email']); } else { $registerFilterArray['registrationMessage1'] = '<p class="success">' . sprintf(__('A user account has been created for %1$s.', 'profilebuilder'), $registered_name) . '</p><!-- .success -->'; echo $registerFilterArray['registrationMessage1'] = apply_filters('wppb_register_account_created1', $registerFilterArray['registrationMessage1'], $registered_name); } $redirectLink = wppb_curpageurl(); if (file_exists(WPPB_PLUGIN_DIR . '/premium/addons/addon.php')) { //check to see if the redirecting addon is present and activated $wppb_addon_settings = get_option('wppb_addon_settings'); if ($wppb_addon_settings['wppb_customRedirect'] == 'show') { //check to see if the redirect location is not an empty string and is activated $customRedirectSettings = get_option('customRedirectSettings'); if (trim($customRedirectSettings['afterRegisterTarget']) != '' && $customRedirectSettings['afterRegister'] == 'yes') { $redirectLink = trim($customRedirectSettings['afterRegisterTarget']); if (wppb_check_missing_http($redirectLink)) { $redirectLink = 'http://' . $redirectLink; } } } } $registerFilterArray['redirectMessage1'] = '<font id="messageTextColor">' . sprintf(__('You will soon be redirected automatically. If you see this page for more than 3 seconds, please click %1$s.%2$s', 'profilebuilder'), '<a href="' . $redirectLink . '">' . __('here', 'profilebuilder') . '</a>', '<meta http-equiv="Refresh" content="3;url=' . $redirectLink . '" />') . '</font><br/><br/>'; echo $registerFilterArray['redirectMessage1'] = apply_filters('wppb_register_redirect_after_creation1', $registerFilterArray['redirectMessage1'], $redirectLink); } else { if ($multisite_message) { $registerFilterArray['wpmuRegistrationMessage2'] = '<p class="success">' . __('An email has been sent to you with information on how to activate your account.', 'profilebuilder') . '</p><!-- .success -->'; echo $registerFilterArray['wpmuRegistrationMessage2'] = apply_filters('wppb_register_account_created2', $registerFilterArray['wpmuRegistrationMessage2'], $registered_name); } else { $registerFilterArray['registrationMessage2'] = '<p class="success">' . sprintf(__('Thank you for registering %1$s.', 'profilebuilder'), $registered_name) . '</p><!-- .success -->'; echo $registerFilterArray['registrationMessage2'] = apply_filters('wppb_register_account_created2', $registerFilterArray['registrationMessage2'], $registered_name); } $redirectLink = wppb_curpageurl(); if (file_exists(WPPB_PLUGIN_DIR . '/premium/addons/addon.php')) { //check to see if the redirecting addon is present and activated $wppb_addon_settings = get_option('wppb_addon_settings'); if ($wppb_addon_settings['wppb_customRedirect'] == 'show') { //check to see if the redirect location is not an empty string and is activated $customRedirectSettings = get_option('customRedirectSettings'); if (trim($customRedirectSettings['afterRegisterTarget']) != '' && $customRedirectSettings['afterRegister'] == 'yes') { $redirectLink = trim($customRedirectSettings['afterRegisterTarget']); if (wppb_check_missing_http($redirectLink)) { $redirectLink = 'http://' . $redirectLink; } } } } $registerFilterArray['redirectMessage2'] = '<font id="messageTextColor">' . sprintf(__('You will soon be redirected automatically. If you see this page for more than 3 seconds, please click %1$s.%2$s', 'profilebuilder'), '<a href="' . $redirectLink . '">' . __('here', 'profilebuilder') . '</a>', '<meta http-equiv="Refresh" content="3;url=' . $redirectLink . '" />') . '</font><br/><br/>'; echo $registerFilterArray['redirectMessage2'] = apply_filters('wppb_register_redirect_after_creation2', $registerFilterArray['redirectMessage2'], $redirectLink); } if (isset($_POST['send_credentials_via_email'])) { if ($sentEmailStatus == 1) { $registerFilterArray['emailMessage1'] = '<p class="error">' . __('An error occured while trying to send the notification email.', 'profilebuilder') . '</p><!-- .error -->'; $registerFilterArray['emailMessage1'] = apply_filters('wppb_register_send_notification_email_fail', $registerFilterArray['emailMessage1']); echo $registerFilterArray['emailMessage1']; } elseif ($sentEmailStatus == 2) { if ($multisite_message) { $registerFilterArray['wpmuEmailMessage2'] = '<p class="success">' . __('An email containing activation instructions was successfully sent.', 'profilebuilder') . '</p><!-- .success -->'; $registerFilterArray['wpmuEmailMessage2'] = apply_filters('wppb_register_send_notification_email_success', $registerFilterArray['wpmuEmailMessage2']); echo $registerFilterArray['wpmuEmailMessage2']; } else { $registerFilterArray['emailMessage2'] = '<p class="success">' . __('An email containing the username and password was successfully sent.', 'profilebuilder') . '</p><!-- .success -->'; $registerFilterArray['emailMessage2'] = apply_filters('wppb_register_send_notification_email_success', $registerFilterArray['emailMessage2']); echo $registerFilterArray['emailMessage2']; } } } } else { if ($error) { $registerFilterArray['errorMessage'] = '<p class="error">' . $error . '</p><!-- .error -->'; $registerFilterArray['errorMessage'] = apply_filters('wppb_register_error_messaging', $registerFilterArray['errorMessage'], $error); echo $registerFilterArray['errorMessage']; } if (current_user_can('create_users') && $registration) { $registerFilterArray['alertMessage1'] = '<p class="alert">' . __('Users can register themselves or you can manually create users here.', 'profilebuilder') . '</p><!-- .alert -->'; $registerFilterArray['alertMessage1'] = apply_filters('wppb_register_alert_messaging1', $registerFilterArray['alertMessage1']); echo $registerFilterArray['alertMessage1']; } elseif (current_user_can('create_users')) { $registerFilterArray['alertMessage2'] = '<p class="alert">' . __('Users cannot currently register themselves, but you can manually create users here.', 'profilebuilder') . '</p><!-- .alert -->'; $registerFilterArray['alertMessage2'] = apply_filters('wppb_register_alert_messaging2', $registerFilterArray['alertMessage2']); echo $registerFilterArray['alertMessage2']; } elseif (!current_user_can('create_users') && !$registration) { $registerFilterArray['alertMessage3'] = '<p class="alert">' . __('Only an administrator can add new users.', 'profilebuilder') . '</p><!-- .alert -->'; $registerFilterArray['alertMessage3'] = apply_filters('wppb_register_alert_messaging3', $registerFilterArray['alertMessage3']); echo $registerFilterArray['alertMessage3']; } if ($registration || current_user_can('create_users')) { /* use this action hook to add extra content before the register form. */ do_action('wppb_before_register_fields'); ?> <form enctype="multipart/form-data" method="post" id="adduser" class="user-forms" action="http://<?php echo $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?> "> <?php echo '<input type="hidden" name="MAX_FILE_SIZE" value="' . WPPB_SERVER_MAX_UPLOAD_SIZE_BYTE . '" /><!-- set the MAX_FILE_SIZE to the server\'s current max upload size in bytes -->'; $registerFilterArray2['name1'] = '<p class="registerNameHeading"><strong>' . __('Name', 'profilebuilder') . '</strong></p>'; $registerFilterArray2['name1'] = apply_filters('wppb_register_content_name1', $registerFilterArray2['name1']); if ($wppb_defaultOptions['username'] == 'show') { $errorVar = ''; $errorMark = ''; if ($wppb_defaultOptions['usernameRequired'] == 'yes') { $errorMark = '<font color="red" title="This field is required for registration.">*</font>'; if (isset($_POST['user_name'])) { if (trim($_POST['user_name']) == '') { $errorMark = '<img src="' . WPPB_PLUGIN_URL . '/assets/images/pencil_delete.png" title="' . __('This field must be filled out before registering (It was marked as required by the administrator)', 'profilebuilder') . '"/>'; $errorVar = ' errorHolder'; } } } if (isset($wppb_generalSettings['loginWith']) && $wppb_generalSettings['loginWith'] == 'email') { if ($wppb_defaultOptions['email'] == 'show') { $errorVar = ''; $errorMark = ''; if ($wppb_defaultOptions['emailRequired'] == 'yes') { $errorMark = '<font color="red" title="' . __('This field is marked as required by the administrator', 'profilebuilder') . '">*</font>'; if (isset($_POST['email'])) { if (trim($_POST['email']) == '' || !is_email(trim($_POST['email']))) { $errorMark = '<img src="' . WPPB_PLUGIN_URL . '/assets/images/pencil_delete.png" title="This field is required for registration."/>'; $errorVar = ' errorHolder'; } } } $localVar = ''; if (isset($_POST['email'])) { $localVar = $_POST['email']; } $registerFilterArray2['name2'] = ' <p class="form-email' . $errorVar . '"> <label for="email">' . __('E-mail', 'profilebuilder') . $errorMark . '</label> <input class="text-input" name="email" type="text" id="email" value="' . trim($localVar) . '" /> </p><!-- .form-email -->'; $registerFilterArray2['name2'] = apply_filters('wppb_register_content_name2_with_email', $registerFilterArray2['name2'], trim($localVar), $errorVar, $errorMark); } } else { $localVar = ''; if (isset($_POST['user_name'])) { $localVar = $_POST['user_name']; } $registerFilterArray2['name2'] = ' <p class="form-username' . $errorVar . '"> <label for="user_name">' . __('Username', 'profilebuilder') . $errorMark . '</label> <input class="text-input" name="user_name" type="text" id="user_name" value="' . trim($localVar) . '" /> </p><!-- .form-username -->'; $registerFilterArray2['name2'] = apply_filters('wppb_register_content_name2', $registerFilterArray2['name2'], trim($localVar), $errorVar, $errorMark); } } if ($wppb_defaultOptions['firstname'] == 'show') { $errorVar = ''; $errorMark = ''; if ($wppb_defaultOptions['firstnameRequired'] == 'yes') { $errorMark = '<font color="red" title="' . __('This field is marked as required by the administrator', 'profilebuilder') . '">*</font>'; if (isset($_POST['first_name'])) { if (trim($_POST['first_name']) == '') { $errorMark = '<img src="' . WPPB_PLUGIN_URL . '/assets/images/pencil_delete.png" title="' . __('This field must be filled out before registering (It was marked as required by the administrator)', 'profilebuilder') . '"/>'; $errorVar = ' errorHolder'; } } } $localVar = ''; if (isset($_POST['first_name'])) { $localVar = $_POST['first_name']; } $registerFilterArray2['name3'] = ' <p class="first_name' . $errorVar . '"> <label for="first_name">' . __('First Name', 'profilebuilder') . $errorMark . '</label> <input class="text-input" name="first_name" type="text" id="first_name" value="' . trim($localVar) . '" /> </p><!-- .first_name -->'; $registerFilterArray2['name3'] = apply_filters('wppb_register_content_name3', $registerFilterArray2['name3'], trim($localVar), $errorVar, $errorMark); } if ($wppb_defaultOptions['lastname'] == 'show') { $errorVar = ''; $errorMark = ''; if ($wppb_defaultOptions['lastnameRequired'] == 'yes') { $errorMark = '<font color="red" title="' . __('This field is marked as required by the administrator', 'profilebuilder') . '">*</font>'; if (isset($_POST['last_name'])) { if (trim($_POST['last_name']) == '') { $errorMark = '<img src="' . WPPB_PLUGIN_URL . '/assets/images/pencil_delete.png" title="' . __('This field must be filled out before registering (It was marked as required by the administrator)', 'profilebuilder') . '"/>'; $errorVar = ' errorHolder'; } } } $localVar = ''; if (isset($_POST['last_name'])) { $localVar = $_POST['last_name']; } $registerFilterArray2['name4'] = ' <p class="last_name' . $errorVar . '"> <label for="last_name">' . __('Last Name', 'profilebuilder') . $errorMark . '</label> <input class="text-input" name="last_name" type="text" id="last_name" value="' . trim($localVar) . '" /> </p><!-- .last_name -->'; $registerFilterArray2['name4'] = apply_filters('wppb_register_content_name4', $registerFilterArray2['name4'], trim($localVar), $errorVar, $errorMark); } if ($wppb_defaultOptions['nickname'] == 'show') { $errorVar = ''; $errorMark = ''; if ($wppb_defaultOptions['nicknameRequired'] == 'yes') { $errorMark = '<font color="red" title="' . __('This field is marked as required by the administrator', 'profilebuilder') . '">*</font>'; if (isset($_POST['nickname'])) { if (trim($_POST['nickname']) == '') { $errorMark = '<img src="' . WPPB_PLUGIN_URL . '/assets/images/pencil_delete.png" title="' . __('This field must be filled out before registering (It was marked as required by the administrator)', 'profilebuilder') . '"/>'; $errorVar = ' errorHolder'; } } } $localVar = ''; if (isset($_POST['nickname'])) { $localVar = $_POST['nickname']; } $registerFilterArray2['name5'] = ' <p class="nickname' . $errorVar . '"> <label for="nickname">' . __('Nickname', 'profilebuilder') . $errorMark . '</label> <input class="text-input" name="nickname" type="text" id="nickname" value="' . trim($localVar) . '" /> </p><!-- .nickname -->'; $registerFilterArray2['name5'] = apply_filters('wppb_register_content_name5', $registerFilterArray2['name5'], trim($localVar), $errorVar, $errorMark); } $registerFilterArray2['info1'] = '<p class="registerContactInfoHeading"><strong>' . __('Contact Info', 'profilebuilder') . '</strong></p>'; $registerFilterArray2['info1'] = apply_filters('wppb_register_content_info1', $registerFilterArray2['info1']); if (isset($wppb_generalSettings['loginWith']) && $wppb_generalSettings['loginWith'] == 'email') { } else { if ($wppb_defaultOptions['email'] == 'show') { $errorVar = ''; $errorMark = ''; if ($wppb_defaultOptions['emailRequired'] == 'yes') { $errorMark = '<font color="red" title="' . __('This field is marked as required by the administrator', 'profilebuilder') . '">*</font>'; if (isset($_POST['email'])) { if (trim($_POST['email']) == '' || !is_email(trim($_POST['email']))) { $errorMark = '<img src="' . WPPB_PLUGIN_URL . '/assets/images/pencil_delete.png" title="This field is required for registration."/>'; $errorVar = ' errorHolder'; } } } $localVar = ''; if (isset($_POST['email'])) { $localVar = $_POST['email']; } $registerFilterArray2['info2'] = ' <p class="form-email' . $errorVar . '"> <label for="email">' . __('E-mail', 'profilebuilder') . $errorMark . '</label> <input class="text-input" name="email" type="text" id="email" value="' . trim($localVar) . '" /> </p><!-- .form-email -->'; $registerFilterArray2['info2'] = apply_filters('wppb_register_content_info2', $registerFilterArray2['info2'], trim($localVar), $errorVar, $errorMark); } } if ($wppb_defaultOptions['website'] == 'show') { $errorVar = ''; $errorMark = ''; if ($wppb_defaultOptions['websiteRequired'] == 'yes') { $errorMark = '<font color="red" title="' . __('This field is marked as required by the administrator', 'profilebuilder') . '">*</font>'; if (isset($_POST['website'])) { if (trim($_POST['website']) == '') { $errorMark = '<img src="' . WPPB_PLUGIN_URL . '/assets/images/pencil_delete.png" title="' . __('This field must be filled out before registering (It was marked as required by the administrator)', 'profilebuilder') . '"/>'; $errorVar = ' errorHolder'; } } } $localVar = ''; if (isset($_POST['website'])) { $localVar = $_POST['website']; } $registerFilterArray2['info3'] = ' <p class="form-website' . $errorVar . '"> <label for="website">' . __('Website', 'profilebuilder') . $errorMark . '</label> <input class="text-input" name="website" type="text" id="website" value="' . trim($localVar) . '" /> </p><!-- .form-website -->'; $registerFilterArray2['info3'] = apply_filters('wppb_register_content_info3', $registerFilterArray2['info3'], trim($localVar), $errorVar, $errorMark); } if ($wppb_defaultOptions['aim'] == 'show') { $errorVar = ''; $errorMark = ''; if ($wppb_defaultOptions['aimRequired'] == 'yes') { $errorMark = '<font color="red" title="' . __('This field is marked as required by the administrator', 'profilebuilder') . '">*</font>'; if (isset($_POST['aim'])) { if (trim($_POST['aim']) == '') { $errorMark = '<img src="' . WPPB_PLUGIN_URL . '/assets/images/pencil_delete.png" title="' . __('This field must be filled out before registering (It was marked as required by the administrator)', 'profilebuilder') . '"/>'; $errorVar = ' errorHolder'; } } } $localVar = ''; if (isset($_POST['aim'])) { $localVar = $_POST['aim']; } $registerFilterArray2['info4'] = ' <p class="form-aim' . $errorVar . '"> <label for="aim">' . __('AIM', 'profilebuilder') . $errorMark . '</label> <input class="text-input" name="aim" type="text" id="aim" value="' . trim($localVar) . '" /> </p><!-- .form-aim -->'; $registerFilterArray2['info4'] = apply_filters('wppb_register_content_info4', $registerFilterArray2['info4'], trim($localVar), $errorVar, $errorMark); } if ($wppb_defaultOptions['yahoo'] == 'show') { $errorVar = ''; $errorMark = ''; if ($wppb_defaultOptions['yahooRequired'] == 'yes') { $errorMark = '<font color="red" title="' . __('This field is marked as required by the administrator', 'profilebuilder') . '">*</font>'; if (isset($_POST['yim'])) { if (trim($_POST['yim']) == '') { $errorMark = '<img src="' . WPPB_PLUGIN_URL . '/assets/images/pencil_delete.png" title="' . __('This field must be filled out before registering (It was marked as required by the administrator)', 'profilebuilder') . '"/>'; $errorVar = ' errorHolder'; } } } $localVar = ''; if (isset($_POST['yim'])) { $localVar = $_POST['yim']; } $registerFilterArray2['info5'] = ' <p class="form-yim' . $errorVar . '"> <label for="yim">' . __('Yahoo IM', 'profilebuilder') . $errorMark . '</label> <input class="text-input" name="yim" type="text" id="yim" value="' . trim($localVar) . '" /> </p><!-- .form-yim -->'; $registerFilterArray2['info5'] = apply_filters('wppb_register_content_info5', $registerFilterArray2['info5'], trim($localVar), $errorVar, $errorMark); } if ($wppb_defaultOptions['jabber'] == 'show') { $errorVar = ''; $errorMark = ''; if ($wppb_defaultOptions['jabberRequired'] == 'yes') { $errorMark = '<font color="red" title="' . __('This field is marked as required by the administrator', 'profilebuilder') . '">*</font>'; if (isset($_POST['jabber'])) { if (trim($_POST['jabber']) == '') { $errorMark = '<img src="' . WPPB_PLUGIN_URL . '/assets/images/pencil_delete.png" title="' . __('This field must be filled out before registering (It was marked as required by the administrator)', 'profilebuilder') . '"/>'; $errorVar = ' errorHolder'; } } } $localVar = ''; if (isset($_POST['jabber'])) { $localVar = $_POST['jabber']; } $registerFilterArray2['info6'] = ' <p class="form-jabber' . $errorVar . '"> <label for="jabber">' . __('Jabber / Google Talk', 'profilebuilder') . $errorMark . '</label> <input class="text-input" name="jabber" type="text" id="jabber" value="' . trim($localVar) . '" /> </p><!-- .form-jabber -->'; $registerFilterArray2['info6'] = apply_filters('wppb_register_content_info6', $registerFilterArray2['info6'], trim($localVar), $errorVar, $errorMark); } $registerFilterArray2['ay1'] = '<p class="registerAboutYourselfHeader"><strong>' . __('About Yourself', 'profilebuilder') . '</strong></p>'; $registerFilterArray2['ay1'] = apply_filters('wppb_register_content_about_yourself1', $registerFilterArray2['ay1']); if ($wppb_defaultOptions['bio'] == 'show') { $errorVar = ''; $errorMark = ''; if ($wppb_defaultOptions['bioRequired'] == 'yes') { $errorMark = '<font color="red" title="' . __('This field is marked as required by the administrator', 'profilebuilder') . '">*</font>'; if (isset($_POST['description'])) { if (trim($_POST['description']) == '') { $errorMark = '<img src="' . WPPB_PLUGIN_URL . '/assets/images/pencil_delete.png" title="' . __('This field must be filled out before registering (It was marked as required by the administrator)', 'profilebuilder') . '"/>'; $errorVar = ' errorHolder'; } } } $localVar = ''; if (isset($_POST['description'])) { $localVar = $_POST['description']; } $registerFilterArray2['ay2'] = ' <p class="form-description' . $errorVar . '"> <label for="description">' . __('Biographical Info', 'profilebuilder') . $errorMark . '</label> <textarea class="text-input" name="description" id="description" rows="5" cols="30">' . trim($localVar) . '</textarea> </p><!-- .form-description -->'; $registerFilterArray2['ay2'] = apply_filters('wppb_register_content_about_yourself2', $registerFilterArray2['ay2'], trim($localVar), $errorVar, $errorMark); } if ($wppb_defaultOptions['password'] == 'show') { $errorMark = ''; $errorMark2 = ''; $errorVar = ''; $errorVar2 = ''; if ($wppb_defaultOptions['passwordRequired'] == 'yes') { $errorMark = '<font color="red" title="This field is required for registration.">*</font>'; $errorMark2 = '<font color="red" title="This field is required for registration.">*</font>'; if (isset($_POST['passw1'])) { if (trim($_POST['passw1']) == '') { $errorMark = '<img src="' . WPPB_PLUGIN_URL . '/assets/images/pencil_delete.png" title="This field is required for registration."/>'; $errorVar = ' errorHolder'; } } if (isset($_POST['passw2'])) { if (trim($_POST['passw2']) == '') { $errorMark2 = '<img src="' . WPPB_PLUGIN_URL . '/assets/images/pencil_delete.png" title="This field is required for registration."/>'; $errorVar2 = ' errorHolder'; } } } $localVar1 = ''; if (isset($_POST['passw1'])) { $localVar1 = $_POST['passw1']; } $localVar2 = ''; if (isset($_POST['passw2'])) { $localVar2 = $_POST['passw2']; } $registerFilterArray2['ay3'] = ' <p class="form-password' . $errorVar . '"> <label for="pass1">' . __('Password', 'profilebuilder') . $errorMark . '</label> <input class="text-input" name="passw1" type="password" id="pass1" value="' . trim($localVar1) . '" /> </p><!-- .form-password --> <p class="form-password' . $errorVar2 . '"> <label for="pass2">' . __('Repeat Password', 'profilebuilder') . $errorMark2 . '</label> <input class="text-input" name="passw2" type="password" id="pass2" value="' . trim($localVar2) . '" /> </p><!-- .form-password -->'; $registerFilterArray2['ay3'] = apply_filters('wppb_register_content_about_yourself3', $registerFilterArray2['ay3'], trim($localVar1), trim($localVar2), $errorVar, $errorMark, $errorVar2, $errorMark2); } $wppb_premium = WPPB_PLUGIN_DIR . '/premium/functions/'; if (file_exists($wppb_premium . 'extra.fields.php')) { require_once $wppb_premium . 'extra.fields.php'; //register_user_extra_fields($error, $_POST, $extraFieldsErrorHolder); $page = 'register'; $returnedValue = wppb_extra_fields($current_user->id, $extraFieldsErrorHolder, $registerFilterArray, $page, $error, $_POST); //copy over extra fields to the rest of the fieldso on the edit profile foreach ($returnedValue as $key => $value) { $registerFilterArray2[$key] = apply_filters('wppb_register_content_' . $key, $value); } } if (function_exists('wppb_add_recaptcha_to_registration_form')) { $wppb_addon_settings = get_option('wppb_addon_settings'); if ($wppb_addon_settings['wppb_reCaptcha'] == 'show') { $reCAPTCHAForm = wppb_add_recaptcha_to_registration_form(); $labelName = apply_filters('wppb_register_anti_spam_title', __('Anti-Spam', 'profilebuilder')); $registerFilterArray2['reCAPTCHAForm'] = '<div class="form-reCAPTCHA"><label class="form-reCAPTCHA-label" for="' . $labelName . '">' . $labelName . '</label>' . $reCAPTCHAForm . '</div><!-- .form-reCAPTCHA -->'; } } // additional filter, just in case it is needed $registerFilterArray2['extraRegistrationFilter'] = ''; $registerFilterArray2['extraRegistrationFilter'] = apply_filters('extraRegistrationField', $registerFilterArray2['extraRegistrationFilter']); // END additional filter, just in case it is needed $wppb_generalSettings = get_option('wppb_general_settings'); if ($wppb_generalSettings['emailConfirmation'] != 'yes') { if (!is_multisite()) { if (isset($_POST['send_credentials_via_email'])) { $checkedVar = ' checked'; } else { $checkedVar = ''; } $registerFilterArray2['confirmationEmailForm'] = ' <p class="send-confirmation-email"> <label for="send-confirmation-email"> <input id="send_credentials_via_email" type="checkbox" name="send_credentials_via_email" value="sending"' . $checkedVar . '/> ' . __('Send these credentials via email.', 'profilebuilder') . ' </label> </p><!-- .send-confirmation-email -->'; $registerFilterArray2['confirmationEmailForm'] = apply_filters('wppb_register_confirmation_email_form', $registerFilterArray2['confirmationEmailForm'], $checkedVar); } } $registerFilterArray2 = apply_filters('wppb_register', $registerFilterArray2); foreach ($registerFilterArray2 as $key => $value) { echo $value; } ?> <p class="form-submit"> <input name="adduser" type="submit" id="addusersub" class="submit button" value="<?php if (current_user_can('create_users')) { _e('Add User', 'profilebuilder'); } else { _e('Register', 'profilebuilder'); } ?> " /> <input name="action" type="hidden" id="action" value="adduser" /> <input type="hidden" name="formName" value="register" /> </p><!-- .form-submit --> <?php wp_nonce_field('verify_true_registration', 'register_nonce_field'); ?> </form><!-- #adduser --> <?php } } /* use this action hook to add extra content after the register form. */ do_action('wppb_after_register_fields'); ?> </div> <?php $output = ob_get_contents(); ob_end_clean(); return $output; }
/** * Update term based on arguments provided. * * The $args will indiscriminately override all values with the same field name. * Care must be taken to not override important information need to update or * update will fail (or perhaps create a new term, neither would be acceptable). * * Defaults will set 'alias_of', 'description', 'parent', and 'slug' if not * defined in $args already. * * 'alias_of' will create a term group, if it doesn't already exist, and update * it for the $term. * * If the 'slug' argument in $args is missing, then the 'name' in $args will be * used. It should also be noted that if you set 'slug' and it isn't unique then * a WP_Error will be passed back. If you don't pass any slug, then a unique one * will be created for you. * * For what can be overrode in `$args`, check the term scheme can contain and stay * away from the term keys. * * @since 2.3.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param int $term_id The ID of the term * @param string $taxonomy The context in which to relate the term to the object. * @param array|string $args Optional. Array of get_terms() arguments. Default empty array. * @return array|WP_Error Returns Term ID and Taxonomy Term ID */ function wp_update_term($term_id, $taxonomy, $args = array()) { global $wpdb; if (!taxonomy_exists($taxonomy)) { return new WP_Error('invalid_taxonomy', __('Invalid taxonomy')); } $term_id = (int) $term_id; // First, get all of the original args $term = get_term($term_id, $taxonomy); if (is_wp_error($term)) { return $term; } if (!$term) { return new WP_Error('invalid_term', __('Empty Term')); } $term = (array) $term->data; // Escape data pulled from DB. $term = wp_slash($term); // Merge old and new args with new args overwriting old ones. $args = array_merge($term, $args); $defaults = array('alias_of' => '', 'description' => '', 'parent' => 0, 'slug' => ''); $args = wp_parse_args($args, $defaults); $args = sanitize_term($args, $taxonomy, 'db'); $parsed_args = $args; // expected_slashed ($name) $name = wp_unslash($args['name']); $description = wp_unslash($args['description']); $parsed_args['name'] = $name; $parsed_args['description'] = $description; if ('' == trim($name)) { return new WP_Error('empty_term_name', __('A name is required for this term')); } if ($parsed_args['parent'] > 0 && !term_exists((int) $parsed_args['parent'])) { return new WP_Error('missing_parent', __('Parent term does not exist.')); } $empty_slug = false; if (empty($args['slug'])) { $empty_slug = true; $slug = sanitize_title($name); } else { $slug = $args['slug']; } $parsed_args['slug'] = $slug; $term_group = isset($parsed_args['term_group']) ? $parsed_args['term_group'] : 0; if ($args['alias_of']) { $alias = get_term_by('slug', $args['alias_of'], $taxonomy); if (!empty($alias->term_group)) { // The alias we want is already in a group, so let's use that one. $term_group = $alias->term_group; } elseif (!empty($alias->term_id)) { /* * The alias is not in a group, so we create a new one * and add the alias to it. */ $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM {$wpdb->terms}") + 1; wp_update_term($alias->term_id, $taxonomy, array('term_group' => $term_group)); } $parsed_args['term_group'] = $term_group; } /** * Filter the term parent. * * Hook to this filter to see if it will cause a hierarchy loop. * * @since 3.1.0 * * @param int $parent ID of the parent term. * @param int $term_id Term ID. * @param string $taxonomy Taxonomy slug. * @param array $parsed_args An array of potentially altered update arguments for the given term. * @param array $args An array of update arguments for the given term. */ $parent = apply_filters('wp_update_term_parent', $args['parent'], $term_id, $taxonomy, $parsed_args, $args); // Check for duplicate slug $duplicate = get_term_by('slug', $slug, $taxonomy); if ($duplicate && $duplicate->term_id != $term_id) { // If an empty slug was passed or the parent changed, reset the slug to something unique. // Otherwise, bail. if ($empty_slug || $parent != $term['parent']) { $slug = wp_unique_term_slug($slug, (object) $args); } else { return new WP_Error('duplicate_term_slug', sprintf(__('The slug “%s” is already in use by another term'), $slug)); } } $tt_id = (int) $wpdb->get_var($wpdb->prepare("SELECT tt.term_taxonomy_id FROM {$wpdb->term_taxonomy} AS tt INNER JOIN {$wpdb->terms} AS t ON tt.term_id = t.term_id WHERE tt.taxonomy = %s AND t.term_id = %d", $taxonomy, $term_id)); // Check whether this is a shared term that needs splitting. $_term_id = _split_shared_term($term_id, $tt_id); if (!is_wp_error($_term_id)) { $term_id = $_term_id; } /** * Fires immediately before the given terms are edited. * * @since 2.9.0 * * @param int $term_id Term ID. * @param string $taxonomy Taxonomy slug. */ do_action('edit_terms', $term_id, $taxonomy); $wpdb->update($wpdb->terms, compact('name', 'slug', 'term_group'), compact('term_id')); if (empty($slug)) { $slug = sanitize_title($name, $term_id); $wpdb->update($wpdb->terms, compact('slug'), compact('term_id')); } /** * Fires immediately after the given terms are edited. * * @since 2.9.0 * * @param int $term_id Term ID * @param string $taxonomy Taxonomy slug. */ do_action('edited_terms', $term_id, $taxonomy); /** * Fires immediate before a term-taxonomy relationship is updated. * * @since 2.9.0 * * @param int $tt_id Term taxonomy ID. * @param string $taxonomy Taxonomy slug. */ do_action('edit_term_taxonomy', $tt_id, $taxonomy); $wpdb->update($wpdb->term_taxonomy, compact('term_id', 'taxonomy', 'description', 'parent'), array('term_taxonomy_id' => $tt_id)); /** * Fires immediately after a term-taxonomy relationship is updated. * * @since 2.9.0 * * @param int $tt_id Term taxonomy ID. * @param string $taxonomy Taxonomy slug. */ do_action('edited_term_taxonomy', $tt_id, $taxonomy); // Clean the relationship caches for all object types using this term. $objects = $wpdb->get_col($wpdb->prepare("SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id = %d", $tt_id)); $tax_object = get_taxonomy($taxonomy); foreach ($tax_object->object_type as $object_type) { clean_object_term_cache($objects, $object_type); } /** * Fires after a term has been updated, but before the term cache has been cleaned. * * @since 2.3.0 * * @param int $term_id Term ID. * @param int $tt_id Term taxonomy ID. * @param string $taxonomy Taxonomy slug. */ do_action("edit_term", $term_id, $tt_id, $taxonomy); /** * Fires after a term in a specific taxonomy has been updated, but before the term * cache has been cleaned. * * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug. * * @since 2.3.0 * * @param int $term_id Term ID. * @param int $tt_id Term taxonomy ID. */ do_action("edit_{$taxonomy}", $term_id, $tt_id); /** This filter is documented in wp-includes/taxonomy-functions.php */ $term_id = apply_filters('term_id_filter', $term_id, $tt_id); clean_term_cache($term_id, $taxonomy); /** * Fires after a term has been updated, and the term cache has been cleaned. * * @since 2.3.0 * * @param int $term_id Term ID. * @param int $tt_id Term taxonomy ID. * @param string $taxonomy Taxonomy slug. */ do_action("edited_term", $term_id, $tt_id, $taxonomy); /** * Fires after a term for a specific taxonomy has been updated, and the term * cache has been cleaned. * * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug. * * @since 2.3.0 * * @param int $term_id Term ID. * @param int $tt_id Term taxonomy ID. */ do_action("edited_{$taxonomy}", $term_id, $tt_id); return array('term_id' => $term_id, 'term_taxonomy_id' => $tt_id); }
/** * Removes a term from the database. * * If the term is a parent of other terms, then the children will be updated to * that term's parent. * * Metadata associated with the term will be deleted. * * @since 2.3.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param int $term Term ID. * @param string $taxonomy Taxonomy Name. * @param array|string $args { * Optional. Array of arguments to override the default term ID. Default empty array. * * @type int $default The term ID to make the default term. This will only override * the terms found if there is only one term found. Any other and * the found terms are used. * @type bool $force_default Optional. Whether to force the supplied term as default to be * assigned even if the object was not going to be term-less. * Default false. * } * @return bool|int|WP_Error True on success, false if term does not exist. Zero on attempted * deletion of default Category. WP_Error if the taxonomy does not exist. */ function wp_delete_term($term, $taxonomy, $args = array()) { global $wpdb; $term = (int) $term; if (!($ids = term_exists($term, $taxonomy))) { return false; } if (is_wp_error($ids)) { return $ids; } $tt_id = $ids['term_taxonomy_id']; $defaults = array(); if ('category' == $taxonomy) { $defaults['default'] = get_option('default_category'); if ($defaults['default'] == $term) { return 0; } // Don't delete the default category } $args = wp_parse_args($args, $defaults); if (isset($args['default'])) { $default = (int) $args['default']; if (!term_exists($default, $taxonomy)) { unset($default); } } if (isset($args['force_default'])) { $force_default = $args['force_default']; } /** * Fires when deleting a term, before any modifications are made to posts or terms. * * @since 4.1.0 * * @param int $term Term ID. * @param string $taxonomy Taxonomy Name. */ do_action('pre_delete_term', $term, $taxonomy); // Update children to point to new parent if (is_taxonomy_hierarchical($taxonomy)) { $term_obj = get_term($term, $taxonomy); if (is_wp_error($term_obj)) { return $term_obj; } $parent = $term_obj->parent; $edit_ids = $wpdb->get_results("SELECT term_id, term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE `parent` = " . (int) $term_obj->term_id); $edit_tt_ids = wp_list_pluck($edit_ids, 'term_taxonomy_id'); /** * Fires immediately before a term to delete's children are reassigned a parent. * * @since 2.9.0 * * @param array $edit_tt_ids An array of term taxonomy IDs for the given term. */ do_action('edit_term_taxonomies', $edit_tt_ids); $wpdb->update($wpdb->term_taxonomy, compact('parent'), array('parent' => $term_obj->term_id) + compact('taxonomy')); // Clean the cache for all child terms. $edit_term_ids = wp_list_pluck($edit_ids, 'term_id'); clean_term_cache($edit_term_ids, $taxonomy); /** * Fires immediately after a term to delete's children are reassigned a parent. * * @since 2.9.0 * * @param array $edit_tt_ids An array of term taxonomy IDs for the given term. */ do_action('edited_term_taxonomies', $edit_tt_ids); } // Get the term before deleting it or its term relationships so we can pass to actions below. $deleted_term = get_term($term, $taxonomy); $object_ids = (array) $wpdb->get_col($wpdb->prepare("SELECT object_id FROM {$wpdb->term_relationships} WHERE term_taxonomy_id = %d", $tt_id)); foreach ($object_ids as $object_id) { $terms = wp_get_object_terms($object_id, $taxonomy, array('fields' => 'ids', 'orderby' => 'none')); if (1 == count($terms) && isset($default)) { $terms = array($default); } else { $terms = array_diff($terms, array($term)); if (isset($default) && isset($force_default) && $force_default) { $terms = array_merge($terms, array($default)); } } $terms = array_map('intval', $terms); wp_set_object_terms($object_id, $terms, $taxonomy); } // Clean the relationship caches for all object types using this term. $tax_object = get_taxonomy($taxonomy); foreach ($tax_object->object_type as $object_type) { clean_object_term_cache($object_ids, $object_type); } $term_meta_ids = $wpdb->get_col($wpdb->prepare("SELECT meta_id FROM {$wpdb->termmeta} WHERE term_id = %d ", $term)); foreach ($term_meta_ids as $mid) { delete_metadata_by_mid('term', $mid); } /** * Fires immediately before a term taxonomy ID is deleted. * * @since 2.9.0 * * @param int $tt_id Term taxonomy ID. */ do_action('delete_term_taxonomy', $tt_id); $wpdb->delete($wpdb->term_taxonomy, array('term_taxonomy_id' => $tt_id)); /** * Fires immediately after a term taxonomy ID is deleted. * * @since 2.9.0 * * @param int $tt_id Term taxonomy ID. */ do_action('deleted_term_taxonomy', $tt_id); // Delete the term if no taxonomies use it. if (!$wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->term_taxonomy} WHERE term_id = %d", $term))) { $wpdb->delete($wpdb->terms, array('term_id' => $term)); } clean_term_cache($term, $taxonomy); /** * Fires after a term is deleted from the database and the cache is cleaned. * * @since 2.5.0 * @since 4.5.0 Introduced the `$object_ids` argument. * * @param int $term Term ID. * @param int $tt_id Term taxonomy ID. * @param string $taxonomy Taxonomy slug. * @param mixed $deleted_term Copy of the already-deleted term, in the form specified * by the parent function. WP_Error otherwise. * @param array $object_ids List of term object IDs. */ do_action('delete_term', $term, $tt_id, $taxonomy, $deleted_term, $object_ids); /** * Fires after a term in a specific taxonomy is deleted. * * The dynamic portion of the hook name, `$taxonomy`, refers to the specific * taxonomy the term belonged to. * * @since 2.3.0 * @since 4.5.0 Introduced the `$object_ids` argument. * * @param int $term Term ID. * @param int $tt_id Term taxonomy ID. * @param mixed $deleted_term Copy of the already-deleted term, in the form specified * by the parent function. WP_Error otherwise. * @param array $object_ids List of term object IDs. */ do_action("delete_{$taxonomy}", $term, $tt_id, $deleted_term, $object_ids); return true; }
function process_posts() { if (!($fp = fopen($this->file, "r"))) { echo '<p><strong>' . __('Failed to open file.', 'wc2') . '</strong></p>'; wp_import_cleanup($this->id); return false; } global $wpdb; $wc2_item = WC2_DB_Item::get_instance(); //all delete //$wc2_item->delete_all_item_data(); //die(); $err = new WP_Error(); $sp = ","; $lines = array(); $buf = ''; while (!feof($fp)) { $temp = fgets($fp, 10240); if (0 == strlen($temp)) { continue; } $num = substr_count($temp, '"'); if (0 == $num % 2 && '' == $buf) { $lines[] = $temp; } elseif (1 == $num % 2 && '' == $buf) { $buf .= $temp; } elseif (0 == $num % 2 && '' != $buf) { $buf .= $temp; } elseif (1 == $num % 2 && '' != $buf) { $buf .= $temp; $lines[] = $buf; $buf = ''; } } fclose($fp); //Post data - fixed define('COL_POST_ID', 0); define('COL_POST_AUTHOR', 1); define('COL_POST_CONTENT', 2); define('COL_POST_TITLE', 3); define('COL_POST_EXCERPT', 4); define('COL_POST_STATUS', 5); define('COL_POST_COMMENT_STATUS', 6); define('COL_POST_PASSWORD', 7); define('COL_POST_NAME', 8); define('COL_POST_MODIFIED', 9); define('COL_POST_CATEGORY', 10); define('COL_POST_TAG', 11); define('COL_POST_CUSTOM_FIELD', 12); define('COL_ITEM_CODE', 13); define('COL_ITEM_NAME', 14); $item_base_column = $wc2_item->get_item_base_column(); $item_meta_column = $wc2_item->get_item_meta_column(); $item_sku_column = $wc2_item->get_item_sku_column(); $item_sku_meta_column = $wc2_item->get_item_sku_meta_column(); $system = wc2_get_option('system'); $this->encode_type = isset($system['csv_encode_type']) ? $system['csv_encode_type'] : 0; $start_col = 13; $sku_start_col = $start_col; foreach ((array) $item_base_column as $key => $column) { if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) { $sku_start_col++; } } foreach ((array) $item_meta_column as $key => $column) { if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) { $sku_start_col++; } } $post_status = array('publish', 'future', 'draft', 'pending', 'private'); $pre_item_code = ''; $item_id = 0; $sku_id = 1; $this->data_rows = count($lines); $this->success = 0; $this->false = 0; //Progressbar 処理件数SET echo '<script type="text/javascript">PG_Set_Max(' . $this->data_rows . ');</script>' . "\r\n"; ob_flush(); flush(); foreach ($lines as $row => $line) { $datas = array(); $datas = explode($sp, trim($line)); $this->values = array(); $buf = ''; foreach ($datas as $data) { $num = substr_count($data, '"'); if (0 == $num % 2 && '' == $buf) { if ('"' == substr($data, 0, 1)) { $data = substr($data, 1); } if ('"' == substr($data, -1)) { $data = substr($data, 0, -1); } $data = str_replace(array('""'), '"', $data); $this->values[] = false !== $data ? $data : ''; } elseif (1 == $num % 2 && '' == $buf) { $buf .= $data; } elseif (0 == $num % 2 && '' != $buf) { $buf .= $sp . $data; } elseif (1 == $num % 2 && '' != $buf) { $buf .= $sp . $data; if ('"' == substr($buf, 0, 1)) { $buf = substr($buf, 1); } if ('"' == substr($buf, -1)) { $buf = substr($buf, 0, -1); } $buf = str_replace(array('""'), '"', $buf); $this->values[] = false !== $buf ? $buf : ''; $buf = ''; } } if ('Post ID' == $this->values[COL_POST_ID]) { $this->data_rows -= 1; $this->progress_add(); continue; } if ($pre_item_code == $this->values[COL_ITEM_CODE] && WC2_Utils::is_blank($this->values[COL_POST_ID])) { $mode = 'add'; $post_id = ''; } else { $post_id = !WC2_Utils::is_blank($this->values[COL_POST_ID]) ? (int) $this->values[COL_POST_ID] : ''; if ($post_id) { $post_ob = get_post($post_id); if (!isset($post_ob->ID) || empty($post_ob)) { $this->error_log($row, __("Post-ID {$post_id} does not exist.", 'wc2')); $this->create_log(); $this->progress_add(); continue; } $mode = 'upd'; } else { $mode = 'add'; } } $wc2_item->set_the_post_id($post_id); //data_check foreach ($this->values as $key => $val) { $value = trim($val); switch ($key) { case COL_POST_ID: if (!preg_match("/^[0-9]+\$/", $value) && 0 != strlen($value)) { $this->error_log($row, __('A value of the Post-ID is abnormal.', 'wc2')); } break; case COL_POST_AUTHOR: case COL_POST_COMMENT_STATUS: case COL_POST_PASSWORD: case COL_POST_NAME: case COL_POST_TITLE: case COL_POST_CONTENT: case COL_POST_EXCERPT: break; case COL_POST_STATUS: if (0 == strlen($value) || !in_array($value, $post_status)) { $this->error_log($row, __('A value of the display status is abnormal.', 'wc2')); } break; case COL_POST_MODIFIED: if ('future' == $this->values[COL_POST_STATUS] && (0 == strlen($value) || '0000-00-00 00:00:00' == $value)) { if (preg_match($date_pattern, $value, $match)) { if (checkdate($match[2], $match[3], $match[1]) && (0 < $match[4] && 24 > $match[4]) && (0 < $match[5] && 60 > $match[5]) && (0 < $match[6] && 60 > $match[6])) { } else { $this->error_log($row, __('A value of the schedule is abnormal.', 'wc2')); } } else { $this->error_log($row, __('A value of the schedule is abnormal.', 'wc2')); } } else { if (0 != strlen($value) && '0000-00-00 00:00:00' != $value) { if (preg_match("/^[0-9]+\$/", substr($value, 0, 4))) { if (strtotime($value) === false) { $this->error_log($row, __('A value of the schedule is abnormal.', 'wc2')); } } else { $datetime = explode(' ', $value); $date_str = $this->dates_interconv($datetime[0]) . ' ' . $datetime[1]; if (strtotime($date_str) === false) { $this->error_log($row, __('A value of the schedule is abnormal.', 'wc2')); } } } } break; case COL_POST_CATEGORY: if (0 == strlen($value)) { $this->error_log($row, __('A category is non-input.', 'wc2')); } break; case COL_POST_TAG: case COL_POST_CUSTOM_FIELD: break; case COL_ITEM_CODE: if (0 == strlen($value)) { $this->error_log($row, __('An item code is non-input.', 'wc2')); } else { $post_ids = $wc2_item->get_some_post_ids_by_item_code($value); if ('upd' == $mode) { if (1 < count($post_ids)) { $this->error_log($row, __('This Item-Code has been duplicated.', 'wc2')); foreach ($post_ids as $res_val) { $this->error_log($row, "item_code=" . $value . ", post_id=" . $res_val['item_post_id']); } } elseif (1 === count($post_ids)) { if ($post_ids[0]['item_post_id'] != $post_id) { $this->error_log($row, __('This Item-Code has already been used.', 'wc2')); $this->error_log($row, "item_code=" . $value . ", post_id=" . $post_ids[0]['item_post_id']); } } } else { if ('add' == $mode) { if ($value != $pre_item_code) { if (0 < count($post_ids)) { $this->error_log($row, __('This Item-Code has already been used.', 'wc2')); foreach ($post_ids as $res_val) { $this->error_log($row, "item_code=" . $value . ", post_id=" . $res_val['item_post_id']); } } } } } } break; case COL_ITEM_NAME: if (0 == strlen($value)) { $this->error_log($row, __('An item name is non-input.', 'wc2')); } break; } } //表示する Item column をエラーチェック $check_num = $start_col; foreach ($item_base_column as $key => $column) { if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) { $check_column[$key] = $check_num; $check_num++; } } foreach ($item_meta_column as $key => $column) { if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) { $check_column[$key] = $check_num; $check_num++; } } foreach ($item_sku_column as $key => $column) { if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) { $check_column[$key] = $check_num; $check_num++; } } foreach ($item_sku_meta_column as $key => $column) { if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) { $check_column[$key] = $check_num; $check_num++; } } foreach ($check_column as $column_key => $data_num) { switch ($column_key) { case ITEM_PRODUCT_TYPE: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the Product type is abnormal.', 'wc2')); } break; case ITEM_CHARGES_TYPE: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the Billing type is abnormal.', 'wc2')); } break; case ITEM_PURCHASE_LIMIT_LOWEST: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the Purchase limit(lowest) is abnormal.', 'wc2')); } break; case ITEM_PURCHASE_LIMIT_HIGHEST: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the Purchase limit(highest) is abnormal.', 'wc2')); } break; case ITEM_POINT_RATE: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the point rate is abnormal.', 'wc2')); } break; case ITEM_QUANTITY_DISCOUNT_NUM1: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the Quantity discount1(number) is abnormal.', 'wc2')); } break; case ITEM_QUANTITY_DISCOUNT_RATE1: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the Quantity discount1(rate) is abnormal.', 'wc2')); } break; case ITEM_QUANTITY_DISCOUNT_NUM2: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the Quantity discount2(number) is abnormal.', 'wc2')); } break; case ITEM_QUANTITY_DISCOUNT_RATE2: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the Quantity discount2(rate) is abnormal.', 'wc2')); } break; case ITEM_QUANTITY_DISCOUNT_NUM3: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the Quantity discount3(number) is abnormal.', 'wc2')); } break; case ITEM_QUANTITY_DISCOUNT_RATE3: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the Quantity discount3(rate) is abnormal.', 'wc2')); } break; case ITEM_SKU_CODE: if (0 == strlen($this->values[$data_num])) { $this->error_log($row, __('A SKU code is non-input.', 'wc2')); } break; case ITEM_SKU_NAME: case ITEM_SKU_UNIT: break; case ITEM_SKU_STOCK: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the SKU stock is abnormal.', 'wc2')); } break; case ITEM_SKU_STATUS: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the SKU status is abnormal.', 'wc2')); } break; case ITEM_SKU_PRICE: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the SKU price is abnormal.', 'wc2')); } break; case ITEM_SKU_COSTPRICE: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the SKU cost price is abnormal.', 'wc2')); } break; case ITEM_SKU_LISTPRICE: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the SKU list price is abnormal.', 'wc2')); } break; case ITEM_SKU_SET_QUANTITY_DISCOUNT: if (!preg_match("/^[0-9]+\$/", $this->values[$data_num])) { $this->error_log($row, __('A value of the Quantity discount applies is abnormal.', 'wc2')); } break; } } if ('' != $this->get_log_line()) { $this->create_log(); $this->progress_add(); continue; } $post = array(); if ($pre_item_code != $this->values[COL_ITEM_CODE]) { $sku_id = 1; if ($this->values[COL_POST_MODIFIED] == '' || $this->values[COL_POST_MODIFIED] == '0000-00-00 00:00:00') { $post['post_date'] = current_time('mysql'); $post['post_date_gmt'] = current_time('mysql', 1); $post['post_modified'] = current_time('mysql'); $post['post_modified_gmt'] = current_time('mysql', 1); } else { if (preg_match("/^[0-9]+\$/", substr($this->values[COL_POST_MODIFIED], 0, 4))) { $time_data = strtotime($this->values[COL_POST_MODIFIED]); } else { $datetime = explode(' ', $this->values[COL_POST_MODIFIED]); $date_str = $this->dates_interconv($datetime[0]) . ' ' . $datetime[1]; $time_data = strtotime($date_str); } $post['post_date'] = date('Y-m-d H:i:s', $time_data); $post['post_date_gmt'] = gmdate('Y-m-d H:i:s', $time_data); $post['post_modified'] = date('Y-m-d H:i:s', $time_data); $post['post_modified_gmt'] = gmdate('Y-m-d H:i:s', $time_data); } if ('publish' == $this->values[COL_POST_STATUS]) { $now = current_time('mysql'); if (mysql2date('U', $post['post_modified'], false) > mysql2date('U', $now, false)) { $this->values[COL_POST_STATUS] = 'future'; } } elseif ('future' == $this->values[COL_POST_STATUS]) { $now = current_time('mysql'); if (mysql2date('U', $post['post_modified'], false) <= mysql2date('U', $now, false)) { $this->values[COL_POST_STATUS] = 'publish'; } } $post['ID'] = $post_id; $post['post_author'] = !WC2_Utils::is_blank($this->values[COL_POST_AUTHOR]) ? $this->values[COL_POST_AUTHOR] : 1; $post['post_content'] = $this->convert_encoding($this->values[COL_POST_CONTENT]); $post['post_title'] = $this->convert_encoding($this->values[COL_POST_TITLE]); $post['post_excerpt'] = $this->convert_encoding($this->values[COL_POST_EXCERPT]); $post['post_status'] = $this->values[COL_POST_STATUS]; $post['comment_status'] = !WC2_Utils::is_blank($this->values[COL_POST_COMMENT_STATUS]) ? $this->values[COL_POST_COMMENT_STATUS] : 'close'; $post['ping_status'] = 'close'; $post['post_password'] = '******' == $post['post_status'] ? '' : $this->values[COL_POST_PASSWORD]; $post['post_type'] = ITEM_POST_TYPE; $post['post_parent'] = 0; $post_name = sanitize_title($this->convert_encoding($this->values[COL_POST_NAME])); $post['post_name'] = wp_unique_post_slug($post_name, $post_id, $post['post_status'], $post['post_type'], $post['post_parent']); $post['to_ping'] = ''; $post['pinged'] = ''; $post['menu_order'] = 0; $post['post_content_filtered'] = ''; if (empty($post['post_name']) && !in_array($post['post_status'], array('draft', 'pending', 'auto-draft'))) { $post['post_name'] = sanitize_title($post['post_title'], $post_id); } if ($mode == 'add') { $post['guid'] = ''; if (false === $wpdb->insert($wpdb->posts, $post)) { $this->error_log($row, __('This data was not registered in the database.', 'wc2')); $pre_item_code = $this->values[COL_ITEM_CODE]; $this->create_log(); $this->progress_add(); continue; } $post_id = $wpdb->insert_id; $wc2_item->set_the_post_id($post_id); $where = array('ID' => $post_id); $wpdb->update($wpdb->posts, array('guid' => get_permalink($post_id)), $where); } elseif ($mode == 'upd') { $where = array('ID' => $post_id); if (false === $wpdb->update($wpdb->posts, $post, $where)) { $this->error_log($row, __('The data were not registered with a database.', 'wc2')); $pre_item_code = $this->values[COL_ITEM_CODE]; $this->create_log(); $this->progress_add(); continue; } //delete all metas of Item $meta_key_table = array(); $cfrows = explode(';', trim($this->values[COL_POST_CUSTOM_FIELD])); //if( !(1 === count($cfrows) && '' == reset($cfrows)) ) { if ('' != reset($cfrows)) { foreach ($cfrows as $cf) { list($meta_key, $meta_value) = explode('=', $cf, 2); if (!WC2_Utils::is_blank($meta_key)) { array_push($meta_key_table, $this->convert_encoding($meta_key)); } } } $meta_key_table = apply_filters('wc2_filter_importitem_delete_postmeta', $meta_key_table); $res = $wc2_item->delete_custome_field_key($meta_key_table); if (false === $res) { $this->error_log($row, __('Error : delete postmeta', 'wc2')); $pre_item_code = $this->values[COL_ITEM_CODE]; $this->create_log(); $this->progress_add(); continue; } //delete Item revisions $res = $wc2_item->delete_item_revision(); if (false === $res) { $this->error_log($row, __('Error : delete revisions', 'wc2')); $pre_item_code = $this->values[COL_ITEM_CODE]; $this->create_log(); $this->progress_add(); continue; } //delete relationships of category $res = $wc2_item->delete_term_relationship(); if (false === $res) { $this->error_log($row, __('Error : delete term_relationships(category)', 'wc2')); $pre_item_code = $this->values[COL_ITEM_CODE]; $this->create_log(); $this->progress_add(); continue; } //delete relationships of tag //$query = "SELECT term_taxonomy_id, COUNT(*) AS ct FROM {$wpdb->term_relationships} GROUP BY term_taxonomy_id"; //$relation_data = $wpdb->get_results( $query, ARRAY_A ); $relation_data = $wc2_item->get_count_term_taxonomy(); foreach ((array) $relation_data as $relation_rows) { $term_taxonomy_where['term_taxonomy_id'] = $relation_rows['term_taxonomy_id']; // $term_taxonomy_id['term_taxonomy_id'] = $relation_rows['term_taxonomy_id']; $term_taxonomy_updatas['count'] = $relation_rows['ct']; if (false === $wpdb->update($wpdb->term_taxonomy, $term_taxonomy_updatas, $term_taxonomy_where)) { $this->error_log($row, __('Error : delete term_relationships(tag)', 'wc2')); $pre_item_code = $this->values[COL_ITEM_CODE]; continue; } } } //add term_relationships, edit term_taxonomy //category $categories = explode(';', $this->values[COL_POST_CATEGORY]); $category_ids = array(); foreach ((array) $categories as $category) { $cat = get_term_by('slug', $category, 'item'); if ($cat == false) { $category = (string) $category; $this->error_log($row, __(sprintf('Since the category slug "%s" does not exist or could not be category registration.', $this->convert_encoding($category)), 'wc2')); continue; } $category_ids[] = $cat->term_id; } $term_taxonomy_ids = wp_set_post_terms($post_id, $category_ids, 'item'); foreach ($term_taxonomy_ids as $term_taxonomy_id) { $wc2_item->term_taxonomy_count_post($term_taxonomy_id); } //tag $tags_concat = str_replace(';', ',', $this->convert_encoding($this->values[COL_POST_TAG])); $term_taxonomy_ids = wp_set_post_terms($post_id, $tags_concat, 'item-tag'); foreach ($term_taxonomy_ids as $term_taxonomy_id) { $wc2_item->term_taxonomy_count_post($term_taxonomy_id); } //add custom field $cfrows = explode(';', trim($this->values[COL_POST_CUSTOM_FIELD])); //if( !(1 === count($cfrows) && '' == reset($cfrows)) ) { if ('' != reset($cfrows)) { $valstr = ''; foreach ($cfrows as $cf) { list($meta_key, $meta_value) = explode('=', $cf, 2); if (!WC2_Utils::is_blank($meta_key)) { update_post_meta($post_id, $this->convert_encoding($meta_key), $this->convert_encoding($meta_value)); } } } $wc2_item->clear_column(); //Item data set $col = $start_col; foreach ($item_base_column as $key => $column) { if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) { $wc2_item->set_the_item_value($key, $this->set_value($col, $column['type'])); $col++; } } foreach ($item_meta_column as $key => $column) { if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) { $wc2_item->set_the_item_value($key, $this->set_value($col, $column['type'])); $col++; } } //SKU data set $col = $sku_start_col; foreach ($item_sku_column as $key => $column) { if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) { $wc2_item->set_the_item_sku_value($key, $sku_id, $this->set_value($col, $column['type'])); $col++; } } foreach ($item_sku_meta_column as $key => $column) { if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) { $wc2_item->set_the_item_sku_value($key, $sku_id, $this->set_value($col, $column['type'])); $col++; } } if ($mode == 'add') { $wc2_item->add_item_data(); } elseif ($mode == 'upd') { $wc2_item->update_item_data(); } } else { //sku登録のみの行 $sku_id++; //SKU data set $col = $sku_start_col; foreach ($item_sku_column as $key => $column) { if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) { $wc2_item->set_the_item_sku_value($key, $sku_id, $this->set_value($col, $column['type'])); $col++; } } foreach ($item_sku_meta_column as $key => $column) { if ($column['display'] != 'none' and $column['type'] != TYPE_PARENT) { $wc2_item->set_the_item_sku_value($key, $sku_id, $this->set_value($col, $column['type'])); $col++; } } $item_id = $wc2_item->get_item_id_by_post_id($post_id); $sku_data = $wc2_item->get_item_sku_data($item_id, $sku_id); if (0 == $wc2_item->count_sku_data($sku_id)) { if (0 < $sku_id and '' != $wc2_item->get_the_item_sku_code($sku_id)) { $res = $wc2_item->add_item_sku_data($sku_id, $wc2_item->get_item_sku_data($item_id, $sku_id)); if (false === $res) { break; } } } else { $res = $wc2_item->update_item_sku_data($sku_id, $wc2_item->get_item_sku_data($item_id, $sku_id)); if (false === $res) { break; } } } if ('' != $this->get_log_line()) { $this->create_log(); } //登録成功数加算 $this->success += 1; $pre_item_code = $this->values[COL_ITEM_CODE]; clean_post_cache($post_id); wp_cache_delete($post_id, 'posts'); wp_cache_delete($post_id, 'post_meta'); clean_object_term_cache($post_id, 'post'); //進捗加算 $this->progress_add(); } wp_import_cleanup($this->id); $this->false = $this->data_rows - $this->success; echo '<h3>' . __('All Done.', 'wc2') . '</h3> <h3>' . sprintf(__('Success %d failure %d', 'wc2'), $this->success, $this->false) . '</h3>'; if (0 < strlen($this->log)) { WC2_Utils::wc2_log($this->log, "import_item.log"); echo str_replace("\n", "<br />", $this->log); } }
/** * Removes a term from the database. * * If the term is a parent of other terms, then the children will be updated to * that term's parent. * * The $args 'default' will only override the terms found, if there is only one * term found. Any other and the found terms are used. * * The $args 'force_default' will force the term supplied as default to be * assigned even if the object was not going to be termless * @package WordPress * @subpackage Taxonomy * @since 2.3.0 * * @uses $wpdb * @uses do_action() Calls both 'delete_term' and 'delete_$taxonomy' action * hooks, passing term object, term id. 'delete_term' gets an additional * parameter with the $taxonomy parameter. * * @param int $term Term ID * @param string $taxonomy Taxonomy Name * @param array|string $args Optional. Change 'default' term id and override found term ids. * @return bool|WP_Error Returns false if not term; true if completes delete action. */ function wp_delete_term( $term, $taxonomy, $args = array() ) { global $wpdb; $term = (int) $term; if ( ! $ids = term_exists($term, $taxonomy) ) return false; if ( is_wp_error( $ids ) ) return $ids; $tt_id = $ids['term_taxonomy_id']; $defaults = array(); if ( 'category' == $taxonomy ) { $defaults['default'] = get_option( 'default_category' ); if ( $defaults['default'] == $term ) return 0; // Don't delete the default category } $args = wp_parse_args($args, $defaults); extract($args, EXTR_SKIP); if ( isset( $default ) ) { $default = (int) $default; if ( ! term_exists($default, $taxonomy) ) unset($default); } // Update children to point to new parent if ( is_taxonomy_hierarchical($taxonomy) ) { $term_obj = get_term($term, $taxonomy); if ( is_wp_error( $term_obj ) ) return $term_obj; $parent = $term_obj->parent; $edit_tt_ids = $wpdb->get_col( "SELECT `term_taxonomy_id` FROM $wpdb->term_taxonomy WHERE `parent` = " . (int)$term_obj->term_id ); do_action( 'edit_term_taxonomies', $edit_tt_ids ); $wpdb->update( $wpdb->term_taxonomy, compact( 'parent' ), array( 'parent' => $term_obj->term_id) + compact( 'taxonomy' ) ); do_action( 'edited_term_taxonomies', $edit_tt_ids ); } $objects = $wpdb->get_col( $wpdb->prepare( "SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $tt_id ) ); foreach ( (array) $objects as $object ) { $terms = wp_get_object_terms($object, $taxonomy, array('fields' => 'ids', 'orderby' => 'none')); if ( 1 == count($terms) && isset($default) ) { $terms = array($default); } else { $terms = array_diff($terms, array($term)); if (isset($default) && isset($force_default) && $force_default) $terms = array_merge($terms, array($default)); } $terms = array_map('intval', $terms); wp_set_object_terms($object, $terms, $taxonomy); } // Clean the relationship caches for all object types using this term $tax_object = get_taxonomy( $taxonomy ); foreach ( $tax_object->object_type as $object_type ) clean_object_term_cache( $objects, $object_type ); // Get the object before deletion so we can pass to actions below $deleted_term = get_term( $term, $taxonomy ); do_action( 'delete_term_taxonomy', $tt_id ); $wpdb->delete( $wpdb->term_taxonomy, array( 'term_taxonomy_id' => $tt_id ) ); do_action( 'deleted_term_taxonomy', $tt_id ); // Delete the term if no taxonomies use it. if ( !$wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_taxonomy WHERE term_id = %d", $term) ) ) $wpdb->delete( $wpdb->terms, array( 'term_id' => $term ) ); clean_term_cache($term, $taxonomy); do_action( 'delete_term', $term, $tt_id, $taxonomy, $deleted_term ); do_action( "delete_$taxonomy", $term, $tt_id, $deleted_term ); return true; }
/** * When the term cache is cleaned, clean the object term cache too * * @since 2.0 * * @param array $ids An array of term IDs. * @param string $taxonomy Taxonomy slug. */ function clean_term_cache($ids) { clean_object_term_cache($ids, 'term'); }
function wppb_update_user_status_on_admin_registration($user_id) { wp_set_object_terms($user_id, array('unapproved'), 'user_status', false); clean_object_term_cache($user_id, 'user_status'); }
/** * Rename tags */ function rename_tags($old = '', $new = '') { $return_value = array('status' => 'ok', 'message' => ''); if (trim(str_replace(',', '', stripslashes($new))) == '') { $return_value['message'] = __('No new tag specified!', 'nggallery'); $return_value['status'] = 'error'; return $return_value; } // String to array $old_tags = explode(',', $old); $new_tags = explode(',', $new); // Remove empty element and trim $old_tags = array_filter($old_tags, 'nggtags_delete_empty_element'); $new_tags = array_filter($new_tags, 'nggtags_delete_empty_element'); // If old/new tag are empty => exit ! if (empty($old_tags) || empty($new_tags)) { $return_value['message'] = __('No new/old valid tag specified!', 'nggallery'); $return_value['status'] = 'error'; return $return_value; } $counter = 0; if (count($old_tags) == count($new_tags)) { // Rename only foreach ((array) $old_tags as $i => $old_tag) { $new_name = $new_tags[$i]; // Get term by name $term = get_term_by('name', $old_tag, 'ngg_tag'); if (!$term) { continue; } // Get objects from term ID $objects_id = get_objects_in_term($term->term_id, 'ngg_tag', array('fields' => 'all_with_object_id')); // Delete old term wp_delete_term($term->term_id, 'ngg_tag'); // Set objects to new term ! (Append no replace) foreach ((array) $objects_id as $object_id) { wp_set_object_terms($object_id, $new_name, 'ngg_tag', true); } // Clean cache clean_object_term_cache($objects_id, 'ngg_tag'); clean_term_cache($term->term_id, 'ngg_tag'); // Increment $counter++; } if ($counter == 0) { $return_value['message'] = __('No tag renamed.', 'nggallery'); } else { $return_value['message'] = sprintf(__('Renamed tag(s) «%1$s» to «%2$s»', 'nggallery'), $old, $new); } } elseif (count($new_tags) == 1) { // Merge // Set new tag $new_tag = $new_tags[0]; if (empty($new_tag)) { $return_value['message'] = __('No valid new tag.', 'nggallery'); $return_value['status'] = 'error'; return $return_value; } // Get terms ID from old terms names $terms_id = array(); foreach ((array) $old_tags as $old_tag) { $term = get_term_by('name', addslashes($old_tag), 'ngg_tag'); $terms_id[] = (int) $term->term_id; } // Get objects from terms ID $objects_id = get_objects_in_term($terms_id, 'ngg_tag', array('fields' => 'all_with_object_id')); // No objects ? exit ! if (!$objects_id) { $return_value['message'] = __('No objects (post/page) found for specified old tags.', 'nggallery'); $return_value['status'] = 'error'; return $return_value; } // Delete old terms foreach ((array) $terms_id as $term_id) { wp_delete_term($term_id, 'ngg_tag'); } // Set objects to new term ! (Append no replace) foreach ((array) $objects_id as $object_id) { wp_set_object_terms($object_id, $new_tag, 'ngg_tag', true); $counter++; } // Test if term is also a category if (term_exists($new_tag, 'category')) { // Edit the slug to use the new term $slug = sanitize_title($new_tag); nggTags::edit_tag_slug($new_tag, $slug); unset($slug); } // Clean cache clean_object_term_cache($objects_id, 'ngg_tag'); clean_term_cache($terms_id, 'ngg_tag'); if ($counter == 0) { $return_value['message'] = __('No tag merged.', 'nggallery'); } else { $return_value['message'] = sprintf(__('Merge tag(s) «%1$s» to «%2$s». %3$s objects edited.', 'nggallery'), $old, $new, $counter); } } else { // Error $return_value['message'] = sprintf(__('Error. Not enough tags provided to rename or merge.', 'nggallery'), $old); $return_value['status'] = 'error'; } do_action('ngg_manage_tags', $new_tags); return $return_value; }
/** * Will clean the post in the cache. * * Cleaning means delete from the cache of the post. Will call to clean the term * object cache associated with the post ID. * * clean_post_cache() will call itself recursively for each child post. * * This function not run if $_wp_suspend_cache_invalidation is not empty. See * wp_suspend_cache_invalidation(). * * @package WordPress * @subpackage Cache * @since 2.0.0 * * @uses do_action() Calls 'clean_post_cache' on $id before adding children (if any). * * @param int $id The Post ID in the cache to clean */ function clean_post_cache($id) { global $_wp_suspend_cache_invalidation, $wpdb; if ( !empty($_wp_suspend_cache_invalidation) ) return; $id = (int) $id; wp_cache_delete($id, 'posts'); wp_cache_delete($id, 'post_meta'); clean_object_term_cache($id, 'post'); wp_cache_delete( 'wp_get_archives', 'general' ); do_action('clean_post_cache', $id); if ( $children = $wpdb->get_col( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d", $id) ) ) { foreach( $children as $cid ) clean_post_cache( $cid ); } }
/** * uni_copy_calendar_event */ public function uni_copy_calendar_event() { $aResult = $this->_r(); $iCopyDateString = !empty($_POST['uni_input_copy_to']) ? esc_sql($_POST['uni_input_copy_to']) : ''; $iEventId = esc_sql($_POST['uni_event_id']); $iCalId = esc_sql($_POST['uni_cal_id']); $sNonce = esc_sql($_POST['uni_auth_nonce']); $sAntiCheat = esc_sql($_POST['cheaters_always_disable_js']); if (empty($sAntiCheat) || $sAntiCheat != 'true_bro' || !wp_verify_nonce($_POST['uni_auth_nonce'], 'uni_authenticate_nonce')) { wp_send_json($aResult); } if (!empty($iCopyDateString) && !empty($iEventId) && !empty($iCalId)) { // data of current event $oEvent = get_post($iEventId); $aPostCustom = get_post_custom($iEventId); $iEventTitle = get_the_title($iEventId); $sEventContent = $oEvent->post_content; $aEventCats = wp_get_post_terms($iEventId, 'uni_calendar_event_cat'); if (!empty($aEventCats) && !is_wp_error($aEventCats)) { $iEventCatId = $aEventCats[0]->term_id; } $iDelta = $aPostCustom['_uni_event_timestamp_end'][0] - $aPostCustom['_uni_event_timestamp_start'][0]; // creating of the new event $iNewPostId = wp_insert_post(array('post_type' => 'uni_calendar_event', 'post_title' => $iEventTitle, 'post_content' => $sEventContent, 'post_status' => 'publish')); if ($iNewPostId != 0) { update_post_meta($iNewPostId, '_uni_event_parent_calendar', $iCalId); $iCopyDateTimestamp = strtotime($iCopyDateString); update_post_meta($iNewPostId, '_uni_event_timestamp_start', $iCopyDateTimestamp); update_post_meta($iNewPostId, '_uni_event_timestamp_end', $iCopyDateTimestamp + $iDelta); update_post_meta($iNewPostId, '_uni_event_user_id', $aPostCustom['_uni_event_user_id'][0]); if (!empty($iEventCatId)) { $iEventCatId = intval($iEventCatId); wp_set_object_terms($iNewPostId, $iEventCatId, 'uni_calendar_event_cat', false); clean_object_term_cache($iNewPostId, 'uni_calendar_event_cat'); } $aResult['status'] = 'success'; $aResult['message'] = sprintf(__('%s Success! %s', 'uni-calendar'), '<div class="notice is-dismissible"><p>', '</p></div>'); $aResult['refetch'] = 'yes'; //$aResult['redirect'] = add_query_arg( array( 'page' => 'uni-events-calendars', 'action' => 'edit-events', 'cal_id' => $iCalId, 'uni_auth_nonce' => wp_create_nonce('uni_authenticate_nonce') ), admin_url('admin.php') ); } else { $aResult['message'] = sprintf(__('%s Error: event not created! %s', 'uni-calendar'), '<div class="notice is-dismissible"><p>', '</p></div>'); } } else { $aResult['message'] = sprintf(__('%s Something went wrong(( %s', 'uni-calendar'), '<div class="notice is-dismissible"><p>', '</p></div>'); } wp_send_json($aResult); }
function flush() { static $done = false; if ($done) { return false; } # can't flush if WP isn't loaded if (!function_exists('get_option')) { return false; } $done = true; global $wpdb; $this->flush = true; if (method_exists('static_cache', 'disable')) { static_cache::disable(); } # flush posts $posts = $wpdb->get_results("SELECT ID, post_title, post_name, post_date, post_type, post_status, post_author, post_parent FROM {$wpdb->posts} WHERE post_status IN ('publish', 'private') OR post_type = 'attachment'"); # force WP widgets to flush wp_cache_delete('widget_recent_posts', 'widget'); wp_cache_delete('recent_comments', 'widget'); wp_cache_delete('get_calendar', 'calendar'); wp_cache_delete('wp_get_archives', 'general'); wp_cache_delete('all_page_ids', 'posts'); wp_cache_delete('get_pages', 'posts'); $post_ids = array(); foreach ($posts as $post) { $post_ids[] = $post->ID; $this->delete($post->ID, 'posts'); $this->delete($post->ID, 'post_meta'); clean_object_term_cache($post->ID, 'post'); do_action('clean_post_cache', $post->ID); # fill a temporary bucket so as to handle permalinks $key = $this->key($post->ID, 'posts'); $this->cache[$key] = $post; if (class_exists('sem_cache') && $post->post_type == 'post') { sem_cache::do_flush_author($post->post_author); sem_cache::do_flush_date($post->post_date); } } unset($posts); if (class_exists('sem_cache')) { # flush get_permalink() intensive stuff before flushing terms foreach ($post_ids as $post_id) { sem_cache::do_flush_post($post_id); } # flush home sem_cache::do_flush_home(); } # flush terms $terms = $wpdb->get_results("SELECT term_id, taxonomy FROM {$wpdb->term_taxonomy} WHERE count > 0"); $taxonomies = array(); $term_ids = array(); if (class_exists('sem_cache')) { foreach ($terms as $term) { sem_cache::do_flush_term($term->term_id, $term->taxonomy); } } foreach ($terms as $term) { $taxonomies[] = $term->taxonomy; $term_ids[] = $term->term_id; $this->delete($term->term_id, $term->taxonomy); } $taxonomies = array_unique($taxonomies); foreach ($taxonomies as $taxonomy) { $this->delete('all_ids', $taxonomy); $this->delete('get', $taxonomy); delete_option("{$taxonomy}_children"); do_action('clean_term_cache', $term_ids, $taxonomy); } $this->delete('last_changed', 'terms'); unset($terms); # flush users $user_ids = $wpdb->get_col("SELECT ID FROM {$wpdb->users}"); foreach ($user_ids as $user_id) { $this->delete($user_id, 'users'); } unset($user_ids); # backup key transients $transients = array('update_core', 'update_plugins', 'update_themes', 'sem_memberships', 'sem_update_plugins', 'sem_update_themes'); $extra = array('feed_220431e2eb0959fa9c7fcb07c6e22632', 'feed_mod_220431e2eb0959fa9c7fcb07c6e22632'); foreach (array_merge($transients, $extra) as $var) { ${$var} = get_transient($var); } # flush options $options = $wpdb->get_col("SELECT option_name FROM {$wpdb->options}"); foreach ($options as $option) { if (!in_array($option, array_merge($transients, $extra))) { if (preg_match("/^_transient_/", $option)) { delete_option($option); } else { $this->delete($option, 'options'); } } } $this->delete('notoptions', 'options'); $this->delete('alloptions', 'options'); unset($options); # restore key transients foreach ($transients as $var) { if (${$var} !== false) { set_transient($var, ${$var}); } } if ($feed_220431e2eb0959fa9c7fcb07c6e22632 !== false) { $var = 'feed_220431e2eb0959fa9c7fcb07c6e22632'; set_transient($var, ${$var}, min(3600, cache_timeout)); $var = 'feed_mod_220431e2eb0959fa9c7fcb07c6e22632'; set_transient($var, time(), min(3600, cache_timeout)); } return true; }
/** * Activate a signup. * * * @param string $activation_key The activation key provided to the user. * @return array An array containing information about the activated user and/or blog */ function wppb_manual_activate_signup($activation_key) { global $wpdb; if (is_multisite()) { $signup = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->signups} WHERE activation_key = %s", $activation_key)); } else { $signup = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "signups WHERE activation_key = %s", $activation_key)); } if (!empty($signup) && !$signup->active) { $meta = unserialize($signup->meta); $user_login = esc_sql($signup->user_login); $user_email = esc_sql($signup->user_email); $password = base64_decode($meta['user_pass']); $user_id = username_exists($user_login); if (!$user_id) { $user_id = wppb_create_user($user_login, $password, $user_email); } else { $user_already_exists = true; } if (!$user_id) { return __('Could not create user!', 'profilebuilder'); } elseif (isset($user_already_exists) && $user_already_exists == true) { return __('That username is already activated!', 'profilebuilder'); } else { $now = current_time('mysql', true); $retVal = is_multisite() ? $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $activation_key)) : $wpdb->update($wpdb->prefix . 'signups', array('active' => 1, 'activated' => $now), array('activation_key' => $activation_key)); wppb_add_meta_to_user_on_activation($user_id, '', $meta); // if admin approval is activated, then block the user untill he gets approved $wppb_general_settings = get_option('wppb_general_settings'); if (isset($wppb_general_settings['adminApproval']) && $wppb_general_settings['adminApproval'] == 'yes') { wp_set_object_terms($user_id, array('unapproved'), 'user_status', false); clean_object_term_cache($user_id, 'user_status'); } wppb_notify_user_registration_email(get_bloginfo('name'), $user_login, $user_email, 'sending', $password, isset($wppb_general_settings['adminApproval']) ? $wppb_general_settings['adminApproval'] : 'no'); do_action('wppb_activate_user', $user_id, $password, $meta); return $retVal ? 'ok' : __('There was an error while trying to activate the user', 'profilebuilder'); } } }
/** * Saves the terms selected on the edit user/profile page in the admin. * * @param int $user_id The ID of the user to save the terms for. */ public function save_user_mla_academic_interests_terms($user_id) { $tax = get_taxonomy('mla_academic_interests'); /* Make sure the current user can edit the user and assign terms before proceeding. */ if (!current_user_can('edit_user', $user_id) && current_user_can($tax->cap->assign_terms)) { return false; } /* if ( ! wp_verify_nonce( $_POST['_wpnonce'] ) ) { return false; } */ // If array add any new keywords. if (is_array($_POST['academic-interests'])) { foreach ($_POST['academic-interests'] as $term_id) { $term_key = term_exists($term_id, 'mla_academic_interests'); if (empty($term_key)) { $term_key = wp_insert_term(sanitize_text_field($term_id), 'mla_academic_interests'); } if (!is_wp_error($term_key)) { $term_ids[] = intval($term_key['term_id']); } else { error_log('*****CAC Academic Interests Error - bad tag*****' . var_export($term_key, true)); } } } // Set object terms for tags. $term_taxonomy_ids = wp_set_object_terms($user_id, $term_ids, 'mla_academic_interests'); clean_object_term_cache($user_id, 'mla_academic_interests'); // Set user meta for theme query. delete_user_meta($user_id, 'academic_interests'); foreach ($term_taxonomy_ids as $term_taxonomy_id) { add_user_meta($user_id, 'academic_interests', $term_taxonomy_id, $unique = false); } }
/** * clean_post_cache() - Will clean the post in the cache * * Cleaning means delete from the cache of the post. Will call to clean * the term object cache associated with the post ID. * * @package WordPress * @subpackage Cache * @since 2.0 * * @uses do_action() Will call the 'clean_post_cache' hook action. * * @param int $id The Post ID in the cache to clean */ function clean_post_cache($id) { global $wpdb; $id = (int) $id; wp_cache_delete($id, 'posts'); wp_cache_delete($id, 'post_meta'); clean_object_term_cache($id, 'post'); wp_cache_delete('wp_get_archives', 'general'); do_action('clean_post_cache', $id); if ($children = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_parent = %d", $id))) { foreach ($children as $cid) { clean_post_cache($cid); } } }
/** * Activate a signup. * * * @param string $activation_key The activation key provided to the user. * @return array An array containing information about the activated user and/or blog */ function qum_manual_activate_signup($activation_key) { global $wpdb; if (is_multisite()) { $signup = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->signups} WHERE activation_key = %s", $activation_key)); } else { $signup = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . $wpdb->prefix . "signups WHERE activation_key = %s", $activation_key)); } if (!empty($signup) && !$signup->active) { $meta = unserialize($signup->meta); $user_login = esc_sql($signup->user_login); $user_email = esc_sql($signup->user_email); /* the password is in hashed form in the signup table and we will copy it later to the user */ $password = NULL; $user_id = username_exists($user_login); if (!$user_id) { $user_id = qum_create_user($user_login, $password, $user_email); } else { $user_already_exists = true; } if (!$user_id) { return __('Could not create user!', 'quickusermanager'); } elseif (isset($user_already_exists) && $user_already_exists == true) { return __('That username is already activated!', 'quickusermanager'); } else { $now = current_time('mysql', true); $retVal = is_multisite() ? $wpdb->update($wpdb->signups, array('active' => 1, 'activated' => $now), array('activation_key' => $activation_key)) : $wpdb->update($wpdb->base_prefix . 'signups', array('active' => 1, 'activated' => $now), array('activation_key' => $activation_key)); qum_add_meta_to_user_on_activation($user_id, '', $meta); // if admin approval is activated, then block the user untill he gets approved $qum_general_settings = get_option('qum_general_settings'); if (isset($qum_general_settings['adminApproval']) && $qum_general_settings['adminApproval'] == 'yes') { wp_set_object_terms($user_id, array('unapproved'), 'user_status', false); clean_object_term_cache($user_id, 'user_status'); } /* copy the hashed password from signup meta to wp user table */ if (!empty($meta['user_pass'])) { /* we might still have the base64 encoded password in signups and not the hash */ if (base64_encode(base64_decode($meta['user_pass'], true)) === $meta['user_pass']) { $meta['user_pass'] = wp_hash_password($meta['user_pass']); } $wpdb->update($wpdb->users, array('user_pass' => $meta['user_pass']), array('ID' => $user_id)); } qum_notify_user_registration_email(get_bloginfo('name'), $user_login, $user_email, 'sending', $password, isset($qum_general_settings['adminApproval']) ? $qum_general_settings['adminApproval'] : 'no'); do_action('qum_activate_user', $user_id, $password, $meta); return $retVal ? 'ok' : __('There was an error while trying to activate the user', 'quickusermanager'); } } }
function wppbc_disable_admin_approval_for_user_role($user_id) { if (current_user_can('delete_users')) { wp_set_object_terms($user_id, NULL, 'user_status'); clean_object_term_cache($user_id, 'user_status'); } }
/** * Builds the sitemap and writes it into a xml file. * * ATTENTION PLUGIN DEVELOPERS! DONT CALL THIS METHOD DIRECTLY! * The method is probably not available, since it is only loaded when needed. * Use do_action("sm_rebuild"); if you want to rebuild the sitemap. * Please refer to the documentation.txt for more details. * * @since 3.0 * @access public * @author Arne Brachhold <himself [at] arnebrachhold [dot] de> * @return array An array with messages such as failed writes etc. */ function BuildSitemap() { global $nxtdb, $posts, $nxt_version; $this->Initate(); if ($this->GetOption("b_memory") != '') { @ini_set("memory_limit", $this->GetOption("b_memory")); } if ($this->GetOption("b_time") != -1) { @set_time_limit($this->GetOption("b_time")); } //This object saves the status information of the script directly to the database $status = new GoogleSitemapGeneratorStatus(); //Other plugins can detect if the building process is active $this->_isActive = true; //$this->AddElement(new GoogleSitemapGeneratorXmlEntry()); //Debug mode? $debug = $this->GetOption("b_debug"); if ($this->GetOption("b_xml")) { $fileName = $this->GetXmlPath(); $status->StartXml($this->GetXmlPath(), $this->GetXmlUrl()); if ($this->IsFileWritable($fileName)) { $this->_fileHandle = fopen($fileName, "w"); if (!$this->_fileHandle) { $status->EndXml(false, "Not openable"); } } else { $status->EndXml(false, "not writable"); } } //Write gzipped sitemap file if ($this->IsGzipEnabled()) { $fileName = $this->GetZipPath(); $status->StartZip($this->GetZipPath(), $this->GetZipUrl()); if ($this->IsFileWritable($fileName)) { $this->_fileZipHandle = gzopen($fileName, "w1"); if (!$this->_fileZipHandle) { $status->EndZip(false, "Not openable"); } } else { $status->EndZip(false, "not writable"); } } if (!$this->_fileHandle && !$this->_fileZipHandle) { $status->End(); return; } //Content of the XML file $this->AddElement(new GoogleSitemapGeneratorXmlEntry('<?xml version="1.0" encoding="UTF-8"' . '?' . '>')); $styleSheet = $this->GetDefaultStyle() && $this->GetOption('b_style_default') === true ? $this->GetDefaultStyle() : $this->GetOption('b_style'); if (!empty($styleSheet)) { $this->AddElement(new GoogleSitemapGeneratorXmlEntry('<' . '?xml-stylesheet type="text/xsl" href="' . $styleSheet . '"?' . '>')); } $this->AddElement(new GoogleSitemapGeneratorDebugEntry("generator=\"nxtclass/" . get_bloginfo('version') . "\"")); $this->AddElement(new GoogleSitemapGeneratorDebugEntry("sitemap-generator-url=\"http://www.arnebrachhold.de\" sitemap-generator-version=\"" . $this->GetVersion() . "\"")); $this->AddElement(new GoogleSitemapGeneratorDebugEntry("generated-on=\"" . date(get_option("date_format") . " " . get_option("time_format")) . "\"")); //All comments as an asso. Array (postID=>commentCount) $comments = $this->GetOption("b_prio_provider") != "" ? $this->GetComments() : array(); //Full number of comments $commentCount = count($comments) > 0 ? $this->GetCommentCount($comments) : 0; if ($debug && $this->GetOption("b_prio_provider") != "") { $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Total comment count: " . $commentCount)); } //Go XML! $this->AddElement(new GoogleSitemapGeneratorXmlEntry('<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">')); $home = get_bloginfo('url'); $homePid = 0; // Load qTranslate settings require_once "sitemap-qtranslate.php"; $qt = qt_settings(); //Add the home page (WITH a slash!) if ($this->GetOption("in_home")) { if ('page' == get_option('show_on_front') && get_option('page_on_front')) { $pageOnFront = get_option('page_on_front'); $p = get_page($pageOnFront); if ($p) { $homePid = $p->ID; if (!$qt["enabled"]) { $this->AddUrl(trailingslashit($home), $this->GetTimestampFromMySql($p->post_modified_gmt && $p->post_modified_gmt != '0000-00-00 00:00:00' ? $p->post_modified_gmt : $p->post_date_gmt), $this->GetOption("cf_home"), $this->GetOption("pr_home")); } qt_permalink($qt, trailingslashit($home), null, $p->post_modified_gmt && $p->post_modified_gmt != '0000-00-00 00:00:00' ? $p->post_modified_gmt : $p->post_date_gmt, $this->GetOption("cf_home"), $this->GetOption("pr_home"), $this); } } else { if (!$qt["enabled"]) { $this->AddUrl(trailingslashit($home), $this->GetTimestampFromMySql(get_lastpostmodified('GMT')), $this->GetOption("cf_home"), $this->GetOption("pr_home")); } qt_permalink($qt, trailingslashit($home), null, get_lastpostmodified('GMT'), $this->GetOption("cf_home"), $this->GetOption("pr_home"), $this); } } //Add the posts if ($this->GetOption("in_posts") || $this->GetOption("in_pages")) { if ($debug) { $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start Postings")); } //Pre 2.1 compatibility. 2.1 introduced 'future' as post_status so we don't need to check post_date $nxtCompat = floatval($nxt_version) < 2.1; $excludes = $this->GetOption('b_exclude'); //Excluded posts and pages (user enetered ID) $exclCats = $this->GetOption("b_exclude_cats"); // Excluded cats if ($exclCats && count($exclCats) > 0 && $this->IsTaxonomySupported()) { $excludedCatPosts = get_objects_in_term($exclCats, "category"); // Get all posts in excl. cats. Unforttunately this also gives us pages, revisions and so on... //Remove the pages, revisions etc from the exclude by category list, because they are always in the uncategorized one. if (count($excludedCatPosts) > 0) { $exclPages = $nxtdb->get_col("SELECT ID FROM `" . $nxtdb->posts . "` WHERE post_type!='post' AND ID IN ('" . implode("','", $excludedCatPosts) . "')"); $exclPages = array_map('intval', $exclPages); //Remove the pages from the exlusion list before if (count($exclPages) > 0) { $excludedCatPosts = array_diff($excludedCatPosts, $exclPages); } //Merge the category exclusion list with the users one if (count($excludedCatPosts) > 0) { $excludes = array_merge($excludes, $excludedCatPosts); } } } $contentStmt = ''; if ($qt["enabled"]) { $contentStmt .= ', post_content '; } $postPageStmt = ''; $inSubPages = $this->GetOption('in_posts_sub') === true; if ($inSubPages && $this->GetOption('in_posts') === true) { $pageDivider = '<!--nextpage-->'; $postPageStmt = ", (character_length(`post_content`) - character_length(REPLACE(`post_content`, '{$pageDivider}', ''))) / " . strlen($pageDivider) . " as postPages"; } $sql = "SELECT `ID`, `post_author`, `post_date`, `post_date_gmt`, `post_status`, `post_name`, `post_modified`, `post_modified_gmt`, `post_parent`, `post_type` {$postPageStmt} {$contentStmt} FROM `" . $nxtdb->posts . "` WHERE "; $where = '('; if ($this->GetOption('in_posts')) { //nxt < 2.1: posts are post_status = publish //nxt >= 2.1: post_type must be 'post', no date check required because future posts are post_status='future' if ($nxtCompat) { $where .= "(post_status = 'publish' AND post_date_gmt <= '" . gmdate('Y-m-d H:i:59') . "')"; } else { if ($this->IsCustomPostTypesSupported() && count($this->GetOption('in_customtypes')) > 0) { $where .= " (post_status = 'publish' AND (post_type in ('','post'"; foreach ($this->GetOption('in_customtypes') as $customType) { $where .= ",'{$customType}'"; } $where .= "))) "; } else { $where .= " (post_status = 'publish' AND (post_type = 'post' OR post_type = '')) "; } } } if ($this->GetOption('in_pages')) { if ($this->GetOption('in_posts')) { $where .= " OR "; } if ($nxtCompat) { //nxt < 2.1: posts have post_status = published, pages have post_status = static $where .= " post_status='static' "; } else { //nxt >= 2.1: posts have post_type = 'post' and pages have post_type = 'page'. Both must be published. $where .= " (post_status = 'publish' AND post_type = 'page') "; } } $where .= ") "; if (is_array($excludes) && count($excludes) > 0) { $where .= " AND ID NOT IN ('" . implode("','", $excludes) . "')"; } $where .= " AND post_password='' ORDER BY post_modified DESC"; $sql .= $where; if ($this->GetOption("b_max_posts") > 0) { $sql .= " LIMIT 0," . $this->GetOption("b_max_posts"); } $postCount = intval($nxtdb->get_var("SELECT COUNT(*) AS cnt FROM `" . $nxtdb->posts . "` WHERE " . $where, 0, 0)); //Create a new connection because we are using mysql_unbuffered_query and don't want to disturb the nxt connection //Safe Mode for other plugins which use mysql_query() without a connection handler and will destroy our resultset :( $con = $postRes = null; //In 2.2, a bug which prevented additional DB connections was fixed if (floatval($nxt_version) < 2.2) { $this->SetOption("b_safemode", true); } if ($this->GetOption("b_safemode") === true) { $postRes = mysql_query($sql, $nxtdb->dbh); if (!$postRes) { trigger_error("MySQL query failed: " . mysql_error(), E_USER_NOTICE); //E_USER_NOTICE will be displayed on our debug mode return; } } else { $con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD, true); if (!$con) { trigger_error("MySQL Connection failed: " . mysql_error(), E_USER_NOTICE); return; } if (!mysql_select_db(DB_NAME, $con)) { trigger_error("MySQL DB Select failed: " . mysql_error(), E_USER_NOTICE); return; } $postRes = mysql_unbuffered_query($sql, $con); if (!$postRes) { trigger_error("MySQL unbuffered query failed: " . mysql_error(), E_USER_NOTICE); return; } } if ($postRes) { //#type $prioProvider GoogleSitemapGeneratorPrioProviderBase $prioProvider = NULL; if ($this->GetOption("b_prio_provider") != '') { $providerClass = $this->GetOption('b_prio_provider'); $prioProvider = new $providerClass($commentCount, $postCount); } //$posts is used by Alex King's Popularity Contest plugin //if($posts == null || !is_array($posts)) { // $posts = &$postRes; //} $z = 1; $zz = 1; //Default priorities $default_prio_posts = $this->GetOption('pr_posts'); $default_prio_pages = $this->GetOption('pr_pages'); //Change frequencies $cf_pages = $this->GetOption('cf_pages'); $cf_posts = $this->GetOption('cf_posts'); $minPrio = $this->GetOption('pr_posts_min'); //Cycle through all posts and add them while ($post = mysql_fetch_object($postRes)) { //Fill the cache with our DB result. Since it's incomplete (no text-content for example), we will clean it later. $cache = array(&$post); update_post_cache($cache); //Set the current working post for other plugins which depend on "the loop" $GLOBALS['post'] =& $post; $permalink = get_permalink($post->ID); if ($permalink != $home && $post->ID != $homePid) { $isPage = false; if ($nxtCompat) { $isPage = $post->post_status == 'static'; } else { $isPage = $post->post_type == 'page'; } //Default Priority if auto calc is disabled $prio = 0; if ($isPage) { //Priority for static pages $prio = $default_prio_pages; } else { //Priority for normal posts $prio = $default_prio_posts; } //If priority calc. is enabled, calculate (but only for posts, not pages)! if ($prioProvider !== null && !$isPage) { //Comment count for this post $cmtcnt = isset($comments[$post->ID]) ? $comments[$post->ID] : 0; $prio = $prioProvider->GetPostPriority($post->ID, $cmtcnt, $post); if ($debug) { $this->AddElement(new GoogleSitemapGeneratorDebugEntry('Debug: Priority report of postID ' . $post->ID . ': Comments: ' . $cmtcnt . ' of ' . $commentCount . ' = ' . $prio . ' points')); } } if (!$isPage && $minPrio > 0 && $prio < $minPrio) { $prio = $minPrio; } //Add it if (!$qt["enabled"]) { $this->AddUrl($permalink, $this->GetTimestampFromMySql($post->post_modified_gmt && $post->post_modified_gmt != '0000-00-00 00:00:00' ? $post->post_modified_gmt : $post->post_date_gmt), $isPage ? $cf_pages : $cf_posts, $prio); } qt_permalink($qt, $permalink, $post->post_content, $post->post_modified_gmt && $post->post_modified_gmt != '0000-00-00 00:00:00' ? $post->post_modified_gmt : $post->post_date_gmt, $isPage ? $cf_pages : $cf_posts, $prio, $this); if ($inSubPages) { $subPage = ''; for ($p = 1; $p <= $post->postPages; $p++) { if (get_option('permalink_structure') == '') { $subPage = $permalink . '&page=' . ($p + 1); } else { $subPage = trailingslashit($permalink) . user_trailingslashit($p + 1, 'single_paged'); } if (!$qt["enabled"]) { $this->AddUrl($subPage, $this->GetTimestampFromMySql($post->post_modified_gmt && $post->post_modified_gmt != '0000-00-00 00:00:00' ? $post->post_modified_gmt : $post->post_date_gmt), $isPage ? $cf_pages : $cf_posts, $prio); } //qt_permalink($qt, $subPage, $post->post_content, ($post->post_modified_gmt && $post->post_modified_gmt!='0000-00-00 00:00:00'?$post->post_modified_gmt:$post->post_date_gmt), ($isPage?$cf_pages:$cf_posts), $prio, $this); } } } //Update the status every 100 posts and at the end. //If the script breaks because of memory or time limit, //we have a "last reponded" value which can be compared to the server settings if ($zz == 100 || $z == $postCount) { $status->SaveStep($z); $zz = 0; } else { $zz++; } $z++; //Clean cache because it's incomplete if (version_compare($nxt_version, "2.5", ">=")) { //nxt 2.5 makes a mysql query for every clean_post_cache to clear the child cache //so I've copied the function here until a patch arrives... nxt_cache_delete($post->ID, 'posts'); nxt_cache_delete($post->ID, 'post_meta'); clean_object_term_cache($post->ID, 'post'); } else { clean_post_cache($post->ID); } } unset($postRes); unset($prioProvider); if ($this->GetOption("b_safemode") !== true && $con) { mysql_close($con); } } if ($debug) { $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Postings")); } } //Add the cats if ($this->GetOption("in_cats")) { if ($debug) { $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start Cats")); } $exclCats = $this->GetOption("b_exclude_cats"); // Excluded cats if ($exclCats == null) { $exclCats = array(); } if (!$this->IsTaxonomySupported()) { $catsRes = $nxtdb->get_results("\r\n\t\t\t\t\t\t\tSELECT\r\n\t\t\t\t\t\t\t\tc.cat_ID AS ID,\r\n\t\t\t\t\t\t\t\tMAX(p.post_modified_gmt) AS last_mod\r\n\t\t\t\t\t\t\tFROM\r\n\t\t\t\t\t\t\t\t`" . $nxtdb->categories . "` c,\r\n\t\t\t\t\t\t\t\t`" . $nxtdb->post2cat . "` pc,\r\n\t\t\t\t\t\t\t\t`" . $nxtdb->posts . "` p\r\n\t\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\t\tpc.category_id = c.cat_ID\r\n\t\t\t\t\t\t\t\tAND p.ID = pc.post_id\r\n\t\t\t\t\t\t\t\tAND p.post_status = 'publish'\r\n\t\t\t\t\t\t\t\tAND p.post_type='post'\r\n\t\t\t\t\t\t\tGROUP\r\n\t\t\t\t\t\t\t\tBY c.cat_id\r\n\t\t\t\t\t\t\t"); if ($catsRes) { foreach ($catsRes as $cat) { if ($cat && $cat->ID && $cat->ID > 0 && !in_array($cat->ID, $exclCats)) { if ($debug) { if ($debug) { $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Cat-ID:" . $cat->ID)); } } if (!$qt["enabled"]) { $this->AddUrl(get_category_link($cat->ID), $this->GetTimestampFromMySql($cat->last_mod), $this->GetOption("cf_cats"), $this->GetOption("pr_cats")); } qt_permalink($qt, get_category_link($cat->ID), null, $cat->last_mod, $this->GetOption("cf_cats"), $this->GetOption("pr_cats"), $this); } } } } else { $cats = get_terms("category", array("hide_empty" => true, "hierarchical" => false)); if ($cats && is_array($cats) && count($cats) > 0) { foreach ($cats as $cat) { if (!in_array($cat->term_id, $exclCats)) { if (!$qt["enabled"]) { $this->AddUrl(get_category_link($cat->term_id), 0, $this->GetOption("cf_cats"), $this->GetOption("pr_cats")); } qt_permalink($qt, get_category_link($cat->term_id), null, 0, $this->GetOption("cf_cats"), $this->GetOption("pr_cats"), $this); } } } } if ($debug) { $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Cats")); } } //Add the archives if ($this->GetOption("in_arch")) { if ($debug) { $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start Archive")); } $now = current_time('mysql'); //nxt2.1 introduced post_status='future', for earlier nxt versions we need to check the post_date_gmt $arcresults = $nxtdb->get_results("\r\n\t\t\t\t\t\tSELECT DISTINCT\r\n\t\t\t\t\t\t\tYEAR(post_date_gmt) AS `year`,\r\n\t\t\t\t\t\t\tMONTH(post_date_gmt) AS `month`,\r\n\t\t\t\t\t\t\tMAX(post_date_gmt) as last_mod,\r\n\t\t\t\t\t\t\tcount(ID) as posts\r\n\t\t\t\t\t\tFROM\r\n\t\t\t\t\t\t\t{$nxtdb->posts}\r\n\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\tpost_date < '{$now}'\r\n\t\t\t\t\t\t\tAND post_status = 'publish'\r\n\t\t\t\t\t\t\tAND post_type = 'post'\r\n\t\t\t\t\t\t\t" . (floatval($nxt_version) < 2.1 ? "AND {$nxtdb->posts}.post_date_gmt <= '" . gmdate('Y-m-d H:i:59') . "'" : "") . "\r\n\t\t\t\t\t\tGROUP BY\r\n\t\t\t\t\t\t\tYEAR(post_date_gmt),\r\n\t\t\t\t\t\t\tMONTH(post_date_gmt)\r\n\t\t\t\t\t\tORDER BY\r\n\t\t\t\t\t\t\tpost_date_gmt DESC"); if ($arcresults) { foreach ($arcresults as $arcresult) { $url = get_month_link($arcresult->year, $arcresult->month); $changeFreq = ""; //Archive is the current one if ($arcresult->month == date("n") && $arcresult->year == date("Y")) { $changeFreq = $this->GetOption("cf_arch_curr"); } else { // Archive is older $changeFreq = $this->GetOption("cf_arch_old"); } if (!$qt["enabled"]) { $this->AddUrl($url, $this->GetTimestampFromMySql($arcresult->last_mod), $changeFreq, $this->GetOption("pr_arch")); } qt_permalink($qt, $url, null, $arcresult->last_mod, $changeFreq, $this->GetOption("pr_arch"), $this); } } if ($debug) { $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Archive")); } } //Add the author pages if ($this->GetOption("in_auth")) { if ($debug) { $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start Author pages")); } $linkFunc = null; //get_author_link is deprecated in nxt 2.1, try to use get_author_posts_url first. if (function_exists('get_author_posts_url')) { $linkFunc = 'get_author_posts_url'; } else { if (function_exists('get_author_link')) { $linkFunc = 'get_author_link'; } } //Who knows what happens in later nxt versions, so check again if it worked if ($linkFunc !== null) { //Unfortunately there is no API function to get all authors, so we have to do it the dirty way... //We retrieve only users with published and not password protected posts (and not pages) //nxt2.1 introduced post_status='future', for earlier nxt versions we need to check the post_date_gmt $sql = "SELECT DISTINCT\r\n\t\t\t\t\t\t\tu.ID,\r\n\t\t\t\t\t\t\tu.user_nicename,\r\n\t\t\t\t\t\t\tMAX(p.post_modified_gmt) AS last_post\r\n\t\t\t\t\t\tFROM\r\n\t\t\t\t\t\t\t{$nxtdb->users} u,\r\n\t\t\t\t\t\t\t{$nxtdb->posts} p\r\n\t\t\t\t\t\tWHERE\r\n\t\t\t\t\t\t\tp.post_author = u.ID\r\n\t\t\t\t\t\t\tAND p.post_status = 'publish'\r\n\t\t\t\t\t\t\tAND p.post_type = 'post'\r\n\t\t\t\t\t\t\tAND p.post_password = ''\r\n\t\t\t\t\t\t\t" . (floatval($nxt_version) < 2.1 ? "AND p.post_date_gmt <= '" . gmdate('Y-m-d H:i:59') . "'" : "") . "\r\n\t\t\t\t\t\tGROUP BY\r\n\t\t\t\t\t\t\tu.ID,\r\n\t\t\t\t\t\t\tu.user_nicename"; $authors = $nxtdb->get_results($sql); if ($authors && is_array($authors)) { foreach ($authors as $author) { if ($debug) { if ($debug) { $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Author-ID:" . $author->ID)); } } $url = $linkFunc == 'get_author_posts_url' ? get_author_posts_url($author->ID, $author->user_nicename) : get_author_link(false, $author->ID, $author->user_nicename); if (!$qt["enabled"]) { $this->AddUrl($url, $this->GetTimestampFromMySql($author->last_post), $this->GetOption("cf_auth"), $this->GetOption("pr_auth")); } qt_permalink($qt, $url, null, $author->last_post, $this->GetOption("cf_auth"), $this->GetOption("pr_auth"), $this); } } } else { //Too bad, no author pages for you :( if ($debug) { $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: No valid author link function found")); } } if ($debug) { $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Author pages")); } } //Add tag pages if ($this->GetOption("in_tags") && $this->IsTaxonomySupported()) { if ($debug) { $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start Tags")); } $tags = get_terms("post_tag", array("hide_empty" => true, "hierarchical" => false)); if ($tags && is_array($tags) && count($tags) > 0) { foreach ($tags as $tag) { if (!$qt["enabled"]) { $this->AddUrl(get_tag_link($tag->term_id), 0, $this->GetOption("cf_tags"), $this->GetOption("pr_tags")); } qt_permalink($qt, get_tag_link($tag->term_id), null, 0, $this->GetOption("cf_tags"), $this->GetOption("pr_tags"), $this); } } if ($debug) { $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Tags")); } } //Add custom taxonomy pages if ($this->GetOption("in_tax") && $this->IsTaxonomySupported()) { if ($debug) { $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start custom taxonomies")); } $enabledTaxonomies = $this->GetOption("in_tax"); $taxList = array(); foreach ($enabledTaxonomies as $taxName) { $taxonomy = get_taxonomy($taxName); if ($taxonomy) { $taxList[] = $nxtdb->escape($taxonomy->name); } } if (count($taxList) > 0) { //We're selecting all term information (t.*) plus some additional fields //like the last mod date and the taxonomy name, so nxt doesnt need to make //additional queries to build the permalink structure. //This does NOT work for categories and tags yet, because nxt uses get_category_link //and get_tag_link internally and that would cause one additional query per term! $sql = "\r\n\t\t\t\t\tSELECT\r\n\t\t\t\t\t\tt.*,\r\n\t\t\t\t\t\ttt.taxonomy AS _taxonomy,\r\n\t\t\t\t\t\tUNIX_TIMESTAMP(MAX(post_date_gmt)) as _mod_date\r\n\t\t\t\t\tFROM\r\n\t\t\t\t\t\t{$nxtdb->posts} p ,\r\n\t\t\t\t\t\t{$nxtdb->term_relationships} r,\r\n\t\t\t\t\t\t{$nxtdb->terms} t,\r\n\t\t\t\t\t\t{$nxtdb->term_taxonomy} tt\r\n\t\t\t\t\tWHERE\r\n\t\t\t\t\t\tp.ID = r.object_id\r\n\t\t\t\t\t\tAND p.post_status = 'publish'\r\n\t\t\t\t\t\tAND p.post_type = 'post'\r\n\t\t\t\t\t\tAND p.post_password = ''\r\n\t\t\t\t\t\tAND r.term_taxonomy_id = t.term_id\r\n\t\t\t\t\t\tAND t.term_id = tt.term_id\r\n\t\t\t\t\t\tAND tt.count > 0\r\n\t\t\t\t\t\tAND tt.taxonomy IN ('" . implode("','", $taxList) . "')\r\n\t\t\t\t\tGROUP BY\r\n\t\t\t\t\t\tt.term_id"; $termInfo = $nxtdb->get_results($sql); foreach ($termInfo as $term) { $this->AddUrl(get_term_link($term, $term->_taxonomy), $term->_mod_date, $this->GetOption("cf_tags"), $this->GetOption("pr_tags")); } } if ($debug) { $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End custom taxonomies")); } } //Add the custom pages if ($debug) { $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start Custom Pages")); } if ($this->_pages && is_array($this->_pages) && count($this->_pages) > 0) { //#type $page GoogleSitemapGeneratorPage foreach ($this->_pages as $page) { $this->AddUrl($page->GetUrl(), $page->getLastMod(), $page->getChangeFreq(), $page->getPriority()); } } if ($debug) { $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End Custom Pages")); } if ($debug) { $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: Start additional URLs")); } do_action('sm_buildmap'); if ($debug) { $this->AddElement(new GoogleSitemapGeneratorDebugEntry("Debug: End additional URLs")); } $this->AddElement(new GoogleSitemapGeneratorXmlEntry("</urlset>")); $pingUrl = ''; if ($this->GetOption("b_xml")) { if ($this->_fileHandle && fclose($this->_fileHandle)) { $this->_fileHandle = null; $status->EndXml(true); $pingUrl = $this->GetXmlUrl(); } else { $status->EndXml(false, "Could not close the sitemap file."); } } if ($this->IsGzipEnabled()) { if ($this->_fileZipHandle && fclose($this->_fileZipHandle)) { $this->_fileZipHandle = null; $status->EndZip(true); $pingUrl = $this->GetZipUrl(); } else { $status->EndZip(false, "Could not close the zipped sitemap file"); } } //Ping Google if ($this->GetOption("b_ping") && !empty($pingUrl)) { $sPingUrl = "http://www.google.com/webmasters/sitemaps/ping?sitemap=" . urlencode($pingUrl); $status->StartGooglePing($sPingUrl); $pingres = $this->RemoteOpen($sPingUrl); if ($pingres == NULL || $pingres === false) { $status->EndGooglePing(false, $this->_lastError); trigger_error("Failed to ping Google: " . htmlspecialchars(strip_tags($pingres)), E_USER_NOTICE); } else { $status->EndGooglePing(true); } } //Ping Ask.com if ($this->GetOption("b_pingask") && !empty($pingUrl)) { $sPingUrl = "http://submissions.ask.com/ping?sitemap=" . urlencode($pingUrl); $status->StartAskPing($sPingUrl); $pingres = $this->RemoteOpen($sPingUrl); if ($pingres == NULL || $pingres === false || strpos($pingres, "successfully received and added") === false) { //Ask.com returns 200 OK even if there was an error, so we need to check the content. $status->EndAskPing(false, $this->_lastError); trigger_error("Failed to ping Ask.com: " . htmlspecialchars(strip_tags($pingres)), E_USER_NOTICE); } else { $status->EndAskPing(true); } } //Ping Bing if ($this->GetOption("b_pingmsn") && !empty($pingUrl)) { $sPingUrl = "http://www.bing.com/webmaster/ping.aspx?siteMap=" . urlencode($pingUrl); $status->StartMsnPing($sPingUrl); $pingres = $this->RemoteOpen($sPingUrl); //Bing returns ip/country-based success messages, so there is no way to check the content. Rely on HTTP 500 only then... if ($pingres == NULL || $pingres === false || strpos($pingres, " ") === false) { trigger_error("Failed to ping Bing: " . htmlspecialchars(strip_tags($pingres)), E_USER_NOTICE); $status->EndMsnPing(false, $this->_lastError); } else { $status->EndMsnPing(true); } } $status->End(); $this->_isActive = false; //done... return $status; }
/** * Deletes bookmark cache * * @since 2.7.0 */ function clean_bookmark_cache($bookmark_id) { wp_cache_delete($bookmark_id, 'bookmark'); wp_cache_delete('get_bookmarks', 'bookmark'); clean_object_term_cache($bookmark_id, 'link'); }
/** * Will clean a post in the cache. * * Will call to clean the term object cache associated with the post ID. * * @since bbPress (r4040) * * @uses do_action() Calls 'bbp_clean_post_cache' on $id * @param object|int $_post The post object or ID to remove from the cache */ function bbp_clean_post_cache($_post = '') { // Bail if no post $_post = get_post($_post); if (empty($_post)) { return; } wp_cache_delete($_post->ID, 'posts'); wp_cache_delete($_post->ID, 'post_meta'); clean_object_term_cache($_post->ID, $_post->post_type); do_action('bbp_clean_post_cache', $_post->ID, $_post); // Child query types to clean $post_types = array(bbp_get_topic_post_type(), bbp_get_forum_post_type(), bbp_get_reply_post_type()); // Loop through query types and clean caches foreach ($post_types as $post_type) { wp_cache_delete('bbp_get_forum_' . $_post->ID . '_reply_id', 'bbpress'); wp_cache_delete('bbp_parent_' . $_post->ID . '_type_' . $post_type . '_child_last_id', 'bbpress'); wp_cache_delete('bbp_parent_' . $_post->ID . '_type_' . $post_type . '_child_count', 'bbpress'); wp_cache_delete('bbp_parent_public_' . $_post->ID . '_type_' . $post_type . '_child_ids', 'bbpress'); wp_cache_delete('bbp_parent_all_' . $_post->ID . '_type_' . $post_type . '_child_ids', 'bbpress'); } // Invalidate parent caches if (!empty($_post->post_parent)) { bbp_clean_post_cache($_post->post_parent); } }
/** * Will clean the attachment in the cache. * * Cleaning means delete from the cache. Optionally will clean the term * object cache associated with the attachment ID. * * This function will not run if $_wp_suspend_cache_invalidation is not empty. * * @since 3.0.0 * * @global bool $_wp_suspend_cache_invalidation * * @param int $id The attachment ID in the cache to clean. * @param bool $clean_terms Optional. Whether to clean terms cache. Default false. */ function clean_attachment_cache($id, $clean_terms = false) { global $_wp_suspend_cache_invalidation; if (!empty($_wp_suspend_cache_invalidation)) { return; } $id = (int) $id; wp_cache_delete($id, 'posts'); wp_cache_delete($id, 'post_meta'); if ($clean_terms) { clean_object_term_cache($id, 'attachment'); } /** * Fires after the given attachment's cache is cleaned. * * @since 3.0.0 * * @param int $id Attachment ID. */ do_action('clean_attachment_cache', $id); }
function clean_post_cache($id) { global $post_cache, $post_meta_cache, $post_term_cache, $blog_id; if (isset($post_cache[$blog_id][$id])) { unset($post_cache[$blog_id][$id]); } if (isset($post_meta_cache[$blog_id][$id])) { unset($post_meta_cache[$blog_id][$id]); } clean_object_term_cache($id, 'post'); }
/** * Builds the sitemap and writes it into a xml file. * * @return array An array with messages such as failed writes etc. */ function BuildSitemap() { global $wpdb, $posts, $wp_version; //Other plugins can detect if the building process is active $this->_isActive = true; if (true) { $fileName = $this->GetXmlPath(); if ($this->IsFileWritable($fileName)) { $this->_fileHandle = fopen($fileName, "w"); } } //Write gzipped sitemap file if ($this->IsGzipEnabled()) { $fileName = $this->GetZipPath(); if ($this->IsFileWritable($fileName)) { $this->_fileZipHandle = gzopen($fileName, "w1"); } } if (!$this->_fileHandle && !$this->_fileZipHandle) { return; } //Content of the XML file $this->AddElement(new TF_SEO_SitemapGeneratorXmlEntry('<?xml version="1.0" encoding="UTF-8"' . '?' . '>')); //All comments as an asso. Array (postID=>commentCount) $comments = array(); //Full number of comments $commentCount = 0; //Go XML! $this->AddElement(new TF_SEO_SitemapGeneratorXmlEntry('<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">')); $home = home_url(); $homePid = 0; //Add the home page (WITH a slash!) if (true) { if ('page' == get_option('show_on_front') && get_option('page_on_front')) { $pageOnFront = get_option('page_on_front'); $p = get_page($pageOnFront); if ($p) { $homePid = $p->ID; $this->AddUrl(trailingslashit($home), $this->GetTimestampFromMySql($p->post_modified_gmt && $p->post_modified_gmt != '0000-00-00 00:00:00' ? $p->post_modified_gmt : $p->post_date_gmt), $this->GetOption("cf_home"), $this->GetOption("pr_home")); } } else { $this->AddUrl(trailingslashit($home), $this->GetTimestampFromMySql(get_lastpostmodified('GMT')), $this->GetOption("cf_home"), $this->GetOption("pr_home")); } } //Add the posts if (true) { $wpCompat = false; $excludes = ''; //Excluded posts and pages (user enetered ID) $exclCats = ''; // Excluded cats $sql = "SELECT `ID`, `post_author`, `post_date`, `post_date_gmt`, `post_status`, `post_name`, `post_modified`, `post_modified_gmt`, `post_parent`, `post_type` FROM `" . $wpdb->posts . "` WHERE "; $where = '('; if (true) { $where .= " (post_status = 'publish' AND (post_type in (''"; foreach (get_post_types() as $customType) { if (!in_array($customType, array('revision', 'nav_menu_item', 'attachment'))) { if (!tfuse_options('seo_xmls_exclude_posttype_' . $customType, false) && 'STOP!' != tfuse_options('seo_xmls_exclude_posttype_' . $customType, 'STOP!')) { $where .= ",'{$customType}'"; } } } $where .= "))) "; } $where .= ") "; $where .= " AND post_password='' ORDER BY post_modified DESC"; $sql .= $where; if ($this->GetOption("b_max_posts") > 0) { $sql .= " LIMIT 0," . $this->GetOption("b_max_posts"); } $postCount = intval($wpdb->get_var("SELECT COUNT(*) AS cnt FROM `" . $wpdb->posts . "` WHERE " . $where, 0, 0)); //Create a new connection because we are using mysql_unbuffered_query and don't want to disturb the WP connection //Safe Mode for other plugins which use mysql_query() without a connection handler and will destroy our resultset :( $con = $postRes = null; if (true) { $postRes = mysql_query($sql, $wpdb->dbh); if (!$postRes) { trigger_error("MySQL query failed: " . mysql_error(), E_USER_NOTICE); //E_USER_NOTICE will be displayed on our debug mode return; } } if ($postRes) { $prioProvider = NULL; $z = 1; $zz = 1; //Default priorities $default_prio_posts = $this->GetOption('pr_posts'); $default_prio_pages = $this->GetOption('pr_pages'); //Change frequencies $cf_pages = $this->GetOption('cf_pages'); $cf_posts = $this->GetOption('cf_posts'); $minPrio = $this->GetOption('pr_posts_min'); //Cycle through all posts and add them while ($post = mysql_fetch_object($postRes)) { //Fill the cache with our DB result. Since it's incomplete (no text-content for example), we will clean it later. $cache = array(&$post); update_post_cache($cache); //Set the current working post for other plugins which depend on "the loop" $GLOBALS['post'] =& $post; $permalink = get_permalink($post->ID); if ($permalink != $home && $post->ID != $homePid) { $isPage = false; if ($wpCompat) { $isPage = $post->post_status == 'static'; } else { $isPage = $post->post_type == 'page'; } //Default Priority if auto calc is disabled $prio = 0; if ($isPage) { //Priority for static pages $prio = $default_prio_pages; } else { //Priority for normal posts $prio = $default_prio_posts; } if (!$isPage && $minPrio > 0 && $prio < $minPrio) { $prio = $minPrio; } //Add it $this->AddUrl($permalink, $this->GetTimestampFromMySql($post->post_modified_gmt && $post->post_modified_gmt != '0000-00-00 00:00:00' ? $post->post_modified_gmt : $post->post_date_gmt), $isPage ? $cf_pages : $cf_posts, $prio); if (false) { $subPage = ''; for ($p = 1; $p <= $post->postPages; $p++) { if (get_option('permalink_structure') == '') { $subPage = $permalink . '&paged=' . ($p + 1); } else { $subPage = trailingslashit($permalink) . user_trailingslashit($p + 1, 'single_paged'); } $this->AddUrl($subPage, $this->GetTimestampFromMySql($post->post_modified_gmt && $post->post_modified_gmt != '0000-00-00 00:00:00' ? $post->post_modified_gmt : $post->post_date_gmt), $isPage ? $cf_pages : $cf_posts, $prio); } } } //Update the status every 100 posts and at the end. //If the script breaks because of memory or time limit, //we have a "last reponded" value which can be compared to the server settings if ($zz == 100 || $z == $postCount) { $zz = 0; } else { $zz++; } $z++; //Clean cache because it's incomplete if (version_compare($wp_version, "2.5", ">=")) { //WP 2.5 makes a mysql query for every clean_post_cache to clear the child cache //so I've copied the function here until a patch arrives... wp_cache_delete($post->ID, 'posts'); wp_cache_delete($post->ID, 'post_meta'); clean_object_term_cache($post->ID, 'post'); } else { clean_post_cache($post->ID); } } unset($postRes); unset($prioProvider); } } //Add custom taxonomy pages if (true) { $taxList = array(); foreach (get_taxonomies() as $taxName) { if (!in_array($taxName, array('nav_menu', 'link_category', 'post_format'))) { $taxonomy = get_taxonomy($taxName); if (isset($taxonomy->labels->name) && trim($taxonomy->labels->name) != '') { if (!tfuse_options('seo_xmls_exclude_taxonomy_' . $taxName, false) && 'STOP!' != tfuse_options('seo_xmls_exclude_taxonomy_' . $taxName, 'STOP!')) { if ($taxonomy) { $taxList[] = $wpdb->escape($taxonomy->name); } } } } } if (count($taxList) > 0) { //We're selecting all term information (t.*) plus some additional fields //like the last mod date and the taxonomy name, so WP doesnt need to make //additional queries to build the permalink structure. //This does NOT work for categories and tags yet, because WP uses get_category_link //and get_tag_link internally and that would cause one additional query per term! $sql = "\r\r\n\t\t\t\t\tSELECT\r\r\n\t\t\t\t\t\tt.*,\r\r\n\t\t\t\t\t\ttt.taxonomy AS _taxonomy,\r\r\n\t\t\t\t\t\tUNIX_TIMESTAMP(MAX(post_date_gmt)) as _mod_date\r\r\n\t\t\t\t\tFROM\r\r\n\t\t\t\t\t\t{$wpdb->posts} p ,\r\r\n\t\t\t\t\t\t{$wpdb->term_relationships} r,\r\r\n\t\t\t\t\t\t{$wpdb->terms} t,\r\r\n\t\t\t\t\t\t{$wpdb->term_taxonomy} tt\r\r\n\t\t\t\t\tWHERE\r\r\n\t\t\t\t\t\tp.ID = r.object_id\r\r\n\t\t\t\t\t\tAND p.post_status = 'publish'\r\r\n\t\t\t\t\t\tAND p.post_password = ''\r\r\n\t\t\t\t\t\tAND r.term_taxonomy_id = t.term_id\r\r\n\t\t\t\t\t\tAND t.term_id = tt.term_id\r\r\n\t\t\t\t\t\tAND tt.count > 0\r\r\n\t\t\t\t\t\tAND tt.taxonomy IN ('" . implode("','", $taxList) . "')\r\r\n\t\t\t\t\tGROUP BY \r\r\n\t\t\t\t\t\tt.term_id"; $termInfo = $wpdb->get_results($sql); foreach ($termInfo as $term) { if (!in_array($term->_taxonomy, array('nav_menu', 'link_category', 'post_format'))) { $this->AddUrl(get_term_link($term->slug, $term->_taxonomy), $term->_mod_date, $this->GetOption("cf_tags"), $this->GetOption("pr_tags")); } } } } //Add the custom pages if ($this->_pages && is_array($this->_pages) && count($this->_pages) > 0) { //#type $page TF_SEO_SitemapGeneratorPage foreach ($this->_pages as $page) { $this->AddUrl($page->GetUrl(), $page->getLastMod(), $page->getChangeFreq(), $page->getPriority()); } } do_action('tf_seo_buildmap'); $this->AddElement(new TF_SEO_SitemapGeneratorXmlEntry("</urlset>")); $pingUrl = ''; if (true) { if ($this->_fileHandle && fclose($this->_fileHandle)) { $this->_fileHandle = null; $pingUrl = $this->GetXmlUrl(); } } if ($this->IsGzipEnabled()) { if ($this->_fileZipHandle && fclose($this->_fileZipHandle)) { $this->_fileZipHandle = null; $pingUrl = $this->GetZipUrl(); } } //Ping Google if (!empty($pingUrl)) { $sPingUrl = "http://www.google.com/webmasters/sitemaps/ping?sitemap=" . urlencode($pingUrl); $pingres = $this->RemoteOpen($sPingUrl); if ($pingres == NULL || $pingres === false) { trigger_error("Failed to ping Google: " . htmlspecialchars(strip_tags($pingres)), E_USER_NOTICE); } } //Ping Ask.com if (!empty($pingUrl)) { $sPingUrl = "http://submissions.ask.com/ping?sitemap=" . urlencode($pingUrl); $pingres = $this->RemoteOpen($sPingUrl); if ($pingres == NULL || $pingres === false || strpos($pingres, "successfully received and added") === false) { //Ask.com returns 200 OK even if there was an error, so we need to check the content. trigger_error("Failed to ping Ask.com: " . htmlspecialchars(strip_tags($pingres)), E_USER_NOTICE); } } //Ping Bing if (!empty($pingUrl)) { $sPingUrl = "http://www.bing.com/webmaster/ping.aspx?siteMap=" . urlencode($pingUrl); $pingres = $this->RemoteOpen($sPingUrl); //Bing returns ip/country-based success messages, so there is no way to check the content. Rely on HTTP 500 only then... if ($pingres == NULL || $pingres === false || strpos($pingres, " ") === false) { trigger_error("Failed to ping Bing: " . htmlspecialchars(strip_tags($pingres)), E_USER_NOTICE); } } $this->_isActive = false; //done... return; }
public function duplicate_terms($original_post_id, $lang) { $this->synchronize_terms($original_post_id, $lang, true); clean_object_term_cache($original_post_id, get_post_type($original_post_id)); }
/** * Will clean the attachment in the cache. * * Cleaning means delete from the cache. Optionaly will clean the term * object cache associated with the attachment ID. * * This function will not run if $_wp_suspend_cache_invalidation is not empty. See * wp_suspend_cache_invalidation(). * * @package WordPress * @subpackage Cache * @since 3.0.0 * * @uses do_action() Calls 'clean_attachment_cache' on $id. * * @param int $id The attachment ID in the cache to clean * @param bool $clean_terms optional. Whether to clean terms cache */ function clean_attachment_cache($id, $clean_terms = false) { global $_wp_suspend_cache_invalidation; if (!empty($_wp_suspend_cache_invalidation)) { return; } $id = (int) $id; wp_cache_delete($id, 'posts'); wp_cache_delete($id, 'post_meta'); if ($clean_terms) { clean_object_term_cache($id, 'attachment'); } do_action('clean_attachment_cache', $id); }
/** * Method for add terms for all or specified posts * * @param string $taxonomy * @param string $match * @param string $new * @return boolean * @author Amaury Balmer */ function addMatchTerms($taxonomy = 'post_tag', $match, $new) { if (trim(str_replace(',', '', stripslashes($new))) == '') { $this->message = __('No new term(s) specified!', 'simpletags'); $this->status = 'error'; return false; } $match_terms = explode(',', $match); $new_terms = explode(',', $new); $match_terms = array_filter($match_terms, '_delete_empty_element'); $new_terms = array_filter($new_terms, '_delete_empty_element'); $counter = 0; if (!empty($match_terms)) { // Match and add // Get terms ID from old match names $terms_id = array(); foreach ((array) $match_terms as $match_term) { $term = get_term_by('name', $match_term, $taxonomy); $terms_id[] = (int) $term->term_id; } // Get object ID with terms ID $objects_id = get_objects_in_term($terms_id, $taxonomy, array('fields' => 'all_with_object_id')); // Add new tags for specified post foreach ((array) $objects_id as $object_id) { wp_set_object_terms($object_id, $new_terms, $taxonomy, true); // Append terms $counter++; } // Clean cache clean_object_term_cache($objects_id, $taxonomy); clean_term_cache($terms_id, $taxonomy); } else { // Add for all posts // Page or not ? $post_type_sql = is_page_have_tags() ? "post_type IN('page', 'post')" : "post_type = 'post'"; // TODO, CPT // Get all posts ID global $wpdb; $objects_id = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE {$post_type_sql}"); // Add new tags for all posts foreach ((array) $objects_id as $object_id) { wp_set_object_terms($object_id, $new_terms, $taxonomy, true); // Append terms $counter++; } // Clean cache clean_object_term_cache($objects_id, $taxonomy); } if ($counter == 0) { $this->message = __('No term added.', 'simpletags'); } else { $this->message = sprintf(__('Term(s) added to %1s post(s).', 'simpletags'), $counter); } return true; }