/** * Saves the settings on a given tab. * * @param array $tab The tab we are saving. * @param int $post_id The ID of the post we are saving. * @param WP_Post $post The post (or page) object that is being saved. * @return void * @author Paul Hughes * @since 3.0 */ public function saveMuutPostTab($tab, $post_id, $post) { $muut_tabs_to_save = array(); foreach ($this->defaultTabs as $default_tab) { $muut_tabs_to_save[] = $default_tab['name']; } if (!in_array($tab['name'], $muut_tabs_to_save) || !empty($tab['post_types']) && !in_array($post->post_type, (array) $tab['post_types'])) { return; } switch ($tab['name']) { case 'commenting-tab': $tab_options = array(); if (isset($_POST[$tab['meta_name']])) { $tab_options = $_POST[$tab['meta_name']]; } $boolean_values = array('disable_uploads'); foreach ($boolean_values as $boolean_value) { $tab_options[$boolean_value] = isset($tab_options[$boolean_value]) ? $tab_options[$boolean_value] : '0'; } Muut_Post_Utility::setPostOption($post_id, $tab['meta_name'], $tab_options); break; case 'channel-tab': $tab_options = array(); if (isset($_POST[$tab['meta_name']])) { $tab_options = $_POST[$tab['meta_name']]; $tab_current_options = Muut_Post_Utility::getPostOption($post_id, $tab['meta_name']); } $boolean_values = array('hide_online', 'disable_uploads'); foreach ($boolean_values as $boolean_value) { $tab_options[$boolean_value] = isset($tab_options[$boolean_value]) ? $tab_options[$boolean_value] : '0'; } $channel_path = isset($tab_options['channel_path']) ? $tab_options['channel_path'] : ''; if (!isset($tab_options['channel_path']) || $tab_options['channel_path'] == '' || !$tab_options['channel_path']) { // If no path is saved yet, let's generate one and save it. $path = sanitize_title($post->post_name); $ancestors = get_post_ancestors($post); foreach ($ancestors as $ancestor) { if (Muut_Post_Utility::isMuutChannelPage($ancestor) && Muut_Post_Utility::getChannelRemotePathForPage($ancestor, true)) { $path = Muut_Post_Utility::getChannelRemotePathForPage($ancestor, true) . '/' . $path; } } $channel_path = $path; } elseif (isset($tab_options['channel_path']) && $tab_options['channel_path'] != '') { $channel_path = Muut_Post_Utility::sanitizeMuutPath($tab_options['channel_path']); } $tab_options['channel_path'] = $channel_path; Muut_Post_Utility::setPostOption($post_id, $tab['meta_name'], $tab_options); break; case 'forum-tab': $tab_options = array(); if (isset($_POST[$tab['meta_name']])) { $tab_options = $_POST[$tab['meta_name']]; } $boolean_values = array('hide_online', 'disable_uploads', 'show_comments_in_forum'); foreach ($boolean_values as $boolean_value) { $tab_options[$boolean_value] = isset($tab_options[$boolean_value]) ? $tab_options[$boolean_value] : '0'; } // Remove the default setting for showing comments in forum, if it was copied // over from an older version of the plugin. if (muut()->getOption('show_comments_in_forum_default')) { muut()->setOption('show_comments_in_forum_default', null); } Muut_Post_Utility::setPostOption($post_id, $tab['meta_name'], $tab_options); Muut_Post_Utility::setAsForumPage($post_id); break; } }
/** * Process the widget arguments to save the customization for that instance. * * @param array $new_instance The changed/new arguments. * @param array $old_instance The previous/old arguments. * @return void * @author Paul Hughes * @since 3.0.2 */ public function update($new_instance, $old_instance) { $instance = array(); $instance['title'] = !empty($new_instance['title']) ? strip_tags($new_instance['title']) : ''; $instance['disable_uploads'] = !empty($new_instance['disable_uploads']) ? $new_instance['disable_uploads'] : '0'; // Make sure that the path is saved as SOMETHING. $default_path = isset($old_instance['muut_path']) ? $old_instance['muut_path'] : ''; $default_path = empty($default_path) ? sanitize_title($instance['title']) : $default_path; $default_path = empty($default_path) ? sanitize_title($this->get_field_id('muut_path')) : $default_path; $default_path = !isset($old_instance['muut_path']) ? '' : $default_path; $instance['muut_path'] = !empty($new_instance['muut_path']) ? Muut_Post_Utility::sanitizeMuutPath($new_instance['muut_path']) : $default_path; return $instance; }