| 1 |
<?php |
| 2 |
/** |
| 3 |
* Friend New Private Post Widget |
| 4 |
* |
| 5 |
* A widget that allows you to create a new private post. |
| 6 |
* |
| 7 |
* @package Friends |
| 8 |
* @since 0.8 |
| 9 |
*/ |
| 10 |
|
| 11 |
namespace Friends; |
| 12 |
|
| 13 |
/** |
| 14 |
* This is the class for the Friend New Private Post Widget. |
| 15 |
* |
| 16 |
* @package Friends |
| 17 |
* @author Alex Kirk |
| 18 |
*/ |
| 19 |
class Widget_New_Private_Post extends \WP_Widget { |
| 20 |
/** |
| 21 |
* Constructor |
| 22 |
*/ |
| 23 |
public function __construct() { |
| 24 |
parent::__construct( |
| 25 |
'friends-widget-new-private-post', |
| 26 |
__( 'New Private Post', 'friends' ), |
| 27 |
array( |
| 28 |
'description' => __( 'Allows the creation of a new private post from within the page.', 'friends' ), |
| 29 |
) |
| 30 |
); |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Render the widget. |
| 35 |
* |
| 36 |
* @param array $args Sidebar arguments. |
| 37 |
* @param array $instance Widget instance settings. |
| 38 |
*/ |
| 39 |
public function widget( $args, $instance ) { |
| 40 |
$instance = wp_parse_args( $instance, $this->defaults() ); |
| 41 |
|
| 42 |
$title = apply_filters( 'widget_title', $instance['title'] ); |
| 43 |
echo $args['before_widget']; |
| 44 |
if ( ! empty( $title ) ) { |
| 45 |
echo $args['before_title'] . $title . $args['after_title']; |
| 46 |
} |
| 47 |
|
| 48 |
?> |
| 49 |
<form method="post" action="<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>" class="friends-post-inline"> |
| 50 |
<?php wp_nonce_field( 'friends_publish' ); ?> |
| 51 |
<input type="hidden" name="action" value="friends_publish" /> |
| 52 |
<input type="text" name="title" value="" placeholder="<?php /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ echo esc_attr( __( 'Title' ) ); ?>" /><br /> |
| 53 |
<textarea name="content" rows="5" cols="70" placeholder="<?php echo /* translators: %s is a user display name. */ esc_attr( sprintf( __( 'What do you want to post just to your friends, %s?', 'friends' ), wp_get_current_user()->display_name ) ); ?>"></textarea><br /> |
| 54 |
<button><?php _e( 'Post to your friends', 'friends' ); ?></button> |
| 55 |
<small class="description"> |
| 56 |
<?php |
| 57 |
// translators: %1$s is the menu label "Visibility", %2$s is the menu label "Private". |
| 58 |
echo wp_kses( sprintf( __( '(You can also use the <a href=%1$s>WordPress editor</a> and set %2$s to %3$s.)', 'friends' ), '"' . self_admin_url( 'post-new.php' ) . '"', __( 'Visibility' ), __( 'Private' ) ), array( 'a' => array( 'href' => array() ) ) ); // phpcs:ignore WordPress.WP.I18n.MissingArgDomain |
| 59 |
?> |
| 60 |
</small> |
| 61 |
<input type="hidden" name="status" value="private" /></span> |
| 62 |
</form> |
| 63 |
<?php |
| 64 |
echo $args['after_widget']; |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
/** |
| 69 |
* Update widget configuration. |
| 70 |
* |
| 71 |
* @param array $new_instance New settings. |
| 72 |
* @param array $old_instance Old settings. |
| 73 |
* @return array Sanitized instance settings. |
| 74 |
*/ |
| 75 |
public function update( $new_instance, $old_instance ) { |
| 76 |
$instance = $this->defaults; |
| 77 |
|
| 78 |
return $instance; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Return an associative array of default values |
| 83 |
* |
| 84 |
* These values are used in new widgets. |
| 85 |
* |
| 86 |
* @return array Array of default values for the Widget's options |
| 87 |
*/ |
| 88 |
public function defaults() { |
| 89 |
return array( |
| 90 |
'title' => __( 'Friends', 'friends' ), |
| 91 |
); |
| 92 |
} |
| 93 |
|
| 94 |
/** |
| 95 |
* Register this widget. |
| 96 |
*/ |
| 97 |
public static function register() { |
| 98 |
register_widget( __CLASS__ ); |
| 99 |
} |
| 100 |
} |
| 101 |
|