__( 'Ready-made, one switch each. They add next steps to Today and send the few emails you always mean to send. Everything they do shows on the contact\'s timeline.', 'nodebook' ) ) );
echo '
' . esc_html__( 'Emails go out through your site\'s own mail. They are never sent to anyone whose email bounced or who marked it as spam.', 'nodebook' ) . '
';
}
echo '';
}
Nodebook_Admin::footer();
}
/**
* One recipe: tile, name, what it does, a switch; and its settings in a fold-out.
*
* @param string $key Recipe.
* @param array $r Catalog entry.
* @param array $s Its settings.
* @param int $count Times it ran in 30 days.
*/
private static function row( $key, array $r, array $s, $count ) {
$is = ! empty( $s['on'] );
$uid = 'nb-auto-sw-' . $key;
$line = $is ? ( $count
/* translators: %s: number of times */
? sprintf( _n( 'On · ran %s time in 30 days', 'On · ran %s times in 30 days', $count, 'nodebook' ), number_format_i18n( $count ) )
: __( 'On · nothing to do yet', 'nodebook' ) ) : __( 'Off', 'nodebook' );
$before = ! empty( $r['defaults']['before'] );
$has_days = isset( $s['days'] ) && ( (int) $r['defaults']['days'] > 0 || $before );
$has_settings = $has_days || isset( $s['subject'] ) || isset( $s['fields'] );
if ( 'review_ask' === $key && '' === (string) $s['url'] ) {
$line = $is ? __( 'On · add your review link below to start', 'nodebook' ) : $line;
}
echo '';
}
/** Save one recipe and come back to it. */
public static function save() {
Nodebook_Admin::require_cap();
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'Only administrators can change automations.', 'nodebook' ), 403 );
}
$key = isset( $_POST['key'] ) ? sanitize_key( wp_unslash( $_POST['key'] ) ) : '';
check_admin_referer( 'nodebook_recipe_' . $key );
$in = array(
'on' => ! empty( $_POST['on'] ),
);
$cur = Nodebook_Recipes::get( $key );
// Fields not on the form keep their value.
foreach ( array( 'days', 'subject', 'body', 'url' ) as $f ) {
if ( isset( $_POST[ $f ] ) ) {
$in[ $f ] = 'body' === $f ? sanitize_textarea_field( wp_unslash( $_POST[ $f ] ) ) : ( 'url' === $f ? esc_url_raw( wp_unslash( $_POST[ $f ] ) ) : sanitize_text_field( wp_unslash( $_POST[ $f ] ) ) );
} elseif ( isset( $cur[ $f ] ) ) {
$in[ $f ] = $cur[ $f ];
}
}
if ( isset( $cur['fields'] ) ) {
// The fold-out was submitted when "days" came with it; otherwise keep the picked dates.
$in['fields'] = isset( $_POST['days'] ) ? ( isset( $_POST['fields'] ) ? array_map( 'sanitize_key', (array) wp_unslash( $_POST['fields'] ) ) : array() ) : $cur['fields'];
}
Nodebook_Recipes::save( $key, $in );
Nodebook_Admin::redirect( Nodebook_Admin::url( self::PAGE ) . '#nb-auto-' . $key, 'saved' );
}
}