Skip to content

Commit

Permalink
1.3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
someguy9 committed Mar 19, 2024
1 parent a22c886 commit 453da94
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
43 changes: 31 additions & 12 deletions mightyshare.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: MightyShare
* Plugin URI: https://mightyshare.io/wordpress/
* Description: Automatically generate social share preview images with MightyShare!
* Version: 1.3.12
* Version: 1.3.13
* Text Domain: mightyshare
* Author: MightyShare
* Author URI: https://mightyshare.io
Expand All @@ -13,7 +13,7 @@
exit; // Exit if accessed directly.
}

define( 'MIGHTYSHARE_VERSION', '1.3.12' );
define( 'MIGHTYSHARE_VERSION', '1.3.13' );
define( 'MIGHTYSHARE_DIR_URL', plugin_dir_url( __FILE__ ) );
define( 'MIGHTYSHARE_DIR_URI', plugin_dir_path( __FILE__ ) );

Expand Down Expand Up @@ -67,7 +67,7 @@ function mightshare_metaboxes( $metaboxes ) {
$current_post_id = esc_attr( wp_unslash( $_GET['post'] ) );

if ( ! empty( $current_post_id ) ) {
if ( !empty( $options['enabled_on']['post_types'] ) && get_post_type( $current_post_id ) && in_array( get_post_type( $current_post_id ), $options['enabled_on']['post_types'], true ) ) {
if ( ! empty( $options['enabled_on']['post_types'] ) && get_post_type( $current_post_id ) && in_array( get_post_type( $current_post_id ), $options['enabled_on']['post_types'], true ) ) {
$default_enabled = ' (Enabled)';
}

Expand Down Expand Up @@ -755,6 +755,19 @@ public function get_image_url( $url, $options, $key ) {
}
}

class Mightyshare_Public_Functions {
public static function get_mightyshare_url($post_id = 0, $options = array()) {
$mightyshare_frontend = new Mightyshare_Frontend();
$template_parts = $mightyshare_frontend->get_mightyshare_post_details($post_id);

if ( ! empty( $options ) ) {
$template_parts = array_merge($template_parts, $options);
}

return Mightyshare_Frontend::mightyshare_generate_og_image($template_parts);
}
}

class Mightyshare_Frontend {

public function __construct() {
Expand Down Expand Up @@ -917,11 +930,12 @@ public function mightyshare_render_opengraph( $attachment_url ) {
}

// Generate Social Image for Post using MightyShare.
public function mightyshare_generate_og_image( $template_parts = null ) {
public static function mightyshare_generate_og_image( $template_parts = null ) {
global $wp;

if ( ! $template_parts ) {
$template_parts = $this->get_mightyshare_post_details();
$mightyshare_frontend = new Mightyshare_Frontend();
$template_parts = $mightyshare_frontend->get_mightyshare_post_details();
}

// Get API Key.
Expand All @@ -930,8 +944,8 @@ public function mightyshare_generate_og_image( $template_parts = null ) {

// Setup defaults for render.
$render_options['cache'] = 'true';
$render_options['height'] = '630';
$render_options['width'] = '1200';
$render_options['height'] = ! empty( $template_parts['height'] ) ? $template_parts['height'] : '630';
$render_options['width'] = ! empty( $template_parts['width'] ) ? $template_parts['width'] : '1200';

// Grab the template.
if ( ! empty( $template_parts['template'] ) ) {
Expand Down Expand Up @@ -980,7 +994,7 @@ public function mightyshare_generate_og_image( $template_parts = null ) {

$mightyshare = new Mightyshare_Generate_Engine();

return $mightyshare->get_image_url( home_url( $wp->request ), $render_options, $key );
return $mightyshare->get_image_url( ! empty( $template_parts['overwrite_page_url'] ) ? $template_parts['overwrite_page_url'] : home_url( $wp->request ), $render_options, $key );
}

// Get the current post's details no matter type.
Expand All @@ -994,8 +1008,9 @@ public function get_mightyshare_post_details() {
}

global $wp_query;
global $post;

$template_parts = get_queried_object();
$template_parts = get_queried_object() ? get_queried_object() : $post;
$returned_template_parts = array();

// Defaults.
Expand All @@ -1011,30 +1026,34 @@ public function get_mightyshare_post_details() {
$returned_template_parts['enable_description'] = true;
}

if ( $wp_query->is_singular && !empty( $template_parts ) ) {
if ( ( $wp_query->is_singular || $wp_query->is_feed ) && ! empty( $template_parts ) ) {
$returned_template_parts['ID'] = $template_parts->ID;
$returned_template_parts['title'] = $template_parts->post_title;
$returned_template_parts['description'] = $template_parts->post_excerpt;
$returned_template_parts['type'] = $template_parts->post_type;
$returned_template_parts['object_type'] = 'post_types';
}

if ( $wp_query->is_archive && !empty( $template_parts ) ) {
if ( $wp_query->is_archive && ! empty( $template_parts ) ) {
$returned_template_parts['ID'] = $template_parts->term_id;
$returned_template_parts['title'] = $template_parts->name;
$returned_template_parts['description'] = $template_parts->category_description;
$returned_template_parts['type'] = $template_parts->taxonomy;
$returned_template_parts['object_type'] = 'taxonomies';
}

if ( $wp_query->is_author && !empty( $template_parts ) ) {
if ( $wp_query->is_author && ! empty( $template_parts ) ) {
$returned_template_parts['ID'] = $template_parts->ID;
$returned_template_parts['title'] = $template_parts->display_name;
$returned_template_parts['description'] = get_the_author_meta('description', $template_parts->ID);
$returned_template_parts['type'] = 'user';
$returned_template_parts['object_type'] = 'users';
}

if ( $wp_query->is_feed ) {
$returned_template_parts['overwrite_page_url'] = get_the_permalink($template_parts->ID);
}

// Get post type overwrites.
if ( ! empty ( $returned_template_parts['object_type'] ) && ! empty ( $returned_template_parts['type'] ) && ! empty ( $options['post_type_overwrites'][ $returned_template_parts['object_type'] ][ $returned_template_parts['type'] ] ) ) {
$overwrites = $options['post_type_overwrites'][ $returned_template_parts['object_type'] ][ $returned_template_parts['type'] ];
Expand Down
8 changes: 6 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Contributors: someguy9
Donate link: https://www.buymeacoffee.com/someguy
Tags: Social Preview, Open Graph, Social Media, Twitter Card, Open Graph Images
Requires at least: 5.4
Tested up to: 6.4
Tested up to: 6.5
Requires PHP: 7.4
Stable tag: 1.3.12
Stable tag: 1.3.13
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl.html

Expand Down Expand Up @@ -70,6 +70,10 @@ If you are using an SEO plugin be sure to have a default image set for the type

== Changelog ==

= 1.3.13 =
* WordPress 6.5 compatibility.
* [Frontend PHP](https://mightyshare.io/docs/get_mightyshare_url/) function added for developers to use.

= 1.3.12 =
* New template added (news-2).

Expand Down

0 comments on commit 453da94

Please sign in to comment.