'single' ) ); if ( 'single' === $args['type'] ) { add_filter( 'get_the_author_bizznis_author_box_single', '__return_true' ); } elseif ( 'archive' === $args['type'] ) { add_filter( 'get_the_author_bizznis_author_box_archive', '__return_true' ); } } /** * Redirect the user to an admin page, and add query args to the URL string for alerts, etc. * * @since 1.0.0 */ function bizznis_admin_redirect( $page, array $query_args = array() ) { if ( ! $page ) { return; } $url = html_entity_decode( menu_page_url( $page, 0 ) ); foreach ( (array) $query_args as $key => $value ) { if ( empty( $key ) && empty( $value ) ) { unset( $query_args[$key] ); } } $url = add_query_arg( $query_args, $url ); wp_redirect( esc_url_raw( $url ) ); } /** * Redirect singular page to an alternate URL. * * @since 1.0.0 */ add_action( 'template_redirect', 'bizznis_custom_field_redirect' ); function bizznis_custom_field_redirect() { if ( ! is_singular() ) { return; } if ( $url = bizznis_get_custom_field( 'redirect' ) ) { wp_redirect( esc_url_raw( $url ), 301 ); exit; } } /** * Return a specific value from the associative array passed as the second argument to 'add_theme_support()'. * * @since 1.0.0 * @param string $feature The theme feature. * @param string $arg The theme feature argument. * @param string $default Optional. Fallback if value is blank or doesn't exist. * Default is empty string. * * @return mixed Return value if associative array, true if indexed array, or * $default if theme doesn't support $feature or $arg doesn't exist. */ function bizznis_get_theme_support_arg( $feature, $arg, $default = '' ) { $support = get_theme_support( $feature ); if ( ! $arg && $support ) { return true; } if ( ! $support || ! isset( $support[0] ) ) { return $default; } if ( array_key_exists( $arg, (array) $support[0] ) ) { return $support[0][ $arg ]; } if ( in_array( $arg, (array) $support[0] ) ) { return true; } return $default; } /** * Detect active plugin by constant, class or function existence. * * @since 1.0.0 */ function bizznis_detect_plugin( array $plugins ) { # Check for classes if ( isset( $plugins['classes'] ) ) { foreach ( $plugins['classes'] as $name ) { if ( class_exists( $name ) ) { return true; } } } # Check for functions if ( isset( $plugins['functions'] ) ) { foreach ( $plugins['functions'] as $name ) { if ( function_exists( $name ) ) { return true; } } } # Check for constants if ( isset( $plugins['constants'] ) ) { foreach ( $plugins['constants'] as $name ) { if ( defined( $name ) ) { return true; } } } # No class, function or constant found to exist return false; } /** * Check that we're targeting a specific Bizznis admin page. * * @since 1.0.0 */ function bizznis_is_menu_page( $pagehook = '' ) { global $page_hook; if ( isset( $page_hook ) && $page_hook == $pagehook ) { return true; } # May be too early for $page_hook if ( isset( $_REQUEST['page'] ) && $_REQUEST['page'] == $pagehook ) { return true; } # May be too early for $page_hook if ( isset( $_REQUEST['tab'] ) && $_REQUEST['tab'] == $pagehook ) { return true; } # May be too early for $page_hook if ( isset( $_REQUEST['section'] ) && $_REQUEST['section'] == $pagehook ) { return true; } return false; } /** * Check whether we are currently viewing the site via the WordPress Customizer. * * @since 1.0.0 */ function bizznis_is_customizer() { global $wp_customize; return is_a( $wp_customize, 'WP_Customize_Manager' ) && $wp_customize->is_preview(); } /** * Get the 'post_type' from the global '$post' if supplied value is empty. * * @since 1.0.0 */ function bizznis_get_global_post_type_name( $post_type_name = '' ) { if ( ! $post_type_name ) { $post_type_name = get_post_type(); if ( false === get_post_type() ) { $post_type_name = get_query_var( 'post_type' ); } } return $post_type_name; } /** * Determine if theme support bizznis-accessibility is activated by the child theme. * Assumes the presence of a screen-reader-text class in the stylesheet (required generated class as from WordPress 4.2) * * Adds screen-reader-text by default. * Skip links to primary navigation, main contant, sidebars and footer, semantic headings and a keyboard accessible drop-down-menu * can be added as extra features as: 'skip-links', 'headings', 'drop-down-menu' * * @since 1.2.0 * * @param string $arg Optional. Specific accessibility feature to check for support. * Accepts `drop-down-menu` and `headings`. Default is empty string. * * @return bool True if current theme supports bizznis-accessibility, or an specific feature of it, false otherwise. */ function bizznis_a11y( $arg = '' ) { $feature = 'bizznis-accessibility'; # No args if ( empty( $arg ) ) { return current_theme_supports( $feature ); } # Get accessibility theme support $support = get_theme_support( $feature ); # No support for feature. if ( ! $support ) { return false; } # No args passed in to add_theme_support(), so accept all. if ( ! isset( $support[0] ) ) { return true; } # Support for specific arg found. if ( in_array( $arg, $support[0] ) ) { return true; } } /** * Build links to install plugins. * * @since 1.0.0 */ function bizznis_plugin_install_link( $plugin_slug = '', $text = '' ) { if ( is_main_site() ) { $url = network_admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_slug . '&TB_iframe=true&width=600&height=550' ); } else { $url = admin_url( 'plugin-install.php?tab=plugin-information&plugin=' . $plugin_slug . '&TB_iframe=true&width=600&height=550' ); } return sprintf( '%s', esc_url( $url ), esc_html( $text ) ); } /** * Check if the root page of the site is being viewed. * * is_front_page() returns false for the root page of a website when * - the WordPress "Front page displays" setting is set to "A static page" * - "Front page" is left undefined * - "Posts page" is assigned to an existing page * * This function checks for is_front_page() or the root page of the website * in this edge case. * * @since 2.2.0 * * @return bool True if this is the root page of the site, false othewise. */ function bizznis_is_root_page() { if ( is_front_page() || ( is_home() && get_option( 'page_for_posts' ) && ! get_option( 'page_on_front' ) && ! get_queried_object() ) ) { return true; } return false; }