Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial universal code sign-up. #574

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion constant-contact-forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,14 @@ class Constant_Contact {
*/
private $beaver_builder;

/**
* An instance of the ConstantContact_Inline_Forms class.
*
* @since NEXT
* @var ConstantContact_Inline_Forms
*/
private $inline_forms;

/*
* An instance of the ConstantContact_Elementor class.
*
Expand Down Expand Up @@ -437,6 +445,7 @@ public function plugin_classes() {
// Load if Beaver Builder is active.
$this->beaver_builder = new ConstantContact_Beaver_Builder( $this );
}
$this->inline_forms = new ConstantContact_Inline_Forms( $this );
$this->builder = new ConstantContact_Builder( $this );
$this->builder_fields = new ConstantContact_Builder_Fields( $this );
$this->check = new ConstantContact_Check( $this );
Expand Down Expand Up @@ -830,7 +839,7 @@ public function is_constant_contact() {
return false;
}

$ctct_types = [ 'ctct_forms', 'ctct_lists' ];
$ctct_types = [ 'ctct_forms', 'ctct_lists', 'ctct_inline_forms' ];
$post_type = filter_input( INPUT_GET, 'post_type', FILTER_SANITIZE_STRING );
$post = filter_input( INPUT_GET, 'post', FILTER_SANITIZE_NUMBER_INT );

Expand Down
2 changes: 0 additions & 2 deletions includes/class-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ public function hooks() {
*/
public function current_screen( $screen ) {

$post_type_array = [ 'ctct_forms', 'ctct_lists' ];

// Determine if the current page being viewed is Constant Contact.
if ( constant_contact()->is_constant_contact() ) {
add_action( 'in_admin_header', [ $this, 'admin_page_toolbar' ] );
Expand Down
1 change: 0 additions & 1 deletion includes/class-builder-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ public function opt_ins_metabox() {
'id' => $this->prefix . 'redirect_uri',
'type' => 'text',
'description' => sprintf(
/* Translators: 1: basic field info, 2: warning about invalid values, 3: recommended field value */
'%1$s</br><strong>%2$s</strong><br/>%3$s',
esc_html__( 'Leave blank to keep users on the current page.', 'constant-contact-forms' ),
esc_html__( 'NOTE: This URL must be within the current site and may not be a direct link to a media file (e.g., a PDF document). Providing a Redirect URL that is outside the current site or is a media file will cause issues with Constant Constact functionality, including contacts not being added to lists successfully.', 'constant-contact-forms' ),
Expand Down
59 changes: 59 additions & 0 deletions includes/class-cpts.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function __construct( $plugin ) {
public function hooks() {
add_action( 'init', [ $this, 'forms_post_type' ] );
add_action( 'init', [ $this, 'lists_post_type' ] );
add_action( 'init', [ $this, 'signup_post_type' ] );

add_filter( 'post_updated_messages', [ $this, 'post_updated_messages' ] );
add_filter( 'enter_title_here', [ $this, 'change_default_title' ] );
Expand Down Expand Up @@ -170,6 +171,64 @@ public function lists_post_type() {
}
}

/**
* Register Custom Post Type.
*
* @since 1.0.0
*/
public function signup_post_type() {

$labels = [
'name' => _x( 'Inline Forms', 'Post Type General Name', 'constant-contact-forms' ),
'singular_name' => _x( 'Inline Form', 'Post Type Singular Name', 'constant-contact-forms' ),
'menu_name' => __( 'Inline Forms', 'constant-contact-forms' ),
'name_admin_bar' => __( 'Inline Forms', 'constant-contact-forms' ),
'archives' => __( 'Inline Form Archives', 'constant-contact-forms' ),
'parent_item_colon' => __( 'Parent Inline Form:', 'constant-contact-forms' ),
'all_items' => __( 'Inline Forms', 'constant-contact-forms' ),
'add_new_item' => __( 'Add New Inline Form', 'constant-contact-forms' ),
'add_new' => __( 'Add New Inline Form', 'constant-contact-forms' ),
'new_item' => __( 'New Inline Form', 'constant-contact-forms' ),
'edit_item' => __( 'Edit Inline Form', 'constant-contact-forms' ),
'update_item' => __( 'Update Inline Form', 'constant-contact-forms' ),
'view_item' => __( 'View Inline Form', 'constant-contact-forms' ),
'search_items' => __( 'Search Inline Form', 'constant-contact-forms' ),
'not_found' => __( 'Not found', 'constant-contact-forms' ),
'not_found_in_trash' => __( 'Not found in Trash', 'constant-contact-forms' ),
'featured_image' => __( 'Featured Image', 'constant-contact-forms' ),
'set_featured_image' => __( 'Set featured image', 'constant-contact-forms' ),
'remove_featured_image' => __( 'Remove featured image', 'constant-contact-forms' ),
'use_featured_image' => __( 'Use as featured image', 'constant-contact-forms' ),
'insert_into_item' => __( 'Insert into Inline Form', 'constant-contact-forms' ),
'uploaded_to_this_item' => __( 'Uploaded to this Inline Form', 'constant-contact-forms' ),
'items_inline_form' => __( 'Inline Forms list', 'constant-contact-forms' ),
'items_inline_form_navigation' => __( 'Inline Forms list navigation', 'constant-contact-forms' ),
'filter_items_list' => __( 'Filter Inline forms list', 'constant-contact-forms' ),
];
$args = [
'label' => __( 'Constant Contact', 'constant-contact-forms' ),
'description' => __( 'Constant Contact inline forms.', 'constant-contact-forms' ),
'labels' => $labels,
'supports' => [ 'title' ],
'taxonomies' => [],
'hierarchical' => false,
'public' => false,
'show_ui' => true,
'show_in_menu' => 'edit.php?post_type=ctct_forms',
'menu_position' => 20,
'menu_icon' => 'dashicons-megaphone',
'show_in_admin_bar' => false,
'show_in_nav_menus' => false,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => true,
'publicly_queryable' => false,
'capability_type' => 'page',
];

register_post_type( 'ctct_inline_forms', $args );
}

/**
* Custom post udate messages to match CPT naming.
*
Expand Down
220 changes: 220 additions & 0 deletions includes/class-inline-forms.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
<?php
/**
* Sign-up Forms
*
* @package ConstantContact
* @subpackage Inline Forms
* @author Constant Contact
* @since NEXT
*
* phpcs:disable WebDevStudios.All.RequireAuthor -- Don't require author tag in docblocks.
*/

/**
* This class get's everything up an running for Inline Forms.
*
* @since NEXT
*/
class ConstantContact_Inline_Forms {

/**
* Parent plugin class.
*
* @since NEXT
* @var object
*/
protected $plugin;

/**
* Inline Forms Slug.
*
* @since NEXT
* @var string
*/
private $slug = 'ctct_inline_forms';

/**
* Constructor.
*
* @since NEXT
*
* @param object $plugin Parent plugin.
*/
public function __construct( $plugin ) {
$this->plugin = $plugin;
$this->hooks();
}

/**
* Initiate our hooks.
*
* @since 1.0.0
*/
public function hooks() {
add_action( 'wp_head', [ $this, 'inject_universal_code' ] );
add_action( 'cmb2_admin_init', [ $this, 'register_metaboxes' ] );
add_action( 'cmb2_admin_init', [ $this, 'generated_shortcode' ] );
add_shortcode('ctct-inline-form', [$this, 'render_inline_form']);
add_filter( 'manage_ctct_inline_forms_posts_columns', [ $this, 'set_custom_columns' ] );
add_action( 'manage_ctct_inline_forms_posts_custom_column', [ $this, 'custom_columns' ], 10, 2 );
}

/**
* Attempt to inject Universal Code of All Sign-up Forms.
*
* @author Scott Anderson <[email protected]>
* @since NEXT
*
* @return void
*/
public function inject_universal_code() : void {
$universal_code = constant_contact_get_option( '_ctct_signup_universal_code', '' );
$disable_universal_code = constant_contact_get_option( '_ctct_signup_uc_disable', 'off' );

if ( '' === $universal_code || 'on' === $disable_universal_code ) {
return;
}
echo $universal_code;
}

/**
* Register Metaboxes for Inline Forms.
*
* @author Scott Anderson <[email protected]>
* @since NEXT
*
* @return void
*/
public function register_metaboxes() {
$inline_details = new_cmb2_box(array(
'id' => 'ctct_inline_metabox',
'title' => esc_html__('Inline Forms Details', 'constant-contact-forms'),
'object_types' => array('ctct_inline_forms'),
));

$inline_details->add_field(array(
'name' => esc_html__('Date Received', 'constant-contact-forms'),
'id' => 'ctct_inline_code',
'type' => 'textarea_code',
));
}

/**
* Render Inline Form.
*
* @author Scott Anderson <[email protected]>
* @since NEXT
* @param array $args Shortcode Args
*
* @return string
*/
public function render_inline_form( $args ) {

if ( ! array_key_exists( 'form', $args ) ) {
return;
}

$post_id = absint( sanitize_text_field( $args['form'] ) );

$inline_code = get_post_meta( $post_id, 'ctct_inline_code', true );

if ( '' === $inline_code ) {
return;
}

return $inline_code;
}

/**
* Show a metabox rendering inline forms shortcode.
*
* @author Scott Anderson <[email protected]>
* @since NEXT
*
* @return void
*/
public function generated_shortcode() {
$generated = new_cmb2_box( [
'id' => 'ctct_inline_generated_metabox',
'title' => esc_html__( 'Shortcode', 'constant-contact-forms' ),
'object_types' => [ $this->slug ],
'context' => 'side',
'priority' => 'low',
'show_names' => true,
] );

$generated->add_field( [
'name' => esc_html__( 'Shortcode to use', 'constant-contact-forms' ),
'id' => 'ctct_' . 'generated_shortcode',
'type' => 'text_medium',
'desc' => sprintf(
/* Translators: Placeholders here represent `<em>` and `<strong>` HTML tags. */
esc_html__( 'Shortcode to embed — %1$s%2$sYou can copy and paste this in a post to display your form.%3$s%4$s', 'constant-contact-forms' ),
'<small>',
'<em>',
'</em>',
'</small>'
),
'default' => ( $generated->object_id > 0 ) ? '[ctct-inline-form form="' . $generated->object_id . '"]' : '',
'attributes' => [
'readonly' => 'readonly',
],
] );
}

/**
* Add columns to Inline Forms post type.
*
* @internal
*
* @since NEXT
*
* @param array $columns post list columns.
* @return array $columns Array of columns to add.
*/
public function set_custom_columns( $columns ) {

$columns['shortcodes'] = esc_html__( 'Shortcode', 'constant-contact-forms' );

return $columns;
}

/**
* Content of custom post columns.
*
* @internal
*
* @since NEXT
*
* @param string $column Column title.
* @param integer $post_id Post id of post item.
*
* @return void
*/
public function custom_columns( $column, $post_id ) {
$post_id = absint( $post_id );

if ( ! $post_id ) {
return;
}

$table_list_ids = get_post_meta( $post_id, '_ctct_list', true );
$table_list_ids = is_array( $table_list_ids ) ? $table_list_ids : [ $table_list_ids ];

switch ( $column ) {
case 'shortcodes':
echo '<div class="ctct-shortcode-wrap"><input class="ctct-shortcode" type="text" value="';
echo esc_html( '[ctct-inline-form form="' . $post_id . '"]' );
echo '" readonly="readonly">';
echo '<button type="button" class="button" data-copied="' . esc_html( 'Copied!', 'constant-contact-forms' ) . '">';
echo esc_html__( 'Copy', 'constant-contact-forms' );
echo '</button>';
echo '</div>';
break;
case 'description':
echo wp_kses_post( wpautop( get_post_meta( $post_id, '_ctct_description', true ) ) );
break;
}
}

}
43 changes: 43 additions & 0 deletions includes/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,49 @@ protected function register_fields_general() {
'id' => '_ctct_alternative_legal_text',
'type' => 'textarea',
] );


$before_global_css = sprintf(
/* translators: 1: horizontal rule and opening heading tag, 2: signup section H, 3: closing heading tag */
'%1$s%2$s%3$s',
'<hr><h2>',
esc_html__( 'Global Form CSS Settings', 'constant-contact-forms' ),
'</h2>'
);

$cmb->add_field( [
'name' => esc_html__( 'CSS Classes', 'constant-contact-forms' ),
'id' => '_ctct_form_custom_classes',
'type' => 'text',
'description' => esc_html__(
'Provide custom classes for the form separated by a single space.',
'constant-contact-forms'
),
'before_row' => $before_global_css,
] );

$before_signup_css = sprintf(
/* translators: 1: horizontal rule and opening heading tag, 2: signup section H, 3: closing heading tag */
'%1$s%2$s%3$s',
'<hr><h2>',
esc_html__( 'Sign-up Form Settings', 'constant-contact-forms' ),
'</h2>'
);

$cmb->add_field( [
'name' => esc_html__( 'Universal Code', 'constant-contact-forms' ),
'desc' => esc_html__( 'Universal Code found in Constant Contact Sign-up Dashboard.', 'constant-contact-forms' ),
'id' => '_ctct_signup_universal_code',
'type' => 'textarea_code',
'before_row' => $before_signup_css,
] );

$cmb->add_field( [
'name' => esc_html__( 'Disable Universal Code', 'constant-contact-forms' ),
'desc' => esc_html__( 'Temporarily disable Universal Code for debugging.', 'constant-contact-forms' ),
'id' => '_ctct_signup_uc_disable',
'type' => 'checkbox',
] );

}

Expand Down