Changed source root directory

This commit is contained in:
2026-03-05 16:30:11 +01:00
parent dc85447ee1
commit 538f85d7a2
5868 changed files with 749734 additions and 99 deletions

View File

@@ -0,0 +1,791 @@
<?php
require_once FLAMINGO_PLUGIN_DIR . '/admin/includes/admin-functions.php';
require_once FLAMINGO_PLUGIN_DIR . '/admin/includes/privacy.php';
add_action( 'admin_menu', 'flamingo_admin_menu', 8, 0 );
function flamingo_admin_menu() {
add_menu_page(
__( 'Flamingo Address Book', 'flamingo' ),
__( 'Flamingo', 'flamingo' ),
'flamingo_edit_contacts',
'flamingo',
'flamingo_contact_admin_page',
'dashicons-feedback',
28
);
$contact_admin = add_submenu_page(
'flamingo',
__( 'Flamingo Address Book', 'flamingo' ),
__( 'Address Book', 'flamingo' ),
'flamingo_edit_contacts',
'flamingo',
'flamingo_contact_admin_page'
);
add_action(
'load-' . $contact_admin,
'flamingo_load_contact_admin',
10, 0
);
$inbound_admin = add_submenu_page(
'flamingo',
__( 'Flamingo Inbound Messages', 'flamingo' ),
__( 'Inbound Messages', 'flamingo' ),
'flamingo_edit_inbound_messages',
'flamingo_inbound',
'flamingo_inbound_admin_page'
);
add_action(
'load-' . $inbound_admin,
'flamingo_load_inbound_admin',
10, 0
);
}
add_filter( 'set_screen_option_flamingo_contacts_per_page',
'flamingo_set_screen_options', 10, 3
);
add_filter( 'set_screen_option_flamingo_inbound_messages_per_page',
'flamingo_set_screen_options', 10, 3
);
function flamingo_set_screen_options( $result, $option, $value ) {
$flamingo_screens = array(
'flamingo_contacts_per_page',
'flamingo_inbound_messages_per_page',
);
if ( in_array( $option, $flamingo_screens ) ) {
$result = $value;
}
return $result;
}
add_action( 'admin_enqueue_scripts', 'flamingo_admin_enqueue_scripts', 10, 1 );
function flamingo_admin_enqueue_scripts( $hook_suffix ) {
if ( false === strpos( $hook_suffix, 'flamingo' ) ) {
return;
}
wp_enqueue_style( 'flamingo-admin',
flamingo_plugin_url( 'admin/includes/css/style.css' ),
array(), FLAMINGO_VERSION, 'all'
);
if ( is_rtl() ) {
wp_enqueue_style( 'flamingo-admin-rtl',
flamingo_plugin_url( 'admin/includes/css/style-rtl.css' ),
array(), FLAMINGO_VERSION, 'all'
);
}
$assets = include FLAMINGO_PLUGIN_DIR . '/admin/includes/js/index.asset.php';
$assets = wp_parse_args( $assets, array(
'dependencies' => array(),
'version' => FLAMINGO_VERSION,
) );
wp_enqueue_script( 'flamingo-admin',
flamingo_plugin_url( 'admin/includes/js/index.js' ),
$assets['dependencies'],
$assets['version'],
array( 'in_footer' => true )
);
wp_set_script_translations( 'flamingo-admin', 'flamingo' );
$current_screen = get_current_screen();
wp_add_inline_script( 'flamingo-admin',
sprintf(
'var flamingo = %s;',
wp_json_encode( array(
'screenId' => $current_screen->id,
), JSON_PRETTY_PRINT )
),
'before'
);
}
/* Updated Message */
add_action( 'flamingo_admin_updated_message',
'flamingo_admin_updated_message',
10, 0
);
function flamingo_admin_updated_message() {
if ( empty( $_REQUEST['message'] ) ) {
return;
}
if ( 'contactupdated' === $_REQUEST['message'] ) {
$message = __( 'Contact updated.', 'flamingo' );
} elseif ( 'contactdeleted' === $_REQUEST['message'] ) {
$message = __( 'Contact deleted.', 'flamingo' );
} elseif ( 'inboundupdated' === $_REQUEST['message'] ) {
$message = __( 'Messages updated.', 'flamingo' );
} elseif ( 'inboundtrashed' === $_REQUEST['message'] ) {
$message = __( 'Messages trashed.', 'flamingo' );
} elseif ( 'inbounduntrashed' === $_REQUEST['message'] ) {
$message = __( 'Messages restored.', 'flamingo' );
} elseif ( 'inbounddeleted' === $_REQUEST['message'] ) {
$message = __( 'Messages deleted.', 'flamingo' );
} elseif ( 'inboundspammed' === $_REQUEST['message'] ) {
$message = __( 'Messages got marked as spam.', 'flamingo' );
} elseif ( 'inboundunspammed' === $_REQUEST['message'] ) {
$message = __( 'Messages got marked as not spam.', 'flamingo' );
}
if ( ! empty( $message ) ) {
wp_admin_notice( $message, array(
'type' => 'success',
'dismissible' => true,
) );
}
}
/* Contact */
function flamingo_load_contact_admin() {
$action = flamingo_current_action();
$redirect_to = menu_page_url( 'flamingo', false );
if ( 'save' === $action and ! empty( $_REQUEST['post'] ) ) {
$post = new Flamingo_Contact( $_REQUEST['post'] );
if ( ! empty( $post ) ) {
if ( ! current_user_can( 'flamingo_edit_contact', $post->id() ) ) {
wp_die(
wp_kses_data( __( 'You are not allowed to edit this item.', 'flamingo' ) )
);
}
check_admin_referer( 'flamingo-update-contact_' . $post->id() );
$post->props = (array) $_POST['contact'];
$post->name = trim( $_POST['contact']['name'] );
$post->tags = (
! empty( $_POST['tax_input'][Flamingo_Contact::contact_tag_taxonomy] )
? explode(
',', $_POST['tax_input'][Flamingo_Contact::contact_tag_taxonomy]
)
: array()
);
$post->save();
$redirect_to = add_query_arg(
array(
'action' => 'edit',
'post' => $post->id(),
'message' => 'contactupdated',
), $redirect_to
);
}
wp_safe_redirect( $redirect_to );
exit();
}
if ( 'delete' === $action and ! empty( $_REQUEST['post'] ) ) {
if ( ! is_array( $_REQUEST['post'] ) ) {
check_admin_referer( 'flamingo-delete-contact_' . $_REQUEST['post'] );
} else {
check_admin_referer( 'bulk-posts' );
}
$deleted = 0;
foreach ( (array) $_REQUEST['post'] as $post ) {
$post = new Flamingo_Contact( $post );
if ( empty( $post ) ) {
continue;
}
if ( ! current_user_can( 'flamingo_delete_contact', $post->id() ) ) {
wp_die(
wp_kses_data( __( 'You are not allowed to delete this item.', 'flamingo' ) )
);
}
if ( ! $post->delete() ) {
wp_die(
wp_kses_data( __( 'Error in deleting.', 'flamingo' ) )
);
}
$deleted += 1;
}
if ( ! empty( $deleted ) ) {
$redirect_to = add_query_arg(
array( 'message' => 'contactdeleted' ), $redirect_to
);
}
wp_safe_redirect( $redirect_to );
exit();
}
if ( ! empty( $_GET['export'] ) ) {
check_admin_referer( 'bulk-posts' );
$csv_class = apply_filters( 'flamingo_contact_csv_class',
'Flamingo_Contact_CSV'
);
if ( is_subclass_of( $csv_class, 'Flamingo_CSV' ) ) {
$csv_obj = new $csv_class;
$csv_obj->send_http_headers();
$csv_obj->print_data();
}
exit();
}
if ( 'edit' === $action ) {
$post_id = (int) ( $_REQUEST['post'] ?? '0' );
if ( ! $post_id ) {
wp_safe_redirect( $redirect_to );
exit();
}
if (
! current_user_can( 'flamingo_edit_contact', $post_id ) or
Flamingo_Contact::post_type !== get_post_type( $post_id )
) {
wp_die(
wp_kses_data( __( 'You are not allowed to edit this item.', 'flamingo' ) )
);
}
add_meta_box( 'submitdiv', __( 'Save', 'flamingo' ),
'flamingo_contact_submit_meta_box', null, 'side', 'core'
);
add_meta_box( 'contacttagsdiv', __( 'Tags', 'flamingo' ),
'flamingo_contact_tags_meta_box', null, 'side', 'core'
);
add_meta_box( 'contactnamediv', __( 'Name', 'flamingo' ),
'flamingo_contact_name_meta_box', null, 'normal', 'core'
);
} else {
if ( ! class_exists( 'Flamingo_Contacts_List_Table' ) ) {
require_once FLAMINGO_PLUGIN_DIR
. '/admin/includes/class-contacts-list-table.php';
}
$current_screen = get_current_screen();
add_filter( 'manage_' . $current_screen->id . '_columns',
array( 'Flamingo_Contacts_List_Table', 'define_columns' ),
10, 0
);
add_screen_option( 'per_page', array(
'default' => 20,
'option' => 'flamingo_contacts_per_page',
) );
}
}
function flamingo_contact_admin_page() {
if ( 'edit' === flamingo_current_action() ) {
flamingo_contact_edit_page();
return;
}
$list_table = new Flamingo_Contacts_List_Table();
$list_table->prepare_items();
?>
<div class="wrap">
<h1 class="wp-heading-inline"><?php
echo esc_html( __( 'Flamingo Address Book', 'flamingo' ) );
?></h1>
<?php
if ( isset( $_REQUEST['s'] ) and strlen( $_REQUEST['s'] ) ) {
echo sprintf(
'<span class="subtitle">%s</span>',
wp_kses_data( sprintf(
/* translators: %s: Search query. */
__( 'Search results for: <strong>%s</strong>', 'flamingo' ),
esc_html( $_REQUEST['s'] )
) )
);
}
?>
<hr class="wp-header-end">
<?php do_action( 'flamingo_admin_updated_message' ); ?>
<form method="get" action="">
<input type="hidden" name="page" value="<?php echo esc_attr( $_REQUEST['page'] ); ?>" />
<?php $list_table->search_box( __( 'Search contacts', 'flamingo' ), 'flamingo-contact' ); ?>
<?php $list_table->display(); ?>
</form>
</div>
<?php
}
function flamingo_contact_edit_page() {
$post = new Flamingo_Contact( $_REQUEST['post'] );
if ( empty( $post ) ) {
return;
}
require_once FLAMINGO_PLUGIN_DIR . '/admin/includes/meta-boxes.php';
include FLAMINGO_PLUGIN_DIR . '/admin/edit-contact-form.php';
}
/* Inbound Messages */
function flamingo_load_inbound_admin() {
$action = flamingo_current_action();
$redirect_to = menu_page_url( 'flamingo_inbound', false );
if ( isset( $_GET['post_status'] ) ) {
$redirect_to = add_query_arg(
array(
'post_status' => $_GET['post_status'],
),
$redirect_to
);
}
if ( 'save' === $action and ! empty( $_REQUEST['post'] ) ) {
$post = new Flamingo_Inbound_Message( $_REQUEST['post'] );
if ( ! empty( $post ) ) {
if ( ! current_user_can( 'flamingo_edit_inbound_message', $post->id() ) ) {
wp_die(
wp_kses_data( __( 'You are not allowed to edit this item.', 'flamingo' ) )
);
}
check_admin_referer( 'flamingo-update-inbound_' . $post->id() );
$status = $_POST['inbound']['status'] ?? '';
if ( ! $post->spam and 'spam' === $status ) {
$post->spam();
} elseif ( $post->spam and 'ham' === $status ) {
$post->unspam();
}
$redirect_to = add_query_arg(
array(
'action' => 'edit',
'post' => $post->id(),
'message' => 'inboundupdated',
), $redirect_to
);
}
wp_safe_redirect( $redirect_to );
exit();
}
if ( 'trash' === $action and ! empty( $_REQUEST['post'] ) ) {
if ( ! is_array( $_REQUEST['post'] ) ) {
check_admin_referer(
'flamingo-trash-inbound-message_' . $_REQUEST['post']
);
} else {
check_admin_referer( 'bulk-posts' );
}
$trashed = 0;
foreach ( (array) $_REQUEST['post'] as $post ) {
$post = new Flamingo_Inbound_Message( $post );
if ( empty( $post ) ) {
continue;
}
if ( ! current_user_can(
'flamingo_delete_inbound_message', $post->id() ) ) {
wp_die(
wp_kses_data( __( 'You are not allowed to move this item to the Trash.', 'flamingo' ) )
);
}
if ( ! $post->trash() ) {
wp_die(
wp_kses_data( __( 'Error in moving to Trash.', 'flamingo' ) )
);
}
$trashed += 1;
}
if ( ! empty( $trashed ) ) {
$redirect_to = add_query_arg(
array(
'message' => 'inboundtrashed',
),
$redirect_to
);
}
wp_safe_redirect( $redirect_to );
exit();
}
if ( 'untrash' === $action and ! empty( $_REQUEST['post'] ) ) {
if ( ! is_array( $_REQUEST['post'] ) ) {
check_admin_referer(
'flamingo-untrash-inbound-message_' . $_REQUEST['post']
);
} else {
check_admin_referer( 'bulk-posts' );
}
$untrashed = 0;
foreach ( (array) $_REQUEST['post'] as $post ) {
$post = new Flamingo_Inbound_Message( $post );
if ( empty( $post ) ) {
continue;
}
if (
! current_user_can( 'flamingo_delete_inbound_message', $post->id() )
) {
wp_die(
wp_kses_data( __( 'You are not allowed to restore this item from the Trash.', 'flamingo' ) )
);
}
if ( ! $post->untrash() ) {
wp_die(
wp_kses_data( __( 'Error in restoring from Trash.', 'flamingo' ) )
);
}
$untrashed += 1;
}
if ( ! empty( $untrashed ) ) {
$redirect_to = add_query_arg(
array(
'message' => 'inbounduntrashed',
), $redirect_to
);
}
wp_safe_redirect( $redirect_to );
exit();
}
if ( 'delete_all' === $action ) {
check_admin_referer( 'bulk-posts' );
$_REQUEST['post'] = flamingo_get_all_ids_in_trash(
Flamingo_Inbound_Message::post_type
);
$action = 'delete';
}
if ( 'delete' === $action and ! empty( $_REQUEST['post'] ) ) {
if ( ! is_array( $_REQUEST['post'] ) ) {
check_admin_referer(
'flamingo-delete-inbound-message_' . $_REQUEST['post']
);
} else {
check_admin_referer( 'bulk-posts' );
}
$deleted = 0;
foreach ( (array) $_REQUEST['post'] as $post ) {
$post = new Flamingo_Inbound_Message( $post );
if ( empty( $post ) ) {
continue;
}
if (
! current_user_can( 'flamingo_delete_inbound_message', $post->id() )
) {
wp_die(
wp_kses_data( __( 'You are not allowed to delete this item.', 'flamingo' ) )
);
}
if ( ! $post->delete() ) {
wp_die(
wp_kses_data( __( 'Error in deleting.', 'flamingo' ) )
);
}
$deleted += 1;
}
if ( ! empty( $deleted ) ) {
$redirect_to = add_query_arg(
array(
'message' => 'inbounddeleted',
),
$redirect_to
);
}
wp_safe_redirect( $redirect_to );
exit();
}
if ( 'spam' === $action and ! empty( $_REQUEST['post'] ) ) {
if ( ! is_array( $_REQUEST['post'] ) ) {
check_admin_referer(
'flamingo-spam-inbound-message_' . $_REQUEST['post']
);
} else {
check_admin_referer( 'bulk-posts' );
}
$submitted = 0;
foreach ( (array) $_REQUEST['post'] as $post ) {
$post = new Flamingo_Inbound_Message( $post );
if ( empty( $post ) ) {
continue;
}
if (
! current_user_can( 'flamingo_spam_inbound_message', $post->id() )
) {
wp_die(
wp_kses_data( __( 'You are not allowed to spam this item.', 'flamingo' ) )
);
}
if ( $post->spam() ) {
$submitted += 1;
}
}
if ( ! empty( $submitted ) ) {
$redirect_to = add_query_arg(
array(
'message' => 'inboundspammed',
),
$redirect_to
);
}
wp_safe_redirect( $redirect_to );
exit();
}
if ( 'unspam' === $action and ! empty( $_REQUEST['post'] ) ) {
if ( ! is_array( $_REQUEST['post'] ) ) {
check_admin_referer(
'flamingo-unspam-inbound-message_' . $_REQUEST['post']
);
} else {
check_admin_referer( 'bulk-posts' );
}
$submitted = 0;
foreach ( (array) $_REQUEST['post'] as $post ) {
$post = new Flamingo_Inbound_Message( $post );
if ( empty( $post ) ) {
continue;
}
if (
! current_user_can( 'flamingo_unspam_inbound_message', $post->id() )
) {
wp_die(
wp_kses_data( __( 'You are not allowed to unspam this item.', 'flamingo' ) )
);
}
if ( $post->unspam() ) {
$submitted += 1;
}
}
if ( ! empty( $submitted ) ) {
$redirect_to = add_query_arg(
array(
'message' => 'inboundunspammed',
),
$redirect_to
);
}
wp_safe_redirect( $redirect_to );
exit();
}
if ( ! empty( $_GET['export'] ) ) {
check_admin_referer( 'bulk-posts' );
$csv_class = apply_filters( 'flamingo_inbound_csv_class',
'Flamingo_Inbound_CSV'
);
if ( is_subclass_of( $csv_class, 'Flamingo_CSV' ) ) {
$csv_obj = new $csv_class;
$csv_obj->send_http_headers();
$csv_obj->print_data();
}
exit();
}
if ( 'edit' === $action ) {
$post_id = (int) ( $_REQUEST['post'] ?? '0' );
if ( ! $post_id ) {
wp_safe_redirect( $redirect_to );
exit();
}
if (
! current_user_can( 'flamingo_edit_inbound_message', $post_id ) or
Flamingo_Inbound_Message::post_type !== get_post_type( $post_id )
) {
wp_die(
wp_kses_data( __( 'You are not allowed to edit this item.', 'flamingo' ) )
);
}
$post = new Flamingo_Inbound_Message( $post_id );
add_meta_box( 'submitdiv', __( 'Status', 'flamingo' ),
'flamingo_inbound_submit_meta_box', null, 'side', 'core'
);
if ( ! empty( $post->fields ) ) {
add_meta_box( 'inboundfieldsdiv', __( 'Fields', 'flamingo' ),
'flamingo_inbound_fields_meta_box', null, 'normal', 'core'
);
}
if ( ! empty( $post->consent ) ) {
add_meta_box( 'inboundconsentdiv', __( 'Consent', 'flamingo' ),
'flamingo_inbound_consent_meta_box', null, 'normal', 'core'
);
}
if ( ! empty( $post->recaptcha ) ) {
add_meta_box( 'inboundrecaptchadiv', __( 'reCAPTCHA', 'flamingo' ),
'flamingo_inbound_recaptcha_meta_box', null, 'normal', 'core'
);
}
if ( ! empty( $post->meta ) ) {
add_meta_box( 'inboundmetadiv', __( 'Meta', 'flamingo' ),
'flamingo_inbound_meta_meta_box', null, 'normal', 'core'
);
}
} else {
if ( ! class_exists( 'Flamingo_Inbound_Messages_List_Table' ) ) {
require_once FLAMINGO_PLUGIN_DIR . '/admin/includes/class-inbound-messages-list-table.php';
}
$current_screen = get_current_screen();
add_filter( 'manage_' . $current_screen->id . '_columns',
array( 'Flamingo_Inbound_Messages_List_Table', 'define_columns' ),
10, 0
);
add_screen_option( 'per_page', array(
'default' => 20,
'option' => 'flamingo_inbound_messages_per_page',
) );
}
}
function flamingo_inbound_admin_page() {
if ( 'edit' === flamingo_current_action() ) {
flamingo_inbound_edit_page();
return;
}
$list_table = new Flamingo_Inbound_Messages_List_Table();
$list_table->prepare_items();
?>
<div class="wrap">
<h1 class="wp-heading-inline"><?php
echo esc_html( __( 'Inbound Messages', 'flamingo' ) );
?></h1>
<?php
if ( isset( $_REQUEST['s'] ) and strlen( $_REQUEST['s'] ) ) {
echo sprintf(
'<span class="subtitle">%s</span>',
wp_kses_data( sprintf(
/* translators: %s: Search query. */
__( 'Search results for: <strong>%s</strong>', 'flamingo' ),
esc_html( $_REQUEST['s'] )
) )
);
}
?>
<hr class="wp-header-end">
<?php do_action( 'flamingo_admin_updated_message' ); ?>
<?php $list_table->views(); ?>
<form method="get" action="">
<input type="hidden" name="page" value="<?php echo esc_attr( $_REQUEST['page'] ); ?>" />
<input type="hidden" name="post_status" value="<?php echo isset( $_REQUEST['post_status'] ) ? esc_attr( $_REQUEST['post_status'] ) : ''; ?>" />
<?php $list_table->search_box( __( 'Search messages', 'flamingo' ), 'flamingo-inbound' ); ?>
<?php $list_table->display(); ?>
</form>
</div>
<?php
}
function flamingo_inbound_edit_page() {
$post = new Flamingo_Inbound_Message( $_REQUEST['post'] );
if ( empty( $post ) ) {
return;
}
require_once FLAMINGO_PLUGIN_DIR . '/admin/includes/meta-boxes.php';
include FLAMINGO_PLUGIN_DIR . '/admin/edit-inbound-form.php';
}

