function add_post_fields($post_type, $post_obj = null) { //var_dump($post_type, $post_obj); $attachments = array(); if ($post_obj) { $attachments = auiu_get_attachments($post_obj->ID); } ?> <li> <label><?php echo auiu_get_option('attachment_label', 'auiu_labels', 'Attachments'); ?> </label> <div class="clear"></div> </li> <li> <div id="auiu-attachment-upload-container"> <div id="auiu-attachment-upload-filelist"> <ul class="auiu-attachment-list"> <script>window.auiuFileCount = 0;</script> <?php if ($attachments) { foreach ($attachments as $attach) { echo $this->attach_html($attach['id']); echo '<script>window.auiuFileCount += 1;</script>'; } } ?> </ul> </div> <a id="auiu-attachment-upload-pickfiles" class="button" href="#"><?php echo auiu_get_option('attachment_btn_label', 'auiu_labels', 'Add another'); ?> </a> </div> <div class="clear"></div> </li> <?php }
/** * Block user access to admin panel for specific roles * * @global string $pagenow */ function block_admin_access() { global $pagenow; // bail out if we are from WP Cli if (defined('WP_CLI')) { return; } $access_level = auiu_get_option('admin_access', 'auiu_others', 'read'); $valid_pages = array('admin-ajax.php', 'async-upload.php', 'media-upload.php'); if (!current_user_can($access_level) && !in_array($pagenow, $valid_pages)) { wp_die(__('Access Denied. Your site administrator has blocked your access to the WordPress back-office.', 'auiu')); } }
function auiu_build_custom_field_form($position = 'top', $edit = false, $post_id = 0) { global $wpdb; //check, if custom field is enabled $enabled = auiu_get_option('enable_custom_field', 'auiu_frontend_posting', 'off'); //var_dump( $enabled ); if ($enabled != 'on') { return false; } $table = $wpdb->prefix . 'auiu_customfields'; $results = $wpdb->get_results("SELECT * FROM {$table} WHERE `region`='{$position}' ORDER BY `order`", OBJECT); if (is_array($results)) { foreach ($results as $field) { if (auiu_starts_with($field->field, 'cf_')) { if ($edit && $post_id) { $value = get_post_meta($post_id, $field->field, true); } else { $value = ''; } switch ($field->type) { case 'text': ?> <li> <label for="<?php echo $field->field; ?> "> <?php echo stripslashes($field->label); ?> <?php if ($field->required == 'yes') { ?> <span class="required">*</span> <?php } ?> </label> <?php $class = $field->required == 'yes' ? 'requiredField' : ''; ?> <input class="<?php echo $class; ?> " type="text" name="<?php echo $field->field; ?> " id="<?php echo $field->field; ?> " minlength="2" value="<?php echo stripslashes($value); ?> " <?php if ($field->desc) { ?> placeholder="<?php echo stripslashes($field->desc); ?> " <?php } ?> > <div class="clear"></div> </li> <?php break; case 'textarea': ?> <li> <label for="<?php echo $field->field; ?> "> <?php echo stripslashes($field->label); ?> <?php if ($field->required == 'yes') { ?> <span class="required">*</span> <?php } ?> </label> <?php $class = $field->required == 'yes' ? 'requiredField' : ''; ?> <textarea class="<?php echo $class; ?> " name="<?php echo $field->field; ?> " id="<?php echo $field->field; ?> "><?php echo stripslashes($value); ?> </textarea> <div class="clear"></div> <?php if ($field->desc) { ?> <p class="description"><?php echo stripslashes($field->desc); ?> </p> <div class="clear"></div> <?php } ?> </li> <?php break; case 'select': ?> <li> <label for="<?php echo $field->field; ?> "> <?php echo stripslashes($field->label); ?> <?php if ($field->required == 'yes') { ?> <span class="required">*</span> <?php } ?> </label> <select name="<?php echo $field->field; ?> "> <?php $options = explode(',', $field->values); if (is_array($options)) { foreach ($options as $opt) { $opt = trim(strip_tags($opt)); echo "<option value='{$opt}' " . selected($value, $opt, false) . ">{$opt}</option>"; } } ?> </select> <div class="clear"></div> <?php if ($field->desc) { ?> <p class="description"><?php echo stripslashes($field->desc); ?> </p> <div class="clear"></div> <?php } ?> </li> <?php break; case 'checkbox': ?> <li> <label for="<?php echo $field->field; ?> "> <?php echo stripslashes($field->label); ?> <?php if ($field->required == 'yes') { ?> <span class="required">*</span> <?php } ?> </label> <div class="auiu-check-container"> <input type="hidden" name="<?php echo esc_attr($field->field); ?> " value="" /> <?php $options = explode(',', $field->values); $values = explode(',', $value); if (is_array($options)) { foreach ($options as $opt) { $opt = trim(strip_tags($opt)); ?> <?php $class = $field->required == 'yes' ? 'requiredField' : ''; ?> <input type="checkbox" id="auiu-checkbox" class="<?php echo $class; ?> " <?php echo in_array($opt, $values) ? 'checked="checked"' : ''; ?> name="<?php echo esc_attr($field->field); ?> []" value="<?php echo esc_attr($opt); ?> " /> <span><?php echo $opt; ?> </span> </label> <?php } } ?> </div> <div class="clear"></div> <?php if ($field->desc) { ?> <p class="description"><?php echo stripslashes($field->desc); ?> </p> <div class="clear"></div> <?php } ?> </li> <?php break; default: } //switch } else { switch ($field->type) { case 'text': ?> <li> <label for="<?php echo $field->field; ?> "> <?php echo stripslashes($field->label); ?> <?php if ($field->required == 'yes') { ?> <span class="required">*</span> <?php } ?> </label> <?php $class = $field->required == 'yes' ? 'requiredField' : ''; ?> <input class="<?php echo $class; ?> " type="text" name="<?php echo $field->field; ?> " id="<?php echo $field->field; ?> " minlength="2" value="<?php echo stripslashes($value); ?> "> <div class="clear"></div> <?php if ($field->desc) { ?> <p class="description"><?php echo stripslashes($field->desc); ?> </p> <div class="clear"></div> <?php } ?> </li> <?php break; case 'select': $fld = substr($field->field, 3); $terms = get_terms($fld); //var_dump( $fld ); if ($terms) { foreach ($terms as $t) { $term_option .= '<option value="' . $t->term_id . '">' . $t->name . '</option>'; } } ?> <li> <label for="<?php echo $field->field; ?> "> <?php echo stripslashes($field->label); ?> <?php if ($field->required == 'yes') { ?> <span class="required">*</span> <?php } ?> </label> <select name="<?php echo $field->field; ?> "> <?php echo $term_option; ?> </select> <div class="clear"></div> <?php if ($field->desc) { ?> <p class="description"><?php echo stripslashes($field->desc); ?> </p> <div class="clear"></div> <?php } ?> </li> <?php default: } } } //foreach } // is_array }
/** * Validate the post submit data * * @global type $userdata * @param type $post_type */ function submit_post() { //I moved the initialization of the errors array here so it can catch any captcha problems $errors = array(); $enabled_captcha = auiu_get_option('enable_recaptcha', 'auiu_others', 'no'); if ($enabled_captcha == 'yes') { require_once 'lib/recaptchalib.php'; $response = null; $privatekey = auiu_get_option('captcha_private_key', 'auiu_others'); // check secret key $reCaptcha = new ReCaptcha($privatekey); if ($_POST["g-recaptcha-response"]) { $response = $reCaptcha->verifyResponse($_SERVER["REMOTE_ADDR"], $_POST["g-recaptcha-response"]); } if ($response == null || !$response->success) { $errors[] = __('You did not check the CAPTCHA. Please try again.', 'auiu'); } } global $userdata; //if there is some attachement, validate them if (!empty($_FILES['auiu_post_attachments'])) { $errors = auiu_check_upload(); } $title = trim($_POST['auiu_post_title']); $content = trim($_POST['auiu_post_content']); $tags = ''; if (isset($_POST['auiu_post_tags'])) { $tags = auiu_clean_tags($_POST['auiu_post_tags']); } //validate title if (empty($title)) { $errors[] = __('Empty post title', 'auiu'); } else { $title = trim(strip_tags($title)); } //validate cat if (auiu_get_option('allow_cats', 'auiu_frontend_posting', 'on') == 'on') { $cat_type = auiu_get_option('cat_type', 'auiu_frontend_posting', 'normal'); if (!isset($_POST['category'])) { $errors[] = __('Please choose a category', 'auiu'); } else { if ($cat_type == 'normal' && $_POST['category'][0] == '-1') { $errors[] = __('Please choose a category', 'auiu'); } else { if (count($_POST['category']) < 1) { $errors[] = __('Please choose a category', 'auiu'); } } } } //validate post content if (empty($content)) { $errors[] = __('Empty post content', 'auiu'); } else { $content = trim($content); } //process tags if (!empty($tags)) { $tags = explode(',', $tags); } //post attachment $attach_id = isset($_POST['auiu_featured_img']) ? intval($_POST['auiu_featured_img']) : 0; //post type $post_type = trim(strip_tags($_POST['auiu_post_type'])); //process the custom fields $custom_fields = array(); $fields = auiu_get_custom_fields(); if (is_array($fields)) { foreach ($fields as $cf) { if (array_key_exists($cf['field'], $_POST)) { if (is_array($_POST[$cf['field']])) { $temp = implode(',', $_POST[$cf['field']]); } else { $temp = trim(strip_tags($_POST[$cf['field']])); } //var_dump($temp, $cf); if ($cf['type'] == 'yes' && !$temp) { $errors[] = sprintf(__('"%s" is missing', 'auiu'), $cf['label']); } else { $custom_fields[$cf['field']] = $temp; } } //array_key_exists } //foreach } //is_array $errors = apply_filters('auiu_add_post_validation', $errors); //if not any errors, proceed if ($errors) { echo auiu_error_msg($errors); return; } $post_stat = auiu_get_option('post_status', 'auiu_frontend_posting'); //users are allowed to choose category if (auiu_get_option('allow_cats', 'auiu_frontend_posting', 'on') == 'on') { $post_category = $_POST['category']; } else { $post_category = array(auiu_get_option('default_cat', 'auiu_frontend_posting')); } $my_post = array('post_title' => $title, 'post_content' => $content, 'post_status' => $post_stat, 'post_category' => $post_category, 'post_type' => $post_type, 'tags_input' => $tags); //plugin API to extend the functionality $my_post = apply_filters('auiu_add_post_args', $my_post); //var_dump( $_POST, $my_post );die(); //insert the post $post_id = wp_insert_post($my_post); if ($post_id) { // Set taxonomy $default_taxonomy = get_option('auiu_frontend_posting'); $default_taxonomy = $default_taxonomy['default_taxonomy']; wp_set_post_terms($post_id, $post_category, $default_taxonomy); //upload attachment to the post auiu_upload_attachment($post_id); //send mail notification if (auiu_get_option('post_notification', 'auiu_others', 'yes') == 'yes') { auiu_notify_post_mail($userdata, $post_id); } //add the custom fields if ($custom_fields) { foreach ($custom_fields as $key => $val) { add_post_meta($post_id, $key, $val, true); } } //set post thumbnail if has any if ($attach_id) { set_post_thumbnail($post_id, $attach_id); } //plugin API to extend the functionality do_action('auiu_add_post_after_insert', $post_id); //echo '<div class="success">' . __('Post published successfully', 'auiu') . '</div>'; if ($post_id) { $redirect = apply_filters('auiu_after_post_redirect', get_permalink($post_id), $post_id); wp_redirect($redirect); //wp_redirect( home_url() ); exit; } } }
function auiu_custom_styles() { $button_background = auiu_get_option('button_background', 'auiu_styles'); $button_textcolor = auiu_get_option('button_textcolor', 'auiu_styles'); $button_hoverback = auiu_get_option('button_hoverback', 'auiu_styles'); $button_hovertext = auiu_get_option('button_hovertext', 'auiu_styles'); $button_radius = (int) auiu_get_option('button_radius', 'auiu_styles'); $button_font = auiu_get_option('button_font', 'auiu_styles'); $button_transform = auiu_get_option('button_transform', 'auiu_styles'); $button_size = (int) auiu_get_option('button_size', 'auiu_styles'); $label_size = (int) auiu_get_option('label_size', 'auiu_styles'); $label_weight = auiu_get_option('label_weight', 'auiu_styles'); $label_font = auiu_get_option('label_font', 'auiu_styles'); $description_size = (int) auiu_get_option('description_size', 'auiu_styles'); $description_font = auiu_get_option('description_font', 'auiu_styles'); $dropfile_size = auiu_get_option('dropfile_size', 'auiu_styles'); $dropfile_font = auiu_get_option('dropfile_font', 'auiu_styles'); $category_select_size = (int) auiu_get_option('category_select_size', 'auiu_styles'); $category_select_font = auiu_get_option('category_select_font', 'auiu_styles'); ?> <style type="text/css"> a#auiu-ft-upload-pickfiles, #auiu-ft-upload-filelist .button { background: none repeat scroll 0 0 <?php echo $button_background; ?> ; border: none; color: <?php echo $button_textcolor; ?> ; border-radius: <?php echo $button_radius; ?> px; font-family: <?php echo $button_font; ?> ; text-transform: <?php echo $button_transform; ?> ; font-size: <?php echo $button_size; ?> px; } a#auiu-ft-upload-pickfiles:hover, #auiu-ft-upload-filelist .button:hover { background: none repeat scroll 0 0 <?php echo $button_hoverback; ?> ; border: none; color: <?php echo $button_hovertext; ?> ; } .auiu-post-form input[type="submit"] { background: none repeat scroll 0 0 <?php echo $button_back; ?> ; border: none; color: <?php echo $button_textcolor; ?> ; border-radius: <?php echo $button_radius; ?> px; font-family: <?php echo $button_font; ?> ; text-transform: <?php echo $button_transform; ?> ; font-size: <?php echo $button_size; ?> px; } .auiu-post-form input[type="submit"]:hover { background: none repeat scroll 0 0 <?php echo $button_hover_back; ?> ; border: none; color: <?php echo $button_hovertext; ?> ; } .auiu-post-form label { font-size: <?php echo $label_size; ?> px; font-weight: <?php echo $label_weight; ?> ; font-family: <?php echo $label_font; ?> ; } .auiu-post-form p.description { font-size: <?php echo $description_size; ?> px; font-family: <?php echo $description_font; ?> ; } .auiu-dropfile-text { font-size: <?php echo $dropfile_size; ?> px; font-family: <?php echo $dropfile_font; ?> ; } .auiu-post-form .category-wrap select { font-size: <?php echo $category_select_size; ?> px; font-family: <?php echo $category_select_font; ?> ; } </style> <?php }