728x90

am developing a plugin and in the admin where I provide a field that is filled in by users with a date. I am wondering if there is a native datepicker in the WP Admin I that is available.

I usually include a small jQuery datepicker script that does it, but if one is already available I would prefer that for obvious reasons like lighter code, UI consistency, etc. This seems like something that would/should be included but I've not been able to find such documentation on what jQuery stuff, if any, are available in the Admin.

    Answer has already been given, but I'd like to extend it a bit to include CSS (Wordpress doesn't provide stylesheets for jQuery UI), to help anyone passing trying to use this kind of scripts.

    Basically (and very simply), you need to have at least these three lines of code:

        wp_enqueue_script('jquery-ui-datepicker');
        wp_register_style('jquery-ui', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css');
        wp_enqueue_style('jquery-ui');

    Explanation line by line:

    1. Load jQuery UI Datepicker (library already registered by Wordpress, nothing else is necessary)
    2. Register Stylesheet with handle jquery-ui (I used the one hosted by Google, you can use whichever you prefer)
    3. Effectively include stylesheet into the ones loaded by Wordpress in this page

    And now your Datepickers will all be nice and colourful! :)

    HTML5 gift

    This is not what the OP was asking for, but it's somewhat related to the question: if you don't want to bother adding the Datepicker, you could try the HTML5 date input type, letting the browser create a very nice (and default) datepicker:

    <input type="date" name="the_date" />

    Yes, nothing else is needed (and it works in the back-end of Wordpress, too: https://jsfiddle.net/2jxdvea0/

    More info on MDN: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date

    Note As @mark pointed out, the input does not work for Firefox (as well as for other browsers). This is noted in the MDN page, but of course it should be mentioned here as well. There are, of course, workarounds to this problem, but it would be beyond the sake of this question to write about them.

    Update 03-11-2017 As of @kosso's comment, Firefox support for this is coming in version 57

      Yes. Wordpress includes this in the core. Here are a couple articles about it:

      WP Codex: Function Reference/wp enqueue script

      Paul Underwood's Iris Color Picker Tutorial (same principles apply to datepicker)

        Add the following line of code to enqueue the jquery ui datepicker library from your plugin:

        wp_enqueue_script('jquery-ui-datepicker');

        You can download the stylesheet file from the jquery ui library site and include it in your plugin. You would then enqueue the CSS file like the following:

        wp_enqueue_style('jquery-ui-css', 'http://www.example.com/your-plugin-path/css/jquery-ui.css');

        Alternatively, You can include the jquery ui CSS from Google (you don’t need to ship the CSS files with your plugin if you go via this route):

        wp_enqueue_style('jquery-ui-css', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css');

        Add the following JQuery code to your javascript file so it attaches the datepicker to any fields with a class of “custom_date”:

        <script type="text/javascript">
        jQuery(document).ready(function($) {
        $('.custom_date').datepicker({
        dateFormat : 'yy-mm-dd'
        });
        });
        </script>

        Now, you can simply add class “custom_date” to the date fields in the HTML code and it will show a date picker calender when a user clicks on that field.

        <input type="text" class="custom_date" name="start_date" value=""/>
        728x90

        I'm using WAMP in my local machine, when a FORM(method="POST") with 2000 input fields is submitted I'm able to read only 1001 _POST variable. i.e With Netbeans debugger I can clearly see _POST size is always 1001 if there are more than 1001 input fields in the form.

        I used this http://ideone.com/GAw14 java code to generate form with N input fields and tested.

        The same is working fine in another machine(WAMP), where I can see all the POST variables.

        Please help me to solve my problem.

          PHP 5.3.9 introduced the max_input_vars config option, which is defaulted to a value of 1000. Check out the Runtime Configuration section of the PHP manual. The default value and the change log are at the top of the page.

          The value can be changed by updating the server's php.ini, adding an .htaccess file, or adding a line to httpd.conf.

            If you are using Suhosin with Hardened PHP, you might be hitting a maximum variables limit that it imposes. In your php.ini, you can just add

            [suhosin]
            suhosin.request.max_vars = 1000
            suhosin.post.max_vars = 1000

            changing 1000 to whatever you want and restart your webserver.

            I ran into this on the Drupal Permissions page when there were a lot of modules installed with a large number of roles, which resulted in a ton of checkboxes. It would only save a certain number of them before anything after would just get ignored.

            It sounds like this is probably not your problem, but since it's fairly likely that someone in the future may stumble upon this when searching for something related I'll go ahead and throw this in since it took me ages to figure out when I was stumped.

              I solved my $_POST max inputs -problem by adding the following to php.ini:

              max_input_vars = 5000
              suhosin.request.max_vars = 5000
              suhosin.post.max_vars = 5000

              Note the suhosin.request.max_vars also.

                I solved this problem. Open the PHP.INI configuration file and add these lines

                [suhosin]

                suhosin.post.max_vars = 20000

                suhosin.request.max_vars = 20000

                I suspect the problem is with the amount of data coming with your POST request. There is no setting which limits the number of $_POST vars that can be set. However there is a memory limit for POST data which is 8MB by default.

                In your php.ini file try modifying the value of post_max_size and set it to a higher value. Don't forget to restart apache after the change is made.

                  protected by Community Jul 12 '15 at 4:28

                  Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count). 

                  Would you like to answer one of these unanswered questions instead?

                  Not the answer you're looking for? Browse other questions tagged    or ask your own question.


                  728x90

                  HTML STYLE CSS 인쇄시 페이지 기본 여백 설정하기.

                  이전 포스트에서 크롬과 익스플로러에서 각각 인쇄 미리보기 페이지가 팝업 되게 하는 자바스크립트 소스를 봤었습니다. 각각 띄워놓고 보니 여백이 달라서 다른 페이지 처럼 보입니다.

                  인쇄가 될때 문서의 기본 여백을 설정해 줘야 겠습니다. 간단 하네요.
                  인쇄하고자 하는 페이지에서 아래와 같이 style 태그를 추가해 줍니다.
                  1<style type="text/css" media="print">  
                  2    @page{  size:auto; margin : 15mm;  }
                  3</style>
                  크롬 인쇄 미리보기에서 여백이 '기본값' 일때 저 값이 적용 되네요.
                  익스플로러에서 여백이 제대로 들어가나 확인해보니 19mm가 되있더군요. 적용이 안되나 싶어서 여백 설정 창에서 확인을 눌러보니 문서 내 여백이 커집니다. 이미 15mm로 적용이 되어 있었던 겁니다.

                  여백값은 margin 값을 변경해 주면 됩니다.

                  꿀같은 출처는 역시 스택오버플로우.
                  http://stackoverflow.com/questions/1960939/disabling-browser-print-options-headers-footers-margins-from-page


                  'WEB' 카테고리의 다른 글

                  unexpected 'use' (T_USE) when trying to use composer  (0) 2018.06.14
                  How to increase maximum POST variable in PHP?  (0) 2018.06.01
                  리눅스 문자셋(charset) 설정  (0) 2018.05.17
                  PHP로 xml과 json 파싱  (0) 2018.05.17
                  PHP Simple HTML DOM Parser  (0) 2018.05.17
                  728x90

                  Almost nothing is more frustrating for a user than searching around for a login link in order to get to important content.

                  The following method found at Vandweerd.com will automatically detect whether a user is logged in or not and put a login or a logout link right on your menu bar.

                  *** Please note, this method only works when you are using WordPress’ custom menus. (The menu function available in the admin section: Appearance > Menus.)

                  Add Code to Your Functions File

                  You will need to add a bit of code to your functions file for this. But after copying and pasting this code, you’re finished.

                  Go to Appearance > Editor > Theme Functions (functions.php). Place the following code in the bottom your functions file and hit “Update File.”

                  add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
                  function add_login_logout_link($items, $args) {
                          ob_start();
                          wp_loginout('index.php');
                          $loginoutlink = ob_get_contents();
                          ob_end_clean();
                          $items .= '<li>'. $loginoutlink .'</li>';
                      return $items;
                  }

                  The Result

                  Keep in mind that these links will appear wherever you put your custom menus – be they at the top of your page, in your sidebar, or anywhere else.

                  Photo: login icon from BigStock

                  + Recent posts