'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 */ function bizznis_get_theme_support_arg( $feature, $arg, $default = '' ) { $support = get_theme_support( $feature ); if ( ! $support || ! isset( $support[0] ) || ! array_key_exists( $arg, (array) $support[0] ) ) { return $default; } return $support[0][ $arg ]; } /** * 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; } 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; if ( isset( $wp_customize ) ) { return true; } return false; } /** * 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 ) { global $wp_query; $post_type_name = get_post_type( $wp_query->get_queried_object_id() ); } return $post_type_name; } /** * 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' ); } $title_text = sprintf( __( 'Install %s', 'bizznis' ), $text ); return sprintf( '%s', esc_url( $url ), esc_attr( $title_text ), esc_html( $text ) ); }