protected function column_name(WP_MSM_Profile $profile)
 {
     echo '<strong>' . esc_html($profile->displayName) . '</strong>';
     $urlBase = WP_MSM_Admin::pageURL('profiles');
     $editUrl = add_query_arg(array('action' => 'edit', 'profile' => $profile->name), $urlBase);
     $duplicateUrl = add_query_arg(array('action' => 'duplicate', 'profile' => $profile->name, '_wpnonce' => wp_create_nonce('wpmsm_duplicate_profile_' . $profile->name)), $urlBase);
     $deleteUrl = add_query_arg(array('action' => 'delete', 'profile' => $profile->name, '_wpnonce' => wp_create_nonce('wpmsm_delete_profile_' . $profile->name)), $urlBase);
     $actions = array('edit' => '<a href="' . esc_url($editUrl) . '">' . _x('Edit', 'verb', 'WordPress-MultiServer-Migration') . '</a>', 'duplicate' => '<a href="' . esc_url($duplicateUrl) . '">' . _x('Duplicate', 'verb', 'WordPress-MultiServer-Migration') . '</a>', 'delete' => '<a href="' . esc_url($deleteUrl) . '">' . __('Delete', 'WordPress-MultiServer-Migration') . '</a>');
     if ($this->profileManager->is_default_profile($profile->name)) {
         unset($actions['edit']);
         unset($actions['delete']);
     }
     echo $this->row_actions($actions);
 }
コード例 #2
0
 public static function preLoadPage()
 {
     if (!empty($_GET['subpage']) && $_GET['subpage'] == 'profiles') {
         $action = empty($_GET['action']) ? '' : stripslashes($_GET['action']);
         switch ($action) {
             case 'edit':
                 $submitted = empty($_POST['wpmsm']) ? false : $_POST['wpmsm'];
                 if (empty($_POST['_wpnonce']) || !$submitted) {
                     break;
                 }
                 check_admin_referer("wpmsm_edit_profile_{$_GET['profile']}");
                 $submitted = stripslashes_deep($submitted);
                 $profileManager = new WP_MSM_Profile_Manager();
                 $profile = $profileManager->get_profile($_GET['profile']);
                 if (!$profile) {
                     wp_die(__('That profile does not exist.', 'WordPress-MultiServer-Migration'));
                 }
                 $slugName = $submitted['name'];
                 $slugName = sanitize_title_with_dashes($slugName);
                 if ($slugName != $profile->name && $profileManager->get_profile($slugName)) {
                     add_settings_error('', 'name-collision', __('Invalid name. Name already exists.', 'WordPress-MultiServer-Migration'));
                     break;
                 }
                 if (empty($submitted['exclude_table'])) {
                     $submitted['exclude_table'] = array();
                 }
                 $profile->name = $slugName;
                 $profile->displayName = $submitted['name'];
                 $profile->description = $submitted['description'];
                 $profile->canExport = 'no' === $submitted['disable_export'];
                 $profile->dbTablesToExclude = $submitted['exclude_table'];
                 $profileManager->update_profile($_GET['profile'], $profile);
                 if ($_GET['profile'] != $profile->name) {
                     $redirectUrl = add_query_arg(array('action' => 'edit', 'profile' => $profile->name), self::pageURL('profiles'));
                     wp_redirect($redirectUrl);
                     exit;
                 }
                 add_settings_error('', 'profile-updated', __('The profile was updated.', 'WordPress-MultiServer-Migration'), 'updated');
                 break;
             case 'delete':
                 $profile = empty($_GET['profile']) ? '' : $_GET['profile'];
                 check_admin_referer("wpmsm_delete_profile_{$profile}");
                 $profileManager = new WP_MSM_Profile_Manager();
                 if (!$profileManager->get_profile($profile)) {
                     wp_die(__('That profile does not exist.', 'WordPress-MultiServer-Migration'));
                 } elseif ($profileManager->is_default_profile($profile)) {
                     wp_die(__('Cannot delete default profiles.', 'WordPress-MultiServer-Migration'));
                 }
                 $profileManager->delete_profile($profile);
                 $redirectUrl = add_query_arg(array('action' => 'deleted'), self::pageURL('profiles'));
                 wp_redirect($redirectUrl);
                 exit;
                 break;
             case 'duplicate':
                 $profile = empty($_GET['profile']) ? '' : $_GET['profile'];
                 check_admin_referer("wpmsm_duplicate_profile_{$profile}");
                 $profileManager = new WP_MSM_Profile_Manager();
                 $theProfile = $profileManager->get_profile($profile);
                 if (!$theProfile) {
                     wp_die(__("That profile does not exist.", 'WordPress-MultiServer-Migration'));
                 }
                 $newProfile = $theProfile->_toArray();
                 $counter = 2;
                 while ($profileManager->get_profile($theProfile->name . $counter)) {
                     $counter++;
                 }
                 $newProfile['name'] = $theProfile->name . $counter;
                 $newProfile['displayName'] = $theProfile->displayName . " {$counter}";
                 $newProfile = new WP_MSM_Profile($newProfile);
                 $profileManager->add_profile($newProfile->name, $newProfile);
                 $redirectUrl = add_query_arg(array('action' => 'edit', 'profile' => $newProfile->name), self::pageURL('profiles'));
                 wp_redirect($redirectUrl);
                 exit;
                 break;
             case 'deleted':
                 // Add a settings error and then intentionally fall through to the default listing action.
                 add_settings_error('', 'profile-deleted', __('The profile was successfully deleted.', 'WordPress-MultiServer-Migration'), 'updated');
             default:
                 self::$profileListTable = new WP_MSM_Profile_List_Table();
                 self::$profileListTable->prepare_items();
         }
     }
 }