View File

@@ -0,0 +1,70 @@
<?php
// don't load directly
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
if ( ! empty( $post->id() ) ) {
$nonce_action = 'flamingo-update-contact_' . $post->id();
} else {
$nonce_action = 'flamingo-add-contact';
}
?>
<div class="wrap">
<h1><?php echo esc_html( __( 'Edit Contact', 'flamingo' ) ); ?></h1>
<?php do_action( 'flamingo_admin_updated_message', $post ); ?>
<form name="editcontact" id="editcontact" method="post" action="<?php echo esc_url( add_query_arg( array( 'post' => $post->id() ), menu_page_url( 'flamingo', false ) ) ); ?>">
<?php
wp_nonce_field( $nonce_action );
wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
?>
<div id="poststuff">
<div id="post-body" class="metabox-holder columns-2">
<div id="post-body-content">
<div id="titlediv">
<div id="titlewrap">
<?php if ( ! empty( $post->id() ) ) : ?>
<input type="text" name="post_title" size="30" tabindex="1" value="<?php echo esc_attr( $post->email ); ?>" id="title" disabled="disabled" />
<?php else : ?>
<label class="hide-if-no-js" style="visibility:hidden" id="title-prompt-text" for="title"><?php echo esc_html( __( 'Enter email here', 'flamingo' ) ); ?></label>
<input type="text" name="post_title" size="30" tabindex="1" value="<?php echo esc_attr( $post->email ); ?>" id="title" autocomplete="off" />
<?php endif; ?>
</div>
</div>
</div><!-- #post-body-content -->
<div id="postbox-container-1" class="postbox-container">
<?php
do_meta_boxes( null, 'side', $post );
?>
</div><!-- #postbox-container-1 -->
<div id="postbox-container-2" class="postbox-container">
<?php
do_meta_boxes( null, 'normal', $post );
do_meta_boxes( null, 'advanced', $post );
?>
</div><!-- #postbox-container-2 -->
</div><!-- #post-body -->
<br class="clear" />
</div><!-- #poststuff -->
<?php if ( $post->id() ) : ?>
<input type="hidden" name="action" value="save" />
<input type="hidden" name="post" value="<?php echo (int) $post->id(); ?>" />
<?php else: ?>
<input type="hidden" name="action" value="add" />
<?php endif; ?>
</form>
</div><!-- .wrap -->

View File

@@ -0,0 +1,82 @@
<?php
// don't load directly
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
if ( ! empty( $post->id() ) ) {
$nonce_action = 'flamingo-update-inbound_' . $post->id();
} else {
$nonce_action = 'flamingo-add-inbound';
}
?>
<div class="wrap">
<h1><?php echo esc_html( __( 'Inbound Message', 'flamingo' ) ); ?></h1>
<?php do_action( 'flamingo_admin_updated_message', $post ); ?>
<form name="editinbound" id="editinbound" method="post" action="<?php echo esc_url( add_query_arg( array( 'post' => $post->id() ), menu_page_url( 'flamingo_inbound', false ) ) ); ?>">
<?php
wp_nonce_field( $nonce_action );
wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
?>
<div id="poststuff">
<div id="post-body" class="metabox-holder columns-2">
<div id="post-body-content">
<table class="message-main-fields">
<tbody>
<tr class="message-subject">
<th><?php echo esc_html( __( 'Subject', 'flamingo' ) ); ?>:</th>
<td><?php echo esc_html( $post->subject ); ?></td>
</tr>
<tr class="message-from">
<th><?php echo esc_html( __( 'From', 'flamingo' ) ); ?>:</th>
<td><?php if ( ! empty( $post->from_email ) ) { ?><a href="<?php
echo esc_url( add_query_arg(
array(
's' => $post->from_email,
),
menu_page_url( 'flamingo', false )
) );
?>" aria-label="<?php echo esc_attr( $post->from ); ?>"><?php echo esc_html( $post->from ); ?></a><?php } else { echo esc_html( $post->from ); } ?></td>
</tr>
</tbody>
</table>
</div><!-- #post-body-content -->
<div id="postbox-container-1" class="postbox-container">
<?php
do_meta_boxes( null, 'side', $post );
?>
</div><!-- #postbox-container-1 -->
<div id="postbox-container-2" class="postbox-container">
<?php
do_meta_boxes( null, 'normal', $post );
do_meta_boxes( null, 'advanced', $post );
?>
</div><!-- #postbox-container-2 -->
</div><!-- #post-body -->
<br class="clear" />
</div><!-- #poststuff -->
<?php if ( $post->id() ) : ?>
<input type="hidden" name="action" value="save" />
<input type="hidden" name="post" value="<?php echo (int) $post->id(); ?>" />
<?php else: ?>
<input type="hidden" name="action" value="add" />
<?php endif; ?>
</form>
</div><!-- .wrap -->

View File

@@ -0,0 +1,27 @@
<?php
function flamingo_current_action() {
if ( isset( $_REQUEST['delete_all'] ) or isset( $_REQUEST['delete_all2'] ) ) {
return 'delete_all';
}
if ( isset( $_REQUEST['action'] ) and -1 !== $_REQUEST['action'] ) {
return $_REQUEST['action'];
}
if ( isset( $_REQUEST['action2'] ) and -1 !== $_REQUEST['action2'] ) {
return $_REQUEST['action2'];
}
return false;
}
function flamingo_get_all_ids_in_trash( $post_type ) {
global $wpdb;
return $wpdb->get_col( $wpdb->prepare(
"SELECT ID FROM %i WHERE post_status = 'trash' AND post_type = %s",
$wpdb->posts,
$post_type
) );
}

View File

@@ -0,0 +1,356 @@
<?php
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
}
class Flamingo_Contacts_List_Table extends WP_List_Table {
public static function define_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'email' => __( 'Email', 'flamingo' ),
'full_name' => __( 'Name', 'flamingo' ),
'tags' => __( 'Tags', 'flamingo' ),
'history' => __( 'History', 'flamingo' ),
'last_contacted' => __( 'Last contact', 'flamingo' ),
);
$columns = apply_filters(
'manage_flamingo_contact_posts_columns', $columns
);
return $columns;
}
public function __construct() {
parent::__construct( array(
'singular' => 'post',
'plural' => 'posts',
'ajax' => false,
) );
}
public function prepare_items() {
$per_page = $this->get_items_per_page(
'flamingo_contacts_per_page'
);
$args = array(
'posts_per_page' => $per_page,
'offset' => ( $this->get_pagenum() - 1 ) * $per_page,
'orderby' => 'meta_value',
'order' => 'DESC',
'meta_key' => '_last_contacted',
);
if ( ! empty( $_REQUEST['s'] ) ) {
$args['s'] = $_REQUEST['s'];
}
if ( ! empty( $_REQUEST['orderby'] ) ) {
if ( 'email' === $_REQUEST['orderby'] ) {
$args['meta_key'] = '_email';
} elseif ( 'name' === $_REQUEST['orderby'] ) {
$args['meta_key'] = '_name';
}
}
if (
! empty( $_REQUEST['order'] ) and
'asc' === strtolower( $_REQUEST['order'] )
) {
$args['order'] = 'ASC';
}
if ( ! empty( $_REQUEST['contact_tag_id'] ) ) {
$args['contact_tag_id'] = explode( ',', $_REQUEST['contact_tag_id'] );
}
$this->items = Flamingo_Contact::find( $args );
$total_items = Flamingo_Contact::count();
$total_pages = ceil( $total_items / $per_page );
$this->set_pagination_args( array(
'total_items' => $total_items,
'total_pages' => $total_pages,
'per_page' => $per_page,
) );
}
public function get_columns() {
return get_column_headers( get_current_screen() );
}
protected function get_sortable_columns() {
$columns = array(
'email' => array( 'email', false ),
'full_name' => array( 'name', false ),
'last_contacted' => array( 'last_contacted', true ),
);
return $columns;
}
protected function get_bulk_actions() {
$actions = array(
'delete' => __( 'Delete', 'flamingo' ),
);
return $actions;
}
protected function extra_tablenav( $which ) {
$tag = 0;
if ( ! empty( $_REQUEST['contact_tag_id'] ) ) {
$tag_id = explode( ',', $_REQUEST['contact_tag_id'] );
$term = get_term( $tag_id[0], Flamingo_Contact::contact_tag_taxonomy );
if ( ! empty( $term ) and ! is_wp_error( $term ) ) {
$tag = $term->term_id;
}
}
?>
<div class="alignleft actions">
<?php
if ( 'top' == $which ) {
$filters = array();
$filters[] = wp_dropdown_categories( array(
'taxonomy' => Flamingo_Contact::contact_tag_taxonomy,
'name' => 'contact_tag_id',
'show_option_all' => __( 'View all tags', 'flamingo' ),
'hide_empty' => 1,
'hide_if_empty' => 1,
'orderby' => 'name',
'selected' => $tag,
) );
if ( array_filter( $filters ) ) {
submit_button( __( 'Filter', 'flamingo' ),
'secondary', false, false, array( 'id' => 'post-query-submit' )
);
}
submit_button( __( 'Export', 'flamingo' ), 'secondary', 'export', false );
}
?>
</div>
<?php
}
protected function column_default( $item, $column_name ) {
do_action( 'manage_flamingo_contact_posts_custom_column',
$column_name, $item->id()
);
}
protected function column_cb( $item ) {
return sprintf(
'<input type="checkbox" name="%1$s[]" value="%2$s" />',
$this->_args['singular'],
$item->id()
);
}
protected function column_email( $item ) {
$edit_link = add_query_arg( array(
'post' => $item->id(),
'action' => 'edit',
), menu_page_url( 'flamingo', false ) );
if ( current_user_can( 'flamingo_edit_contact', $item->id() ) ) {
return sprintf(
'<strong><a class="row-title" href="%1$s" aria-label="%2$s">%3$s</a></strong>',
esc_url( $edit_link ),
esc_attr( sprintf(
/* translators: %s: Item title. */
__( '&#8220;%s&#8221; (Edit)', 'flamingo' ),
$item->email
) ),
esc_html( $item->email )
);
} else {
return sprintf(
'<strong>%1$s</strong>',
esc_html( $item->email )
);
}
}
protected function handle_row_actions( $item, $column_name, $primary ) {
if ( $column_name !== $primary ) {
return '';
}
$actions = array();
$link = add_query_arg( array(
'post' => $item->id(),
'action' => 'edit',
), menu_page_url( 'flamingo', false ) );
if ( current_user_can( 'flamingo_edit_contact', $item->id() ) ) {
$actions['edit'] = sprintf(
'<a href="%1$s">%2$s</a>',
esc_url( $link ),
esc_html( __( 'Edit', 'flamingo' ) )
);
}
return $this->row_actions( $actions );
}
protected function column_full_name( $item ) {
return esc_html( $item->name );
}
protected function column_tags( $item ) {
if ( empty( $item->tags ) ) {
return esc_html( __( 'No tags', 'flamingo' ) );
}
$output = '';
foreach ( (array) $item->tags as $tag ) {
$term = get_term_by( 'name', $tag,
Flamingo_Contact::contact_tag_taxonomy
);
if ( empty( $term ) or is_wp_error( $term ) ) {
continue;
}
if ( $output ) {
$output .= ', ';
}
$link = add_query_arg( array(
'contact_tag_id' => $term->term_id,
), menu_page_url( 'flamingo', false ) );
$output .= sprintf( '<a href="%1$s" aria-label="%2$s">%3$s</a>',
esc_url( $link ),
esc_attr( $term->name ),
esc_html( $term->name )
);
}
return $output;
}
protected function column_history( $item ) {
$history = array();
// User
if ( $user = get_user_by( 'email', $item->email ) ) {
$link = sprintf( 'user-edit.php?user_id=%d', $user->ID );
$history[] = sprintf(
'<a href="%2$s">%1$s</a>',
esc_html( __( 'User', 'flamingo' ) ),
admin_url( $link )
);
}
// Comment
$comment_count = (int) get_comments( array(
'count' => true,
'author_email' => $item->email,
'status' => 'approve',
'type' => 'comment',
) );
if ( 0 < $comment_count ) {
$link = sprintf( 'edit-comments.php?s=%s', urlencode( $item->email ) );
$history[] = sprintf(
'<a href="%2$s">%1$s</a>',
esc_html( sprintf(
/* translators: %d: Number of comments. */
__( 'Comment (%d)', 'flamingo' ),
$comment_count
) ),
admin_url( $link )
);
}
// Contact channels
$terms = get_terms( array(
'taxonomy' => Flamingo_Inbound_Message::channel_taxonomy,
) );
if ( ! empty( $terms ) and ! is_wp_error( $terms ) ) {
foreach ( (array) $terms as $term ) {
Flamingo_Inbound_Message::find( array(
'channel' => $term->slug,
's' => $item->email,
) );
$count = (int) Flamingo_Inbound_Message::count();
if ( ! $count ) {
continue;
}
$link = add_query_arg( array(
'channel' => $term->slug,
's' => $item->email,
), menu_page_url( 'flamingo_inbound', false ) );
$history[] = sprintf(
'<a href="%2$s">%1$s</a>',
esc_html( sprintf(
/* translators: 1: contact channel name, 2: contact count */
_x( '%1$s (%2$d)', 'contact history', 'flamingo' ),
$term->name,
$count
) ),
esc_url( $link )
);
}
}
$output = '';
foreach ( $history as $item ) {
$output .= sprintf( '<li>%s</li>', $item );
}
return sprintf( '<ul class="contact-history">%s</ul>', $output );
}
protected function column_last_contacted( $item ) {
if (
empty( $item->last_contacted ) or
'0000-00-00 00:00:00' === $item->last_contacted
) {
return '';
}
$datetime = date_create_immutable_from_format(
'Y-m-d H:i:s',
$item->last_contacted,
wp_timezone()
);
if ( false === $datetime ) {
return '';
}
$t_time = sprintf(
/* translators: 1: date, 2: time */
__( '%1$s at %2$s', 'flamingo' ),
/* translators: date format, see https://www.php.net/date */
$datetime->format( __( 'Y/m/d', 'flamingo' ) ),
/* translators: time format, see https://www.php.net/date */
$datetime->format( __( 'g:i a', 'flamingo' ) )
);
return $t_time;
}
}

