/** * 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; }
/** * @param MC4WP_Form $form * * @return string */ public function column_lists(MC4WP_Form $form) { $list_ids = $form->settings['lists']; if (empty($list_ids)) { $content = '<a href="' . mc4wp_get_edit_form_url($form->ID, 'settings') . '" style="color: red;">' . __('No lists selected.', 'mailchimp-for-wp') . '</a>'; return $content; } $names = array(); foreach ($list_ids as $list_id) { $list = $this->mailchimp->get_list($list_id); if ($list instanceof MC4WP_MailChimp_List) { $names[] = sprintf('<a href="https://admin.mailchimp.com/lists/members/?id=%s" target="_blank">', $list->web_id) . esc_html($list->name) . '</a>'; } } return join('<br />', $names); }
/** * Outputs the text for the "type" column * * @param $item * * @return string|void */ public function column_type($item) { if (isset($this->integrations[$item->type])) { $object_link = $this->integrations[$item->type]->get_object_link($item->related_object_ID); if (!empty($object_link)) { return $object_link; } return $this->integrations[$item->type]->name; } if ($item->type === 'mc4wp-form') { $form_id = $item->related_object_ID; try { $form = mc4wp_get_form($form_id); return '<a href="' . mc4wp_get_edit_form_url($form->ID) . '">' . $form->name . '</a>'; } catch (Exception $e) { return __('Form', 'mailchimp-for-wp') . ' ' . $form_id . ' <em>(' . __('deleted', 'mailchimp-for-wp') . ')</em>'; } } elseif ($item->type === 'mc4wp-top-bar') { return 'MailChimp Top Bar'; } return $item->type; }
/** * Build file with given CSS values * * @param int $form_id * @return bool */ protected function build_stylesheet($form_id) { $css_string = $this->get_css_string($form_id); $filename = sprintf(self::DIR . 'form-%d.css', $form_id); // upload CSS file with CSS string as content $upload = wp_upload_dir(); $target = $upload['basedir']; // try to create stylesheets dir with proper permissions @mkdir($target . rtrim(self::DIR, '/'), 0755); @chmod($target . rtrim(self::DIR, '/'), 0755); // remove previous file @unlink($target . $filename); // create new file $success = file_put_contents($target . $filename, $css_string); @chmod($target . $filename, 0755); if (!$success) { $message = __('Error creating stylesheet.', 'mailchimp-for-wp') . '</strong><br />'; $message .= sprintf(__('Please add the generated CSS to your theme stylesheet manually or use a plugin like <em>%s</em>.', 'mailchimp-for-wp'), '<a href="https://wordpress.org/plugins/simple-custom-css/">Simple Custom CSS</a>') . '<br />'; $message .= '<a class="mc4wp-show-css button" href="javascript:void(0);">' . __('Show generated CSS', 'mailchimp-for-wp') . '</a>'; $message .= '<textarea id="mc4wp_generated_css" readonly style="display:none; width: 100%; min-height: 300px; margin-top: 20px;">' . esc_html($css_string) . '</textarea><strong>'; add_settings_error('mc4wp', 'mc4wp-css', $message); return; } // create url $url = $upload['baseurl'] . $filename; $message = sprintf(__('The <a href="%s">CSS Stylesheet</a> was successfully created.', 'mailchimp-for-wp'), $url); // check if stylesheet is being loaded for this form, otherwise show notice. $form = mc4wp_get_form($form_id); if ($form->settings['css'] !== 'styles-builder') { $message .= '</strong><br /><br />' . sprintf(__('Please note that you need to <a href="%s">select "Use Styles Builder" in the form appearance settings</a> if you want to use these styles.', 'mailchimp-for-wp'), mc4wp_get_edit_form_url($form_id, 'appearance')) . '<strong>'; } // show notice add_settings_error('mc4wp', 'mc4wp-css', $message, 'updated'); return true; }