settings_callbacks.php
82 lines
| 1 | <?php |
| 2 | /******************************************************************************* |
| 3 | * File with setting callbacks |
| 4 | *******************************************************************************/ |
| 5 | |
| 6 | /** |
| 7 | * Generates a settings form |
| 8 | * @param void |
| 9 | * @return HTML |
| 10 | **/ |
| 11 | function clarity_admin_settings_page(){ |
| 12 | if (!current_user_can('administrator')) { |
| 13 | return; |
| 14 | }else { |
| 15 | update_option("display_clarity_notice", false); |
| 16 | ?> |
| 17 | <div class="clarity_submenu_page"> |
| 18 | <h1>Clarity Settings</h1> |
| 19 | <form action="options.php" method="post"> |
| 20 | <?php |
| 21 | settings_fields('clarity_settings_fields'); |
| 22 | do_settings_sections('clarity_settings'); |
| 23 | ?> |
| 24 | <?php |
| 25 | submit_button(); |
| 26 | ?> |
| 27 | </form> |
| 28 | </div> |
| 29 | <?php |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Displays settings section |
| 35 | * @param void |
| 36 | * @return HTML |
| 37 | **/ |
| 38 | function clarity_section_project_id_callback(){ |
| 39 | ?> |
| 40 | <div class="clarity_submenu_page_container"> |
| 41 | <p>Before you can start learning how people are using your site, we need to take a few more steps.</p> |
| 42 | <h3>Instructions</h3> |
| 43 | <ol> |
| 44 | <li>If you don't already have a project on Clarity, create a project <a href="https://clarity.microsoft.com/projects?snpf=1">here</a>.</li> |
| 45 | <li>Click on your project, and find the Wordpress installation guide under "Install tracking code on third-party platforms" in setup.</li> |
| 46 | <li>Copy your project id from the Wordpress installation guide.</li> |
| 47 | <li>Paste in the project id in the input box below.</li> |
| 48 | <?php |
| 49 | ?> |
| 50 | </ol> |
| 51 | </div> |
| 52 | <?php |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Generates a settings input for introducing the project ID |
| 57 | * @param void |
| 58 | * @return HTML |
| 59 | **/ |
| 60 | function clarity_settings_field_project_id_callback($args){ |
| 61 | $p_id_option = get_option('clarity_project_id', clarity_project_id_default_value()); |
| 62 | ?> |
| 63 | <input |
| 64 | type="text" |
| 65 | name="clarity_project_id" |
| 66 | value="<?= $p_id_option; ?>" |
| 67 | pattern="[0-9a-z]+" |
| 68 | title="Clarity project id should only contain numbers and letters."> |
| 69 | <?php |
| 70 | |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Generates a settings form |
| 75 | * @param void |
| 76 | * @return HTML |
| 77 | **/ |
| 78 | function clarity_project_id_default_value(){ |
| 79 | $default_value = ''; |
| 80 | return $default_value; |
| 81 | } |
| 82 |