View File

@@ -0,0 +1,455 @@
<?php
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
}
class Flamingo_Inbound_Messages_List_Table extends WP_List_Table {
private $is_trash = false;
private $is_spam = false;
public static function define_columns() {
$columns = array(
'cb' => '<input type="checkbox" />',
'subject' => __( 'Subject', 'flamingo' ),
'from' => __( 'From', 'flamingo' ),
'channel' => __( 'Channel', 'flamingo' ),
'date' => __( 'Date', 'flamingo' ),
);
$columns = apply_filters(
'manage_flamingo_inbound_posts_columns', $columns
);
return $columns;
}
public function __construct() {
parent::__construct( array(
'singular' => 'post',
'plural' => 'posts',
'ajax' => false,
) );
}
public function prepare_items() {
$per_page = $this->get_items_per_page(
'flamingo_inbound_messages_per_page'
);
$args = array(
'posts_per_page' => $per_page,
'offset' => ( $this->get_pagenum() - 1 ) * $per_page,
'orderby' => 'date',
'order' => 'DESC',
);
if ( ! empty( $_REQUEST['s'] ) ) {
$args['s'] = $_REQUEST['s'];
}
if ( ! empty( $_REQUEST['orderby'] ) ) {
if ( 'subject' === $_REQUEST['orderby'] ) {
$args['meta_key'] = '_subject';
$args['orderby'] = 'meta_value';
} elseif ( 'from' === $_REQUEST['orderby'] ) {
$args['meta_key'] = '_from';
$args['orderby'] = 'meta_value';
}
}
if (
! empty( $_REQUEST['order'] ) and
'asc' === strtolower( $_REQUEST['order'] )
) {
$args['order'] = 'ASC';
}
if ( ! empty( $_REQUEST['m'] ) ) {
$args['m'] = $_REQUEST['m'];
}
if ( ! empty( $_REQUEST['channel_id'] ) ) {
$args['channel_id'] = $_REQUEST['channel_id'];
}
if ( ! empty( $_REQUEST['channel'] ) ) {
$args['channel'] = $_REQUEST['channel'];
}
if ( ! empty( $_REQUEST['post_status'] ) ) {
if ( 'trash' === $_REQUEST['post_status'] ) {
$args['post_status'] = 'trash';
$this->is_trash = true;
} elseif ( 'spam' === $_REQUEST['post_status'] ) {
$args['post_status'] = Flamingo_Inbound_Message::spam_status;
$this->is_spam = true;
}
}
$this->items = Flamingo_Inbound_Message::find( $args );
$total_items = Flamingo_Inbound_Message::count();
$total_pages = ceil( $total_items / $per_page );
$this->set_pagination_args( array(
'total_items' => $total_items,
'total_pages' => $total_pages,
'per_page' => $per_page,
) );
}
protected function get_views() {
$base_url = menu_page_url( 'flamingo_inbound', false );
$link_data = array();
// Inbox
Flamingo_Inbound_Message::find( array(
'post_status' => 'any',
) );
$posts_in_inbox = Flamingo_Inbound_Message::count();
$inbox = sprintf(
/* translators: %s: Number of items. */
_nx(
'Inbox <span class="count">(%s)</span>',
'Inbox <span class="count">(%s)</span>',
$posts_in_inbox, 'posts', 'flamingo'
),
number_format_i18n( $posts_in_inbox )
);
$link_data['inbox'] = array(
'url' => $base_url,
'label' => $inbox,
'current' => ! $this->is_trash && ! $this->is_spam,
);
// Spam
Flamingo_Inbound_Message::find( array(
'post_status' => Flamingo_Inbound_Message::spam_status,
) );
$posts_in_spam = Flamingo_Inbound_Message::count();
$spam = sprintf(
/* translators: %s: Number of items. */
_nx(
'Spam <span class="count">(%s)</span>',
'Spam <span class="count">(%s)</span>',
$posts_in_spam, 'posts', 'flamingo'
),
number_format_i18n( $posts_in_spam )
);
$link_data['spam'] = array(
'url' => add_query_arg( 'post_status', 'spam', $base_url ),
'label' => $spam,
'current' => $this->is_spam,
);
// Trash
Flamingo_Inbound_Message::find( array(
'post_status' => 'trash',
) );
$posts_in_trash = Flamingo_Inbound_Message::count();
if ( $posts_in_trash ) {
$trash = sprintf(
/* translators: %s: Number of items. */
_nx(
'Trash <span class="count">(%s)</span>',
'Trash <span class="count">(%s)</span>',
$posts_in_trash, 'posts', 'flamingo'
),
number_format_i18n( $posts_in_trash )
);
$link_data['trash'] = array(
'url' => add_query_arg( 'post_status', 'trash', $base_url ),
'label' => $trash,
'current' => $this->is_trash,
);
}
return $this->get_views_links( $link_data );
}
public function get_columns() {
return get_column_headers( get_current_screen() );
}
protected function get_sortable_columns() {
$columns = array(
'subject' => array( 'subject', false ),
'from' => array( 'from', false ),
'date' => array( 'date', true ),
);
return $columns;
}
protected function get_bulk_actions() {
$actions = array();
if ( $this->is_trash ) {
$actions['untrash'] = __( 'Restore', 'flamingo' );
}
if ( $this->is_trash or ! EMPTY_TRASH_DAYS ) {
$actions['delete'] = __( 'Delete permanently', 'flamingo' );
} else {
$actions['trash'] = __( 'Move to trash', 'flamingo' );
}
if ( $this->is_spam ) {
$actions['unspam'] = __( 'Not spam', 'flamingo' );
} else {
$actions['spam'] = __( 'Mark as spam', 'flamingo' );
}
return $actions;
}
protected function extra_tablenav( $which ) {
$channel = 0;
if ( ! empty( $_REQUEST['channel_id'] ) ) {
$term = get_term( $_REQUEST['channel_id'],
Flamingo_Inbound_Message::channel_taxonomy
);
if ( ! empty( $term ) and ! is_wp_error( $term ) ) {
$channel = $term->term_id;
}
} elseif ( ! empty( $_REQUEST['channel'] ) ) {
$term = get_term_by( 'slug', $_REQUEST['channel'],
Flamingo_Inbound_Message::channel_taxonomy
);
if ( ! empty( $term ) and ! is_wp_error( $term ) ) {
$channel = $term->term_id;
}
}
?>
<div class="alignleft actions">
<?php
if ( 'top' == $which ) {
$this->months_dropdown( Flamingo_Inbound_Message::post_type );
wp_dropdown_categories( array(
'taxonomy' => Flamingo_Inbound_Message::channel_taxonomy,
'name' => 'channel_id',
'show_option_all' => __( 'View all channels', 'flamingo' ),
'show_count' => 0,
'hide_empty' => 1,
'hide_if_empty' => 1,
'orderby' => 'name',
'hierarchical' => 1,
'selected' => $channel,
) );
submit_button( __( 'Filter', 'flamingo' ),
'secondary', false, false, array( 'id' => 'post-query-submit' )
);
if ( ! $this->is_spam and ! $this->is_trash ) {
submit_button( __( 'Export', 'flamingo' ),
'secondary', 'export', false
);
}
}
if (
$this->is_trash and
current_user_can( 'flamingo_delete_inbound_messages' )
) {
submit_button( __( 'Empty trash', 'flamingo' ),
'button-secondary apply', 'delete_all', false
);
}
?>
</div>
<?php
}
protected function column_default( $item, $column_name ) {
do_action( 'manage_flamingo_inbound_posts_custom_column',
$column_name, $item->id()
);
}
protected function column_cb( $item ) {
return sprintf(
'<input type="checkbox" name="%1$s[]" value="%2$s" />',
$this->_args['singular'],
$item->id()
);
}
protected function column_subject( $item ) {
if ( $this->is_trash ) {
return sprintf( '<strong>%s</strong>', esc_html( $item->subject ) );
}
if ( current_user_can( 'flamingo_edit_inbound_message', $item->id() ) ) {
$edit_link = add_query_arg( array(
'post' => $item->id(),
'action' => 'edit',
), menu_page_url( 'flamingo_inbound', false ) );
return sprintf(
'<strong><a class="row-title" href="%1$s" aria-label="%2$s">%3$s</a></strong>',
esc_url( $edit_link ),
esc_attr( sprintf(
/* translators: %s: Item title. */
__( '&#8220;%s&#8221; (Edit)', 'flamingo' ),
$item->subject
) ),
esc_html( $item->subject )
);
}
return sprintf( '<strong>%1$s</strong>',
esc_html( $item->subject )
);
}
protected function handle_row_actions( $item, $column_name, $primary ) {
if ( $column_name !== $primary ) {
return '';
}
$actions = array();
if ( current_user_can( 'flamingo_edit_inbound_message', $item->id() ) ) {
$link = add_query_arg( array(
'post' => $item->id(),
'action' => 'edit',
), menu_page_url( 'flamingo_inbound', false ) );
$actions['edit'] = sprintf( '<a href="%1$s">%2$s</a>',
esc_url( $link ),
esc_html( __( 'View', 'flamingo' ) )
);
}
if (
$item->spam and
current_user_can( 'flamingo_unspam_inbound_message', $item->id() )
) {
$link = add_query_arg( array(
'post' => $item->id(),
'action' => 'unspam',
), menu_page_url( 'flamingo_inbound', false ) );
$link = wp_nonce_url( $link,
'flamingo-unspam-inbound-message_' . $item->id()
);
$actions['unspam'] = sprintf( '<a href="%1$s">%2$s</a>',
esc_url( $link ),
esc_html( __( 'Not spam', 'flamingo' ) )
);
}
if (
! $item->spam and
current_user_can( 'flamingo_spam_inbound_message', $item->id() )
) {
$link = add_query_arg( array(
'post' => $item->id(),
'action' => 'spam',
), menu_page_url( 'flamingo_inbound', false ) );
$link = wp_nonce_url( $link,
'flamingo-spam-inbound-message_' . $item->id()
);
$actions['spam'] = sprintf( '<a href="%1$s">%2$s</a>',
esc_url( $link ),
esc_html( __( 'Spam', 'flamingo' ) )
);
}
return $this->row_actions( $actions );
}
protected function column_from( $item ) {
return esc_html( $item->from );
}
protected function column_channel( $item ) {
if ( empty( $item->channel ) ) {
return '';
}
$term = get_term_by( 'slug', $item->channel,
Flamingo_Inbound_Message::channel_taxonomy
);
if ( empty( $term ) or is_wp_error( $term ) ) {
return $item->channel;
}
$output = '';
$ancestors = (array) get_ancestors( $term->term_id,
Flamingo_Inbound_Message::channel_taxonomy
);
while ( $parent = array_pop( $ancestors ) ) {
$parent = get_term( $parent, Flamingo_Inbound_Message::channel_taxonomy );
if ( empty( $parent ) or is_wp_error( $parent ) ) {
continue;
}
$link = add_query_arg( array(
'channel' => $parent->slug,
), menu_page_url( 'flamingo_inbound', false ) );
$output .= sprintf( '<a href="%1$s" aria-label="%2$s">%3$s</a> / ',
esc_url( $link ),
esc_attr( $parent->name ),
esc_html( $parent->name )
);
}
$link = add_query_arg( array(
'channel' => $term->slug,
), menu_page_url( 'flamingo_inbound', false ) );
$output .= sprintf( '<a href="%1$s" aria-label="%2$s">%3$s</a>',
esc_url( $link ),
esc_attr( $term->name ),
esc_html( $term->name )
);
return $output;
}
protected function column_date( $item ) {
$datetime = get_post_datetime( $item->id() );
if ( false === $datetime ) {
return '';
}
$t_time = sprintf(
/* translators: 1: date, 2: time */
__( '%1$s at %2$s', 'flamingo' ),
/* translators: date format, see https://www.php.net/date */
$datetime->format( __( 'Y/m/d', 'flamingo' ) ),
/* translators: time format, see https://www.php.net/date */
$datetime->format( __( 'g:i a', 'flamingo' ) )
);
return $t_time;
}
}

