/**
     * @param array $settings
     * @param WP_Widget $widget
     */
    public function widget_form($settings, WP_Widget $widget)
    {
        $forms = mc4wp_get_forms();
        ?>
		<p>
			<label for="<?php 
        echo $widget->get_field_id('form_id');
        ?>
"><?php 
        _e('Form:', 'mailchimp-for-wp');
        ?>
</label>
			<select class="widefat" name="<?php 
        echo $widget->get_field_name('form_id');
        ?>
" id="<?php 
        echo $widget->get_field_id('form_id');
        ?>
">
				<option value="0" disabled <?php 
        selected($settings['form_id'], 0);
        ?>
><?php 
        _e('Select the form to show', 'mailchimp-for-wp');
        ?>
</option>
				<?php 
        foreach ($forms as $f) {
            ?>
					<option value="<?php 
            echo esc_attr($f->ID);
            ?>
" <?php 
            selected($settings['form_id'], $f->ID);
            ?>
><?php 
            echo esc_html($f->name);
            ?>
</option>
				<?php 
        }
        ?>
			</select>
		</p>

		<?php 
        if (empty($forms)) {
            ?>
			<p class="help"><?php 
            printf(__('You don\'t have any sign-up forms. <a href="%s">Would you like to create one now?</a>', 'mailchimp-for-wp'), mc4wp_get_add_form_url());
            ?>
</p>
		<?php 
        }
    }
Beispiel #2
0
 /**
  * Show Styles Builder page
  */
 function show_page()
 {
     $forms = mc4wp_get_forms();
     $form_id = $forms[0]->ID;
     // get form to which styles should apply
     if (isset($_GET['form_id'])) {
         $form_id = absint($_GET['form_id']);
     }
     $form = mc4wp_get_form($form_id);
     // get css settings for this form (or 0)
     $builder = new MC4WP_Styles_Builder();
     $styles = $builder->get_form_styles($form_id);
     // create preview url
     $preview_url = add_query_arg(array('form_id' => $form_id, '_mc4wp_styles_builder_preview' => 1), home_url());
     require dirname(__FILE__) . '/../views/styles-builder.php';
 }
Beispiel #3
0
 /**
  * Redirect to correct form action
  *
  * @ignore
  */
 public function redirect_to_form_action()
 {
     if (!empty($_GET['view'])) {
         return;
     }
     // query first available form and go there
     $forms = mc4wp_get_forms(array('numberposts' => 1));
     if ($forms) {
         // if we have a post, go to the "edit form" screen
         $form = array_pop($forms);
         $redirect_url = mc4wp_get_edit_form_url($form->ID);
     } else {
         // we don't have a form yet, go to "add new" screen
         $redirect_url = mc4wp_get_add_form_url();
     }
     wp_redirect($redirect_url);
     exit;
 }
 /**
  * Registers UI for when shortcake is activated
  */
 public function register_shortcake_ui()
 {
     $assets = new MC4WP_Form_Asset_Manager();
     $assets->load_stylesheets();
     $forms = mc4wp_get_forms();
     $options = array();
     foreach ($forms as $form) {
         $options[$form->ID] = $form->name;
     }
     /**
      * Register UI for your shortcode
      *
      * @param string $shortcode_tag
      * @param array $ui_args
      */
     shortcode_ui_register_for_shortcode('mc4wp_form', array('label' => esc_html__('MailChimp Sign-Up Form', 'mailchimp-for-wp'), 'listItemImage' => 'dashicons-feedback', 'attrs' => array(array('label' => esc_html__('Select the form to show', 'mailchimp-for-wp'), 'attr' => 'id', 'type' => 'select', 'options' => $options))));
 }
 /**
  * @return array
  */
 public function get_items()
 {
     $args = array();
     if (!empty($_GET['s'])) {
         $args['s'] = sanitize_text_field($_GET['s']);
     }
     if (!empty($_GET['post_status'])) {
         $args['post_status'] = sanitize_text_field($_GET['post_status']);
     }
     $items = mc4wp_get_forms($args);
     return $items;
 }
 /**
  * Bundle all activated stylesheets into a single "bundle.css" file.
  *
  * TODO: Only re-run if something changed
  */
 public static function bundle_stylesheets()
 {
     $upload = wp_upload_dir();
     // find all forms where "css" is set to "styles-builder"
     $forms = mc4wp_get_forms();
     $enabled_forms = array();
     foreach ($forms as $form) {
         if ($form->settings['css'] === 'styles-builder') {
             $enabled_forms[] = $form->ID;
         }
     }
     // bail if none of the forms have Styles Builder styles enabled
     if (empty($enabled_forms)) {
         return;
     }
     // find all stylesheets created by Styles Builder
     $dir = $upload['basedir'] . rtrim(self::DIR, '/') . '/';
     $stylesheets = glob($dir . 'form-{' . join(',', $enabled_forms) . '}.css', GLOB_BRACE);
     // do nothing if no individual stylesheets where found.
     if (empty($stylesheets)) {
         return;
     }
     // get all content
     $contents = array_map('file_get_contents', $stylesheets);
     // join content together
     $contents = join(PHP_EOL . PHP_EOL, $contents);
     // write joined content to bundle file
     $filename = $dir . self::BUNDLE_FILENAME;
     file_put_contents($filename, $contents);
     // store version as option (for cache busting)
     update_option(self::VERSION_OPTION, time(), false);
 }
Beispiel #7
0
 /**
  * @return array
  */
 public function query()
 {
     $datasets = array();
     $lines = array();
     $day_counts = $this->get_total_day_counts();
     // everything
     $datasets['all'] = array('label' => __('Any sign-up method', 'mailchimp-for-wp'), 'data' => array_map(array($this, 'format_graph_data'), $day_counts, array_keys($day_counts)), 'total_count' => array_sum($day_counts));
     $lines['global'] = array(__("General"), 'all');
     // forms
     $forms = mc4wp_get_forms();
     $lines['forms'] = array(__("Sign-Up Forms", 'mailchimp-for-wp'));
     foreach ($forms as $form) {
         $day_counts = $this->get_day_counts_for_form($form->ID);
         $dataset = array('label' => $form->ID . ' | ' . $form->name, 'data' => array_map(array($this, 'format_graph_data'), $day_counts, array_keys($day_counts)), 'total_count' => array_sum($day_counts));
         $datasets["form-" . $form->ID] = $dataset;
         $lines['forms'][] = "form-" . $form->ID;
     }
     // integrations
     $integrations = mc4wp_get_integrations();
     $lines['integrations'] = array(__('Integrations', 'mailchimp-for-wp'));
     foreach ($integrations as $integration) {
         $day_counts = $this->get_day_counts_for_type($integration->slug);
         $dataset = array('label' => $integration->name, 'data' => array_map(array($this, 'format_graph_data'), $day_counts, array_keys($day_counts)), 'total_count' => array_sum($day_counts));
         $datasets["{$integration->slug}"] = $dataset;
         $lines['integrations'][] = $integration->slug;
     }
     $this->lines = $lines;
     $this->datasets = $datasets;
 }