static function onPluginActivation()
{
if (phpVersionSupported()) {
if (!WpLinkedDataInitializer::isPeclHttpInstalled()) {
add_option('show_pecl_http_missing_warning', true);
}
} else {
deactivate_plugins(__FILE__);
wp_die(wp_sprintf('%1s: ' . __('Sorry, This plugin has taken a bold step in requiring PHP 5.3.0+. Your server is currently running PHP %2s, Please bug your host to upgrade to a recent version of PHP which is less bug-prone.', 'wp-linked-data'), __FILE__, PHP_VERSION));
}
}
/**
* Check some thinks on plugin activation
*
* @since 0.0.1
* @access public
* @static
* @return void
*/
public static function on_activate()
{
// check WordPress version
if (!version_compare($GLOBALS['wp_version'], '4.0', '>=')) {
deactivate_plugins(RW_Demo_Plugin::$plugin_filename);
//@TODO Klassename
die(wp_sprintf('<strong>%s:</strong> ' . __('This plugin requires WordPress 4.0 or newer to work', RW_Demo_Plugin::get_textdomain()), RW_Demo_Plugin::get_plugin_data('Name')));
}
// check php version
if (version_compare(PHP_VERSION, '5.3.0', '<')) {
deactivate_plugins(RW_Demo_Plugin::$plugin_filename);
// @TODO Klassenanme
die(wp_sprintf('<strong>%1s:</strong> ' . __('This plugin requires PHP 5.3 or newer to work. Your current PHP version is %1s, please update.', RW_Demo_Plugin::get_textdomain()), RW_Demo_Plugin::get_plugin_data('Name'), PHP_VERSION));
}
// check buddypress @TODO Nur wenn BuddyPress activity für das Plugin nötig ist
if (!function_exists('bp_activities')) {
deactivate_plugins(RW_Demo_Plugin::$plugin_filename);
//@TODO Klassenname
die(wp_sprintf('<strong>%1s:</strong> ' . __('This plugin requires BuddyPress to work.', RW_Sticky_Activity::get_textdomain()), RW_Sticky_Activity::get_plugin_data('Name'), PHP_VERSION));
}
// @TODO Hier weitere Checks einbaun die das Plugin ggf als Abhängigkeiten hat. MU, bbPress usw
}
//.........这里部分代码省略.........
case 'verify_secrets_mismatch':
$error = esc_html($error);
$this->error = sprintf(__("<strong>Your Jetpack has a glitch.</strong> Something went wrong that’s never supposed to happen. Guess you’re just lucky: %s", 'jetpack'), "<code>{$error}</code>");
if (!Jetpack::is_active()) {
$this->error .= '<br />';
$this->error .= sprintf(__('Try connecting again.', 'jetpack'));
}
break;
}
$message_code = Jetpack::state('message');
$active_state = Jetpack::state('activated_modules');
if (!empty($active_state)) {
$available = Jetpack::get_available_modules();
$active_state = explode(',', $active_state);
$active_state = array_intersect($active_state, $available);
if (count($active_state)) {
foreach ($active_state as $mod) {
$this->stat('module-activated', $mod);
}
} else {
$active_state = false;
}
}
switch ($message_code) {
case 'modules_activated':
$this->message = sprintf(__('Welcome to <strong>Jetpack %s</strong>!', 'jetpack'), JETPACK__VERSION);
if ($active_state) {
$titles = array();
foreach ($active_state as $mod) {
if ($mod_headers = Jetpack::get_module($mod)) {
$titles[] = '<strong>' . preg_replace('/\\s+(?![^<>]++>)/', ' ', $mod_headers['name']) . '</strong>';
}
}
if ($titles) {
$this->message .= '<br /><br />' . wp_sprintf(__('The following new modules have been activated: %l.', 'jetpack'), $titles);
}
}
if ($reactive_state = Jetpack::state('reactivated_modules')) {
$titles = array();
foreach (explode(',', $reactive_state) as $mod) {
if ($mod_headers = Jetpack::get_module($mod)) {
$titles[] = '<strong>' . preg_replace('/\\s+(?![^<>]++>)/', ' ', $mod_headers['name']) . '</strong>';
}
}
if ($titles) {
$this->message .= '<br /><br />' . wp_sprintf(__('The following modules have been updated: %l.', 'jetpack'), $titles);
}
}
break;
case 'module_activated':
if ($module = Jetpack::get_module(Jetpack::state('module'))) {
$this->message = sprintf(__('<strong>%s Activated!</strong> You can deactivate at any time by clicking Learn More and then Deactivate on the module card.', 'jetpack'), $module['name']);
$this->stat('module-activated', Jetpack::state('module'));
}
break;
case 'module_deactivated':
if ($module = Jetpack::get_module(Jetpack::state('module'))) {
$this->message = sprintf(__('<strong>%s Deactivated!</strong> You can activate it again at any time using the activate button on the module card.', 'jetpack'), $module['name']);
$this->stat('module-deactivated', Jetpack::state('module'));
}
break;
case 'module_configured':
$this->message = __('<strong>Module settings were saved.</strong> ', 'jetpack');
break;
case 'already_authorized':
$this->message = __('<strong>Your Jetpack is already connected.</strong> ', 'jetpack');
break;
case 'authorized':
$this->message = __("<strong>You’re fueled up and ready to go.</strong> ", 'jetpack');
$this->message .= "<br />\n";
$this->message .= __('The features below are now active. Click the learn more buttons to explore each feature.', 'jetpack');
break;
}
$deactivated_plugins = Jetpack::state('deactivated_plugins');
if (!empty($deactivated_plugins)) {
$deactivated_plugins = explode(',', $deactivated_plugins);
$deactivated_titles = array();
foreach ($deactivated_plugins as $deactivated_plugin) {
if (!isset($this->plugins_to_deactivate[$deactivated_plugin])) {
continue;
}
$deactivated_titles[] = '<strong>' . str_replace(' ', ' ', $this->plugins_to_deactivate[$deactivated_plugin][1]) . '</strong>';
}
if ($deactivated_titles) {
if ($this->message) {
$this->message .= "<br /><br />\n";
}
$this->message .= wp_sprintf(_n('Jetpack contains the most recent version of the old %l plugin.', 'Jetpack contains the most recent versions of the old %l plugins.', count($deactivated_titles), 'jetpack'), $deactivated_titles);
$this->message .= "<br />\n";
$this->message .= _n('The old version has been deactivated and can be removed from your site.', 'The old versions have been deactivated and can be removed from your site.', count($deactivated_titles), 'jetpack');
}
}
if ($this->message || $this->error) {
add_action('jetpack_notices', array(&$this, 'admin_notices'));
}
if (isset($_GET['configure']) && Jetpack::is_module($_GET['configure'])) {
do_action('jetpack_module_configuration_load_' . $_GET['configure']);
}
add_filter('jetpack_short_module_description', 'wptexturize');
}
/**
* Retrieve all taxonomies associated with a post.
*
* This function can be used within the loop. It will also return an array of
* the taxonomies with links to the taxonomy and name.
*
* @since 2.5.0
*
* @param int $post Optional. Post ID or will use Global Post ID (in loop).
* @param array $args Override the defaults.
* @return array
*/
function get_the_taxonomies($post = 0, $args = array() ) {
$post = get_post( $post );
$args = wp_parse_args( $args, array(
'template' => '%s: %l.',
) );
extract( $args, EXTR_SKIP );
$taxonomies = array();
if ( !$post )
return $taxonomies;
foreach ( get_object_taxonomies($post) as $taxonomy ) {
$t = (array) get_taxonomy($taxonomy);
if ( empty($t['label']) )
$t['label'] = $taxonomy;
if ( empty($t['args']) )
$t['args'] = array();
if ( empty($t['template']) )
$t['template'] = $template;
$terms = get_object_term_cache($post->ID, $taxonomy);
if ( false === $terms )
$terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
$links = array();
foreach ( $terms as $term )
$links[] = "<a href='" . esc_attr( get_term_link($term) ) . "'>$term->name</a>";
if ( $links )
$taxonomies[$taxonomy] = wp_sprintf($t['template'], $t['label'], $links, $terms);
}
return $taxonomies;
}
/**
* Retrieve all taxonomies associated with a post.
*
* This function can be used within the loop. It will also return an array of
* the taxonomies with links to the taxonomy and name.
*
* @since 2.5.0
*
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
* @param array $args {
* Optional. Arguments about how to format the list of taxonomies. Default empty array.
*
* @type string $template Template for displaying a taxonomy label and list of terms.
* Default is "Label: Terms."
* @type string $term_template Template for displaying a single term in the list. Default is the term name
* linked to its archive.
* }
* @return array List of taxonomies.
*/
function get_the_taxonomies($post = 0, $args = array())
{
$post = get_post($post);
$args = wp_parse_args($args, array('template' => __('%s: %l.'), 'term_template' => '<a href="%1$s">%2$s</a>'));
$taxonomies = array();
if (!$post) {
return $taxonomies;
}
foreach (get_object_taxonomies($post) as $taxonomy) {
$t = (array) get_taxonomy($taxonomy);
if (empty($t['label'])) {
$t['label'] = $taxonomy;
}
if (empty($t['args'])) {
$t['args'] = array();
}
if (empty($t['template'])) {
$t['template'] = $args['template'];
}
if (empty($t['term_template'])) {
$t['term_template'] = $args['term_template'];
}
$terms = get_object_term_cache($post->ID, $taxonomy);
if (false === $terms) {
$terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
}
$links = array();
foreach ($terms as $term) {
$links[] = wp_sprintf($t['term_template'], esc_attr(get_term_link($term)), $term->name);
}
if ($links) {
$taxonomies[$taxonomy] = wp_sprintf($t['template'], $t['label'], $links, $terms);
}
}
return $taxonomies;
}
public function meta_tags()
{
global $wp_query;
$period = '';
$template = '';
$meta = array();
/**
* Can be used to specify a list of themes that set their own meta tags.
*
* If current site is using one of the themes listed as conflicting, inserting Jetpack SEO
* meta tags will be prevented.
*
* @module seo-tools
*
* @since 4.4.0
*
* @param array List of conflicted theme names. Defaults to empty array.
*/
$conflicted_themes = apply_filters('jetpack_seo_meta_tags_conflicted_themes', array());
if (isset($conflicted_themes[get_option('template')])) {
return;
}
/**
* Can be used to insert custom site host that will used for meta title.
*
* @module seo-tools
*
* @since 4.4.0
*
* @param string Name of the site host. Defaults to empty string.
*/
$site_host = apply_filters('jetpack_seo_site_host', '');
$meta['title'] = sprintf(_x('%1$s', 'Site Title', 'jetpack'), get_bloginfo('title'));
if (!empty($site_host)) {
$meta['title'] = sprintf(_x('%1$s on %2$s', 'Site Title on WordPress', 'jetpack'), get_bloginfo('title'), $site_host);
}
$front_page_meta = Jetpack_SEO_Utils::get_front_page_meta_description();
$description = $front_page_meta ? $front_page_meta : get_bloginfo('description');
$meta['description'] = trim($description);
// Try to target things if we're on a "specific" page of any kind.
if (is_singular()) {
$meta['title'] = sprintf(_x('%1$s | %2$s', 'Post Title | Site Title on WordPress', 'jetpack'), get_the_title(), $meta['title']);
// Business users can overwrite the description.
if (!(is_front_page() && Jetpack_SEO_Utils::get_front_page_meta_description())) {
$description = Jetpack_SEO_Posts::get_post_description(get_post());
if ($description) {
$description = wp_trim_words(strip_shortcodes(wp_kses($description, array())));
$meta['description'] = $description;
}
}
} elseif (is_author()) {
$obj = get_queried_object();
$meta['title'] = sprintf(_x('Posts by %1$s | %2$s', 'Posts by Author Name | Blog Title on WordPress', 'jetpack'), $obj->display_name, $meta['title']);
$meta['description'] = sprintf(_x('Read all of the posts by %1$s on %2$s', 'Read all of the posts by Author Name on Blog Title', 'jetpack'), $obj->display_name, get_bloginfo('title'));
} elseif (is_tag() || is_category() || is_tax()) {
$obj = get_queried_object();
$meta['title'] = sprintf(_x('Posts about %1$s on %2$s', 'Posts about Category on Blog Title', 'jetpack'), single_term_title('', false), get_bloginfo('title'));
$description = get_term_field('description', $obj->term_id, $obj->taxonomy, 'raw');
if (!is_wp_error($description) && '' != $description) {
$meta['description'] = wp_trim_words($description);
} else {
$authors = $this->get_authors();
$meta['description'] = wp_sprintf(_x('Posts about %1$s written by %2$l', 'Posts about Category written by John and Bob', 'jetpack'), single_term_title('', false), $authors);
}
} elseif (is_date()) {
if (is_year()) {
$period = get_query_var('year');
$template = _nx('%1$s post published by %2$l in the year %3$s', '%1$s posts published by %2$l in the year %3$s', count($wp_query->posts), '10 posts published by John in the year 2012', 'jetpack');
} elseif (is_month()) {
$period = date('F Y', mktime(0, 0, 0, get_query_var('monthnum'), 1, get_query_var('year')));
$template = _nx('%1$s post published by %2$l during %3$s', '%1$s posts published by %2$l during %3$s', count($wp_query->posts), '10 posts publishes by John during May 2012', 'jetpack');
} elseif (is_day()) {
$period = date('F j, Y', mktime(0, 0, 0, get_query_var('monthnum'), get_query_var('day'), get_query_var('year')));
$template = _nx('%1$s post published by %2$l on %3$s', '%1$s posts published by %2$l on %3$s', count($wp_query->posts), '10 posts published by John on May 30, 2012', 'jetpack');
}
$meta['title'] = sprintf(_x('Posts from %1$s on %2$s', 'Posts from May 2012 on Blog Title', 'jetpack'), $period, get_bloginfo('title'));
$authors = $this->get_authors();
$meta['description'] = wp_sprintf($template, count($wp_query->posts), $authors, $period);
}
$custom_title = Jetpack_SEO_Titles::get_custom_title();
if (!empty($custom_title)) {
$meta['title'] = $custom_title;
}
/**
* Can be used to edit the default SEO tools meta tags.
*
* @module seo-tools
*
* @since 4.4.0
*
* @param array Array that consists of meta name and meta content pairs.
*/
$meta = apply_filters('jetpack_seo_meta_tags', $meta);
// Output them
foreach ($meta as $name => $content) {
if (!empty($content)) {
echo '<meta name="' . esc_attr($name) . '" content="' . esc_attr($content) . '" />' . "\n";
}
}
}
请发表评论