/** * Updates the trasher setting of the post with the given ID as well as all related posts. * * @since 3.0.0 * @wp-hook save_post * * @param int $post_id Post ID. * @param WP_post $post Post object. * * @return int The number of posts updated. */ public function update_settings($post_id, WP_Post $post) { if (!$this->nonce->is_valid()) { return 0; } if (!in_array($post->post_status, ['publish', 'draft'], true)) { return 0; } $value = array_key_exists(TrasherSettingRepository::META_KEY, $_POST) ? (bool) $_POST[TrasherSettingRepository::META_KEY] : false; if (!$this->setting_repository->update($post_id, $value)) { return 0; } $current_site_id = get_current_blog_id(); $related_posts = $this->content_relations->get_relations($current_site_id, $post_id, 'post'); unset($related_posts[$current_site_id]); if (!$related_posts) { return 1; } $updated_posts = 1; array_walk($related_posts, function ($post_id, $site_id) use(&$updated_posts, $value) { switch_to_blog($site_id); $updated_posts += $this->setting_repository->update($post_id, $value); restore_current_blog(); }); return $updated_posts; }
/** * Validate and save user input * * @param array $data User input * @return bool */ public function save(array $data) { if (!$this->nonce->is_valid()) { return false; } $id = $this->get_current_blog_id($data, get_current_blog_id()); $value = $this->get_sent_value($data); return update_blog_option($id, $this->option_name, $value); }
/** * Updates the translation completed setting of the post with the given ID. * * @since 3.0.0 * @wp-hook save_post * * @param int $post_id Post ID. * @param WP_Post $post Post object. * * @return bool Whether or not the translation completed setting was updated successfully. */ public function update_setting($post_id, WP_Post $post) { if (!$this->nonce->is_valid()) { return false; } if (!in_array($post->post_status, ['publish', 'draft'], true)) { return false; } $value = array_key_exists(PostRepository::META_KEY, $_POST) ? (bool) $_POST[PostRepository::META_KEY] : false; return $this->post_repository->update_post($post_id, $value); }
/** * Updates the setting with the data in the request for the user with the given ID. * * @since 3.0.0 * @wp-hook profile_update * * @param int $user_id User ID. * * @return bool Whether or not the user setting was updated successfully. */ public function update($user_id) { if (!current_user_can('edit_user', $user_id)) { return false; } if ($this->nonce && !$this->nonce->is_valid()) { return false; } $value = $this->get_value(); return $value ? update_user_meta($user_id, $this->meta_key, $value) : delete_user_meta($user_id, $this->meta_key); }
/** * Is this a valid request? * * @param int $context Post id * @return bool */ public function is_valid($context = NULL) { if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return FALSE; } if ($this->is_real_revision($context)) { return FALSE; } if (!current_user_can('edit_post', $context)) { return FALSE; } return $this->nonce->is_valid(); }
/** * Is the AJAX request allowed and should be processed? * * @return bool */ public function is_allowed() { if (!current_user_can('edit_theme_options')) { return false; } if (!$this->nonce->is_valid()) { return false; } return !empty($_GET['mlp_sites']); }
/** * Updates the post type support settings. * * @since 3.0.0 * @wp-hook mlp_modules_save_fields * * @return bool Whether or not the settings were updated successfully. */ public function update_settings() { if (!$this->nonce->is_valid()) { return false; } $custom_post_types = $this->repository->get_custom_post_types(); if (!$custom_post_types || empty($_POST[self::SETTINGS_NAME])) { return $this->repository->unsupport_all_post_types(); } $custom_post_types = array_keys($custom_post_types); $settings = (array) $_POST[self::SETTINGS_NAME]; $custom_post_types = array_combine($custom_post_types, array_map(function ($slug) use($settings) { if (empty($settings[$slug])) { return PostTypeRepository::CPT_INACTIVE; } return empty($settings["{$slug}|links"]) ? PostTypeRepository::CPT_ACTIVE : PostTypeRepository::CPT_QUERY_BASED; }, $custom_post_types)); return $this->repository->set_supported_post_types($custom_post_types); }
/** * Saves module user input. * * @since 0.1 * * @return void */ public function save_options_page_form_fields() { if (!$this->nonce->is_valid()) { return; } // Get current site options $options = get_site_option('inpsyde_multilingual_quicklink_options'); // Get values from submitted form $options['mlp_quicklink_position'] = isset($_POST['quicklink-position']) ? esc_attr($_POST['quicklink-position']) : false; update_site_option('inpsyde_multilingual_quicklink_options', $options); }
/** * Handle term edits. * * @param int $term_taxonomy_id Term taxonomy ID. * * @return bool */ public function edit_term($term_taxonomy_id) { if (!$this->nonce->is_valid()) { return FALSE; } $success = FALSE; $existing = $this->content_relations->get_relations($this->current_site_id, $term_taxonomy_id, 'term'); foreach ($this->post_data as $target_site_id => $target_term_taxonomy_id) { $result = $this->update_terms($existing, $term_taxonomy_id, $target_site_id, (int) $target_term_taxonomy_id); if ($result) { $success = TRUE; } } return $success; }
/** * Returns the HTML string for the hidden nonce field according to the given nonce object. * * @since 3.0.0 * * @param Nonce $nonce Nonce object. * @param bool $with_referer Optional. Render a referer field as well? Defaults to true. * * @return string The HTML string for the hidden nonce field according to the given nonce object. */ function nonce_field(Nonce $nonce, $with_referer = true) { return sprintf('<input type="hidden" name="%s" value="%s">%s', esc_attr($nonce->action()), esc_attr((string) $nonce), $with_referer ? wp_referer_field(false) : ''); }