4785 | | function wp_quickpress_form( $args = array(), $post_type = 'post'){ |
4786 | | global $post_ID; |
| 4784 | function wp_quickpress_form( $args = array() ) { |
| 4785 | $defaults = array( |
| 4786 | 'form_id' => '', |
| 4787 | 'action' => admin_url( 'post.php' ), |
| 4788 | 'post' => null, // Post object, ID, or null. |
| 4789 | 'post_type' => null, // Post type. Optional. Overridden if 'post' parameter is specified. |
| 4790 | 'fields' => null, // Array of fields. |
| 4791 | 'submit_fields' => null, // Array of submit, hidden, and publishing inputs. |
| 4792 | 'tabindex' => false, // @todo Can we just kill tabindex? |
| 4793 | 'capability' => 'edit_posts', |
| 4794 | 'submit_class' => 'submit', |
| 4795 | 'publish_action_container' => 'span', |
| 4796 | 'publish_action_id' => 'publishing-action', |
| 4797 | 'submit_fields_container' => 'p', |
| 4798 | 'submit_fields_container_class' => 'submit', |
| 4799 | ); |
4788 | | $fields = array( |
| 4801 | $args = wp_parse_args( $args, $defaults ); |
| 4802 | |
| 4803 | // @todo Kill the cap check and arg. Stick to pure presentation only. |
| 4804 | // We can still handle them on a field-by-field basis. |
| 4805 | if ( ! current_user_can( $args['capability'] ) ) { |
| 4806 | do_action( 'quickpress_form_no_form', $args ); |
| 4807 | return; |
| 4808 | } |
| 4809 | |
| 4810 | if ( empty( $args['post'] ) ) { |
| 4811 | if ( null === $args['post_type'] ) |
| 4812 | $args['post_type'] = 'post'; |
| 4813 | $args['post'] = 0; |
| 4814 | } else { |
| 4815 | $post = get_post( $args['post'] ); |
| 4816 | $args['post_type'] = $post->post_type; |
| 4817 | } |
| 4818 | |
| 4819 | $post_type_obj = get_post_type_object( $args['post_type'] ); |
| 4820 | |
| 4821 | // @todo Clean these up still. Arrays? |
| 4822 | $default_fields = array( |
4822 | | $hidden_fields = array( |
4823 | | 'action' => '<input type="hidden" name="action" id="quickpost-action" value="'.$post_type.'-quickpress-save" />', |
4824 | | 'post_id' => '<input type="hidden" name="quickpress_post_ID" value="'. $post_ID .'" />', |
4825 | | 'post_type' => '<input type="hidden" name="post_type" value="'.$post_type.'" />', |
4826 | | ); |
| 4855 | if ( null === $args['fields'] ) { |
| 4856 | $fields = $default_fields; |
| 4857 | } else { |
| 4858 | $fields = array(); |
| 4859 | foreach ( $args['fields'] as $key => $value ) { |
| 4860 | if ( true === $value ) // i.e. tags => true |
| 4861 | $fields[] = $default_fields[ $key ]; |
| 4862 | elseif ( is_string( $value ) ) // i.e. array( 'tags' ) |
| 4863 | $fields[] = $default_fields[ $value ]; |
| 4864 | else |
| 4865 | $fields[] = $value; |
| 4866 | } |
| 4867 | } |
| 4868 | // Sync this so filters are given correct information. |
| 4869 | $args['fields'] = $fields; |
4828 | | $submit_fields = array( |
4829 | | 'save' => '<input type="submit" name="save" id="save-post" class="button" tabindex="%s" value="'. esc_attr('Save Draft') .'" />', |
4830 | | 'reset' => '<input type="reset" tabindex="%s" value="'. esc_attr( 'Reset' ).'" class="button" />', |
| 4871 | $publishing_action = current_user_can( $post_type_obj->cap->publish_posts ) ? __( 'Publish' ) : __( 'Submit for Review' ); |
| 4872 | |
| 4873 | // These are keyed by input name. |
| 4874 | // Accepted keys: type, value, id (defaults to none). |
| 4875 | // These are also accepted for non-hidden inputs: |
| 4876 | // primary (defaults to false), class (defaults to 'button', except for the primary button, when it is 'button-primary'), |
| 4877 | // tabindex (defaults to true), accesskey (defaults to none). |
| 4878 | $default_submit_fields = array( |
| 4879 | 'action' => array( 'type' => 'hidden', 'id' => 'quickpost-action', 'value' => $post_type . '-quickpress-save' ), |
| 4880 | 'quickpress_post_ID' => array( 'type' => 'hidden', 'value' => $post_ID ), |
| 4881 | 'post_type' => array( 'type' => 'hidden', 'value' => $post_type ), |
| 4882 | 'save' => array( 'type' => 'submit', 'value' => __( 'Save Draft' ) ), |
| 4883 | 'reset' => array( 'type' => 'reset', 'value' => __( 'Reset' ) ), |
| 4884 | 'submit' => array( 'type' => 'submit', 'primary' => true, 'accesskey' => 'p', 'value' => $publishing_action ), |
4833 | | $publishing_action = current_user_can('publish_posts') ? esc_attr('Publish') : esc_attr('Submit for Review'); |
| 4887 | if ( null === $args['submit_fields'] ) { |
| 4888 | $submit_fields = $default_submit_fields; |
| 4889 | } else { |
| 4890 | $submit_fields = array(); |
| 4891 | foreach ( $args['submit_fields'] as $key => $value ) { |
| 4892 | // @todo If this is going to work like this, then the hidden/submit fields need to be split back up. |
| 4893 | if ( true === $value ) // i.e. tags => true |
| 4894 | $submit_fields[] = $default_submit_fields[ $key ]; |
| 4895 | elseif ( is_string( $value ) ) // i.e. array( 'tags' ) |
| 4896 | $submit_fields[] = $default_submit_fields[ $value ]; |
| 4897 | else |
| 4898 | $submit_fields[] = $value; |
| 4899 | } |
| 4900 | } |
4835 | | $publishing_fields = array( |
4836 | | 'submit' => '<input type="submit" name="publish" id="publish" accesskey="p" tabindex="%s" class="button-primary" value="' . $publishing_action . '" />', |
4837 | | /*'test' => '<input type="submit" name="publish" id="publish" accesskey="p" tabindex="%n" class="button-primary" value="'. esc_attr('Publish') .'" />', */ |
| 4902 | $primary_fields = array(); |
| 4903 | foreach ( $submit_fields as $key => $f ) { |
| 4904 | if ( ! isset( $f['type'] ) || ! isset( $f['value'] ) ) |
| 4905 | continue; |
| 4906 | $f['name'] = $key; |
| 4907 | if ( ! isset( $f['id'] ) ) |
| 4908 | $f['id'] = false; |
4841 | | $defaults = array( |
4842 | | 'action' => admin_url( 'post.php' ), |
4843 | | 'fields' => $fields, |
4844 | | 'form_id' => '', |
4845 | | 'default_cap' => 'edit_posts', |
4846 | | 'tabindex_start' => '1', |
4847 | | 'ajax' => true, |
4848 | | 'hidden_fields' => $hidden_fields, |
4849 | | 'submit_fields' => $submit_fields, |
4850 | | 'publishing_fields' => $publishing_fields, |
4851 | | 'submit_class' => 'submit', |
4852 | | 'publish_action_container' => 'span', |
4853 | | 'publish_action_id' => 'publishing-action', |
4854 | | 'hidden_and_submit_fields_container' => 'p', |
4855 | | 'hidden_and_submit_fields_container_class' => 'submit', |
4856 | | ); |
| 4919 | // Sync this so filters are given correct information. |
| 4920 | $args['submit_fields'] = $submit_fields; |
| 4921 | // Then we can separate the primary fields. |
| 4922 | foreach ( $submit_fields as $key => $f ) { |
| 4923 | if ( $f['primary'] ) { |
| 4924 | $primary_fields[] = $f; |
| 4925 | unset( $submit_fields[ $key ] ); |
| 4926 | } |
| 4927 | } |
4867 | | $fields = apply_filters( 'quickpress_fields', $args['fields'], $args['form_id'] ); |
4868 | | foreach ($fields as $title => $field){ |
4869 | | if ( empty( $field['capability'] ) || current_user_can( $field['capability'] ) ){ |
4870 | | printf( $field['output'], $args['form_id'], $args['form_id'], $tabindex ); |
4871 | | $tabindex++; |
4872 | | } |
4873 | | } |
4874 | | //Hidden Fields |
4875 | | do_action('quickpress_form_after_fields', $args['form_id'] ); |
| 4936 | do_action( 'quickpress_before_fields', $args ); |
4887 | | // submit |
4888 | | foreach( $args['submit_fields'] as $submit_field ) |
4889 | | printf( $submit_field, $tabindex++ ); |
| 4951 | foreach ( array( $args['submit_fields'], $args['primary_fields'] ) as $fields ) { |
| 4952 | foreach( $fields as $f ) { |
| 4953 | $f['tabindex'] = $tabindex && ! empty( $f['tabindex'] ) ? ' tabindex="' . $tabindex++ . '"' : ''; |
| 4954 | $f['class'] = ! empty( $f['class'] ) ? ' class="' . $f['class'] . '"' : ''; |
| 4955 | $f['id'] = ! empty( $f['id'] ) ? ' id="' . $f['id'] . '"' : ''; |
| 4956 | $f['accesskey'] = ! empty( $f['accesskey'] ) ? ' accesskey="' . $f['accesskey'] . '"' : ''; |
4908 | | echo "</{$args['hidden_and_submit_fields_container']}"; |
4909 | | do_action( 'quickpress_form_after_form_content', $args['form_id']); |
4910 | | echo '</form>'; |
4911 | | do_action('quickpress_form_after_form', $args['form_id'] ); |
4912 | | else: |
4913 | | do_action( 'quickpress_form_no_form', $args['form_id'] ); |
4914 | | endif; |
| 4976 | echo "</{$args['publish_action_container']}>"; |
| 4977 | |
| 4978 | echo "<br class='clear' />"; |
| 4979 | |
| 4980 | do_action( 'quickpress_after_submit_fields', $args ); |
| 4981 | |
| 4982 | echo "</{$args['submit_fields_container']}"; |
| 4983 | |
| 4984 | do_action( 'quickpress_after_form_content', $args ); |
| 4985 | |
| 4986 | echo '</form>'; |
| 4987 | |
| 4988 | do_action( 'quickpress_after_form', $args ); |