object_id ) {
return false;
}
return true;
}
/**
* Conditionally displays a field when used as a callback in the 'show_on_cb' field parameter
*
* @param CMB2_Field $field Field object.
*
* @return bool True if metabox should show
*/
function animatedfsmenu_hide_if_no_cats( $field ) {
// Don't show this field if not in the cats category.
if ( ! has_tag( 'cats', $field->object_id ) ) {
return false;
}
return true;
}
add_action( 'cmb2_admin_init', 'animatedfsmenu_register_theme_options_metabox' );
/**
* Hook in and register a metabox to handle a theme options page and adds a menu item.
*/
function animatedfsmenu_register_theme_options_metabox() {
/**
* Registers options page menu item and form.
*/
$cmb_options = new_cmb2_box(
array(
'id' => 'animatedfsmenu_theme_options_page',
'title' => esc_html__( 'Animated Fullscreen Menu', 'animatedfsm' ),
'object_types' => array( 'options-page' ),
'option_key' => 'animatedfsm_settings',
'icon_url' => 'dashicons-menu',
'tabs' => array(
'settings' => array(
'label' => __( 'Settings', 'animatedfsm' ),
'icon' => 'dashicons-admin-settings',
),
'design' => array(
'label' => __( 'Design/Appearence', 'animatedfsm' ),
'icon' => 'dashicons-admin-appearance',
),
'content' => array(
'label' => __( 'Menu Content', 'animatedfsm' ),
'icon' => 'dashicons-networking',
),
'remove_data' => array(
'label' => __( 'Remove Data', 'animatedfsm' ),
'icon' => 'dashicons-trash',
),
),
'tab_style' => 'classic',
)
);
$cmb_options->add_field(
array(
'name' => esc_html__( 'Activate Animated Fullscreen Menu', 'animatedfsm' ),
'desc' => __( 'Leave unchecked if you want to desactivate it.', 'animatedfsm' ),
'id' => 'animatedfsm_on',
'type' => 'checkbox',
'tab' => 'settings',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
$cmb_options->add_field(
array(
'name' => esc_html__( 'Mobile only?', 'animatedfsm' ),
'desc' => esc_html__( 'This menu should be appears only for mobile devices? We consider mobile devices as fewer than 1024px resolution.', 'animatedfsm' ),
'id' => 'animatedfsm_mobile_only',
'type' => 'checkbox',
'tab' => 'settings',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
$cmb_options->add_field(
array(
'name' => esc_html__( 'Background Image/Color', 'animatedfsm' ),
'id' => 'animatedfsm_title1',
'type' => 'title',
'tab' => 'design',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
$cmb_options->add_field(
array(
'name' => esc_html__( 'Initial Background Menu', 'animatedfsm' ),
'desc' => esc_html__( 'First color (closed Menu).', 'animatedfsm' ),
'id' => 'animatedfsm_background01',
'type' => 'colorpicker',
'default' => '#000000',
'options' => array( 'alpha' => true ),
'tab' => 'design',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
$cmb_options->add_field(
array(
'name' => esc_html__( 'Opened Background Menu', 'animatedfsm' ),
'desc' => esc_html__( 'Menu color when is opened.', 'animatedfsm' ),
'id' => 'animatedfsm_background02',
'type' => 'colorpicker',
'default' => '#3a3a3a',
'options' => array( 'alpha' => true ),
'tab' => 'design',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
$cmb_options->add_field(
array(
'name' => esc_html__( 'Background Image', 'animatedfsm' ),
'desc' => esc_html__( 'Background Image when menu is opened. Leave blank to use colors above.', 'animatedfsm' ),
'id' => 'animatedfsm_backgroundimage',
'type' => 'file',
'tab' => 'design',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
$cmb_options->add_field(
array(
'name' => esc_html__( 'Font/Text Appearance', 'animatedfsm' ),
'id' => 'animatedfsm_title2',
'type' => 'title',
'tab' => 'design',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
$cmb_options->add_field(
array(
'name' => esc_html__( 'Font Color', 'animatedfsm' ),
'desc' => esc_html__( 'Color for fonts, social media icons and navbar hamburger.', 'animatedfsm' ),
'id' => 'animatedfsm_textcolor',
'type' => 'colorpicker',
'default' => '#FFFFFF',
'tab' => 'design',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
$cmb_options->add_field(
array(
'name' => esc_html__( 'Select Menu', 'animatedfsm' ),
'desc' => esc_html__( 'If you select WordPress Menu Location, you need to define your Menu at Appearance->Menus', 'animatedfsm' ),
'id' => 'animatedfsm_menuselected',
'type' => 'select',
'options' => animatedfsm_get_menus(),
'tab' => 'content',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
$cmb_options->add_field(
array(
'name' => esc_html__( 'Close menu on clicking a menu item', 'animatedfsm' ),
'desc' => esc_html__( 'Useful if you are using the menu with anchor links.', 'animatedfsm' ),
'id' => 'animatedfsm_anchor',
'type' => 'checkbox',
'tab' => 'settings',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
$cmb_options->add_field(
array(
'name' => esc_html__( 'Lateral menu at specific pages?', 'animatedfsm' ),
'desc' => esc_html__( 'This option transforms your menu into a lateral side menu. Does not affect mobile devices.', 'animatedfsm' ),
'id' => 'animatedfsm_lateralmenu',
'type' => 'checkbox',
'tab' => 'design',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
$cmb_options->add_field(
array(
'name' => esc_html__( 'Pages with lateral menu', 'animatedfsm' ),
'id' => 'animatedfsm_lateralmenu_pages',
'type' => 'multicheck',
'options' => animatedfsm_get_allpages(),
'attributes' => array(
'data-conditional-id' => 'animatedfsm_lateralmenu',
'data-conditional-value' => 'on',
),
'tab' => 'design',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
$cmb_options->add_field(
array(
'name' => esc_html__( 'Select Font Family', 'animatedfsm' ),
'desc' => esc_html__( 'Font for Menu Text. Leave blank if you want use your actual font from your theme.', 'animatedfsm' ),
'id' => 'animatedfsm_font',
'type' => 'select',
'options' => animatedfsm_get_fonts(),
'tab' => 'design',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
$cmb_options->add_field(
array(
'name' => esc_html__( 'Select Font Weight', 'animatedfsm' ),
'desc' => esc_html__( 'Font Weight for Menu Text.', 'animatedfsm' ),
'id' => 'animatedfsm_fontweight',
'type' => 'select',
'options' => animatedfsm_get_fontsweight(),
'tab' => 'design',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
$cmb_options->add_field(
array(
'name' => esc_html__( 'Include Privacy Policy Page (GPRD)', 'animatedfsm' ),
'desc' => esc_html__( 'This page is selected at Settings -> Privacy.', 'animatedfsm' ),
'id' => 'animatedfsm_privacy_on',
'type' => 'checkbox',
'tab' => 'content',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
$cmb_options->add_field(
array(
'id' => 'socialicons_group',
'name' => '
' . esc_html__( 'Social Icons', 'animatedfsm' ) . '
',
'type' => 'group',
'repeatable' => true,
'required' => false,
'options' => array(
'group_title' => 'Social Icon {#}',
'add_button' => esc_html__( 'Add Another Icon' ),
'remove_button' => 'Remove Icon',
'closed' => true,
'sortable' => true,
),
'tab' => 'content',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
$cmb_options->add_group_field(
'socialicons_group',
array(
'name' => esc_html__( 'Social Icon Title', 'animatedfsm' ),
'desc' => esc_html__( 'Enter the post title for the link text.', 'animatedfsm' ),
'id' => 'title',
'type' => 'text',
)
);
$cmb_options->add_group_field(
'socialicons_group',
array(
'name' => esc_html__( 'Social Icon', 'animatedfsm' ),
'id' => 'icon',
'desc' => __( 'Choose your Icon (Font Awesome library).' ),
'show_names' => true,
'type' => 'icon_picker',
'options' => array(
// Select icons we want to show (shows all dashicons by default).
'icons' => array(
'fa-instagram',
'fa-facebook-f',
'fa-twitter',
'fa-github',
'fa-envelope',
'fa-behance',
'fa-linkedin',
'fa-slack',
'fa-tripadvisor',
'fa-vimeo',
'fa-whatsapp',
'fa-youtube-play',
'fa-wordpress',
'fa-spotify',
),
// Use as multicheck instead of radio, deafult is radio.
'fonts' => array( 'FontAwesome' ),
'multicheck' => false,
),
)
);
$cmb_options->add_group_field(
'socialicons_group',
array(
'name' => esc_html__( 'Social URL', 'animatedfsm' ),
'desc' => esc_html__( 'Enter the url of the social media.', 'animatedfsm' ),
'id' => 'animatedfsm_url',
'type' => 'text_url',
)
);
$cmb_options->add_field(
array(
'name' => esc_html__( 'Animation Settings', 'animatedfsm' ),
'id' => 'animatedfsm_title3',
'type' => 'title',
'tab' => 'design',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
$cmb_options->add_field(
array(
'name' => esc_html__( 'Animation Direction', 'animatedfsm' ),
'desc' => esc_html__( 'Select your animation direction.', 'animatedfsm' ),
'id' => 'animatedfsm_animation',
'type' => 'select',
'options' => array(
'top' => 'From Top to Bottom',
'left' => 'From Left to Right',
'right' => 'From Right to Left',
),
'tab' => 'design',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
$cmb_options->add_field(
array(
'name' => esc_html__( 'Hover Effects', 'animatedfsm' ),
'desc' => esc_html__( 'Select your hover/focus animation.', 'animatedfsm' ),
'id' => 'animatedfsm_hoverfocus',
'type' => 'select',
'options' => array(
'animation_line' => 'Padding Line',
'animation_background' => 'Background Overlay',
),
'tab' => 'design',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
$cmb_options->add_field(
array(
'name' => esc_html__( 'Background Hover Menu', 'animatedfsm' ),
'id' => 'animatedfsm_hoverbackground',
'type' => 'colorpicker',
'options' => animatedfsm_get_allpages(),
'attributes' => array(
'data-conditional-id' => 'animatedfsm_hoverfocus',
'data-conditional-value' => 'animation_background',
),
'default' => 'rgba(0,0,0,0.91)',
'options' => array( 'alpha' => true ),
'tab' => 'design',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
if ( function_exists( 'pll_the_languages' ) ) :
$cmb_options->add_field(
array(
'name' => esc_html__( 'Add Language Switcher', 'animatedfsm' ),
'desc' => esc_html__( 'Check this if you want to use language switcher from Polylang Plugin.', 'animatedfsm' ),
'id' => 'animatedfsm_languageswitcher',
'type' => 'checkbox',
'tab' => 'content',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
endif;
if ( class_exists( 'WooCommerce' ) ) :
$cmb_options->add_field(
array(
'name' => esc_html__( 'Add WooCommerce Menu?', 'animatedfsm' ),
'desc' => esc_html__( 'Adds "My Account", "Shop", "Cart" and "Checkout" menus', 'animatedfsm' ),
'id' => 'animatedfsm_woocommerce_on',
'type' => 'checkbox',
'tab' => 'content',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
endif;
$cmb_options->add_field(
array(
'name' => esc_html__( 'Add Search Bar?', 'animatedfsm' ),
'desc' => esc_html__( 'Adds a native WP search bar.', 'animatedfsm' ),
'id' => 'animatedfsm_searchbar_on',
'type' => 'checkbox',
'tab' => 'content',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
$cmb_options->add_field(
array(
'name' => esc_html__( 'Search input placeholder', 'animatedfsm' ),
'desc' => esc_html__( 'Adds a native WP search bar.', 'animatedfsm' ),
'id' => 'animatedfsm_searchbar_placeholder',
'type' => 'text',
'default' => esc_html__( 'Search something...', 'animatedfsm'),
'tab' => 'content',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
$cmb_options->add_field(
array(
'name' => esc_html__( 'Remove Data after uninstall', 'animatedfsm' ),
'desc' => esc_html__( 'If you do not select this option, your data is not deleted.', 'animatedfsm' ),
'id' => 'animatedfsm_removedata_on',
'type' => 'checkbox',
'tab' => 'remove_data',
'render_row_cb' => array( 'CMB2_Tabs', 'tabs_render_row_cb' ),
)
);
}
function animatedfsm_get_menus() { //phpcs:ignore
$animatedfsm_all_menus = get_terms(
'nav_menu',
array(
'hide_empty' => true,
)
);
$array_menus = [];
$array_menus['none'] = __( 'None/Empty', 'animatedfsm' );
$array_menus['menulocation'] = __( 'WordPress Menu Location', 'animatedfsm' );
if ( $animatedfsm_all_menus ) {
foreach ( $animatedfsm_all_menus as $menu ) {
$array_menus[ $menu->term_id ] = $menu->name;
}
}
return $array_menus;
}
function animatedfsm_get_fonts() { //phpcs:ignore
$google_fonts_name = [
'Nunito Sans',
'Roboto',
'Open Sans',
'Lato',
'Lora',
'Oswald',
'Source Sans Pro',
'Montserrat',
'Raleway',
'PT Sans',
'Prompt',
'Ubuntu',
'Work Sans',
];
$google_fonts;
$google_fonts['inherit'] = 'Default Font from your Theme';
foreach ( $google_fonts_name as $font ) {
$google_fonts[ $font ] = $font;
}
return $google_fonts;
}
function animatedfsm_get_fontsweight() {
$fonts_weight = array(
'300' => '300',
'400' => '400',
'500' => '500',
'700' => '700',
);
return $fonts_weight;
}
function animatedfsm_get_allpages() {
$allpages = array();
$page_ids = get_all_page_ids();
foreach( $page_ids as $page ) {
$allpages[ $page ] = get_the_title( $page );
}
return $allpages;
}