first commit
This commit is contained in:
+169
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
/**
|
||||
* The admin-specific functionality of the module.
|
||||
*
|
||||
* @link https://codesupply.co
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @package Powerkit
|
||||
* @subpackage Modules/Admin
|
||||
*/
|
||||
|
||||
/**
|
||||
* The admin-specific functionality of the module.
|
||||
*/
|
||||
class Powerkit_Opt_In_Forms_Admin extends Powerkit_Module_Admin {
|
||||
|
||||
/**
|
||||
* Initialize
|
||||
*/
|
||||
public function initialize() {
|
||||
add_action( 'admin_menu', array( $this, 'register_options_page' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register admin page
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function register_options_page() {
|
||||
add_options_page( esc_html__( 'Opt-in Forms', 'powerkit' ), esc_html__( 'Opt-in Forms', 'powerkit' ), 'manage_options', powerkit_get_page_slug( $this->slug ), array( $this, 'build_options_page' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Build admin page
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function build_options_page() {
|
||||
|
||||
if ( ! current_user_can( 'manage_options' ) ) {
|
||||
wp_die( esc_html__( 'You do not have sufficient rights to view this page.', 'powerkit' ) );
|
||||
}
|
||||
|
||||
$this->save_options_page();
|
||||
?>
|
||||
|
||||
<div class="wrap pk-wrap">
|
||||
<h1><?php esc_html_e( 'Opt-in Forms', 'powerkit' ); ?></h1>
|
||||
|
||||
<div class="pk-settings">
|
||||
<form method="post">
|
||||
<h3><?php esc_html_e( 'MailChimp', 'powerkit' ); ?></h3>
|
||||
|
||||
<table class="form-table">
|
||||
<tbody>
|
||||
<!-- API Key -->
|
||||
<tr>
|
||||
<th scope="row"><label for="powerkit_mailchimp_token"><?php esc_html_e( 'API Key', 'powerkit' ); ?></label></th>
|
||||
<td><input class="regular-text" id="powerkit_mailchimp_token" name="powerkit_mailchimp_token" type="text" value="<?php echo esc_attr( get_option( 'powerkit_mailchimp_token' ) ); ?>"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<ol>
|
||||
<li><?php esc_html_e( 'Log in to your', 'powerkit' ); ?> <?php echo sprintf( '<a href="%1$s" target="_blank">%2$s</a>', esc_url( 'https://mailchimp.com' ), esc_html__( 'MailChimp account', 'powerkit' ) ); ?>.</li>
|
||||
<li><?php esc_html_e( 'Click your profile name to expand the Account Panel, and choose Account.', 'powerkit' ); ?></li>
|
||||
<li><?php esc_html_e( 'Click the Extras drop-down menu and choose API keys.', 'powerkit' ); ?></li>
|
||||
<li><?php esc_html_e( 'Copy an existing API key or click the Create A Key button.', 'powerkit' ); ?></li>
|
||||
<li><?php esc_html_e( 'Name your key descriptively, so you know what application uses that key.', 'powerkit' ); ?></li>
|
||||
</ol>
|
||||
</td>
|
||||
</tr>
|
||||
<!-- Lists -->
|
||||
<tr>
|
||||
<?php
|
||||
$token = get_option( 'powerkit_mailchimp_token' );
|
||||
|
||||
if ( $token ) {
|
||||
|
||||
$response = null;
|
||||
|
||||
$data = powerkit_mailchimp_request(
|
||||
'GET', 'lists', array(
|
||||
'sort_field' => 'date_created',
|
||||
'sort_dir' => 'DESC',
|
||||
'count' => 1000,
|
||||
)
|
||||
);
|
||||
|
||||
if ( is_array( $data ) ) {
|
||||
$response .= isset( $data['type'] ) ? $data['type'] : '';
|
||||
$response .= isset( $data['title'] ) ? ':' . $data['title'] : '';
|
||||
}
|
||||
|
||||
if ( is_array( $data ) && isset( $data['lists'] ) && $data['lists'] ) {
|
||||
?>
|
||||
<th scope="row"><label for="powerkit_mailchimp_list"><?php esc_html_e( 'Default Audience', 'powerkit' ); ?></label></th>
|
||||
<td>
|
||||
<select class="regular-text" name="powerkit_mailchimp_list" id="powerkit_mailchimp_list">
|
||||
<option value=""><?php esc_html_e( '- not selected -', 'powerkit' ); ?></option>
|
||||
<?php foreach ( $data['lists'] as $item ) : ?>
|
||||
<option <?php selected( $item['id'], get_option( 'powerkit_mailchimp_list' ) ); ?> value="<?php echo esc_attr( $item['id'] ); ?>"><?php echo esc_html( $item['name'] ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</td>
|
||||
<?php } else { ?>
|
||||
<td colspan="2">
|
||||
<code><?php printf( '[%s] %s', esc_html( $response ), esc_html__( 'Invalid API Key or MailChimp access error!', 'powerkit' ) ); ?></code>
|
||||
</td>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</tr>
|
||||
<!-- Enable double opt-in -->
|
||||
<tr>
|
||||
<th scope="row"><label for="powerkit_mailchimp_double_optin"><?php esc_html_e( 'Enable Double opt-in', 'powerkit' ); ?></label></th>
|
||||
<td><input class="regular-text" id="powerkit_mailchimp_double_optin" name="powerkit_mailchimp_double_optin" type="checkbox" value="true" <?php checked( (bool) get_option( 'powerkit_mailchimp_double_optin', false ) ); ?>></td>
|
||||
</tr>
|
||||
<!-- Data Privacy Checkbox Label -->
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<label for="powerkit_mailchimp_privacy">
|
||||
<?php esc_html_e( 'Data Privacy Checkbox Label', 'powerkit' ); ?>
|
||||
<p class="description"><?php esc_html_e( 'Enter the contents that should display as a label for the data privacy checkbox. Leave blank to disable.', 'powerkit' ); ?></p>
|
||||
</label>
|
||||
</th>
|
||||
<td><textarea class="regular-text" id="powerkit_mailchimp_privacy" name="powerkit_mailchimp_privacy" rows="5"><?php echo esc_html( powerkit_mailchimp_get_privacy_text() ); ?></textarea></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php wp_nonce_field(); ?>
|
||||
|
||||
<p class="submit"><input class="button button-primary" name="save_settings" type="submit" value="<?php esc_html_e( 'Save changes', 'powerkit' ); ?>" /></p>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Settings save
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected function save_options_page() {
|
||||
if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( $_POST['_wpnonce'] ) ) { // Input var ok; sanitization ok.
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset( $_POST['save_settings'] ) ) { // Input var ok.
|
||||
|
||||
if ( isset( $_POST['powerkit_mailchimp_token'] ) ) { // Input var ok.
|
||||
update_option( 'powerkit_mailchimp_token', sanitize_text_field( wp_unslash( $_POST['powerkit_mailchimp_token'] ) ) ); // Input var ok.
|
||||
}
|
||||
if ( isset( $_POST['powerkit_mailchimp_list'] ) ) { // Input var ok.
|
||||
update_option( 'powerkit_mailchimp_list', sanitize_text_field( wp_unslash( $_POST['powerkit_mailchimp_list'] ) ) ); // Input var ok.
|
||||
}
|
||||
if ( isset( $_POST['powerkit_mailchimp_double_optin'] ) ) { // Input var ok.
|
||||
update_option( 'powerkit_mailchimp_double_optin', true );
|
||||
} else {
|
||||
update_option( 'powerkit_mailchimp_double_optin', false );
|
||||
}
|
||||
if ( isset( $_POST['powerkit_mailchimp_privacy'] ) ) { // Input var ok.
|
||||
update_option( 'powerkit_mailchimp_privacy', wp_kses( wp_unslash( $_POST['powerkit_mailchimp_privacy'] ), 'post' ) ); // Input var ok. sanitization ok.
|
||||
}
|
||||
printf( '<div id="message" class="updated fade"><p><strong>%s</strong></p></div>', esc_html__( 'Settings saved.', 'powerkit' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* Social Links
|
||||
*
|
||||
* @package Powerkit
|
||||
* @subpackage Modules
|
||||
*/
|
||||
|
||||
if ( class_exists( 'Powerkit_Module' ) ) {
|
||||
/**
|
||||
* Init module
|
||||
*/
|
||||
class Powerkit_Opt_In_Forms extends Powerkit_Module {
|
||||
|
||||
/**
|
||||
* Register module
|
||||
*/
|
||||
public function register() {
|
||||
$this->name = esc_html__( 'Opt-in Forms', 'powerkit' );
|
||||
$this->desc = esc_html__( 'Easily add opt-in (subscription) forms to your website and grow your subscribers’ list with the Opt-In Forms module.', 'powerkit' );
|
||||
$this->slug = 'opt_in_forms';
|
||||
$this->type = 'default';
|
||||
$this->category = 'forms';
|
||||
$this->priority = 70;
|
||||
$this->public = true;
|
||||
$this->enabled = true;
|
||||
$this->links = array(
|
||||
array(
|
||||
'name' => esc_html__( 'Go to settings', 'powerkit' ),
|
||||
'url' => powerkit_get_page_url( $this->slug ),
|
||||
),
|
||||
array(
|
||||
'name' => esc_html__( 'View documentation', 'powerkit' ),
|
||||
'url' => powerkit_get_setting( 'documentation' ) . '/marketing/opt-in-forms/',
|
||||
'target' => '_blank',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize module
|
||||
*/
|
||||
public function initialize() {
|
||||
|
||||
/* Load the required dependencies for this module */
|
||||
|
||||
// Helpers Functions for the module.
|
||||
require_once dirname( __FILE__ ) . '/helpers/helper-powerkit-opt-in-forms.php';
|
||||
|
||||
// The classes responsible for defining all actions.
|
||||
require_once dirname( __FILE__ ) . '/public/class-powerkit-subscription-form-shortcode.php';
|
||||
require_once dirname( __FILE__ ) . '/public/class-powerkit-subscription-form-widget.php';
|
||||
|
||||
if ( function_exists( 'register_block_type' ) ) {
|
||||
require_once dirname( __FILE__ ) . '/public/class-powerkit-subscription-form-block.php';
|
||||
}
|
||||
|
||||
// Admin and public area.
|
||||
require_once dirname( __FILE__ ) . '/admin/class-powerkit-opt-in-forms-admin.php';
|
||||
require_once dirname( __FILE__ ) . '/public/class-powerkit-opt-in-forms-public.php';
|
||||
|
||||
new Powerkit_Opt_In_Forms_Admin( $this->slug );
|
||||
new Powerkit_Opt_In_Forms_Public( $this->slug );
|
||||
}
|
||||
}
|
||||
|
||||
new Powerkit_Opt_In_Forms();
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
/**
|
||||
* Helpers Opt-in Forms
|
||||
*
|
||||
* @package Powerkit
|
||||
* @subpackage Modules/Helper
|
||||
*/
|
||||
|
||||
/**
|
||||
* Get privacy text
|
||||
*/
|
||||
function powerkit_mailchimp_get_privacy_text() {
|
||||
return get_option( 'powerkit_mailchimp_privacy', esc_html__( 'By checking this box, you confirm that you have read and are agreeing to our terms of use regarding the storage of the data submitted through this form.', 'powerkit' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get headers for mailchimp request.
|
||||
*/
|
||||
function powerkit_mailchimp_headers() {
|
||||
global $wp_version;
|
||||
|
||||
$token = get_option( 'powerkit_mailchimp_token' );
|
||||
|
||||
$headers = array();
|
||||
$headers['Authorization'] = 'apikey: ' . $token;
|
||||
$headers['Accept'] = 'application/json';
|
||||
$headers['Content-Type'] = 'application/json';
|
||||
$headers['User-Agent'] = 'DrewM/MailChimp-API/3.0 (github.com/drewm/mailchimp-api)';
|
||||
|
||||
return $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the underlying HTTP request. Not very exciting.
|
||||
*
|
||||
* @param string $http_verb The HTTP verb to use: get, post, put, patch, delete.
|
||||
* @param string $method The API method to be called.
|
||||
* @param array $data Assoc array of parameters to be passed.
|
||||
*/
|
||||
function powerkit_mailchimp_request( $http_verb = 'GET', $method = 'lists', $data = array() ) {
|
||||
$token = get_option( 'powerkit_mailchimp_token' );
|
||||
|
||||
if ( ! $token || false === strpos( $token, '-' ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$url = 'https://<dc>.api.mailchimp.com/3.0/' . ltrim( $method, '/' );
|
||||
|
||||
list(, $data_center ) = explode( '-', $token );
|
||||
|
||||
$url = str_replace( '<dc>', $data_center, $url );
|
||||
|
||||
$args = array(
|
||||
'url' => $url,
|
||||
'method' => $http_verb,
|
||||
'headers' => powerkit_mailchimp_headers(),
|
||||
'timeout' => 10,
|
||||
'sslverify' => apply_filters( 'powerkit_mailchimp_sslverify', true ),
|
||||
);
|
||||
|
||||
if ( ! empty( $data ) ) {
|
||||
if ( in_array( $http_verb, array( 'GET', 'DELETE' ), true ) ) {
|
||||
$url = add_query_arg( $data, $url );
|
||||
} else {
|
||||
$args['body'] = wp_json_encode( $data );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the request arguments for all requests generated by this class.
|
||||
*
|
||||
* @param array $args
|
||||
*/
|
||||
$args = apply_filters( 'powerkit_mailchimp_http_args', $args, $url );
|
||||
|
||||
// Perform request.
|
||||
$response = wp_remote_request( $url, $args );
|
||||
|
||||
// Instagram response.
|
||||
if ( ! is_wp_error( $response ) ) {
|
||||
$response = wp_remote_retrieve_body( $response );
|
||||
|
||||
$response = json_decode( $response, true );
|
||||
} else {
|
||||
powerkit_alert_warning( esc_html__( 'This client has not been approved to access this resource.', 'powerkit' ) );
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Opt In Form block template
|
||||
*
|
||||
* @var $attributes - block attributes
|
||||
* @var $options - layout options
|
||||
*
|
||||
* @link https://codesupply.co
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @package PowerKit
|
||||
* @subpackage PowerKit/templates
|
||||
*/
|
||||
|
||||
if ( ! $attributes['listId'] ) {
|
||||
$attributes['listId'] = 'default';
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'privacy' => powerkit_mailchimp_get_privacy_text(),
|
||||
'type' => 'block',
|
||||
'title' => '',
|
||||
'text' => '',
|
||||
'bg_image_id' => 0,
|
||||
'list_id' => $attributes['listId'],
|
||||
'display_name' => $attributes['showName'],
|
||||
);
|
||||
|
||||
echo '<div class="' . esc_attr( $attributes['className'] ) . '" ' . ( isset( $attributes['anchor'] ) ? ' id="' . esc_attr( $attributes['anchor'] ) . '"' : '' ) . '>';
|
||||
|
||||
// Subscription output.
|
||||
do_action( 'powerkit_subscribe_template', $params );
|
||||
|
||||
echo '</div>';
|
||||
+218
@@ -0,0 +1,218 @@
|
||||
<?php
|
||||
/**
|
||||
* The public-facing functionality of the module.
|
||||
*
|
||||
* @link https://codesupply.co
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @package Powerkit
|
||||
* @subpackage Modules/public
|
||||
*/
|
||||
|
||||
/**
|
||||
* The public-facing functionality of the module.
|
||||
*/
|
||||
class Powerkit_Opt_In_Forms_Public extends Powerkit_Module_Public {
|
||||
|
||||
/**
|
||||
* Initialize
|
||||
*/
|
||||
public function initialize() {
|
||||
add_filter( 'powerkit_pinit_exclude_selectors', array( $this, 'pinit_disable' ) );
|
||||
add_action( 'powerkit_subscribe_template', array( $this, 'register_subscription_form' ) );
|
||||
add_action( 'wp_ajax_powerkit_subscription', array( $this, 'subscription' ) );
|
||||
add_action( 'wp_ajax_nopriv_powerkit_subscription', array( $this, 'subscription' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* PinIt disable
|
||||
*
|
||||
* @param string $selectors List selectors.
|
||||
*/
|
||||
public function pinit_disable( $selectors ) {
|
||||
$selectors[] = '.pk-subscribe-image';
|
||||
|
||||
return $selectors;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Form Template
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @param array $params The params of form.
|
||||
*/
|
||||
public function register_subscription_form( $params = array() ) {
|
||||
$token = get_option( 'powerkit_mailchimp_token' );
|
||||
|
||||
$class = sprintf( 'pk-subscribe-form-%s', $params['type'] );
|
||||
|
||||
$class .= $params['bg_image_id'] ? ' pk-subscribe-with-bg' : '';
|
||||
$class .= $params['display_name'] ? ' pk-subscribe-with-name' : '';
|
||||
|
||||
if ( $token ) {
|
||||
|
||||
if ( ! $params['list_id'] || 'default' === $params['list_id'] ) {
|
||||
$params['list_id'] = get_option( 'powerkit_mailchimp_list' );
|
||||
}
|
||||
|
||||
if ( $params['list_id'] ) {
|
||||
?>
|
||||
<div class="pk-subscribe-form-wrap <?php echo esc_attr( $class ); ?>">
|
||||
<?php if ( $params['bg_image_id'] ) { ?>
|
||||
<div class="pk-subscribe-bg">
|
||||
<?php
|
||||
echo wp_get_attachment_image( $params['bg_image_id'], apply_filters( 'powerkit_subscribe_image_size', 'large' ), false,
|
||||
array( 'class' => 'pk-subscribe-image' )
|
||||
);
|
||||
?>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<div class="pk-subscribe-container <?php echo esc_attr( $params['bg_image_id'] ? ' pk-bg-overlay' : '' ); ?>">
|
||||
<div class="pk-subscribe-data">
|
||||
<?php
|
||||
if ( $params['title'] ) {
|
||||
echo wp_kses( $params['title'], 'pk-title' ); // XSS.
|
||||
}
|
||||
?>
|
||||
|
||||
<?php if ( $params['text'] ) { ?>
|
||||
<p class="pk-subscribe-message <?php echo 'block' !== $params['type'] ? 'pk-font-heading' : ''; ?>"><?php echo esc_html( $params['text'] ); ?></p>
|
||||
<?php } ?>
|
||||
|
||||
<form method="post" class="subscription">
|
||||
|
||||
<input type="hidden" name="list_id" value="<?php echo esc_attr( $params['list_id'] ); ?>">
|
||||
|
||||
<div class="pk-input-group">
|
||||
<?php if ( $params['display_name'] ) { ?>
|
||||
<input type="text" name="USER" class="user form-control" placeholder="<?php echo esc_attr( apply_filters( 'powerkit_subscribe_placeholder_name', esc_html__( 'Enter your name', 'powerkit' ) ) ); ?>">
|
||||
<?php } ?>
|
||||
|
||||
<input type="text" name="EMAIL" class="email form-control" placeholder="<?php echo esc_attr( apply_filters( 'powerkit_subscribe_placeholder_email', esc_html__( 'Enter your email', 'powerkit' ) ) ); ?>">
|
||||
|
||||
<button class="pk-subscribe-submit" type="submit"><?php echo wp_kses( apply_filters( 'powerkit_subscribe_submit', esc_html__( 'Subscribe', 'powerkit' ) ), 'post' ); ?></button>
|
||||
</div>
|
||||
|
||||
<?php wp_referer_field(); ?>
|
||||
</form>
|
||||
|
||||
<?php if ( $params['privacy'] ) { ?>
|
||||
<div class="pk-privacy pk-color-secondary">
|
||||
<label><input name="pk-privacy" type="checkbox"><?php echo wp_kses( $params['privacy'], 'post' ); ?></label>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
} else {
|
||||
/* translators: MailChimp Settings. */
|
||||
powerkit_alert_warning( sprintf( __( 'Please select the "List" for your subscription form in <object><a href="%s" target="_blank">Opt-In Forms Settings</a></object>.', 'powerkit' ), esc_url( powerkit_get_page_url( 'opt_in_forms' ) ) ) );
|
||||
}
|
||||
} else {
|
||||
/* translators: MailChimp Settings. */
|
||||
powerkit_alert_warning( sprintf( __( 'Please add your MailChimp Token in <object><a href="%s" target="_blank">Opt-In Forms Settings</a></object>.', 'powerkit' ), esc_url( powerkit_get_page_url( 'opt_in_forms' ) ) ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscription.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function subscription() {
|
||||
powerkit_uuid_hash();
|
||||
|
||||
// Check wpnonce.
|
||||
if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'] ) ) { // Input var ok; sanitization ok.
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset( $_REQUEST['list_id'] ) ) { // Input var ok.
|
||||
$list_id = sanitize_text_field( wp_unslash( $_REQUEST['list_id'] ) ); // Input var ok.
|
||||
}
|
||||
|
||||
if ( isset( $_REQUEST['USER'] ) ) { // Input var ok.
|
||||
$user = sanitize_text_field( wp_unslash( $_REQUEST['USER'] ) ); // Input var ok.
|
||||
}
|
||||
|
||||
if ( isset( $_REQUEST['EMAIL'] ) ) { // Input var ok.
|
||||
$email = sanitize_email( wp_unslash( $_REQUEST['EMAIL'] ) ); // Input var ok.
|
||||
}
|
||||
|
||||
if ( ! isset( $list_id ) || ! $list_id ) {
|
||||
wp_send_json_error( esc_html__( 'Something is wrong with your list ID.', 'powerkit' ) );
|
||||
}
|
||||
|
||||
if ( ! isset( $email ) || ! $email || ! filter_var( $email, FILTER_VALIDATE_EMAIL ) ) {
|
||||
wp_send_json_error( esc_html__( 'Email is invalid.', 'powerkit' ) );
|
||||
}
|
||||
|
||||
$token = get_option( 'powerkit_mailchimp_token' );
|
||||
|
||||
if ( $token ) {
|
||||
|
||||
if ( get_option( 'powerkit_mailchimp_double_optin', false ) ) {
|
||||
$status = 'pending';
|
||||
} else {
|
||||
$status = 'subscribed';
|
||||
}
|
||||
|
||||
// Request parameters.
|
||||
$args = array(
|
||||
'email_address' => $email,
|
||||
'status' => $status,
|
||||
);
|
||||
|
||||
// If display first name field.
|
||||
if ( isset( $user ) ) {
|
||||
$args['merge_fields'] = array(
|
||||
'FNAME' => $user,
|
||||
);
|
||||
}
|
||||
|
||||
$result = powerkit_mailchimp_request( 'POST', "lists/$list_id/members", $args );
|
||||
|
||||
if ( isset( $result['status'] ) && 'subscribed' === $result['status'] ) {
|
||||
|
||||
wp_send_json_success( esc_html__( 'You have successfully subscribed.', 'powerkit' ) );
|
||||
|
||||
} elseif ( isset( $result['status'] ) && 'pending' === $result['status'] ) {
|
||||
|
||||
wp_send_json_success( esc_html__( 'You have successfully subscribed. Confirm the subscription in your mailbox.', 'powerkit' ) );
|
||||
|
||||
} elseif ( isset( $result['title'] ) && 'Member Exists' === $result['title'] ) {
|
||||
|
||||
wp_send_json_error( esc_html__( 'You are already subscribed.', 'powerkit' ) );
|
||||
|
||||
} else {
|
||||
|
||||
if ( isset( $result['status'] ) && isset( $result['detail'] ) && 400 <= $result['status'] ) {
|
||||
$result = $result['detail'];
|
||||
}
|
||||
|
||||
wp_send_json_error( $result );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the stylesheets for the public-facing side of the site.
|
||||
*/
|
||||
public function wp_enqueue_scripts() {
|
||||
// Styles.
|
||||
wp_enqueue_style( 'powerkit-opt-in-forms', powerkit_style( plugin_dir_url( __FILE__ ) . 'css/public-powerkit-opt-in-forms.css' ), array(), powerkit_get_setting( 'version' ), 'all' );
|
||||
|
||||
// Add RTL support.
|
||||
wp_style_add_data( 'powerkit-opt-in-forms', 'rtl', 'replace' );
|
||||
|
||||
// Scripts.
|
||||
wp_enqueue_script( 'powerkit-opt-in-forms', plugin_dir_url( __FILE__ ) . 'js/public-powerkit-opt-in-forms.js', array( 'jquery' ), powerkit_get_setting( 'version' ), true );
|
||||
|
||||
wp_localize_script( 'powerkit-opt-in-forms', 'opt_in', array(
|
||||
'ajax_url' => admin_url( 'admin-ajax.php' ),
|
||||
'warning_privacy' => esc_html__( 'Please confirm that you agree with our policies.', 'powerkit' ),
|
||||
) );
|
||||
}
|
||||
}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
/**
|
||||
* The Gutenberg Block.
|
||||
*
|
||||
* @link https://codesupply.co
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @package Powerkit
|
||||
* @subpackage Modules/public
|
||||
*/
|
||||
|
||||
/**
|
||||
* The initialize block.
|
||||
*/
|
||||
class Powerkit_Subscription_Block {
|
||||
|
||||
/**
|
||||
* Initialize
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'init', array( $this, 'block' ) );
|
||||
add_filter( 'canvas_register_block_type', array( $this, 'register_block_type' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue the block's assets for the editor.
|
||||
*/
|
||||
public function block() {
|
||||
// Styles.
|
||||
wp_register_style(
|
||||
'powerkit-subscription-block-editor-style',
|
||||
plugins_url( 'css/public-powerkit-opt-in-forms.css', __FILE__ ),
|
||||
array( 'wp-edit-blocks' ),
|
||||
filemtime( plugin_dir_path( __FILE__ ) . 'css/public-powerkit-opt-in-forms.css' )
|
||||
);
|
||||
|
||||
wp_style_add_data( 'powerkit-subscription-block-editor-style', 'rtl', 'replace' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register block
|
||||
*
|
||||
* @param array $blocks all registered blocks.
|
||||
* @return array
|
||||
*/
|
||||
public function register_block_type( $blocks ) {
|
||||
$blocks[] = array(
|
||||
'name' => 'canvas/opt-in-form',
|
||||
'title' => esc_html__( 'Opt-In Form', 'powerkit' ),
|
||||
'description' => '',
|
||||
'category' => 'canvas',
|
||||
'keywords' => array( 'form', 'subscription', 'mailchimp' ),
|
||||
'icon' => '
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
|
||||
<path d="M19 15V19H5V15H19ZM20 13H4C3.45 13 3 13.45 3 14V20C3 20.55 3.45 21 4 21H20C20.55 21 21 20.55 21 20V14C21 13.45 20.55 13 20 13ZM7 18.5C6.18 18.5 5.5 17.83 5.5 17C5.5 16.17 6.18 15.5 7 15.5C7.82 15.5 8.5 16.17 8.5 17C8.5 17.83 7.83 18.5 7 18.5ZM19 5V9H5V5H19ZM20 3H4C3.45 3 3 3.45 3 4V10C3 10.55 3.45 11 4 11H20C20.55 11 21 10.55 21 10V4C21 3.45 20.55 3 20 3ZM7 8.5C6.18 8.5 5.5 7.83 5.5 7C5.5 6.17 6.18 5.5 7 5.5C7.82 5.5 8.5 6.18 8.5 7C8.5 7.82 7.83 8.5 7 8.5Z" />
|
||||
</svg>
|
||||
',
|
||||
'supports' => array(
|
||||
'className' => true,
|
||||
'anchor' => true,
|
||||
'html' => false,
|
||||
'canvasSpacings' => true,
|
||||
'canvasBorder' => true,
|
||||
'canvasResponsive' => true,
|
||||
),
|
||||
'styles' => array(),
|
||||
'location' => array(),
|
||||
|
||||
'sections' => array(
|
||||
'general' => array(
|
||||
'title' => esc_html__( 'Block Settings', 'powerkit' ),
|
||||
'priority' => 5,
|
||||
'open' => true,
|
||||
),
|
||||
),
|
||||
'layouts' => array(),
|
||||
'fields' => array(
|
||||
array(
|
||||
'key' => 'listId',
|
||||
'label' => esc_html__( 'List ID', 'powerkit' ),
|
||||
'help' => '
|
||||
<em>' . esc_html__( 'If empty, List ID from Settings → Opt-In Forms will be used.', 'powerkit' ) . '</em>
|
||||
<ol>
|
||||
<li>' . esc_html__( 'Log in to your', 'powerkit' ) . ' <a href="https://mailchimp.com" target="_blank">' . esc_html__( 'MailChimp account', 'powerkit' ) . '</a></li>
|
||||
<li>' . esc_html__( 'Go to your Lists.', 'powerkit' ) . '</li>
|
||||
<li>' . esc_html__( 'Select the desired list and in the drop-down menu and go to Settings.', 'powerkit' ) . '</li>
|
||||
<li>' . esc_html__( 'Copy your list ID from the field “Unique ID for list …”.', 'powerkit' ) . '</li>
|
||||
</ol>
|
||||
',
|
||||
'section' => 'general',
|
||||
'type' => 'text',
|
||||
'default' => '',
|
||||
),
|
||||
array(
|
||||
'key' => 'showName',
|
||||
'label' => esc_html__( 'Display First Name Field', 'powerkit' ),
|
||||
'help' => esc_html__( 'Make sure you map the field in the MailChimp settings', 'powerkit' ),
|
||||
'section' => 'general',
|
||||
'type' => 'toggle',
|
||||
'default' => false,
|
||||
),
|
||||
|
||||
array(
|
||||
'key' => 'colorLegend',
|
||||
'label' => esc_html__( 'Color Legend', 'powerkit' ),
|
||||
'section' => 'general',
|
||||
'type' => 'color',
|
||||
'output' => array(
|
||||
array(
|
||||
'element' => '$ .pk-subscribe-form-wrap .pk-privacy label',
|
||||
'property' => 'color',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'template' => dirname( __FILE__ ) . '/block/render.php',
|
||||
|
||||
// enqueue registered scripts/styles.
|
||||
'editor_style' => 'powerkit-subscription-block-editor-style',
|
||||
);
|
||||
|
||||
return $blocks;
|
||||
}
|
||||
}
|
||||
|
||||
new Powerkit_Subscription_Block();
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
/**
|
||||
* Shortcode Subscription Form
|
||||
*
|
||||
* @link https://codesupply.co
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @package Powerkit
|
||||
* @subpackage Powerkit/shortcodes
|
||||
*/
|
||||
|
||||
/**
|
||||
* Subscription Form Shortcode
|
||||
*
|
||||
* @param array $atts User defined attributes in shortcode tag.
|
||||
* @param string $content Shorcode tag content.
|
||||
* @return string Shortcode result HTML.
|
||||
*/
|
||||
function powerkit_subscription_shortcode( $atts, $content = '' ) {
|
||||
|
||||
$params = powerkit_shortcode_atts( shortcode_atts( array(
|
||||
'privacy' => powerkit_mailchimp_get_privacy_text(),
|
||||
'title' => '',
|
||||
'text' => '',
|
||||
'bg_image_id' => '',
|
||||
'list_id' => 'default',
|
||||
'type' => 'block',
|
||||
'display_name' => false,
|
||||
), $atts ) );
|
||||
|
||||
ob_start();
|
||||
|
||||
$tag = apply_filters( 'powerkit_subscription_title_tag', 'h3' );
|
||||
|
||||
if ( $params['title'] ) {
|
||||
$params['title'] = sprintf( '<%1$s class="pk-title">%2$s</%1$s>', $tag, $params['title'] );
|
||||
}
|
||||
|
||||
do_action( 'powerkit_subscribe_template', $params );
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
add_shortcode( 'powerkit_subscription_form', 'powerkit_subscription_shortcode' );
|
||||
|
||||
/**
|
||||
* Map Facebook Page Shortcode into the Basic Shortcodes Plugin
|
||||
*/
|
||||
if ( function_exists( 'powerkit_basic_shortcodes_register' ) ) {
|
||||
|
||||
$shortcode_map = array(
|
||||
'name' => 'subscription_form',
|
||||
'title' => esc_html__( 'Subscription Form', 'powerkit' ),
|
||||
'priority' => 160,
|
||||
'base' => 'powerkit_subscription_form',
|
||||
'autoregister' => false,
|
||||
'fields' => array(
|
||||
array(
|
||||
'type' => 'input',
|
||||
'name' => 'title',
|
||||
'label' => esc_html__( 'Title', 'powerkit' ),
|
||||
),
|
||||
array(
|
||||
'type' => 'input',
|
||||
'name' => 'bg_image_id',
|
||||
'label' => esc_html__( 'Background image ID', 'powerkit' ),
|
||||
),
|
||||
array(
|
||||
'type' => 'input',
|
||||
'name' => 'text',
|
||||
'label' => esc_html__( 'Message', 'powerkit' ),
|
||||
),
|
||||
array(
|
||||
'type' => 'input',
|
||||
'name' => 'list_id',
|
||||
'label' => esc_html__( 'List ID', 'powerkit' ),
|
||||
'desc' => '1. ' . esc_html__( 'Log in to your', 'powerkit' ) . ' ' . sprintf( '<a href="%1$s" target="_blank">%2$s</a>', esc_url( 'https://mailchimp.com' ), esc_html__( 'MailChimp account', 'powerkit' ) )
|
||||
. '<br>2. ' . esc_html__( 'Go to your Lists.', 'powerkit' )
|
||||
. '<br>3. ' . esc_html__( 'Select the desired list and in the drop-down menu and go to Settings.', 'powerkit' )
|
||||
. '<br>4. ' . esc_html__( 'Copy your list ID from the field “Unique ID for list …”.', 'powerkit' ),
|
||||
),
|
||||
array(
|
||||
'type' => 'checkbox',
|
||||
'name' => 'display_name',
|
||||
'label' => esc_html__( 'Display first name field', 'powerkit' ),
|
||||
'desc' => esc_html__( 'Make sure you map the field in the MailChimp settings', 'powerkit' ),
|
||||
'default' => false,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
powerkit_basic_shortcodes_register( $shortcode_map );
|
||||
}
|
||||
+246
@@ -0,0 +1,246 @@
|
||||
<?php
|
||||
/**
|
||||
* Widget Subscription Form
|
||||
*
|
||||
* @link https://codesupply.co
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @package Powerkit
|
||||
* @subpackage Powerkit/widgets
|
||||
*/
|
||||
|
||||
/**
|
||||
* Widget Subscription Form
|
||||
*/
|
||||
class Powerkit_Subscription_Form_Widget extends WP_Widget {
|
||||
|
||||
/**
|
||||
* Sets up a new widget instance.
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
$this->default_settings = apply_filters( 'powerkit_opt_in_subscription_widget_settings', array(
|
||||
'title' => esc_html__( 'Subscription Form', 'powerkit' ),
|
||||
'privacy' => powerkit_mailchimp_get_privacy_text(),
|
||||
'text' => '',
|
||||
'bg_image_id' => false,
|
||||
'list_id' => null,
|
||||
'type' => 'widget',
|
||||
'display_name' => false,
|
||||
) );
|
||||
|
||||
$widget_details = array(
|
||||
'classname' => 'powerkit_opt_in_subscription_widget',
|
||||
'description' => esc_html__( 'Add a subscription form to your sidebar.', 'powerkit' ),
|
||||
);
|
||||
|
||||
// Actions.
|
||||
add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
|
||||
|
||||
parent::__construct( 'powerkit_opt_in_subscription_widget', esc_html__( 'Subscription Form', 'powerkit' ), $widget_details );
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the content for the current widget instance.
|
||||
*
|
||||
* @param array $args Display arguments including 'before_title', 'after_title',
|
||||
* 'before_widget', and 'after_widget'.
|
||||
* @param array $instance Settings for the current widget instance.
|
||||
*/
|
||||
public function widget( $args, $instance ) {
|
||||
|
||||
$params = array_merge( $this->default_settings, $instance );
|
||||
|
||||
// Before Widget.
|
||||
echo $args['before_widget']; // XSS.
|
||||
|
||||
if ( $params['title'] ) {
|
||||
$params['title'] = $args['before_title'] . apply_filters( 'widget_title', $params['title'], $instance, $this->id_base ) . $args['after_title'];
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="widget-body">
|
||||
<?php do_action( 'powerkit_subscribe_template', $params ); ?>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
// After Widget.
|
||||
echo $args['after_widget']; // XSS.
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles updating settings for the current widget instance.
|
||||
*
|
||||
* @param array $new_instance New settings for this instance as input by the user via
|
||||
* WP_Widget::form().
|
||||
* @param array $old_instance Old settings for this instance.
|
||||
* @return array Settings to save or bool false to cancel saving.
|
||||
*/
|
||||
public function update( $new_instance, $old_instance ) {
|
||||
$instance = $new_instance;
|
||||
|
||||
// Display first name field.
|
||||
if ( ! isset( $instance['display_name'] ) ) {
|
||||
$instance['display_name'] = false;
|
||||
}
|
||||
|
||||
return $instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the widget settings form.
|
||||
*
|
||||
* @param array $instance Current settings.
|
||||
*/
|
||||
public function form( $instance ) {
|
||||
$params = array_merge( $this->default_settings, $instance );
|
||||
|
||||
$bg_image_url = $params['bg_image_id'] ? wp_get_attachment_image_url( intval( $params['bg_image_id'] ), 'large' ) : '';
|
||||
?>
|
||||
<!-- Title -->
|
||||
<p><label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'powerkit' ); ?></label>
|
||||
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $params['title'] ); ?>" /></p>
|
||||
|
||||
<!-- Background Image container -->
|
||||
<div class="subscription-upload-image upload-img-container" data-frame-title="<?php esc_html_e( 'Select or upload background image', 'powerkit' ); ?>" data-frame-btn-text="<?php esc_html_e( 'Set background image', 'powerkit' ); ?>">
|
||||
<p class="uploaded-img-box">
|
||||
<label for="<?php echo esc_attr( $this->get_field_id( 'bg_image_id' ) ); ?>"><?php esc_html_e( 'Background image:', 'powerkit' ); ?></label>
|
||||
|
||||
<span class="uploaded-image">
|
||||
<?php if ( $bg_image_url ) : ?>
|
||||
<img src="<?php echo esc_url( $bg_image_url ); ?>" style="display: block; margin-top: 5px; max-width:100%;" />
|
||||
<?php endif; ?>
|
||||
</span>
|
||||
|
||||
<input id="<?php echo esc_attr( $this->get_field_id( 'bg_image_id' ) ); ?>" class="uploaded-img-id" name="<?php echo esc_attr( $this->get_field_name( 'bg_image_id' ) ); ?>" type="hidden" value="<?php echo esc_attr( $params['bg_image_id'] ); ?>" />
|
||||
</p>
|
||||
|
||||
<!-- Add & remove image links -->
|
||||
<p class="hide-if-no-js">
|
||||
<a class="upload-img-link button button-primary <?php echo esc_attr( $bg_image_url ? 'hidden' : '' ); ?>" href="#"><?php esc_html_e( 'Add Image', 'powerkit' ); ?></a>
|
||||
<a class="delete-img-link button button-secondary <?php echo esc_attr( ! $bg_image_url ? 'hidden' : '' ); ?>" href="#"><?php esc_html_e( 'Remove Image', 'powerkit' ); ?></a>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- Subscribe Message -->
|
||||
<p><label for="<?php echo esc_attr( $this->get_field_id( 'text' ) ); ?>"><?php esc_html_e( 'Subscribe message:', 'powerkit' ); ?></label>
|
||||
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'text' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'text' ) ); ?>" type="text" value="<?php echo esc_attr( $params['text'] ); ?>" /></p>
|
||||
|
||||
<!-- List -->
|
||||
<?php
|
||||
$token = get_option( 'powerkit_mailchimp_token' );
|
||||
|
||||
if ( $token ) {
|
||||
|
||||
$data = powerkit_mailchimp_request( 'GET', 'lists', array(
|
||||
'sort_field' => 'date_created',
|
||||
'sort_dir' => 'DESC',
|
||||
'count' => 1000,
|
||||
) );
|
||||
|
||||
if ( is_array( $data ) && isset( $data['lists'] ) && $data['lists'] ) {
|
||||
?>
|
||||
|
||||
<p><label for="<?php echo esc_attr( $this->get_field_id( 'list_id' ) ); ?>"><?php esc_html_e( 'List:', 'powerkit' ); ?></label>
|
||||
<select class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'list_id' ) ); ?>" id="<?php echo esc_attr( $this->get_field_name( 'list_id' ) ); ?>">
|
||||
<option value="default"><?php esc_html_e( 'Default', 'powerkit' ); ?></option>
|
||||
<?php foreach ( $data['lists'] as $item ) : ?>
|
||||
<option <?php selected( $item['id'], $params['list_id'] ); ?> value="<?php echo esc_attr( $item['id'] ); ?>"><?php echo esc_html( $item['name'] ); ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</p>
|
||||
<?php
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<!-- Display first name field -->
|
||||
<p><input id="<?php echo esc_attr( $this->get_field_id( 'display_name' ) ); ?>" class="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'display_name' ) ); ?>" type="checkbox" <?php checked( (bool) $params['display_name'] ); ?> />
|
||||
<label for="<?php echo esc_attr( $this->get_field_id( 'display_name' ) ); ?>"><?php esc_html_e( 'Display first name field', 'powerkit' ); ?></label>
|
||||
<span class="howto">(<?php esc_html_e( 'Make sure you map the field in the MailChimp settings', 'powerkit' ); ?>)</span></p>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin Enqunue Scripts
|
||||
*
|
||||
* @param string $page Current page.
|
||||
*/
|
||||
public function admin_enqueue_scripts( $page ) {
|
||||
if ( 'widgets.php' === $page ) {
|
||||
wp_enqueue_script( 'jquery' );
|
||||
|
||||
wp_enqueue_media();
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<script>
|
||||
jQuery( document ).ready(function( $ ) {
|
||||
|
||||
var powerkitMediaFrame;
|
||||
/* Set all variables to be used in scope */
|
||||
var metaBox = '.subscription-upload-image';
|
||||
|
||||
/* Add Image Link */
|
||||
$( metaBox ).find( '.upload-img-link' ).on( 'click', function( event ){
|
||||
event.preventDefault();
|
||||
|
||||
var parentContainer = $( this ).parents( metaBox );
|
||||
|
||||
// Options.
|
||||
var options = {
|
||||
title: parentContainer.data( 'frame-title' ) ? parentContainer.data( 'frame-title' ) : 'Select or Upload Media',
|
||||
button: {
|
||||
text: parentContainer.data( 'frame-btn-text' ) ? parentContainer.data( 'frame-btn-text' ) : 'Use this media',
|
||||
},
|
||||
library : { type : 'image' },
|
||||
multiple: false // Set to true to allow multiple files to be selected.
|
||||
};
|
||||
|
||||
// Create a new media frame
|
||||
powerkitMediaFrame = wp.media( options );
|
||||
|
||||
// When an image is selected in the media frame...
|
||||
powerkitMediaFrame.on( 'select', function() {
|
||||
|
||||
// Get media attachment details from the frame state.
|
||||
var attachment = powerkitMediaFrame.state().get('selection').first().toJSON();
|
||||
|
||||
// Send the attachment URL to our custom image input field.
|
||||
parentContainer.find( '.uploaded-image' ).html( '<img src="' + attachment.url + '" style="display: block; margin-top: 5px; max-width:100%;"/>' );
|
||||
parentContainer.find( '.uploaded-img-id' ).val( attachment.id ).change();
|
||||
parentContainer.find( '.upload-img-link' ).addClass( 'hidden' );
|
||||
parentContainer.find( '.delete-img-link' ).removeClass( 'hidden' );
|
||||
|
||||
powerkitMediaFrame.close();
|
||||
});
|
||||
|
||||
// Finally, open the modal on click.
|
||||
powerkitMediaFrame.open();
|
||||
});
|
||||
|
||||
|
||||
/* Delete Image Link */
|
||||
$( metaBox ).find( '.delete-img-link' ).on( 'click', function( event ){
|
||||
event.preventDefault();
|
||||
|
||||
$( this ).parents( metaBox ).find( '.uploaded-image' ).html( '' );
|
||||
$( this ).parents( metaBox ).find( '.upload-img-link' ).removeClass( 'hidden' );
|
||||
$( this ).parents( metaBox ).find( '.delete-img-link' ).addClass( 'hidden' );
|
||||
$( this ).parents( metaBox ).find( '.uploaded-img-id' ).val( '' ).change();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
wp_add_inline_script( 'jquery', str_replace( array( '<script>', '</script>' ), '', ob_get_clean() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register Widget
|
||||
*/
|
||||
function powerkit_widget_init_subscription_form() {
|
||||
register_widget( 'Powerkit_Subscription_Form_Widget' );
|
||||
}
|
||||
add_action( 'widgets_init', 'powerkit_widget_init_subscription_form' );
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
/**
|
||||
* All of the CSS for your public-facing functionality should be
|
||||
* included in this file.
|
||||
*/
|
||||
/**
|
||||
* Environment for all styles (variables, additions, etc).
|
||||
*/
|
||||
/*--------------------------------------------------------------*/
|
||||
/*--------------------------------------------------------------*/
|
||||
.pk-subscribe-form-wrap {
|
||||
--pk-subscribe-with-bg-color: #FFFFFF;
|
||||
--pk-subscribe-with-bg-elements-color: #FFFFFF;
|
||||
--pk-subscribe-heading-font-size: 1.25rem;
|
||||
--pk-subscribe-privacy-font-size: 80%;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
.pk-subscribe-form-wrap {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.pk-subscribe-form-wrap .pk-subscribe-bg {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.pk-subscribe-form-wrap .pk-subscribe-bg img {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
-o-object-fit: cover;
|
||||
object-fit: cover;
|
||||
font-family: 'object-fit: cover;';
|
||||
}
|
||||
|
||||
.pk-subscribe-form-wrap .pk-input-group {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.pk-subscribe-form-wrap .pk-alert {
|
||||
margin: 1rem 0 0;
|
||||
}
|
||||
|
||||
.pk-subscribe-form-wrap .pk-font-heading {
|
||||
font-size: var(--pk-subscribe-heading-font-size);
|
||||
}
|
||||
|
||||
.pk-subscribe-form-wrap .pk-privacy {
|
||||
margin: 1rem 0 0;
|
||||
font-size: var(--pk-subscribe-privacy-font-size);
|
||||
}
|
||||
|
||||
.pk-subscribe-form-wrap .pk-privacy label {
|
||||
margin-bottom: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.pk-subscribe-form-wrap .pk-privacy input[type="checkbox"] {
|
||||
margin-left: 0.5rem;
|
||||
}
|
||||
|
||||
.pk-subscribe-form-wrap .pk-subscribe-message a,
|
||||
.pk-subscribe-form-wrap .pk-privacy a {
|
||||
border: none;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.pk-subscribe-form-wrap .pk-subscribe-message a:hover,
|
||||
.pk-subscribe-form-wrap .pk-privacy a:hover {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.pk-subscribe-with-name .pk-input-group {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.pk-subscribe-with-name .pk-input-group input,
|
||||
.pk-subscribe-with-name .pk-input-group button {
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.pk-subscribe-with-name .pk-input-group input:first-child,
|
||||
.pk-subscribe-with-name .pk-input-group button:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.pk-subscribe-with-name .pk-input-group input[type="text"] {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.pk-subscribe-with-bg {
|
||||
color: var(--pk-subscribe-with-bg-color);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.pk-subscribe-with-bg .pk-subscribe-container {
|
||||
position: relative;
|
||||
padding: 2rem;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.pk-subscribe-with-bg .pk-input-group input,
|
||||
.pk-subscribe-with-bg .pk-input-group button {
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.pk-subscribe-with-bg .pk-input-group input:first-child,
|
||||
.pk-subscribe-with-bg .pk-input-group button:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.pk-subscribe-with-bg .section-heading {
|
||||
color: var(--pk-subscribe-with-bg-elements-color);
|
||||
}
|
||||
|
||||
.pk-subscribe-with-bg .pk-title,
|
||||
.pk-subscribe-with-bg .pk-subscribe-message,
|
||||
.pk-subscribe-with-bg .pk-subscribe-message a,
|
||||
.pk-subscribe-with-bg .pk-privacy,
|
||||
.pk-subscribe-with-bg .pk-privacy a {
|
||||
color: var(--pk-subscribe-with-bg-elements-color);
|
||||
}
|
||||
|
||||
.pk-subscribe-with-bg .subscription {
|
||||
box-shadow: none !important;
|
||||
}
|
||||
|
||||
.pk-subscribe-form-widget .pk-bg-overlay {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.pk-subscribe-form-widget .pk-bg-overlay .pk-input-group {
|
||||
background: transparent;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.pk-subscribe-form-widget .pk-bg-overlay .pk-input-group button {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
/**
|
||||
* All of the CSS for your public-facing functionality should be
|
||||
* included in this file.
|
||||
*/
|
||||
/**
|
||||
* Environment for all styles (variables, additions, etc).
|
||||
*/
|
||||
/*--------------------------------------------------------------*/
|
||||
/*--------------------------------------------------------------*/
|
||||
.pk-subscribe-form-wrap {
|
||||
--pk-subscribe-with-bg-color: #FFFFFF;
|
||||
--pk-subscribe-with-bg-elements-color: #FFFFFF;
|
||||
--pk-subscribe-heading-font-size: 1.25rem;
|
||||
--pk-subscribe-privacy-font-size: 80%;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------*/
|
||||
.pk-subscribe-form-wrap {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.pk-subscribe-form-wrap .pk-subscribe-bg {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.pk-subscribe-form-wrap .pk-subscribe-bg img {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
-o-object-fit: cover;
|
||||
object-fit: cover;
|
||||
font-family: 'object-fit: cover;';
|
||||
}
|
||||
|
||||
.pk-subscribe-form-wrap .pk-input-group {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.pk-subscribe-form-wrap .pk-alert {
|
||||
margin: 1rem 0 0;
|
||||
}
|
||||
|
||||
.pk-subscribe-form-wrap .pk-font-heading {
|
||||
font-size: var(--pk-subscribe-heading-font-size);
|
||||
}
|
||||
|
||||
.pk-subscribe-form-wrap .pk-privacy {
|
||||
margin: 1rem 0 0;
|
||||
font-size: var(--pk-subscribe-privacy-font-size);
|
||||
}
|
||||
|
||||
.pk-subscribe-form-wrap .pk-privacy label {
|
||||
margin-bottom: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.pk-subscribe-form-wrap .pk-privacy input[type="checkbox"] {
|
||||
margin-right: 0.5rem;
|
||||
}
|
||||
|
||||
.pk-subscribe-form-wrap .pk-subscribe-message a,
|
||||
.pk-subscribe-form-wrap .pk-privacy a {
|
||||
border: none;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.pk-subscribe-form-wrap .pk-subscribe-message a:hover,
|
||||
.pk-subscribe-form-wrap .pk-privacy a:hover {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.pk-subscribe-with-name .pk-input-group {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.pk-subscribe-with-name .pk-input-group input,
|
||||
.pk-subscribe-with-name .pk-input-group button {
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.pk-subscribe-with-name .pk-input-group input:first-child,
|
||||
.pk-subscribe-with-name .pk-input-group button:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.pk-subscribe-with-name .pk-input-group input[type="text"] {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.pk-subscribe-with-bg {
|
||||
color: var(--pk-subscribe-with-bg-color);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.pk-subscribe-with-bg .pk-subscribe-container {
|
||||
position: relative;
|
||||
padding: 2rem;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.pk-subscribe-with-bg .pk-input-group input,
|
||||
.pk-subscribe-with-bg .pk-input-group button {
|
||||
margin-top: 0.5rem;
|
||||
}
|
||||
|
||||
.pk-subscribe-with-bg .pk-input-group input:first-child,
|
||||
.pk-subscribe-with-bg .pk-input-group button:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.pk-subscribe-with-bg .section-heading {
|
||||
color: var(--pk-subscribe-with-bg-elements-color);
|
||||
}
|
||||
|
||||
.pk-subscribe-with-bg .pk-title,
|
||||
.pk-subscribe-with-bg .pk-subscribe-message,
|
||||
.pk-subscribe-with-bg .pk-subscribe-message a,
|
||||
.pk-subscribe-with-bg .pk-privacy,
|
||||
.pk-subscribe-with-bg .pk-privacy a {
|
||||
color: var(--pk-subscribe-with-bg-elements-color);
|
||||
}
|
||||
|
||||
.pk-subscribe-with-bg .subscription {
|
||||
box-shadow: none !important;
|
||||
}
|
||||
|
||||
.pk-subscribe-form-widget .pk-bg-overlay {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.pk-subscribe-form-widget .pk-bg-overlay .pk-input-group {
|
||||
background: transparent;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.pk-subscribe-form-widget .pk-bg-overlay .pk-input-group button {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
"use strict";
|
||||
|
||||
( function( $ ) {
|
||||
|
||||
/*
|
||||
* AJAX subscription
|
||||
*/
|
||||
$( document ).on( 'submit', '.pk-subscribe-form-wrap form', function( e ) {
|
||||
|
||||
var form = $( this );
|
||||
|
||||
// Remove messages.
|
||||
$( form ).closest('.pk-subscribe-form-wrap').find( '.pk-alert' ).remove();
|
||||
|
||||
// Policies.
|
||||
var privacy = $( form ).closest( '.pk-subscribe-form-wrap' ).find( 'input[name="pk-privacy"]' );
|
||||
|
||||
if ( $( privacy ).length > 0 && ! $( privacy ).prop( 'checked' ) ) {
|
||||
$( privacy ).parent().after( '<p class="pk-alert pk-alert-warning">' + window.opt_in.warning_privacy + '</p>' );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( !$( form ).hasClass( 'pk-loading' ) ) {
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: window.opt_in.ajax_url + '?action=powerkit_subscription',
|
||||
data: $( form ).serialize(),
|
||||
beforeSend: function() {
|
||||
$( form ).addClass( 'pk-loading' );
|
||||
},
|
||||
success: function( data ) {
|
||||
$( form ).removeClass( 'pk-loading' );
|
||||
|
||||
if ( data.success ) {
|
||||
$( form ).after( '<p class="pk-alert pk-alert-success">' + data.data + '</p>' );
|
||||
} else {
|
||||
$( form ).after( '<p class="pk-alert pk-alert-warning">' + data.data + '</p>' );
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
$( form ).after( '<p class="pk-alert pk-alert-warning">Error server!</p>' );
|
||||
|
||||
$( form ).removeClass( 'pk-loading' );
|
||||
}
|
||||
} );
|
||||
|
||||
}
|
||||
return false;
|
||||
} );
|
||||
|
||||
} )( jQuery );
|
||||
Reference in New Issue
Block a user