View File

@@ -0,0 +1,20 @@
table.message-main-fields th, table.message-main-fields td {
text-align: right;
}
table.message-fields td {
padding: 4px 7px 2px 14px;
}
table.message-fields td.field-value li {
margin-right: 1em;
}
.tablenav .actions input.button {
margin: 0 0 0 8px;
}
#misc-publishing-actions .spam-log .dashicons-before::before {
margin: 0 -1px 0 0;
padding: 0 0 0 3px;
}

View File

@@ -0,0 +1,62 @@
ul.contact-history {
margin: 0;
}
#poststuff #submitdiv .inside {
margin: 0;
padding: 0;
}
#poststuff table.form-table tr.contact-prop th {
width: 25%;
}
table.message-main-fields th, table.message-main-fields td {
font-size: 15px;
text-align: left;
padding: 8px 4px;
}
table.message-main-fields th {
width: 20%;
color: #555;
}
table.message-fields td {
padding: 4px 14px 2px 7px;
}
table.message-fields td.field-title {
font-weight: bold;
width: 24%;
}
table.message-fields td.field-value p {
overflow-wrap: anywhere;
}
table.message-fields td.field-value ul {
margin: 0;
}
table.message-fields td.field-value li {
list-style: disc;
margin-left: 1em;
}
.tagsdiv {
margin-top: inherit;
}
.tablenav .actions input.button {
margin: 0 8px 0 0;
}
#misc-publishing-actions .dashicons-before::before {
position: relative;
top: -1px;
margin-left: -1px;
padding-right: 3px;
vertical-align: top;
color: #82878c;
}

