';
$output .= '';
}
return $output;
}
}
/* ---------------------------------------------------------------------------
* Search | SET add custom fields to search query
* --------------------------------------------------------------------------- */
if( ! function_exists( 'mfn_search' ) )
{
function mfn_search( $search_query ) {
global $wpdb;
if( is_search() && $search_query->is_main_query() && $search_query->is_search() ){
$keyword = get_search_query();
if( ! $keyword ) return false;
// WooCommerce uses default search Query
if( function_exists('is_woocommerce') && is_woocommerce() ){
return false;
}
$keyword = '%' . $wpdb->esc_like( $keyword ) . '%';
// Post Title & Post Content
$post_ids_title = $wpdb->get_col( $wpdb->prepare( "
SELECT DISTINCT ID FROM {$wpdb->posts}
WHERE post_title LIKE '%s'
", $keyword, $keyword ) );
// Post Title & Post Content
$post_ids_content = $wpdb->get_col( $wpdb->prepare( "
SELECT DISTINCT ID FROM {$wpdb->posts}
WHERE post_content LIKE '%s'
", $keyword, $keyword ) );
// Custom Fields
$post_ids_meta = $wpdb->get_col( $wpdb->prepare( "
SELECT DISTINCT post_id FROM {$wpdb->postmeta}
WHERE meta_key = 'mfn-page-items-seo'
AND meta_value LIKE '%s'
", $keyword ) );
$post_ids = array_merge( $post_ids_title, $post_ids_content, $post_ids_meta );
if( ! count( $post_ids ) ) return false;
$search_query->set( 's', false );
$search_query->set( 'post__in', $post_ids );
$search_query->set( 'orderby', 'post__in' );
}
}
}
add_action( 'pre_get_posts', 'mfn_search' );
/* ---------------------------------------------------------------------------
* Posts per page & pagination fix
* --------------------------------------------------------------------------- */
if( ! function_exists( 'mfn_option_posts_per_page' ) )
{
function mfn_option_posts_per_page( $value ) {
if ( is_tax( 'portfolio-types' ) ) {
$posts_per_page = mfn_opts_get( 'portfolio-posts', 6, true );
} else {
$posts_per_page = mfn_opts_get( 'blog-posts', 5, true );
}
return $posts_per_page;
}
}
if( ! function_exists( 'mfn_posts_per_page' ) )
{
function mfn_posts_per_page() {
add_filter( 'option_posts_per_page', 'mfn_option_posts_per_page' );
}
}
add_action( 'init', 'mfn_posts_per_page', 0 );
/* ---------------------------------------------------------------------------
* Comments number with text
* --------------------------------------------------------------------------- */
if( ! function_exists( 'mfn_comments_number' ) )
{
function mfn_comments_number() {
$translate['comment'] = mfn_opts_get('translate') ? mfn_opts_get('translate-comment','comment') : __('comment','betheme');
$translate['comments'] = mfn_opts_get('translate') ? mfn_opts_get('translate-comments','comments') : __('comments','betheme');
$translate['comments-off'] = mfn_opts_get('translate') ? mfn_opts_get('translate-comments-off','comments off') : __('comments off','betheme');
$num_comments = get_comments_number(); // get_comments_number returns only a numeric value
if ( comments_open() ) {
if ( $num_comments != 1 ) {
$comments = ''. $num_comments.' '. $translate['comments'];
} else {
$comments = '1 '. $translate['comment'];
}
} else {
$comments = $translate['comments-off'];
}
return $comments;
}
}
/* ---------------------------------------------------------------------------
* Menu title in selected location
* --------------------------------------------------------------------------- */
if( ! function_exists( 'mfn_get_menu_name' ) )
{
function mfn_get_menu_name($location){
if( ! has_nav_menu($location) ){
return false;
}
$menus = get_nav_menu_locations();
$menu_title = wp_get_nav_menu_object($menus[$location])->name;
return $menu_title;
}
}
/* ---------------------------------------------------------------------------
* GET | WordPress Authors
* --------------------------------------------------------------------------- */
if( ! function_exists( 'mfn_get_authors' ) )
{
function mfn_get_authors(){
$authors = get_users();
if( is_array($authors) ){
foreach( $authors as $ka => $author ){
$remove = true;
if( in_array( 'author', $author->roles ) ) $remove = false;
if( in_array( 'editor', $author->roles ) ) $remove = false;
if( in_array( 'administrator', $author->roles ) ) $remove = false;
if( $remove ) unset( $authors[$ka] );
}
}
return $authors;
}
}
/* ---------------------------------------------------------------------------
* Under Construction
* --------------------------------------------------------------------------- */
if( ! function_exists('mfn_under_construction') )
{
function mfn_under_construction(){
if( mfn_opts_get('construction') ){
if( isset( $_POST['_wpcf7_is_ajax_call'] ) ){
// do nothing
} else {
if( ! is_user_logged_in() && ! is_admin()
&& basename( $_SERVER['PHP_SELF']) != 'wp-login.php'
&& basename( $_SERVER['PHP_SELF']) != 'wp-cron.php'
&& basename( $_SERVER['PHP_SELF']) != 'xmlrpc.php' ){
get_template_part('under-construction');
exit();
}
}
}
}
}
add_action('init', 'mfn_under_construction', 30);
/* ---------------------------------------------------------------------------
* Set Max Content Width
* --------------------------------------------------------------------------- */
if ( ! isset( $content_width ) ) $content_width = 1200;
/* ---------------------------------------------------------------------------
* WPML | Date Format
* --------------------------------------------------------------------------- */
if( ! function_exists( 'mfn_wpml_date_format' ) )
{
function mfn_wpml_date_format( $format ) {
if (function_exists('icl_translate'))
$format = icl_translate('Formats', $format, $format);
return $format;
}
}
add_filter('option_date_format', 'mfn_wpml_date_format');
/* ---------------------------------------------------------------------------
* WPML | ID
* @param type string – 'post', 'page', 'post_tag' or 'category'
* --------------------------------------------------------------------------- */
if( ! function_exists( 'mfn_wpml_ID' ) )
{
function mfn_wpml_ID( $id, $type = 'page' ) {
if( function_exists('icl_object_id') ) {
return icl_object_id( $id, $type, true );
} else {
return $id;
}
}
}
/* ---------------------------------------------------------------------------
* WPML | Term slug
* --------------------------------------------------------------------------- */
if( ! function_exists( 'mfn_wpml_term_slug' ) )
{
function mfn_wpml_term_slug( $slug, $type, $multi = false ){
if( function_exists( 'icl_object_id' ) ){
if( $multi ){
// multiple categories
$slugs = explode( ',', $slug );
if( is_array( $slugs ) ){
foreach( $slugs as $slug_k => $slug ){
$slug = trim( $slug );
$term = get_term_by( 'slug', $slug, $type );
$term = apply_filters( 'wpml_object_id', $term->term_id, $type, true );
$slug = get_term_by( 'term_id', $term, $type )->slug;
$slugs[$slug_k] = $slug;
}
}
$slug = implode( ',', $slugs );
} else {
// single category
$term = get_term_by( 'slug', $slug, $type );
$term = apply_filters( 'wpml_object_id', $term->term_id, $type, true );
$slug = get_term_by( 'term_id', $term, $type )->slug;
}
}
return $slug;
}
}
/* ---------------------------------------------------------------------------
* Schema | Auto Get Schema Type By Post Type
* --------------------------------------------------------------------------- */
if( ! function_exists( 'mfn_tag_schema' ) )
{
function mfn_tag_schema(){
$schema = 'http'. mfn_ssl() .'://schema.org/';
// Is Woocommerce product
if( function_exists( 'is_product' ) && is_product() ){
$type = false;
} elseif( is_single() && get_post_type() == 'post' ) {
// Single post
$type = "Article";
} elseif( is_author() ) {
// Author page
$type = 'ProfilePage';
} elseif( is_search() ) {
// Search results
$type = 'SearchResultsPage';
} else {
// Default
$type = 'WebPage';
}
if( mfn_opts_get( 'mfn-seo-schema-type' ) && $type ){
echo ' itemscope itemtype="' . $schema . $type . '"';
}
return true;
}
}
/* ---------------------------------------------------------------------------
* TGM Plugin Activation
* --------------------------------------------------------------------------- */
add_action( 'tgmpa_register', 'mfn_register_required_plugins' );
if( ! function_exists( 'mfn_register_required_plugins' ) )
{
function mfn_register_required_plugins() {
$plugins = array(
// required -----------------------------
array(
'name' => 'Slider Revolution', // The plugin name.
'slug' => 'revslider', // The plugin slug (typically the folder name).
'source' => THEME_DIR .'/plugins/revslider.zip', // The plugin source.
'required' => true, // If false, the plugin is only 'recommended' instead of required.
'version' => '5.3.1.5', // E.g. 1.0.0. If set, the active plugin must be this version or higher. If the plugin version is higher than the plugin version installed, the user will be notified to update the plugin.
// 'force_activation' => false, // If true, plugin is activated upon theme activation and cannot be deactivated until theme switch.
// 'force_deactivation' => false, // If true, plugin is deactivated upon theme switch, useful for theme-specific plugins.
// 'external_url' => '', // If set, overrides default API URL and points to an external URL.
// 'is_callable' => '', // If set, this callable will be be checked for availability to determine if a plugin is active.
),
array(
'name' => 'Contact Form 7',
'slug' => 'contact-form-7',
'required' => true,
'external_url' => 'https://wordpress.org/plugins/contact-form-7/',
),
// recommended -----------------------------
array(
'name' => 'Duplicate Post',
'slug' => 'duplicate-post',
'required' => false,
'external_url' => 'https://wordpress.org/plugins/duplicate-post/',
),
array(
'name' => 'Force Regenerate Thumbnails',
'slug' => 'force-regenerate-thumbnails',
'required' => false,
'external_url' => 'https://wordpress.org/plugins/force-regenerate-thumbnails/',
),
array(
'name' => 'Layer Slider',
'slug' => 'LayerSlider',
'source' => THEME_DIR .'/plugins/layerslider.zip',
'required' => false,
'version' => '6.1.6',
),
array(
'name' => 'Visual Composer',
'slug' => 'js_composer',
'source' => THEME_DIR .'/plugins/js_composer.zip',
'required' => false,
'version' => '5.0.1',
),
);
$config = array(
'id' => 'mfn-be', // Unique ID for hashing notices for multiple instances of TGMPA.
'default_path' => '', // Default absolute path to bundled plugins.
'menu' => 'tgmpa-install-plugins', // Menu slug.
'parent_slug' => 'themes.php', // Parent menu slug.
'capability' => 'edit_theme_options', // Capability needed to view plugin install page, should be a capability associated with the parent menu used.
'has_notices' => true, // Show admin notices or not.
'dismissable' => true, // If false, a user cannot dismiss the nag message.
'dismiss_msg' => '', // If 'dismissable' is false, this message will be output at top of nag.
'is_automatic' => false, // Automatically activate plugins after installation or not.
'message' => '
'. __( 'If you are not sure about server\'s settings and limits, please activate necessary plugins ONLY', 'tgmpa' ) .'
', // Message to output right before the plugins table
'strings' => array(
'page_title' => __( 'Install Required Plugins', 'tgmpa' ),
'menu_title' => __( 'Install Plugins', 'tgmpa' ),
'installing' => __( 'Installing Plugin: %s', 'tgmpa' ), // %s = plugin name.
'oops' => __( 'Something went wrong with the plugin API.', 'tgmpa' ),
'notice_can_install_required' => _n_noop( 'This theme requires the following plugin: %1$s.', 'This theme requires the following plugins: %1$s.', 'tgmpa' ),
'notice_can_install_recommended' => _n_noop( 'This theme recommends the following plugin: %1$s.', 'This theme recommends the following plugins: %1$s.', 'tgmpa' ),
'notice_cannot_install' => _n_noop( 'Sorry, but you do not have the correct permissions to install the %s plugin. Contact the administrator of this site for help on getting the plugin installed.', 'Sorry, but you do not have the correct permissions to install the %s plugins. Contact the administrator of this site for help on getting the plugins installed.', 'tgmpa' ),
'notice_can_activate_required' => _n_noop( 'The following required plugin is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.', 'tgmpa' ),
'notice_can_activate_recommended' => _n_noop( 'The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.', 'tgmpa' ),
'notice_cannot_activate' => _n_noop( 'Sorry, but you do not have the correct permissions to activate the %s plugin. Contact the administrator of this site for help on getting the plugin activated.', 'Sorry, but you do not have the correct permissions to activate the %s plugins. Contact the administrator of this site for help on getting the plugins activated.', 'tgmpa' ),
'notice_ask_to_update' => _n_noop( 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.', 'tgmpa' ),
'notice_cannot_update' => _n_noop( 'Sorry, but you do not have the correct permissions to update the %s plugin. Contact the administrator of this site for help on getting the plugin updated.', 'Sorry, but you do not have the correct permissions to update the %s plugins. Contact the administrator of this site for help on getting the plugins updated.', 'tgmpa' ),
'install_link' => _n_noop( 'Begin installing plugin', 'Begin installing plugins', 'tgmpa' ),
'activate_link' => _n_noop( 'Begin activating plugin', 'Begin activating plugins', 'tgmpa' ),
'return' => __( 'Return to Required Plugins Installer', 'tgmpa' ),
'plugin_activated' => __( 'Plugin activated successfully.', 'tgmpa' ),
'complete' => __( 'All plugins installed and activated successfully. %s', 'tgmpa' ), // %s = dashboard link.
'nag_type' => 'updated' // Determines admin notice type - can only be 'updated', 'update-nag' or 'error'.
),
);
tgmpa( $plugins, $config );
}
}
/** --------------------------------------------------------------------------
* DEPRECATED
* --------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------
* Excerpt
* @deprecated
* --------------------------------------------------------------------------- */
if( ! function_exists( 'mfn_excerpt' ) )
{
function mfn_excerpt($post, $length = 55, $tags_to_keep = '