self::SLUG ), $args ), admin_url( 'admin.php' ) );
}
/** @return Form_Source_Interface[] The form plugins active on this site. */
public static function available_sources() {
return array_values(
array_filter(
self::$sources,
static function ( $source ) {
return $source->is_available();
}
)
);
}
/** @return array Every form of every active source, keyed like Form_Connections::key(). */
private static function all_forms() {
$forms = array();
foreach ( self::available_sources() as $source ) {
foreach ( $source->list_forms() as $form ) {
$forms[ Form_Connections::key( $source->get_slug(), $form['id'] ) ] = $form;
}
}
return $forms;
}
public static function handle_post() {
if ( ! isset( $_POST['emails404_other_forms'] ) || ! current_user_can( Admin_Page::CAPABILITY ) ) {
return;
}
check_admin_referer( self::SAVE_ACTION, 'emails404_nonce' );
$known_ids = array_map(
static function ( $form ) {
return $form['id'];
},
Admin_Page::get_forms()
);
$raw = isset( $_POST['emails404_connections'] ) && is_array( $_POST['emails404_connections'] ) ? wp_unslash( $_POST['emails404_connections'] ) : array(); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- checked against the site's forms in Form_Connections::sanitize().
$forms = self::all_forms();
$result = Form_Connections::sanitize( $raw, $forms, $known_ids );
if ( Event_Page_Forms::is_available() ) {
Event_Page_Forms::save( isset( $_POST['emails404_event_forms'] ) ? wp_unslash( $_POST['emails404_event_forms'] ) : array(), $known_ids ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- sanitized in Event_Page_Forms::save().
}
// Forms of plugins that aren't active right now keep their setting.
$kept = array();
foreach ( Form_Connections::all() as $key => $connection ) {
$slug = strstr( $key, ':', true );
if ( ! in_array( $slug, array_map( array( __CLASS__, 'slug_of' ), self::available_sources() ), true ) ) {
$kept[ $key ] = $connection;
}
}
Form_Connections::save( array_merge( $kept, $result['connections'] ) );
$notice = 'saved';
if ( $result['incomplete'] ) {
$notice = 'incomplete';
$titles = array();
foreach ( $result['incomplete'] as $key ) {
$titles[] = $forms[ $key ]['title'];
}
set_transient( self::INCOMPLETE_TRANSIENT . get_current_user_id(), $titles, MINUTE_IN_SECONDS );
}
wp_safe_redirect( self::url( array( 'emails404_notice' => $notice ) ) );
exit;
}
private static function slug_of( $source ) {
return $source->get_slug();
}
public static function render() {
if ( ! current_user_can( Admin_Page::CAPABILITY ) ) {
wp_die( esc_html__( 'You do not have permission to access this page.', '404-emails' ) );
}
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- a message to show only.
$notice = isset( $_GET['emails404_notice'] ) ? sanitize_key( wp_unslash( $_GET['emails404_notice'] ) ) : '';
?>
' . esc_html__( 'Saved. New sign-ups from these forms will go to 404 Emails.', '404-emails' ) . '
';
} elseif ( 'incomplete' === $notice ) {
$titles = get_transient( self::INCOMPLETE_TRANSIENT . get_current_user_id() );
delete_transient( self::INCOMPLETE_TRANSIENT . get_current_user_id() );
$message = __( 'Saved, except forms where "Who is added" wasn\'t chosen - those aren\'t connected yet.', '404-emails' );
if ( is_array( $titles ) && $titles ) {
/* translators: %s: names of forms, separated by commas. */
$message = sprintf( __( 'Saved. Not connected yet, because "Who is added" wasn\'t chosen: %s', '404-emails' ), implode( ', ', $titles ) );
}
echo '' . esc_html( $message ) . '
';
}
if ( ! Settings::is_connected() ) {
Admin_Page::render_welcome_card();
echo '';
return;
}
?>
' . esc_html__( 'None of these form plugins is active on this site: Contact Form 7, WPForms, Elementor Pro. Forms made in 404 Emails don\'t need this - they add people on their own.', '404-emails' ) . '
';
return;
}
$targets = Admin_Page::get_forms();
if ( ! $targets ) {
printf(
'',
esc_html__( 'Publish a 404 Emails form first - sign-ups need a form to join.', '404-emails' ),
esc_url( Forms_Page::url() ),
esc_html__( 'Go to Forms', '404-emails' )
);
}
?>
list_forms();
?>
get_label() ); ?>
' . esc_html__( 'No forms yet.', '404-emails' ) . '
';
return;
}
?>
get_slug(), $form['id'] );
$name = 'emails404_connections[' . $key . ']';
$saved = Form_Connections::get( $source->get_slug(), $form['id'] );
$email = Form_Connections::find_field( $form, Form_Connections::KIND_EMAIL );
$consents = Form_Connections::consent_fields( $form );
$who = $saved ? $saved['consent'] : Form_Connections::suggested_consent( $form );
$target = $saved ? $saved['form'] : '';
$select_id = 'emails404-target-' . md5( $key );
?>
>
>
>
>
>
60 ) {
return mb_substr( $text, 0, 57 ) . '…';
}
return $text;
}
}