| 1 |
<?php |
| 2 |
/** |
| 3 |
* Post class |
| 4 |
* |
| 5 |
* @package WPZinc\Social |
| 6 |
* @author WP Zinc |
| 7 |
*/ |
| 8 |
|
| 9 |
namespace WPZinc\Social; |
| 10 |
|
| 11 |
/** |
| 12 |
* Registers status settings on Posts as a metabox. |
| 13 |
* |
| 14 |
* @package WPZinc\Social |
| 15 |
* @author WP Zinc |
| 16 |
* @version 3.0.0 |
| 17 |
*/ |
| 18 |
class Post { |
| 19 |
|
| 20 |
/** |
| 21 |
* Holds the base class object. |
| 22 |
* |
| 23 |
* @since 3.2.0 |
| 24 |
* |
| 25 |
* @var object |
| 26 |
*/ |
| 27 |
public $base; |
| 28 |
|
| 29 |
/** |
| 30 |
* Constructor |
| 31 |
* |
| 32 |
* @since 3.0.0 |
| 33 |
* |
| 34 |
* @param object $base Base Plugin Class. |
| 35 |
*/ |
| 36 |
public function __construct( $base ) { |
| 37 |
|
| 38 |
// Store base class. |
| 39 |
$this->base = $base; |
| 40 |
|
| 41 |
// Admin Notices. |
| 42 |
add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
| 43 |
|
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* Outputs a notice if the user is editing a Post, which has a meta key indicating |
| 48 |
* that status(es) were published to the API. |
| 49 |
* |
| 50 |
* @since 3.0.0 |
| 51 |
*/ |
| 52 |
public function admin_notices() { |
| 53 |
|
| 54 |
// Check we can get the current screen the user is viewing. |
| 55 |
$screen = get_current_screen(); |
| 56 |
if ( ! $screen || ! isset( $screen->parent_base ) ) { |
| 57 |
return; |
| 58 |
} |
| 59 |
|
| 60 |
// Check we are on a Post based screen (includes Pages + CPTs). |
| 61 |
if ( $screen->base !== 'post' ) { |
| 62 |
return; |
| 63 |
} |
| 64 |
|
| 65 |
// Check we are editing a Post, Page or CPT. |
| 66 |
if ( $screen->parent_base !== 'edit' ) { |
| 67 |
return; |
| 68 |
} |
| 69 |
|
| 70 |
// Check we have a Post ID. |
| 71 |
if ( ! isset( $_GET['post'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 72 |
return; |
| 73 |
} |
| 74 |
$post_id = absint( $_GET['post'] ); // phpcs:ignore WordPress.Security.NonceVerification |
| 75 |
|
| 76 |
// Check if this Post has a success or error meta key set by this plugin. |
| 77 |
$success = get_post_meta( $post_id, '_' . $this->base->plugin->filter_name . '_success', true ); |
| 78 |
$error = get_post_meta( $post_id, '_' . $this->base->plugin->filter_name . '_error', true ); |
| 79 |
$errors = get_post_meta( $post_id, '_' . $this->base->plugin->filter_name . '_errors', true ); |
| 80 |
|
| 81 |
// Check for success. |
| 82 |
if ( $success ) { |
| 83 |
// Show notice and clear meta key, so we don't display this notice again. |
| 84 |
delete_post_meta( $post_id, '_' . $this->base->plugin->filter_name . '_success' ); |
| 85 |
?> |
| 86 |
<div class="notice notice-success is-dismissible"> |
| 87 |
<p> |
| 88 |
<?php |
| 89 |
echo esc_html( |
| 90 |
sprintf( |
| 91 |
/* translators: %1$s: Plugin Name, %2$s: Social Media Service Name (Buffer, Hootsuite) */ |
| 92 |
__( '%1$s: Post successfully added to %2$s.', 'wp-to-buffer' ), |
| 93 |
$this->base->plugin->displayName, |
| 94 |
$this->base->plugin->account |
| 95 |
) |
| 96 |
); |
| 97 |
?> |
| 98 |
</p> |
| 99 |
</div> |
| 100 |
<?php |
| 101 |
} |
| 102 |
|
| 103 |
// Check for error. |
| 104 |
if ( $error ) { |
| 105 |
// Show notice and clear meta key, so we don't display this notice again. |
| 106 |
delete_post_meta( $post_id, '_' . $this->base->plugin->filter_name . '_error' ); |
| 107 |
delete_post_meta( $post_id, '_' . $this->base->plugin->filter_name . '_errors' ); |
| 108 |
?> |
| 109 |
<div class="notice notice-error is-dismissible"> |
| 110 |
<p> |
| 111 |
<?php |
| 112 |
echo esc_html( |
| 113 |
sprintf( |
| 114 |
/* translators: %1$s: Plugin Name, %2$s: Social Media Service Name (Buffer, Hootsuite) */ |
| 115 |
__( '%1$s: Some status(es) could not be sent to %2$s', 'wp-to-buffer' ), |
| 116 |
$this->base->plugin->displayName, |
| 117 |
$this->base->plugin->account |
| 118 |
) |
| 119 |
); |
| 120 |
?> |
| 121 |
<br /> |
| 122 |
<?php |
| 123 |
foreach ( $errors as $error ) { |
| 124 |
echo esc_html( $error ) . '<br />'; |
| 125 |
} |
| 126 |
?> |
| 127 |
</p> |
| 128 |
</div> |
| 129 |
<?php |
| 130 |
} |
| 131 |
|
| 132 |
} |
| 133 |
|
| 134 |
} |
| 135 |
|