-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflyyer-previews.php
124 lines (107 loc) · 3.83 KB
/
flyyer-previews.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* Plugin Name: Flyyer Previews
* Version: 1.2.0
* Plugin URI: https://flyyer.io/
* Description: Flyyer is the platform for your social media images. Generate images from your website's content and fit for every social platform format (no effort required).
* Author: FLYYER.io
* Requires at least: 3.9
* Tested up to: 5.7
*
* Text Domain: flyyer-previews
* Domain Path: /lang/
*
* @package WordPress
* @author Flyyer
* @since 1.0.0
*/
if (!defined('ABSPATH')) {
exit;
}
// Load plugin class files.
require_once 'includes/class-flyyer-previews.php';
require_once 'includes/class-flyyer-previews-settings.php';
// Load plugin libraries.
require_once 'includes/lib/class-flyyer-previews-admin-api.php';
require_once 'includes/lib/class-flyyer-previews-post-type.php';
require_once 'includes/lib/class-flyyer-previews-taxonomy.php';
// TODO: is autoloading not working?
require_once 'vendor/flyyer/flyyer/src/Flyyer.php';
/**
* Returns the main instance of FLYYER_Previews to prevent the need to use globals.
*
* @since 1.0.0
* @return object FLYYER_Previews
*/
function FLYYER_previews(): FLYYER_Previews // TODO: Remove this hint if necessary
{
$instance = FLYYER_Previews::instance(__FILE__, '1.0.0');
if (is_null($instance->settings)) {
$instance->settings = FLYYER_Previews_Settings::instance($instance);
}
return $instance;
}
FLYYER_previews(); // force init
function FLYYER_remove_default_image_presenters($presenters)
{
return array_map(function ($presenter) {
if ($presenter instanceof Yoast\WP\SEO\Presenters\Open_Graph\Image_Presenter) {
return null;
} else if ($presenter instanceof Yoast\WP\SEO\Presenters\Twitter\Image_Presenter) {
return null;
}
return $presenter;
}, $presenters);
}
add_action('wpseo_frontend_presenters', 'FLYYER_remove_default_image_presenters');
/**
* Adds our custom presenter to the array of presenters.
* https://developer.yoast.com/customization/apis/metadata-api/
*
* @param array $presenters The current array of presenters.
*
* @return array Presenters with our custom presenter added.
*/
function add_flyyer_presenter($presenters)
{
if (\class_exists('FlyyerPresenter')) {
// OK
} else {
/**
* Based on Yoast\WP\SEO\Presenters\Open_Graph\Image_Presenter
*/
class FlyyerPresenter extends Yoast\WP\SEO\Presenters\Abstract_Indexable_Presenter
{
public function present()
{
$flyyer = new Flyyer(get_option('flyyer_project_slug'), esc_url($_SERVER['REQUEST_URI']));
// if (get_option('flyyer_secret_key') && get_option('flyyer_strategy') != "None") {
// $flyyer->secret = get_option('flyyer_secret_key');
// $flyyer->strategy = get_option('flyyer_strategy');
// }
$return = \PHP_EOL . "\t" . '<meta property="og:image" content="' . $flyyer->href() . '" />';
$return .= \PHP_EOL . "\t" . '<meta property="twitter:image" content="' . $flyyer->href() . '" />';
$is_landing = \is_front_page() || \is_home();
$is_collection = \is_category();
$is_page = \is_page() || \is_privacy_policy();
$is_article = \is_single() || \is_author();
if ($is_landing) {
$return .= \PHP_EOL . "\t" . '<meta property="flyyer:type" content="landing" />';
} else if ($is_collection) {
$return .= \PHP_EOL . "\t" . '<meta property="flyyer:type" content="collection" />';
} else if ($is_page) {
$return .= \PHP_EOL . "\t" . '<meta property="flyyer:type" content="page" />';
} else if ($is_article) {
$return .= \PHP_EOL . "\t" . '<meta property="flyyer:type" content="article" />';
}
return $return;
}
public function get()
{
}
}
}
$presenters[] = new FlyyerPresenter();
return $presenters;
}
add_filter('wpseo_frontend_presenters', 'add_flyyer_presenter');