Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Re-enable ms-delete-site.php * Change text. * Add tests * Make ::init() consistent in PB code - different than ::getInstance()
- Loading branch information
Showing
12 changed files
with
179 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
<?php | ||
/** | ||
* @author Pressbooks <code@pressbooks.com> | ||
* @license GPLv2 (or any later version) | ||
*/ | ||
|
||
namespace Pressbooks\Admin\Delete; | ||
|
||
class Book { | ||
|
||
/** | ||
* @var \Pressbooks\Admin\Delete\Book | ||
*/ | ||
private static $instance = null; | ||
|
||
/** | ||
* @return \Pressbooks\Admin\Delete\Book | ||
*/ | ||
static function init() { | ||
if ( is_null( self::$instance ) ) { | ||
$self = new self; | ||
// Hide from side menu | ||
remove_submenu_page( 'tools.php', 'ms-delete-site.php' ); | ||
// Add to top menu | ||
if ( current_user_can( 'delete_site' ) ) { | ||
add_action( 'admin_bar_menu', [ $self, 'addMenu' ], 31 ); | ||
} | ||
// Override delete site email | ||
add_filter( 'delete_site_email_content', [ $self, 'deleteBookEmailContent' ] ); | ||
$self::$instance = $self; | ||
} | ||
return self::$instance; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function __construct() { | ||
} | ||
|
||
/** | ||
* @param \WP_Admin_Bar $wp_admin_bar | ||
*/ | ||
public function addMenu( $wp_admin_bar ) { | ||
$wp_admin_bar->add_node( | ||
[ | ||
'parent' => 'site-name', | ||
'id' => 'delete-book', | ||
'title' => __( 'Delete Book', 'pressbooks' ), | ||
'href' => admin_url( 'ms-delete-site.php' ), | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* @param string $content | ||
* | ||
* @return string | ||
*/ | ||
public function deleteBookEmailContent( $content ) { | ||
|
||
/* translators: Do not translate USERNAME, URL_DELETE, SITE_NAME: those are placeholders. */ | ||
$content = __( "Howdy ###USERNAME###, | ||
You recently clicked the 'Delete Book' link on your book and filled in a | ||
form on that page. | ||
If you really want to delete your book, click the link below. You will not | ||
be asked to confirm again so only click this link if you are absolutely certain: | ||
###URL_DELETE### | ||
If you delete your book, please consider starting a new book project with us | ||
some time in the future! (But remember your current book | ||
is gone forever.) | ||
Thanks for using Pressbooks, | ||
###SITE_NAME###", 'pressbooks' ); | ||
|
||
return $content; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
class Admin_DeleteBookTest extends \WP_UnitTestCase { | ||
|
||
public function test_deleteBookEmailContent() { | ||
$delete_book = new \Pressbooks\Admin\Delete\Book(); | ||
$content = $delete_book->deleteBookEmailContent( 'WordPress' ); | ||
$this->assertNotContains( 'WordPress,', $content ); | ||
$this->assertContains( 'Pressbooks', $content ); | ||
} | ||
|
||
public function test_addMenu() { | ||
$delete_book = new \Pressbooks\Admin\Delete\Book(); | ||
require_once ABSPATH . WPINC . '/class-wp-admin-bar.php'; | ||
$admin_bar = new \WP_Admin_Bar(); | ||
$delete_book->addMenu( $admin_bar ); | ||
$node = $admin_bar->get_node( 'delete-book' ); | ||
$this->assertTrue( is_object( $node ) ); | ||
$this->assertEquals( $node->id, 'delete-book' ); | ||
$this->assertEquals( $node->parent, 'site-name' ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.