View File

@@ -0,0 +1,8 @@
<?php
return array(
'dependencies' => array(
'wp-i18n',
),
'version' => FLAMINGO_VERSION,
);

View File

@@ -0,0 +1 @@
(()=>{"use strict";const e=window.wp.i18n;document.addEventListener("DOMContentLoaded",t=>{document.querySelectorAll(".submitdelete").forEach(t=>{t.addEventListener("click",t=>{if(window.confirm((0,e.__)("You are about to delete this item.\n 'Cancel' to stop, 'OK' to delete.","flamingo")))return!0;t.preventDefault()})}),postboxes.add_postbox_toggles(flamingo.screenId)})})();

View File

@@ -0,0 +1,330 @@
<?php
function flamingo_contact_submit_meta_box( $post ) {
?>
<div class="submitbox" id="submitlink">
<div id="major-publishing-actions">
<div id="delete-action">
<?php
if ( current_user_can( 'flamingo_delete_contact', $post->id() ) ) {
$delete_link = wp_nonce_url(
add_query_arg(
array(
'post' => $post->id(),
'action' => 'delete',
),
menu_page_url( 'flamingo', false )
),
'flamingo-delete-contact_' . $post->id()
);
echo sprintf(
'<a class="submitdelete deletion" href="%1$s">%2$s</a>',
esc_url( $delete_link ),
esc_html( __( 'Delete', 'flamingo' ) )
);
}
?>
</div>
<div id="publishing-action">
<span class="spinner"></span>
<?php if ( ! empty( $post->id() ) ) : ?>
<input name="save" type="submit" class="button-primary" id="publish" tabindex="4" accesskey="p" value="<?php echo esc_attr( __( 'Update contact', 'flamingo' ) ); ?>" />
<?php else : ?>
<input name="save" type="submit" class="button-primary" id="publish" tabindex="4" accesskey="p" value="<?php echo esc_attr( __( 'Add contact', 'flamingo' ) ); ?>" />
<?php endif; ?>
</div>
<div class="clear"></div>
</div><!-- #major-publishing-actions -->
<div class="clear"></div>
</div>
<?php
}
function flamingo_contact_tags_meta_box( $post ) {
$taxonomy = get_taxonomy( Flamingo_Contact::contact_tag_taxonomy );
if ( ! $taxonomy ) {
return;
}
$tags = wp_get_post_terms( $post->id(), $taxonomy->name );
$tag_names = $tag_ids = array();
if ( ! empty( $tags ) and ! is_wp_error( $tags ) ) {
foreach( $tags as $tag ) {
$tag_names[] = $tag->name;
$tag_ids[] = $tag->term_id;
}
}
$tag_names = implode( ', ', $tag_names );
$most_used_tags = get_terms( array(
'taxonomy' => Flamingo_Contact::contact_tag_taxonomy,
'orderby' => 'count',
'order' => 'DESC',
'number' => 10,
'exclude' => $tag_ids,
'fields' => 'names',
) );
if ( is_wp_error( $most_used_tags ) ) {
$most_used_tags = array();
}
?>
<div class="tagsdiv" id="<?php echo esc_attr( $taxonomy->name ); ?>">
<textarea name="<?php echo esc_attr( "tax_input[{$taxonomy->name}]" ); ?>" rows="3" cols="20" class="the-tags" id="<?php echo esc_attr( "tax-input-{$taxonomy->name}" ); ?>"><?php echo esc_textarea( $tag_names ); ?></textarea>
<p class="howto"><?php echo esc_html( __( 'Separate tags with commas', 'flamingo' ) ); ?></p>
<?php if ( $most_used_tags ) : ?>
<p class="howto"><?php echo esc_html( __( 'Choose from the most used tags', 'flamingo' ) ); ?>
<br />
<?php foreach ( $most_used_tags as $tag ) {
echo '<a href="#" class="append-this-to-contact-tags" onclick="appendTag( this.text )">' . esc_html( $tag ) . '</a> ';
} ?>
</p>
<script>
const appendTag = ( tag ) => {
const tagsInput = document.querySelector(
'#tax-input-<?php echo esc_js( $taxonomy->name ); ?>'
);
const tags = tagsInput.value.split( /\s*,\s*/ );
tags.push( tag );
tagsInput.value = tags.filter( tag => '' !== tag ).join( ', ' );
return false;
};
</script>
<?php endif; ?>
</div>
<?php
}
function flamingo_inbound_submit_meta_box( $post ) {
?>
<div class="submitbox" id="submitinbound">
<div id="minor-publishing">
<div id="misc-publishing-actions">
<fieldset class="misc-pub-section" id="comment-status-radio">
<legend class="screen-reader-text"><?php echo esc_html( __( 'Inbound message status', 'flamingo' ) ); ?></legend>
<label><input type="radio"<?php checked( $post->spam, true ); ?> name="inbound[status]" value="spam" /><?php echo esc_html( __( 'Spam', 'flamingo' ) ); ?></label><br />
<label><input type="radio"<?php checked( $post->spam, false ); ?> name="inbound[status]" value="ham" /><?php echo esc_html( __( 'Not spam', 'flamingo' ) ); ?></label>
</fieldset>
<div class="misc-pub-section curtime misc-pub-curtime">
<span class="dashicons-before dashicons-calendar">
<?php
$submitted_timestamp = get_post_timestamp( $post->id() );
$submitted_on = sprintf(
/* translators: Publish box date string. 1: Date, 2: Time. */
__( '%1$s at %2$s', 'flamingo' ),
wp_date(
/* translators: Publish box date format, see https://www.php.net/date */
_x( 'M j, Y', 'publish box date format', 'flamingo' ),
$submitted_timestamp
),
wp_date(
/* translators: Publish box time format, see https://www.php.net/date */
_x( 'H:i', 'publish box time format', 'flamingo' ),
$submitted_timestamp
)
);
echo wp_kses_data( sprintf(
/* translators: %s: Message submission date. */
__( 'Submitted on: <b>%s</b>', 'flamingo' ),
$submitted_on
) );
?>
</span>
</div>
<?php
if ( ! empty( $post->submission_status ) ) {
echo '<div class="misc-pub-section submission-status">', "\n";
echo sprintf(
'<span class="dashicons-before %1$s"> %2$s</span>',
in_array( $post->submission_status, array( 'mail_failed', 'spam' ) )
? 'dashicons-no' : 'dashicons-yes',
wp_kses_data( sprintf(
/* translators: %s: Result of the submission. */
__( 'Submission result: <b>%s</b>', 'flamingo' ),
$post->submission_status
) )
);
echo '</div>', "\n";
}
foreach ( (array) $post->spam_log as $log ) {
echo '<div class="misc-pub-section spam-log">';
echo sprintf(
'<span class="dashicons-before dashicons-shield %1$s"> %2$s</span>',
esc_attr( $log['agent'] ?? '' ),
wp_kses_data( sprintf(
/* translators: %s: reason why this message is regarded as spam */
__( 'Spam log: %s', 'flamingo' ),
$log['reason'] ?? ''
) )
);
echo '</div>';
}
?>
</div><!-- #misc-publishing-actions -->
<div class="clear"></div>
</div><!-- #minor-publishing -->
<div id="major-publishing-actions">
<div id="delete-action">
<?php
if ( current_user_can( 'flamingo_delete_inbound_message', $post->id() ) ) {
if ( ! EMPTY_TRASH_DAYS ) {
$delete_text = __( 'Delete permanently', 'flamingo' );
} else {
$delete_text = __( 'Move to trash', 'flamingo' );
}
$delete_link = add_query_arg(
array(
'post' => $post->id(),
'action' => 'trash',
),
menu_page_url( 'flamingo_inbound', false )
);
$delete_link = wp_nonce_url(
$delete_link,
'flamingo-trash-inbound-message_' . $post->id()
);
echo sprintf( '<a href="%1$s" class="submitdelete deletion">%2$s</a>',
esc_url( $delete_link ),
esc_html( $delete_text )
);
}
?>
</div>
<div id="publishing-action">
<?php
submit_button( __( 'Update', 'flamingo' ), 'primary large', 'save', false );
?>
</div>
<div class="clear"></div>
</div><!-- #major-publishing-actions -->
</div>
<?php
}
function flamingo_contact_name_meta_box( $post ) {
?>
<table class="form-table">
<tbody>
<tr class="contact-prop">
<th><label for="contact_name"><?php echo esc_attr( __( 'Full name', 'flamingo' ) ); ?></th>
<td><input type="text" name="contact[name]" id="contact_name" value="<?php echo esc_attr( $post->get_prop( 'name' ) ); ?>" class="widefat" /></td>
</tr>
<tr class="contact-prop">
<th><label for="contact_first_name"><?php echo esc_attr( __( 'First name', 'flamingo' ) ); ?></th>
<td><input type="text" name="contact[first_name]" id="contact_first_name" value="<?php echo esc_attr( $post->get_prop( 'first_name' ) ); ?>" class="widefat" /></td>
</tr>
<tr class="contact-prop">
<th><label for="contact_last_name"><?php echo esc_attr( __( 'Last name', 'flamingo' ) ); ?></th>
<td><input type="text" name="contact[last_name]" id="contact_last_name" value="<?php echo esc_attr( $post->get_prop( 'last_name' ) ); ?>" class="widefat" /></td>
</tr>
</tbody>
</table>
<?php
}
function flamingo_inbound_fields_meta_box( $post ) {
?>
<table class="widefat message-fields striped">
<tbody>
<?php foreach ( (array) $post->fields as $key => $value ) : ?>
<tr>
<td class="field-title"><?php echo esc_html( $key ); ?></td>
<td class="field-value"><?php echo wp_kses_post( flamingo_htmlize( $value ) ); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php
}
function flamingo_inbound_consent_meta_box( $post ) {
$consent = $post->consent;
if ( empty( $consent ) ) {
return;
}
?>
<table class="widefat message-fields striped">
<tbody>
<?php foreach ( (array) $consent as $key => $value ) : ?>
<tr>
<td class="field-title"><?php echo esc_html( $key ); ?></td>
<td class="field-value"><?php echo wp_kses( $value, wp_kses_allowed_html( 'data' ) ); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php
}
function flamingo_inbound_recaptcha_meta_box( $post ) {
?>
<table class="widefat message-fields striped">
<tbody>
<?php foreach ( (array) $post->recaptcha as $key => $value ) : ?>
<tr>
<td class="field-title"><?php echo esc_html( $key ); ?></td>
<td class="field-value"><?php echo esc_html( wp_json_encode( $value, JSON_PRETTY_PRINT ) ); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php
}
function flamingo_inbound_meta_meta_box( $post ) {
?>
<table class="widefat message-fields striped">
<tbody>
<?php foreach ( (array) $post->meta as $key => $value ) : ?>
<tr>
<td class="field-title"><?php echo esc_html( $key ); ?></td>
<td class="field-value"><?php echo wp_kses_post( flamingo_htmlize( $value ) ); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php
}

View File

@@ -0,0 +1,120 @@
<?php
/**
* Support for personal data eraser tool
*
* @link https://developer.wordpress.org/plugins/privacy/adding-the-personal-data-eraser-to-your-plugin/
*/
add_filter( 'wp_privacy_personal_data_erasers',
'flamingo_privacy_register_personal_data_erasers',
10, 1
);
/**
* Registers callback functions.
*/
function flamingo_privacy_register_personal_data_erasers( $erasers ) {
return array_merge( (array) $erasers, array(
'flamingo-contact' => array(
'eraser_friendly_name' => __( 'Flamingo Address Book', 'flamingo' ),
'callback' => 'flamingo_privacy_contact_eraser',
),
'flamingo-inbound' => array(
'eraser_friendly_name' => __( 'Flamingo Inbound Messages', 'flamingo' ),
'callback' => 'flamingo_privacy_inbound_eraser',
),
) );
}
/**
* Callback for the contact data.
*/
function flamingo_privacy_contact_eraser( $email_address, $page = 1 ) {
$number = 100;
$posts = Flamingo_Contact::find( array(
'meta_key' => '_email',
'meta_value' => $email_address,
'posts_per_page' => $number,
'paged' => (int) $page,
) );
$items_removed = false;
$items_retained = false;
$messages = array();
foreach ( (array) $posts as $post ) {
if ( ! current_user_can( 'flamingo_delete_contact', $post->id() ) ) {
$items_retained = true;
$messages = array(
__( 'Flamingo Address Book: You are not allowed to delete contact data.', 'flamingo' ),
);
continue;
}
if ( $post->delete() ) {
$items_removed = true;
} else {
$items_retained = true;
}
}
$done = Flamingo_Contact::count() < $number;
return array(
'items_removed' => $items_removed,
'items_retained' => $items_retained,
'messages' => array_map( 'esc_html', (array) $messages ),
'done' => $done,
);
}
/**
* Callback for the inbound messages data.
*/
function flamingo_privacy_inbound_eraser( $email_address, $page = 1 ) {
$number = 100;
$posts = Flamingo_Inbound_Message::find( array(
'meta_key' => '_from_email',
'meta_value' => $email_address,
'posts_per_page' => $number,
'paged' => (int) $page,
) );
$items_removed = false;
$items_retained = false;
$messages = array();
foreach ( (array) $posts as $post ) {
if ( ! current_user_can( 'flamingo_delete_inbound_message', $post->id() ) ) {
$items_retained = true;
$messages = array(
__( 'Flamingo Inbound Messages: You are not allowed to delete inbound messages.', 'flamingo' ),
);
continue;
}
if ( $post->delete() ) {
$items_removed = true;
} else {
$items_retained = true;
}
}
$done = Flamingo_Inbound_Message::count() < $number;
return array(
'items_removed' => $items_removed,
'items_retained' => $items_retained,
'messages' => array_map( 'esc_html', (array) $messages ),
'done' => $done,
);
}