admin-addons.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. /**
  3. * Custom CSS and JS
  4. *
  5. */
  6. if ( ! defined( 'ABSPATH' ) ) {
  7. exit; // Exit if accessed directly
  8. }
  9. /**
  10. * CustomCSSandJS_Addons
  11. */
  12. class CustomCSSandJS_Addons {
  13. /**
  14. * Constructor
  15. */
  16. public function __construct() {
  17. // Add actions
  18. $actions = array(
  19. 'add_meta_boxes' => 'add_meta_boxes',
  20. 'edit_form_advanced' => 'only_premium',
  21. );
  22. foreach( $actions as $_key => $_value ) {
  23. add_action( $_key, array( $this, $_value ) );
  24. }
  25. }
  26. function only_premium() {
  27. $current_screen = get_current_screen();
  28. if ( $current_screen->post_type != 'custom-css-js' ) {
  29. return false;
  30. }
  31. ?>
  32. <div class="ccj_only_premium ccj_only_premium-first">
  33. <div>
  34. <a href="https://www.silkypress.com/simple-custom-css-js-pro/?utm_source=wordpress&utm_campaign=ccj_free&utm_medium=banner" target="_blank"><?php _e('Available only in <br />Simple Custom CSS and JS Pro', 'custom-css-js'); ?></a>
  35. </div>
  36. </div>
  37. <?php
  38. }
  39. /**
  40. * Add the URL Preview meta box
  41. */
  42. function add_meta_boxes() {
  43. add_meta_box( 'previewdiv', __('Preview', 'custom-css-js'), array( $this, 'previews_meta_box_callback' ), 'custom-css-js', 'normal' );
  44. add_meta_box( 'url-rules', __('Apply only on these URLs', 'custom-css-js'), array( $this, 'url_rules_meta_box_callback' ), 'custom-css-js', 'normal' );
  45. add_meta_box( 'revisionsdiv', __('Code Revisions', 'custom-css-js'), array( $this, 'revisions_meta_box_callback' ), 'custom-css-js', 'normal' );
  46. }
  47. /**
  48. * The Preview meta box content
  49. */
  50. function previews_meta_box_callback( $post ) {
  51. ?>
  52. <div id="preview-action">
  53. <div>
  54. <input type="text" name="preview_url" id="ccj-preview_url" placeholder="<?php _e('Full URL on which to preview the changes ...', 'custom-css-js'); ?>" disabled="disabled" />
  55. <a class="preview button button-primary button-large" id="ccj-preview"><?php _e('Preview Changes', 'custom-css-js'); ?></a>
  56. </div>
  57. </div>
  58. <?php
  59. }
  60. /**
  61. * Show the URL Rules metabox
  62. */
  63. function url_rules_meta_box_callback( $post ) {
  64. $filters = array(
  65. 'all' => __('All Website', 'custom-css-js'),
  66. 'first-page' => __('Homepage', 'custom-css-js'),
  67. 'contains' => __('Contains', 'custom-css-js'),
  68. 'not-contains' => __('Not contains', 'custom-css-js'),
  69. 'equal-to' => __('Is equal to', 'custom-css-js'),
  70. 'not-equal-to' => __('Not equal to', 'custom-css-js'),
  71. 'begins-with' => __('Starts with', 'custom-css-js'),
  72. 'ends-by' => __('Ends by', 'custom-css-js'),
  73. );
  74. $filters_html = '';
  75. foreach( $filters as $_key => $_value ) {
  76. $filters_html .= '<option value="'.$_key.'">' . $_value . '</option>';
  77. }
  78. $applied_filters = '[{"value":"","type":"all","index":1}]';
  79. ?>
  80. <input type="hidden" name="scan_anchor_filters" id="wplnst-scan-anchor-filters" value='<?php echo $applied_filters; ?>' />
  81. <table id="wplnst-elist-anchor-filters" class="wplnst-elist" cellspacing="0" cellpadding="0" border="0" data-editable="true" data-label="<?php _e('URL', 'custom-css-js'); ?>"></table>
  82. <?php _e('URL', 'custom-css-js'); ?> <select id="wplnst-af-new-type"><?php echo $filters_html ?></select>&nbsp;
  83. <input id="wplnst-af-new" type="text" class="regular-text" value="" placeholder="<?php _e('Text filter', 'custom-css-js'); ?>" />&nbsp;
  84. <input class="button button-primary" type="button" id="wplnst-af-new-add" value="<?php _e('Add', 'custom-css-js'); ?>" /></td>
  85. <?php
  86. }
  87. /**
  88. * Output the revisions
  89. */
  90. function revisions_meta_box_callback( $post ) {
  91. $datef = _x( 'F j, Y @ H:i:s', 'revision date format' );
  92. $users = get_users(array('number' => 3));
  93. $revisions = array(
  94. array(
  95. 'ID' => 1,
  96. 'post_author' => $users[0]->display_name,
  97. 'title' => date_i18n( $datef, time() - 86400 ),
  98. ),
  99. array(
  100. 'ID' => 2,
  101. 'post_author' => isset($users[1]) ? $users[1]->display_name : $users[0]->display_name,
  102. 'title' => date_i18n( $datef, time() - 87639),
  103. ),
  104. array(
  105. 'ID' => 3,
  106. 'post_author' => isset($users[2]) ? $users[2]->display_name : $users[0]->display_name,
  107. 'title' => date_i18n( $datef, time() - 97639),
  108. ),
  109. );
  110. ?>
  111. <table class="revisions">
  112. <thead><tr>
  113. <th class="revisions-compare"><?php _e('Compare', 'custom-css-js'); ?></th>
  114. <th><?php _e('Revision', 'custom-css-js'); ?></th>
  115. <th><?php _e('Author', 'custom-css-js'); ?></th>
  116. <th><input type="checkbox" name="delete[]" value="all" id="ccj-delete-checkbox" /> <?php _e('Delete', 'custom-css-js'); ?></th>
  117. <th><?php _e('Restore', 'custom-css-js'); ?></th>
  118. </tr></thead>
  119. <tbody>
  120. <?php foreach( $revisions as $revision ) : ?>
  121. <?php
  122. $restore_url = '#';
  123. $delete_disabled = '';
  124. $delete_tooltip = '';
  125. $class = '';
  126. ?>
  127. <tr class="<?php echo $class; ?>" id="<?php echo 'revision-row-' . $revision['ID']; ?>">
  128. <td class="revisions-compare">
  129. <input type="radio" name="compare_left" value="<?php echo $revision['ID']; ?>" />
  130. <input type="radio" name="compare_right" value="<?php echo $revision['ID']; ?>" />
  131. </td>
  132. <td><?php echo $revision['title']; ?></td>
  133. <td><?php echo $revision['post_author']; ?></td>
  134. <td class="revisions-delete">
  135. <input type="checkbox" name="delete[]" value="<?php echo $revision['ID']; ?>" <?php echo $delete_disabled . $delete_tooltip; ?>/>
  136. </td>
  137. <td class="revisions-restore">
  138. <a href="<?php echo $restore_url; ?>"><?php _e('Restore', 'custom-css-js'); ?></a>
  139. </td>
  140. </tr>
  141. <?php endforeach; ?>
  142. <tr>
  143. <td>
  144. <input type="button" class="button-secondary" value="<?php esc_attr_e('Compare', 'custom-css-js'); ?>" id="revisions-compare-button" />
  145. </td>
  146. <td colspan="2" style="text-align: center;"> &uarr; This is only an example, not real data. &uarr; </td>
  147. <td>
  148. <input type="button" class="button-secondary" value="<?php esc_attr_e('Delete', 'custom-css-js'); ?>" id="revisions-delete-button" />
  149. </td>
  150. <td> &nbsp; </td>
  151. </tr>
  152. </tbody>
  153. </table>
  154. <?php
  155. }
  156. }
  157. return new CustomCSSandJS_Addons();