Skip to content

Commit

Permalink
Merge pull request #3414 from CalderaWP/feature/3413
Browse files Browse the repository at this point in the history
Hide CF pro tab and menu if not active or filter is not overiding
  • Loading branch information
New0 authored Dec 16, 2019
2 parents 92768bf + 76a92e8 commit fd9e947
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 22 deletions.
44 changes: 34 additions & 10 deletions classes/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -1768,16 +1768,6 @@ public function get_panel_extensions($panels){
'text' => __( 'Processors getting started guide', 'caldera-forms' )
)
),
"antispam" => array(
"name" => __( 'Anti-Spam', 'caldera-forms' ),
"location" => "lower",
"label" => __( 'Anti Spam', 'caldera-forms' ),
"canvas" => $path . "anti-spam.php",
'tip' => array(
'link' => 'https://calderaforms.com/doc/protect-form-spam-caldera-forms/?utm_source=wp-admin&utm_medium=form-editor&utm_term=tabs',
'text' => __( 'Anti-spam documentation', 'caldera-forms' )
)
),
"conditions" => array(
"name" => __( 'Conditions', 'caldera-forms' ),
"location" => "lower",
Expand Down Expand Up @@ -1855,6 +1845,20 @@ public function get_panel_extensions($panels){
),
);

if( Caldera_Forms_Admin::show_pro_ui() ){

$internal_panels['form_layout']["tabs"]["antispam"] = array(
"name" => __( 'Anti-Spam', 'caldera-forms' ),
"location" => "lower",
"label" => __( 'Anti Spam', 'caldera-forms' ),
"canvas" => $path . "anti-spam.php",
'tip' => array(
'link' => 'https://calderaforms.com/doc/protect-form-spam-caldera-forms/?utm_source=wp-admin&utm_medium=form-editor&utm_term=tabs',
'text' => __( 'Anti-spam documentation', 'caldera-forms' )
)
);

}

if( self::is_revision_edit() ){
unset( $internal_panels[ 'revisions' ] );
Expand Down Expand Up @@ -2180,6 +2184,26 @@ public static function add_suggested_privacy_content() {
}
}

/**
* Check if we should show the Caldera Forms Pro UI
*
* If Caldera Forms Pro is activated, UI should show.
* If Caldera Forms Pro is not activated, UI should not show.
* Use caldera_forms_show_pro_ui filter to override.
*
* @return bool
*/
public static function show_pro_ui(){
/**
* Should we add Caldera Forms Pro sub-menu page and UI
*
* @since 1.8.9
* @see https://github.com/CalderaWP/Caldera-Forms/issues/3413
*
* @param bool $show_pro Whether to show or not
*/
return (bool) apply_filters( 'caldera_forms_show_pro_ui', caldera_forms_pro_is_active() );
}


}
Expand Down
5 changes: 4 additions & 1 deletion classes/admin/pro.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ class Caldera_Forms_Admin_Pro {
* @since 1.5.1
*/
public function add_hooks(){
add_action( 'admin_menu', array( $this, 'maybe_add_menu_page' ) );
//@see https://github.com/CalderaWP/Caldera-Forms/issues/3413
if( Caldera_Forms_Admin::show_pro_ui() ){
add_action( 'admin_menu', array( $this, 'maybe_add_menu_page' ) );
}
}

/**
Expand Down
14 changes: 4 additions & 10 deletions includes/cf-pro-client/bootstrap-cf-pro.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,12 @@
$assets_url = plugin_dir_url(__FILE__) . 'dist/';
$view_dir = __DIR__ . '/dist';
$scripts = new scripts($assets_url, $slug, CF_PRO_VER);
if ( Caldera_Forms_Admin::is_edit() ) {
add_action('admin_init', function () use ($scripts, $view_dir) {
$tab = new \calderawp\calderaforms\pro\admin\tab(__DIR__ . '/dist/tab.php');
add_action('caldera_forms_get_panel_extensions', [ $tab, 'add_tab' ]);
container::get_instance()->set_tab_html($scripts->webpack($view_dir, 'tab', false));

});
// Pro Tab removed @see https://github.com/CalderaWP/Caldera-Forms/issues/3413

if( Caldera_Forms_Admin::show_pro_ui() ){
$menu = new menu($view_dir, $slug, $scripts);
add_action('admin_menu', [ $menu, 'display' ]);
}

$menu = new menu($view_dir, $slug, $scripts);
add_action('admin_menu', [ $menu, 'display' ]);
}

//add hooks
Expand Down
14 changes: 13 additions & 1 deletion ui/panels/form-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,19 @@ class="field-config form_role_role_check gen_role_check"
<?php esc_html_e( 'Honeypot', 'caldera-forms' ); ?>
</legend>
<div class="caldera-config-field">
<?php esc_html_e('This setting has moved to Anti-Spam tab', 'caldera-forms' ); ?>
<label for="cf-honey">
<input
id="cf-honey"
type="checkbox"
class="field-config"
name="config[check_honey]"
value="1" <?php if (!empty($element['check_honey'])){ ?>checked="checked"<?php } ?>
aria-describedby="cf-honey-desc"
/>

<?php esc_html_e('Enable', 'caldera-forms'); ?>
: <?php esc_html_e('Uses an anti-spam honeypot', 'caldera-forms'); ?>
</label>
</div>
</fieldset>
</div>
Expand Down

0 comments on commit fd9e947

Please sign in to comment.