Last active
December 12, 2019 17:41
-
-
Save wpmudev-sls/5307014156c63d2901d69ed12f42c8cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: [Forminator] Fix quiz social OG meta tags and SmartCrawl | |
* Plugin URI: https://premium.wpmudev.org/ | |
* Description: Fix an issue with Forminator's quizzes and SmartCrawl's OG meta tags | |
* Author: Alessandro Kaounas @ WPMUDEV | |
* Author URI: https://premium.wpmudev.org/ | |
* License: GPLv2 or later | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
die(); | |
} | |
if ( ! class_exists( 'WPMUDEV_Forminator_SmartCrawl_OG_Meta_Tags' ) ) { | |
class WPMUDEV_Forminator_SmartCrawl_OG_Meta_Tags { | |
private static $_instance = null; | |
public static function get_instance() { | |
if( is_null( self::$_instance ) ){ | |
self::$_instance = new WPMUDEV_Forminator_SmartCrawl_OG_Meta_Tags(); | |
} | |
return self::$_instance; | |
} | |
private function __construct() { | |
$this->init(); | |
return; | |
} | |
private function init(){ | |
add_action( 'init', array( $this, 'wpmudev_forminator_quiz_share_og_meta_tags' ) ); | |
} | |
public function wpmudev_forminator_quiz_share_og_meta_tags(){ | |
global $wp; | |
preg_match( '/entries\/\d+/', add_query_arg( $wp->query_vars ), $quiz_result ); | |
if( $quiz_result ){ | |
remove_action( 'wp_head', 'wpmudev_smartcrawl_og_tags_injection' ); | |
add_filter( 'forminator_quiz_result_page_meta_title', array( $this, 'wpmudev_forminator_quiz_result_page_meta_title' ), 10, 2 ); | |
add_filter( 'forminator_quiz_nowrong_result_page_meta_description', array( $this, 'wpmudev_forminator_quiz_nowrong_result_page_meta_description' ), 10, 2 ); | |
if( class_exists( 'Smartcrawl_OpenGraph_Printer' ) ){ | |
remove_action( 'wp_head', array( Smartcrawl_OpenGraph_Printer::get(), 'dispatch_og_tags_injection' ), 50 ); | |
remove_action( 'wds_head-after_output', array( Smartcrawl_OpenGraph_Printer::get(), 'dispatch_og_tags_injection' ) ); | |
} | |
} | |
} | |
public function wpmudev_forminator_quiz_nowrong_result_page_meta_description( $description, $quiz ){ | |
if( get_post_meta( $quiz->id, 'forminator_form_meta' )[0]['settings']['quiz_name'] == $quiz_title ){ | |
return get_post_meta( $quiz->id, 'forminator_form_meta' )[0]['settings']['quiz_description']; | |
} | |
return $description; | |
} | |
public function wpmudev_forminator_quiz_result_page_meta_title( $title, $quiz ){ | |
$title = isset( $quiz->settings['quiz_name'] ) ? $quiz->settings['quiz_name'] : ''; | |
if ( empty( $title ) ) { | |
$title = single_post_title( '', false ); | |
} | |
if ( empty( $title ) ) { | |
$title = get_bloginfo( 'name' ); | |
} | |
return wp_trim_words( $title, 9 ); | |
} | |
} | |
if ( ! function_exists( 'wpmudev_forminator_smartcrawl_og_meta_tags' ) ) { | |
function wpmudev_forminator_smartcrawl_og_meta_tags() { | |
return WPMUDEV_Forminator_SmartCrawl_OG_Meta_Tags::get_instance(); | |
}; | |
add_action( 'plugins_loaded', 'wpmudev_forminator_smartcrawl_og_meta_tags', 99 ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment