Skip to content

Commit ab6b31a

Browse files
authored
Merge pull request #1028 from Kit/hide-add-new-button-setting
Settings: Disable "Add New" Button
2 parents 08dca1a + af7e9f4 commit ab6b31a

8 files changed

Lines changed: 144 additions & 0 deletions

File tree

admin/class-convertkit-admin-landing-page.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ public function register_add_new_button( $buttons, $post_type ) {
4444
return $buttons;
4545
}
4646

47+
// If the Add New Landing Page / Member Content button is disabled, don't output the button.
48+
if ( $settings->add_new_button_disabled() ) {
49+
return $buttons;
50+
}
51+
4752
// Bail if the Post Type isn't supported.
4853
if ( $post_type !== 'page' ) {
4954
return $buttons;

admin/class-convertkit-admin-restrict-content.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,11 @@ public function register_add_new_button( $buttons, $post_type ) {
241241
return $buttons;
242242
}
243243

244+
// If the Add New Landing Page / Member Content button is disabled, don't output the button.
245+
if ( $settings->add_new_button_disabled() ) {
246+
return $buttons;
247+
}
248+
244249
// Bail if the Post Type isn't supported.
245250
if ( ! in_array( $post_type, convertkit_get_supported_post_types(), true ) ) {
246251
return $buttons;

admin/section/class-convertkit-admin-section-general.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,17 @@ public function register_fields() {
461461
)
462462
);
463463

464+
add_settings_field(
465+
'no_add_new_button',
466+
__( 'Disable Add New Landing Page / Member Content Button', 'convertkit' ),
467+
array( $this, 'no_add_new_button_callback' ),
468+
$this->settings_key,
469+
$this->name . '-advanced',
470+
array(
471+
'label_for' => 'no_add_new_button',
472+
)
473+
);
474+
464475
add_settings_field(
465476
'usage_tracking',
466477
__( 'Usage Tracking', 'convertkit' ),
@@ -1015,6 +1026,23 @@ public function no_css_callback() {
10151026

10161027
}
10171028

1029+
/**
1030+
* Renders the input for the Disable Add New Landing Page / Member Content setting.
1031+
*
1032+
* @since 3.2.0
1033+
*/
1034+
public function no_add_new_button_callback() {
1035+
1036+
// Output field.
1037+
$this->output_checkbox_field(
1038+
'no_add_new_button',
1039+
'on',
1040+
$this->settings->add_new_button_disabled(),
1041+
esc_html__( 'Hide the "Add New" button on Pages for creating Landing Pages and Member Content.', 'convertkit' )
1042+
);
1043+
1044+
}
1045+
10181046
/**
10191047
* Renders the input for the Usage Tracking setting.
10201048
*

includes/class-convertkit-settings.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,19 @@ public function css_disabled() {
542542

543543
}
544544

545+
/**
546+
* Returns whether the Add New Landing Page / Member Content button is disabled in the Plugin settings.
547+
*
548+
* @since 3.2.0
549+
*
550+
* @return bool
551+
*/
552+
public function add_new_button_disabled() {
553+
554+
return ( $this->settings['no_add_new_button'] === 'on' ? true : false );
555+
556+
}
557+
545558
/**
546559
* Returns whether usage tracking is enabled in the Plugin settings.
547560
*
@@ -589,6 +602,7 @@ public function get_defaults() {
589602
'debug' => '', // blank|on.
590603
'no_scripts' => '', // blank|on.
591604
'no_css' => '', // blank|on.
605+
'no_add_new_button' => '', // blank|on.
592606
'usage_tracking' => '', // blank|on.
593607
);
594608

tests/EndToEnd/general/plugin-screens/PluginSettingsGeneralCest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function testAccessibilityAndUTMParameters(EndToEndTester $I)
4545
$I->seeInSource('<label for="debug">');
4646
$I->seeInSource('<label for="no_scripts">');
4747
$I->seeInSource('<label for="no_css">');
48+
$I->seeInSource('<label for="no_add_new_button">');
4849
$I->seeInSource('<label for="usage_tracking">');
4950

5051
// Confirm that the UTM parameters exist for the documentation links.
@@ -778,6 +779,48 @@ public function testEnableAndDisableCSSSetting(EndToEndTester $I)
778779
$I->seeInSource('<link rel="stylesheet" id="convertkit-frontend-css" href="' . $_ENV['WORDPRESS_URL'] . '/wp-content/plugins/convertkit/resources/frontend/css/frontend.css');
779780
}
780781

782+
/**
783+
* Test that no PHP errors or notices are displayed on the Plugin's Setting screen
784+
* when the Disable Add New Landing Page / Member Content button settings is unchecked, and that CSS is output
785+
* on the frontend web site.
786+
*
787+
* @since 3.2.0
788+
*
789+
* @param EndToEndTester $I Tester.
790+
*/
791+
public function testEnableAndDisableAddNewLandingPageMemberContentButtonSetting(EndToEndTester $I)
792+
{
793+
// Setup Plugin.
794+
$I->setupKitPlugin($I);
795+
796+
// Go to the Plugin's Settings Screen.
797+
$I->loadKitSettingsGeneralScreen($I);
798+
799+
// Tick field.
800+
$I->checkOption('#no_add_new_button');
801+
802+
// Click the Save Changes button.
803+
$I->click('Save Changes');
804+
805+
// Check that no PHP warnings or notices were output.
806+
$I->checkNoWarningsAndNoticesOnScreen($I);
807+
808+
// Check the field remains ticked.
809+
$I->seeCheckboxIsChecked('#no_add_new_button');
810+
811+
// Untick field.
812+
$I->uncheckOption('#no_add_new_button');
813+
814+
// Click the Save Changes button.
815+
$I->click('Save Changes');
816+
817+
// Check that no PHP warnings or notices were output.
818+
$I->checkNoWarningsAndNoticesOnScreen($I);
819+
820+
// Check the field remains unticked.
821+
$I->dontSeeCheckboxIsChecked('#no_add_new_button');
822+
}
823+
781824
/**
782825
* Test that no PHP errors or notices are displayed on the Plugin's Setting screen
783826
* when the Usage Tracking settings is unchecked, and that CSS is output

tests/EndToEnd/landing-pages/PageLandingPageSetupWizardCest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,30 @@ public function testAddNewLandingPageButtonNotDisplayedOnPosts(EndToEndTester $I
6060
$I->dontSeeElementInDOM('span.convertkit-action.page-title-action');
6161
}
6262

63+
/**
64+
* Test that the Add New Landing Page button does not display on the Pages screen when the Add New Landing Page / Member Content button is disabled.
65+
*
66+
* @since 3.2.0
67+
*
68+
* @param EndToEndTester $I Tester.
69+
*/
70+
public function testAddNewLandingPageButtonNotDisplayedWhenDisabled(EndToEndTester $I)
71+
{
72+
// Setup Plugin, disabling the Add New Landing Page / Member Content button.
73+
$I->setupKitPlugin(
74+
$I,
75+
[
76+
'no_add_new_button' => 'on',
77+
]
78+
);
79+
80+
// Navigate to Pages.
81+
$I->amOnAdminPage('edit.php?post_type=page');
82+
83+
// Check the buttons are not displayed.
84+
$I->dontSeeElementInDOM('span.convertkit-action.page-title-action');
85+
}
86+
6387
/**
6488
* Test that the Dashboard submenu item for this wizard does not display when a
6589
* third party Admin Menu editor type Plugin is installed and active.

tests/EndToEnd/restrict-content/general/RestrictContentSetupCest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,30 @@ public function testAddNewMemberContentButtonNotDisplayedOnPosts(EndToEndTester
6060
$I->dontSeeElementInDOM('span.convertkit-action.page-title-action');
6161
}
6262

63+
/**
64+
* Test that the Add New Member Content button does not display on the Pages screen when the Add New Member Content button is disabled.
65+
*
66+
* @since 3.2.0
67+
*
68+
* @param EndToEndTester $I Tester.
69+
*/
70+
public function testAddNewMemberContentButtonNotDisplayedWhenDisabled(EndToEndTester $I)
71+
{
72+
// Setup Plugin, disabling the Add New Landing Page / Member Content button.
73+
$I->setupKitPlugin(
74+
$I,
75+
[
76+
'no_add_new_button' => 'on',
77+
]
78+
);
79+
80+
// Navigate to Pages.
81+
$I->amOnAdminPage('edit.php?post_type=page');
82+
83+
// Check the buttons are not displayed.
84+
$I->dontSeeElementInDOM('span.convertkit-action.page-title-action');
85+
}
86+
6387
/**
6488
* Test that the Dashboard submenu item for this wizard does not display when a
6589
* third party Admin Menu editor type Plugin is installed and active.

tests/Support/Helper/KitPlugin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public function setupKitPlugin($I, $options = false)
7272
'debug' => 'on',
7373
'no_scripts' => '',
7474
'no_css' => '',
75+
'no_add_new_button' => '',
7576
'usage_tracking' => '',
7677
'post_form' => $_ENV['CONVERTKIT_API_FORM_ID'],
7778
'page_form' => $_ENV['CONVERTKIT_API_FORM_ID'],

0 commit comments

Comments
 (0)