Нет описания

Themes.php 38KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242
  1. <?php
  2. /*******************************************************************************
  3. * Copyright (c) 2019, Code Atlantic LLC
  4. ******************************************************************************/
  5. if ( ! defined( 'ABSPATH' ) ) {
  6. exit;
  7. }
  8. /**
  9. * Class PUM_Admin_Themes
  10. */
  11. class PUM_Admin_Themes {
  12. /**
  13. * Hook the initialize method to the WP init action.
  14. */
  15. public static function init() {
  16. /** Regitster Metaboxes */
  17. add_action( 'add_meta_boxes', array( __CLASS__, 'meta_box' ) );
  18. /** Process meta saving. */
  19. add_action( 'save_post', array( __CLASS__, 'save' ), 10, 2 );
  20. }
  21. /**
  22. * Registers popup metaboxes.
  23. */
  24. public static function meta_box() {
  25. /** Settings Box **/
  26. add_meta_box( 'pum_theme_settings', __( 'Theme Settings', 'popup-maker' ), array( __CLASS__, 'render_settings_meta_box' ), 'popup_theme', 'normal', 'high' );
  27. /** Preview Window **/
  28. add_meta_box( 'pum_theme_preview', __( 'Theme Preview', 'popup-maker' ), array( __CLASS__, 'render_preview_meta_box' ), 'popup_theme', 'side', 'high' );
  29. }
  30. /**
  31. * Ensures integrity of values.
  32. *
  33. * @param array $values
  34. *
  35. * @return array
  36. */
  37. public static function parse_values( $values = [] ) {
  38. $defaults = self::defaults();
  39. if ( empty( $values ) ) {
  40. return $defaults;
  41. }
  42. $values = self::fill_missing_defaults( $values );
  43. return $values;
  44. }
  45. /**
  46. * Fills default settings only when missing.
  47. *
  48. * Excludes checkbox type fields where a false value is represented by the field being unset.
  49. *
  50. * @param array $settings
  51. *
  52. * @return array
  53. */
  54. public static function fill_missing_defaults( $settings = [] ) {
  55. $excluded_field_types = [ 'checkbox', 'multicheck' ];
  56. $defaults = self::defaults();
  57. foreach ( $defaults as $field_id => $default_value ) {
  58. $field = PUM_Utils_Fields::get_field( self::fields(), $field_id );
  59. if ( isset( $settings[ $field_id ] ) || in_array( $field['type'], $excluded_field_types ) ) {
  60. continue;
  61. }
  62. $settings[ $field_id ] = $default_value;
  63. }
  64. return $settings;
  65. }
  66. /**
  67. * Parse & prepare values for form rendering.
  68. *
  69. * Add additional data for license_key fields, split the measure fields etc.
  70. *
  71. * @param $settings
  72. *
  73. * @return mixed
  74. */
  75. public static function render_form_values( $settings ) {
  76. foreach ( $settings as $key => $value ) {
  77. $field = PUM_Utils_Fields::get_field( self::fields(), $key );
  78. if ( $field ) {
  79. switch ( $field['type'] ) {
  80. case 'measure':
  81. break;
  82. }
  83. }
  84. }
  85. return $settings;
  86. }
  87. /**
  88. * Render the settings meta box wrapper and JS vars.
  89. */
  90. public static function render_settings_meta_box() {
  91. global $post;
  92. $theme = pum_get_theme( $post->ID );
  93. // Get the meta directly rather than from cached object.
  94. $settings = self::parse_values( $theme->get_settings() );
  95. wp_nonce_field( basename( __FILE__ ), 'pum_theme_settings_nonce' );
  96. wp_enqueue_script( 'popup-maker-admin' );
  97. ?>
  98. <script type="text/javascript">
  99. window.pum_theme_settings_editor = <?php echo PUM_Utils_Array::safe_json_encode( apply_filters( 'pum_theme_settings_editor_var', array(
  100. 'form_args' => array(
  101. 'id' => 'pum-theme-settings',
  102. 'tabs' => self::tabs(),
  103. 'sections' => self::sections(),
  104. 'fields' => self::fields(),
  105. ),
  106. 'current_values' => self::render_form_values( $settings ),
  107. ) ) ); ?>;
  108. </script>
  109. <div id="pum-theme-settings-container" class="pum-theme-settings-container">
  110. <div class="pum-no-js" style="padding: 0 12px;">
  111. <p><?php printf( __( 'If you are seeing this, the page is still loading or there are Javascript errors on this page. %sView troubleshooting guide%s', 'popup-maker' ), '<a href="https://docs.wppopupmaker.com/article/373-checking-for-javascript-errors" target="_blank">', '</a>' ); ?></p>
  112. </div>
  113. </div>
  114. <?php
  115. }
  116. /**
  117. *
  118. */
  119. public static function render_preview_meta_box() {
  120. global $post;
  121. $theme = pum_get_theme( $post->ID );
  122. $deprecated_atb_enabled = class_exists( 'PUM_ATB' ) && ! pum_extension_enabled( 'advanced-theme-builder' );
  123. // Remove this div after PUM ATC updated properly
  124. if ( $deprecated_atb_enabled ) {
  125. echo '<div id="PopMake-Preview">';
  126. }
  127. ?>
  128. <div class="pum-theme-preview">
  129. <div class="pum-popup-overlay <?php echo $deprecated_atb_enabled ? 'example-popup-overlay' : '';?>"></div>
  130. <div class="pum-popup-container <?php echo $deprecated_atb_enabled ? 'example-popup' : '';?>">
  131. <div class="pum-popup-title"><?php _e( 'Title Text', 'popup-maker' ); ?></div>
  132. <div class="pum-popup-content">
  133. <?php echo apply_filters( 'pum_example_popup_content', '<p>Suspendisse ipsum eros, tincidunt sed commodo ut, viverra vitae ipsum. Etiam non porta neque. Pellentesque nulla elit, aliquam in ullamcorper at, bibendum sed eros. Morbi non sapien tellus, ac vestibulum eros. In hac habitasse platea dictumst. Nulla vestibulum, diam vel porttitor placerat, eros tortor ultrices lectus, eget faucibus arcu justo eget massa. Maecenas id tellus vitae justo posuere hendrerit aliquet ut dolor.</p>' ); ?>
  134. </div>
  135. <button type="button" class="pum-popup-close <?php echo $deprecated_atb_enabled ? 'close-popup' : '';?>" aria-label="<?php _e( 'Close', 'popup-maker' ); ?>">
  136. <?php echo $theme->get_setting( 'close_text', '&#215;' ); ?>
  137. </button>
  138. </div>
  139. <p class="pum-desc"><?php
  140. $tips = array(
  141. __( 'If you move this theme preview to the bottom of your sidebar here it will follow you down the page?', 'popup-maker' ),
  142. __( 'Clicking on an element in this theme preview will take you to its relevant settings in the editor?', 'popup-maker' ),
  143. );
  144. $key = array_rand( $tips, 1 ); ?>
  145. <i class="dashicons dashicons-info"></i> <?php echo '<strong>' . __( 'Did you know:', 'popup-maker' ) . '</strong> ' . $tips[ $key ]; ?>
  146. </p>
  147. </div>
  148. <?php
  149. // Remove this div after PUM ATC updated properly
  150. if ( $deprecated_atb_enabled ) {
  151. echo '</div>';
  152. }
  153. }
  154. /**
  155. * Used to get deprecated fields for metabox saving of old extensions.
  156. *
  157. * @deprecated 1.8.0
  158. *
  159. * @return mixed
  160. */
  161. public static function deprecated_meta_fields() {
  162. $fields = array();
  163. foreach ( self::deprecated_meta_field_groups() as $group ) {
  164. foreach ( apply_filters( 'popmake_popup_theme_meta_field_group_' . $group, array() ) as $field ) {
  165. $fields[] = 'popup_theme_' . $group . '_' . $field;
  166. }
  167. }
  168. return apply_filters( 'popmake_popup_theme_meta_fields', $fields );
  169. }
  170. /**
  171. * Used to get field groups from extensions.
  172. *
  173. * @deprecated 1.8.0
  174. *
  175. * @return mixed
  176. */
  177. public static function deprecated_meta_field_groups() {
  178. return apply_filters( 'popmake_popup_theme_meta_field_groups', array( 'display', 'close' ) );
  179. }
  180. /**
  181. * @param $post_id
  182. * @param $post
  183. *
  184. * @return bool
  185. */
  186. public static function can_save( $post_id, $post ) {
  187. if ( isset( $post->post_type ) && 'popup_theme' != $post->post_type ) {
  188. return false;
  189. }
  190. if ( ! isset( $_POST['pum_theme_settings_nonce'] ) || ! wp_verify_nonce( $_POST['pum_theme_settings_nonce'], basename( __FILE__ ) ) ) {
  191. return false;
  192. }
  193. if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
  194. return false;
  195. }
  196. if ( isset( $post->post_type ) && 'revision' == $post->post_type ) {
  197. return false;
  198. }
  199. if ( ! current_user_can( 'edit_post', $post_id ) ) {
  200. return false;
  201. }
  202. return true;
  203. }
  204. /**
  205. * @param $post_id
  206. * @param $post
  207. */
  208. public static function save( $post_id, $post ) {
  209. if ( ! self::can_save( $post_id, $post ) ) {
  210. return;
  211. }
  212. $theme = pum_get_theme( $post_id );
  213. $settings = ! empty( $_POST['theme_settings'] ) ? $_POST['theme_settings'] : array();
  214. $settings = wp_parse_args( $settings, self::defaults() );
  215. $settings = apply_filters( 'pum_theme_setting_pre_save', $settings, $post->ID );
  216. // Sanitize form values.
  217. $settings = PUM_Utils_Fields::sanitize_fields( $settings, self::fields() );
  218. // Ensure data integrity.
  219. $settings = self::parse_values( $settings );
  220. //$theme->update_meta( 'popup_theme_settings', $settings );
  221. $theme->update_settings( $settings );
  222. // If this is a built in theme and the user has modified it set a key so that we know not to make automatic upgrades to it in the future.
  223. if ( get_post_meta( $post_id, '_pum_built_in', true ) !== false ) {
  224. update_post_meta( $post_id, '_pum_user_modified', true );
  225. }
  226. self::process_deprecated_saves( $post_id, $post );
  227. do_action( 'pum_save_theme', $post_id, $post );
  228. }
  229. /**
  230. * @param $post_id
  231. * @param $post
  232. */
  233. public static function process_deprecated_saves( $post_id, $post ) {
  234. $field_prefix = 'popup_theme_';
  235. $old_fields = (array) apply_filters( 'popmake_popup_theme_fields', array(
  236. 'overlay' => array(),
  237. 'container' => array(),
  238. 'title' => array(),
  239. 'content' => array(),
  240. 'close' => array(),
  241. ) );
  242. foreach ( $old_fields as $section => $fields ) {
  243. $section_prefix = "{$field_prefix}{$section}";
  244. $meta_values = array();
  245. foreach ( $fields as $field => $args ) {
  246. $field_name = "{$section_prefix}_{$field}";
  247. if ( isset( $_POST[ $field_name ] ) ) {
  248. $meta_values[ $field ] = apply_filters( 'popmake_metabox_save_' . $field_name, $_POST[ $field_name ] );
  249. }
  250. }
  251. update_post_meta( $post_id, "popup_theme_{$section}", $meta_values );
  252. }
  253. // TODO Remove this and all other code here. This should be clean and all code more compartmentalized.
  254. foreach ( self::deprecated_meta_fields() as $field ) {
  255. if ( isset( $_POST[ $field ] ) ) {
  256. $new = apply_filters( 'popmake_metabox_save_' . $field, $_POST[ $field ] );
  257. update_post_meta( $post_id, $field, $new );
  258. } else {
  259. delete_post_meta( $post_id, $field );
  260. }
  261. }
  262. }
  263. /**
  264. * List of tabs & labels for the settings panel.
  265. *
  266. * @return array
  267. */
  268. public static function tabs() {
  269. return apply_filters( 'pum_theme_settings_tabs', array(
  270. 'general' => __( 'General', 'popup-maker' ),
  271. 'overlay' => __( 'Overlay', 'popup-maker' ),
  272. 'container' => __( 'Container', 'popup-maker' ),
  273. 'title' => __( 'Title', 'popup-maker' ),
  274. 'content' => __( 'Content', 'popup-maker' ),
  275. 'close' => __( 'Close', 'popup-maker' ),
  276. 'advanced' => __( 'Advanced', 'popup-maker' ),
  277. ) );
  278. }
  279. /**
  280. * List of tabs & labels for the settings panel.
  281. *
  282. * @return array
  283. */
  284. public static function sections() {
  285. return apply_filters( 'pum_theme_settings_sections', array(
  286. 'general' => array(
  287. 'main' => __( 'General', 'popup-maker' ),
  288. ),
  289. 'overlay' => array(
  290. 'background' => __( 'Background', 'popup-maker' ),
  291. ),
  292. 'container' => array(
  293. 'main' => __( 'Container', 'popup-maker' ),
  294. 'background' => __( 'Background', 'popup-maker' ),
  295. 'border' => __( 'Border', 'popup-maker' ),
  296. 'boxshadow' => __( 'Drop Shadow', 'popup-maker' ),
  297. ),
  298. 'title' => array(
  299. 'typography' => __( 'Font', 'popup-maker' ),
  300. 'textshadow' => __( 'Text Shadow', 'popup-maker' ),
  301. ),
  302. 'content' => array(
  303. 'typography' => __( 'Text', 'popup-maker' ),
  304. ),
  305. 'close' => array(
  306. 'main' => __( 'General', 'popup-maker' ),
  307. 'size' => __( 'Size', 'popup-maker' ),
  308. 'position' => __( 'Position', 'popup-maker' ),
  309. 'background' => __( 'Background', 'popup-maker' ),
  310. 'border' => __( 'Border', 'popup-maker' ),
  311. 'boxshadow' => __( 'Drop Shadow', 'popup-maker' ),
  312. 'typography' => __( 'Font', 'popup-maker' ),
  313. 'textshadow' => __( 'Text Shadow', 'popup-maker' ),
  314. ),
  315. 'advanced' => array(
  316. 'main' => __( 'Advanced', 'popup-maker' ),
  317. ),
  318. ) );
  319. }
  320. /**
  321. * @return mixed
  322. */
  323. public static function border_style_options() {
  324. return apply_filters( 'pum_theme_border_style_options', array(
  325. 'none' => __( 'None', 'popup-maker' ),
  326. 'solid' => __( 'Solid', 'popup-maker' ),
  327. 'dotted' => __( 'Dotted', 'popup-maker' ),
  328. 'dashed' => __( 'Dashed', 'popup-maker' ),
  329. 'double' => __( 'Double', 'popup-maker' ),
  330. 'groove' => __( 'Groove', 'popup-maker' ),
  331. 'inset' => __( 'Inset (inner shadow)', 'popup-maker' ),
  332. 'outset' => __( 'Outset', 'popup-maker' ),
  333. 'ridge' => __( 'Ridge', 'popup-maker' ),
  334. ) );
  335. }
  336. /**
  337. * @return mixed
  338. */
  339. public static function size_unit_options() {
  340. return apply_filters( 'pum_theme_size_unit_options', array(
  341. 'px' => 'px',
  342. '%' => '%',
  343. 'em' => 'em',
  344. 'rem' => 'rem',
  345. ) );
  346. }
  347. /**
  348. * @return mixed
  349. */
  350. public static function font_family_options() {
  351. $fonts = array(
  352. 'inherit' => __( 'Use Your Themes', 'popup-maker' ),
  353. __( 'System Fonts', 'popup-maker' ) => array(
  354. 'Sans-Serif' => 'Sans-Serif',
  355. 'Tahoma' => 'Tahoma',
  356. 'Georgia' => 'Georgia',
  357. 'Comic Sans MS' => 'Comic Sans MS',
  358. 'Arial' => 'Arial',
  359. 'Lucida Grande' => 'Lucida Grande',
  360. 'Times New Roman' => 'Times New Roman',
  361. ),
  362. );
  363. /** @deprecated 1.8.0 This filter is no longer in use */
  364. $old_fonts = apply_filters( 'popmake_font_family_options', array() );
  365. $fonts = array_merge( $fonts, array_flip( $old_fonts ) );
  366. return apply_filters( 'pum_theme_font_family_options', $fonts );
  367. }
  368. /**
  369. * @return mixed
  370. */
  371. public static function font_weight_options() {
  372. return apply_filters( 'pum_theme_font_weight_options', array(
  373. 100 => 100,
  374. 200 => 200,
  375. 300 => 300,
  376. 400 => __( 'Normal', 'popup-maker' ) . ' (400)',
  377. 500 => 500,
  378. 600 => 600,
  379. 700 => __( 'Bold', 'popup-maker' ) . ' (700)',
  380. 800 => 800,
  381. 900 => 900,
  382. ) );
  383. }
  384. /**
  385. * Returns array of popup settings fields.
  386. *
  387. * @return mixed
  388. */
  389. public static function fields() {
  390. static $fields;
  391. if ( ! isset( $fields ) ) {
  392. $size_unit_options = self::size_unit_options();
  393. $border_style_options = self::border_style_options();
  394. $font_family_options = self::font_family_options();
  395. $font_weight_options = self::font_weight_options();
  396. $fields = apply_filters( 'pum_theme_settings_fields', array(
  397. 'general' => apply_filters( 'pum_theme_general_settings_fields', array(
  398. 'main' => array(),
  399. ) ),
  400. 'overlay' => apply_filters( 'pum_theme_overlay_settings_fields', array(
  401. 'background' => array(
  402. 'overlay_background_color' => array(
  403. 'label' => __( 'Color', 'popup-maker' ),
  404. 'type' => 'color',
  405. 'std' => '#ffffff',
  406. 'priority' => 10,
  407. ),
  408. 'overlay_background_opacity' => array(
  409. 'label' => __( 'Opacity', 'popup-maker' ),
  410. 'type' => 'rangeslider',
  411. 'force_minmax' => true,
  412. 'std' => 100,
  413. 'step' => 1,
  414. 'min' => 0,
  415. 'max' => 100,
  416. 'unit' => '%',
  417. 'priority' => 20,
  418. ),
  419. ),
  420. ) ),
  421. 'container' => apply_filters( 'pum_theme_container_settings_fields', array(
  422. 'main' => array(
  423. 'container_padding' => array(
  424. 'label' => __( 'Padding', 'popup-maker' ),
  425. 'type' => 'rangeslider',
  426. 'std' => 18,
  427. 'priority' => 10,
  428. 'step' => 1,
  429. 'min' => 1,
  430. 'max' => 100,
  431. 'unit' => 'px',
  432. ),
  433. 'container_border_radius' => array(
  434. 'label' => __( 'Border Radius', 'popup-maker' ),
  435. 'type' => 'rangeslider',
  436. 'std' => 0,
  437. 'priority' => 20,
  438. 'step' => 1,
  439. 'min' => 1,
  440. 'max' => 80,
  441. 'unit' => 'px',
  442. ),
  443. ),
  444. 'background' => array(
  445. 'container_background_color' => array(
  446. 'label' => __( 'Color', 'popup-maker' ),
  447. 'type' => 'color',
  448. 'std' => '#f9f9f9',
  449. 'priority' => 10,
  450. ),
  451. 'container_background_opacity' => array(
  452. 'label' => __( 'Opacity', 'popup-maker' ),
  453. 'type' => 'rangeslider',
  454. 'force_minmax' => true,
  455. 'std' => 100,
  456. 'priority' => 20,
  457. 'step' => 1,
  458. 'min' => 0,
  459. 'max' => 100,
  460. 'unit' => '%',
  461. ),
  462. ),
  463. 'border' => array(
  464. 'container_border_style' => array(
  465. 'label' => __( 'Style', 'popup-maker' ),
  466. 'type' => 'select',
  467. 'std' => 'none',
  468. 'priority' => 10,
  469. 'options' => $border_style_options,
  470. ),
  471. 'container_border_color' => array(
  472. 'label' => __( 'Color', 'popup-maker' ),
  473. 'type' => 'color',
  474. 'std' => '#000000',
  475. 'priority' => 20,
  476. 'dependencies' => array(
  477. 'container_border_style' => array_keys( PUM_Utils_Array::remove_keys( $border_style_options, array( 'none' ) ) ),
  478. ),
  479. ),
  480. 'container_border_width' => array(
  481. 'label' => __( 'Thickness', 'popup-maker' ),
  482. 'type' => 'rangeslider',
  483. 'std' => 1,
  484. 'priority' => 30,
  485. 'step' => 1,
  486. 'min' => 1,
  487. 'max' => 5,
  488. 'unit' => 'px',
  489. 'dependencies' => array(
  490. 'container_border_style' => array_keys( PUM_Utils_Array::remove_keys( $border_style_options, array( 'none' ) ) ),
  491. ),
  492. ),
  493. ),
  494. 'boxshadow' => array(
  495. 'container_boxshadow_color' => array(
  496. 'label' => __( 'Color', 'popup-maker' ),
  497. 'type' => 'color',
  498. 'std' => '#020202',
  499. 'priority' => 10,
  500. ),
  501. 'container_boxshadow_opacity' => array(
  502. 'label' => __( 'Opacity', 'popup-maker' ),
  503. 'type' => 'rangeslider',
  504. 'std' => 23,
  505. 'priority' => 20,
  506. 'step' => 1,
  507. 'min' => 0,
  508. 'max' => 100,
  509. 'force_minmax' => true,
  510. 'unit' => '%',
  511. ),
  512. 'container_boxshadow_horizontal' => array(
  513. 'label' => __( 'Horizontal Position', 'popup-maker' ),
  514. 'type' => 'rangeslider',
  515. 'std' => 1,
  516. 'priority' => 30,
  517. 'step' => 1,
  518. 'min' => - 50,
  519. 'max' => 50,
  520. 'unit' => 'px',
  521. ),
  522. 'container_boxshadow_vertical' => array(
  523. 'label' => __( 'Vertical Position', 'popup-maker' ),
  524. 'type' => 'rangeslider',
  525. 'std' => 1,
  526. 'priority' => 40,
  527. 'step' => 1,
  528. 'min' => - 50,
  529. 'max' => 50,
  530. 'unit' => 'px',
  531. ),
  532. 'container_boxshadow_blur' => array(
  533. 'label' => __( 'Blur Radius', 'popup-maker' ),
  534. 'type' => 'rangeslider',
  535. 'std' => 3,
  536. 'priority' => 50,
  537. 'step' => 1,
  538. 'min' => 0,
  539. 'max' => 100,
  540. 'unit' => 'px',
  541. ),
  542. 'container_boxshadow_spread' => array(
  543. 'label' => __( 'Spread', 'popup-maker' ),
  544. 'type' => 'rangeslider',
  545. 'std' => 0,
  546. 'priority' => 60,
  547. 'step' => 1,
  548. 'min' => - 100,
  549. 'max' => 100,
  550. 'unit' => 'px',
  551. ),
  552. 'container_boxshadow_inset' => array(
  553. 'label' => __( 'Inset (inner shadow)', 'popup-maker' ),
  554. 'type' => 'select',
  555. 'std' => 'no',
  556. 'priority' => 70,
  557. 'options' => array(
  558. 'no' => __( 'No', 'popup-maker' ),
  559. 'yes' => __( 'Yes', 'popup-maker' ),
  560. ),
  561. ),
  562. ),
  563. ) ),
  564. 'title' => apply_filters( 'pum_theme_title_settings_fields', array(
  565. 'typography' => array(
  566. 'title_font_color' => array(
  567. 'label' => __( 'Color', 'popup-maker' ),
  568. 'type' => 'color',
  569. 'std' => '#000000',
  570. 'priority' => 10,
  571. ),
  572. 'title_font_size' => array(
  573. 'label' => __( 'Font Size', 'popup-maker' ),
  574. 'type' => 'rangeslider',
  575. 'std' => 32,
  576. 'priority' => 20,
  577. 'step' => 1,
  578. 'min' => 8,
  579. 'max' => 48,
  580. 'unit' => 'px',
  581. ),
  582. 'title_line_height' => array(
  583. 'label' => __( 'Line Height', 'popup-maker' ),
  584. 'type' => 'rangeslider',
  585. 'std' => 36,
  586. 'priority' => 30,
  587. 'step' => 1,
  588. 'min' => 8,
  589. 'max' => 54,
  590. 'unit' => 'px',
  591. ),
  592. 'title_font_family' => array(
  593. 'label' => __( 'Font Family', 'popup-maker' ),
  594. 'type' => 'select',
  595. 'select2' => true,
  596. 'std' => 'inherit',
  597. 'priority' => 40,
  598. 'options' => $font_family_options,
  599. ),
  600. 'title_font_weight' => array(
  601. 'label' => __( 'Font Weight', 'popup-maker' ),
  602. 'type' => 'select',
  603. 'std' => 400,
  604. 'priority' => 50,
  605. 'options' => $font_weight_options,
  606. ),
  607. 'title_font_style' => array(
  608. 'label' => __( 'Style', 'popup-maker' ),
  609. 'type' => 'select',
  610. 'std' => 'normal',
  611. 'priority' => 60,
  612. 'options' => array(
  613. '' => __( 'Normal', 'popup-maker' ),
  614. 'italic' => __( 'Italic', 'popup-maker' ),
  615. ),
  616. ),
  617. 'title_text_align' => array(
  618. 'label' => __( 'Alignment', 'popup-maker' ),
  619. 'type' => 'select',
  620. 'std' => 'left',
  621. 'priority' => 70,
  622. 'options' => array(
  623. 'left' => __( 'Left', 'popup-maker' ),
  624. 'center' => __( 'Center', 'popup-maker' ),
  625. 'right' => __( 'Right', 'popup-maker' ),
  626. 'justify' => __( 'Justify', 'popup-maker' ),
  627. ),
  628. ),
  629. ),
  630. 'textshadow' => array(
  631. 'title_textshadow_color' => array(
  632. 'label' => __( 'Color', 'popup-maker' ),
  633. 'type' => 'color',
  634. 'std' => '#020202',
  635. 'priority' => 10,
  636. ),
  637. 'title_textshadow_opacity' => array(
  638. 'label' => __( 'Opacity', 'popup-maker' ),
  639. 'type' => 'rangeslider',
  640. 'std' => 23,
  641. 'priority' => 20,
  642. 'step' => 1,
  643. 'min' => 0,
  644. 'max' => 100,
  645. 'force_minmax' => true,
  646. 'unit' => '%',
  647. ),
  648. 'title_textshadow_horizontal' => array(
  649. 'label' => __( 'Horizontal Position', 'popup-maker' ),
  650. 'type' => 'rangeslider',
  651. 'std' => 0,
  652. 'priority' => 30,
  653. 'step' => 1,
  654. 'min' => - 50,
  655. 'max' => 50,
  656. 'unit' => 'px',
  657. ),
  658. 'title_textshadow_vertical' => array(
  659. 'label' => __( 'Vertical Position', 'popup-maker' ),
  660. 'type' => 'rangeslider',
  661. 'std' => 0,
  662. 'priority' => 40,
  663. 'step' => 1,
  664. 'min' => - 50,
  665. 'max' => 50,
  666. 'unit' => 'px',
  667. ),
  668. 'title_textshadow_blur' => array(
  669. 'label' => __( 'Blur Radius', 'popup-maker' ),
  670. 'type' => 'rangeslider',
  671. 'std' => 0,
  672. 'priority' => 50,
  673. 'step' => 1,
  674. 'min' => 0,
  675. 'max' => 100,
  676. 'unit' => 'px',
  677. ),
  678. ),
  679. ) ),
  680. 'content' => apply_filters( 'pum_theme_content_settings_fields', array(
  681. 'typography' => array(
  682. 'content_font_color' => array(
  683. 'label' => __( 'Color', 'popup-maker' ),
  684. 'type' => 'color',
  685. 'std' => '#8c8c8c',
  686. 'priority' => 10,
  687. ),
  688. 'content_font_family' => array(
  689. 'label' => __( 'Font Family', 'popup-maker' ),
  690. 'type' => 'select',
  691. 'select2' => true,
  692. 'std' => 'inherit',
  693. 'priority' => 20,
  694. 'options' => $font_family_options,
  695. ),
  696. 'content_font_weight' => array(
  697. 'label' => __( 'Font Weight', 'popup-maker' ),
  698. 'type' => 'select',
  699. 'std' => 400,
  700. 'priority' => 30,
  701. 'options' => $font_weight_options,
  702. ),
  703. 'content_font_style' => array(
  704. 'label' => __( 'Style', 'popup-maker' ),
  705. 'type' => 'select',
  706. 'std' => 'inherit',
  707. 'priority' => 40,
  708. 'options' => array(
  709. '' => __( 'Normal', 'popup-maker' ),
  710. 'italic' => __( 'Italic', 'popup-maker' ),
  711. ),
  712. ),
  713. ),
  714. ) ),
  715. 'close' => apply_filters( 'pum_theme_close_settings_fields', array(
  716. 'main' => array(
  717. 'close_text' => array(
  718. 'label' => __( 'Close Button Text', 'popup-maker' ),
  719. 'desc' => __( 'To use a Font Awesome icon instead of text, enter the CSS classes such as "fas fa-camera".', 'popup-maker' ),
  720. 'placeholder' => __( 'CLOSE', 'popup-maker' ),
  721. 'std' => __( 'CLOSE', 'popup-maker' ),
  722. 'priority' => 10,
  723. ),
  724. 'close_position_outside' => array(
  725. 'label' => __( 'Position Outside Container', 'popup-maker' ),
  726. 'desc' => __( 'This moves the position of the close button outside the popup.', 'popup-maker' ),
  727. 'type' => 'checkbox',
  728. 'priority' => 20,
  729. ),
  730. 'close_location' => array(
  731. 'label' => __( 'Location', 'popup-maker' ),
  732. 'type' => 'select',
  733. 'std' => 'topright',
  734. 'priority' => 30,
  735. 'options' => array(
  736. 'topleft' => __( 'Top Left', 'popup-maker' ),
  737. 'topcenter' => __( 'Top Center', 'popup-maker' ),
  738. 'topright' => __( 'Top Right', 'popup-maker' ),
  739. 'middleleft' => __( 'Middle Left', 'popup-maker' ),
  740. 'middleright' => __( 'Middle Right', 'popup-maker' ),
  741. 'bottomleft' => __( 'Bottom Left', 'popup-maker' ),
  742. 'bottomcenter' => __( 'Bottom Center', 'popup-maker' ),
  743. 'bottomright' => __( 'Bottom Right', 'popup-maker' ),
  744. ),
  745. ),
  746. 'close_position_top' => array(
  747. 'label' => __( 'Top', 'popup-maker' ),
  748. 'type' => 'rangeslider',
  749. 'std' => 0,
  750. 'priority' => 40,
  751. 'step' => 1,
  752. 'min' => - 100,
  753. 'max' => 100,
  754. 'unit' => 'px',
  755. 'dependencies' => array(
  756. 'close_location' => array( 'topleft', 'topcenter', 'topright' ),
  757. ),
  758. ),
  759. 'close_position_bottom' => array(
  760. 'label' => __( 'Bottom', 'popup-maker' ),
  761. 'type' => 'rangeslider',
  762. 'std' => 0,
  763. 'priority' => 50,
  764. 'step' => 1,
  765. 'min' => - 100,
  766. 'max' => 100,
  767. 'unit' => 'px',
  768. 'dependencies' => array(
  769. 'close_location' => array( 'bottomleft', 'bottomcenter', 'bottomright' ),
  770. ),
  771. ),
  772. 'close_position_left' => array(
  773. 'label' => __( 'Left', 'popup-maker' ),
  774. 'type' => 'rangeslider',
  775. 'std' => 0,
  776. 'priority' => 60,
  777. 'step' => 1,
  778. 'min' => - 100,
  779. 'max' => 100,
  780. 'unit' => 'px',
  781. 'dependencies' => array(
  782. 'close_location' => array( 'topleft', 'middleleft', 'bottomleft' ),
  783. ),
  784. ),
  785. 'close_position_right' => array(
  786. 'label' => __( 'Right', 'popup-maker' ),
  787. 'type' => 'rangeslider',
  788. 'std' => 0,
  789. 'priority' => 70,
  790. 'step' => 1,
  791. 'min' => - 100,
  792. 'max' => 100,
  793. 'unit' => 'px',
  794. 'dependencies' => array(
  795. 'close_location' => array( 'topright', 'middleright', 'bottomright' ),
  796. ),
  797. ),
  798. ),
  799. 'size' => array(
  800. 'close_padding' => array(
  801. 'label' => __( 'Padding', 'popup-maker' ),
  802. 'type' => 'rangeslider',
  803. 'std' => 8,
  804. 'priority' => 10,
  805. 'step' => 1,
  806. 'min' => 0,
  807. 'max' => 100,
  808. 'unit' => 'px',
  809. ),
  810. 'close_height' => array(
  811. 'label' => __( 'Height', 'popup-maker' ),
  812. 'type' => 'rangeslider',
  813. 'std' => 0,
  814. 'priority' => 20,
  815. 'step' => 1,
  816. 'min' => 0,
  817. 'max' => 100,
  818. 'unit' => 'px',
  819. ),
  820. 'close_width' => array(
  821. 'label' => __( 'Width', 'popup-maker' ),
  822. 'type' => 'rangeslider',
  823. 'std' => 0,
  824. 'priority' => 30,
  825. 'step' => 1,
  826. 'min' => 0,
  827. 'max' => 100,
  828. 'unit' => 'px',
  829. ),
  830. 'close_border_radius' => array(
  831. 'label' => __( 'Border Radius', 'popup-maker' ),
  832. 'type' => 'rangeslider',
  833. 'std' => 0,
  834. 'priority' => 40,
  835. 'step' => 1,
  836. 'min' => 1,
  837. 'max' => 28,
  838. 'unit' => 'px',
  839. ),
  840. ),
  841. 'background' => array(
  842. 'close_background_color' => array(
  843. 'label' => __( 'Color', 'popup-maker' ),
  844. 'type' => 'color',
  845. 'std' => '#00b7cd',
  846. 'priority' => 10,
  847. ),
  848. 'close_background_opacity' => array(
  849. 'label' => __( 'Opacity', 'popup-maker' ),
  850. 'type' => 'rangeslider',
  851. 'std' => 100,
  852. 'priority' => 20,
  853. 'step' => 1,
  854. 'min' => 0,
  855. 'max' => 100,
  856. 'unit' => '%',
  857. 'force_minmax' => true,
  858. ),
  859. ),
  860. 'typography' => array(
  861. 'close_font_color' => array(
  862. 'label' => __( 'Color', 'popup-maker' ),
  863. 'type' => 'color',
  864. 'std' => '#ffffff',
  865. 'priority' => 10,
  866. ),
  867. 'close_font_size' => array(
  868. 'label' => __( 'Font Size', 'popup-maker' ),
  869. 'type' => 'rangeslider',
  870. 'std' => 12,
  871. 'priority' => 20,
  872. 'step' => 1,
  873. 'min' => 8,
  874. 'max' => 32,
  875. 'unit' => 'px',
  876. ),
  877. 'close_line_height' => array(
  878. 'label' => __( 'Line Height', 'popup-maker' ),
  879. 'type' => 'rangeslider',
  880. 'std' => 36,
  881. 'priority' => 30,
  882. 'step' => 1,
  883. 'min' => 8,
  884. 'max' => 54,
  885. 'unit' => 'px',
  886. ),
  887. 'close_font_family' => array(
  888. 'label' => __( 'Font Family', 'popup-maker' ),
  889. 'type' => 'select',
  890. 'select2' => true,
  891. 'std' => 'inherit',
  892. 'priority' => 40,
  893. 'options' => $font_family_options,
  894. ),
  895. 'close_font_weight' => array(
  896. 'label' => __( 'Font Weight', 'popup-maker' ),
  897. 'type' => 'select',
  898. 'std' => 400,
  899. 'priority' => 50,
  900. 'options' => $font_weight_options,
  901. ),
  902. 'close_font_style' => array(
  903. 'label' => __( 'Style', 'popup-maker' ),
  904. 'type' => 'select',
  905. 'std' => 'inherit',
  906. 'priority' => 60,
  907. 'options' => array(
  908. '' => __( 'Normal', 'popup-maker' ),
  909. 'italic' => __( 'Italic', 'popup-maker' ),
  910. ),
  911. ),
  912. ),
  913. 'border' => array(
  914. 'close_border_style' => array(
  915. 'label' => __( 'Style', 'popup-maker' ),
  916. 'type' => 'select',
  917. 'std' => 'none',
  918. 'priority' => 10,
  919. 'options' => $border_style_options,
  920. ),
  921. 'close_border_color' => array(
  922. 'label' => __( 'Color', 'popup-maker' ),
  923. 'type' => 'color',
  924. 'std' => '#ffffff',
  925. 'priority' => 20,
  926. 'dependencies' => array(
  927. 'close_border_style' => array_keys( PUM_Utils_Array::remove_keys( $border_style_options, array( 'none' ) ) ),
  928. ),
  929. ),
  930. 'close_border_width' => array(
  931. 'label' => __( 'Thickness', 'popup-maker' ),
  932. 'type' => 'rangeslider',
  933. 'std' => 1,
  934. 'priority' => 30,
  935. 'step' => 1,
  936. 'min' => 1,
  937. 'max' => 5,
  938. 'unit' => 'px',
  939. 'dependencies' => array(
  940. 'close_border_style' => array_keys( PUM_Utils_Array::remove_keys( $border_style_options, array( 'none' ) ) ),
  941. ),
  942. ),
  943. ),
  944. 'boxshadow' => array(
  945. 'close_boxshadow_color' => array(
  946. 'label' => __( 'Color', 'popup-maker' ),
  947. 'type' => 'color',
  948. 'std' => '#020202',
  949. 'priority' => 10,
  950. ),
  951. 'close_boxshadow_opacity' => array(
  952. 'label' => __( 'Opacity', 'popup-maker' ),
  953. 'type' => 'rangeslider',
  954. 'std' => 23,
  955. 'priority' => 20,
  956. 'step' => 1,
  957. 'min' => 0,
  958. 'max' => 100,
  959. 'unit' => '%',
  960. 'force_minmax' => true,
  961. ),
  962. 'close_boxshadow_horizontal' => array(
  963. 'label' => __( 'Horizontal Position', 'popup-maker' ),
  964. 'type' => 'rangeslider',
  965. 'std' => 1,
  966. 'priority' => 30,
  967. 'step' => 1,
  968. 'min' => - 50,
  969. 'max' => 50,
  970. 'unit' => 'px',
  971. ),
  972. 'close_boxshadow_vertical' => array(
  973. 'label' => __( 'Vertical Position', 'popup-maker' ),
  974. 'type' => 'rangeslider',
  975. 'std' => 1,
  976. 'priority' => 40,
  977. 'step' => 1,
  978. 'min' => - 50,
  979. 'max' => 50,
  980. 'unit' => 'px',
  981. ),
  982. 'close_boxshadow_blur' => array(
  983. 'label' => __( 'Blur Radius', 'popup-maker' ),
  984. 'type' => 'rangeslider',
  985. 'std' => 3,
  986. 'priority' => 50,
  987. 'step' => 1,
  988. 'min' => 0,
  989. 'max' => 100,
  990. 'unit' => 'px',
  991. ),
  992. 'close_boxshadow_spread' => array(
  993. 'label' => __( 'Spread', 'popup-maker' ),
  994. 'type' => 'rangeslider',
  995. 'std' => 0,
  996. 'priority' => 60,
  997. 'step' => 1,
  998. 'min' => - 100,
  999. 'max' => 100,
  1000. 'unit' => 'px',
  1001. ),
  1002. 'close_boxshadow_inset' => array(
  1003. 'label' => __( 'Inset (inner shadow)', 'popup-maker' ),
  1004. 'type' => 'select',
  1005. 'std' => 'no',
  1006. 'priority' => 70,
  1007. 'options' => array(
  1008. 'no' => __( 'No', 'popup-maker' ),
  1009. 'yes' => __( 'Yes', 'popup-maker' ),
  1010. ),
  1011. ),
  1012. ),
  1013. 'textshadow' => array(
  1014. 'close_textshadow_color' => array(
  1015. 'label' => __( 'Color', 'popup-maker' ),
  1016. 'type' => 'color',
  1017. 'std' => '#000000',
  1018. 'priority' => 10,
  1019. ),
  1020. 'close_textshadow_opacity' => array(
  1021. 'label' => __( 'Opacity', 'popup-maker' ),
  1022. 'type' => 'rangeslider',
  1023. 'std' => 23,
  1024. 'priority' => 20,
  1025. 'step' => 1,
  1026. 'min' => 0,
  1027. 'max' => 100,
  1028. 'force_minmax' => true,
  1029. 'unit' => '%',
  1030. ),
  1031. 'close_textshadow_horizontal' => array(
  1032. 'label' => __( 'Horizontal Position', 'popup-maker' ),
  1033. 'type' => 'rangeslider',
  1034. 'std' => 0,
  1035. 'priority' => 30,
  1036. 'step' => 1,
  1037. 'min' => - 50,
  1038. 'max' => 50,
  1039. 'unit' => 'px',
  1040. ),
  1041. 'close_textshadow_vertical' => array(
  1042. 'label' => __( 'Vertical Position', 'popup-maker' ),
  1043. 'type' => 'rangeslider',
  1044. 'std' => 0,
  1045. 'priority' => 40,
  1046. 'step' => 1,
  1047. 'min' => - 50,
  1048. 'max' => 50,
  1049. 'unit' => 'px',
  1050. ),
  1051. 'close_textshadow_blur' => array(
  1052. 'label' => __( 'Blur Radius', 'popup-maker' ),
  1053. 'type' => 'rangeslider',
  1054. 'std' => 0,
  1055. 'priority' => 50,
  1056. 'step' => 1,
  1057. 'min' => 0,
  1058. 'max' => 100,
  1059. 'unit' => 'px',
  1060. ),
  1061. ),
  1062. ) ),
  1063. 'advanced' => apply_filters( 'pum_theme_advanced_settings_fields', array(
  1064. 'main' => array(),
  1065. ) ),
  1066. ) );
  1067. $fields = self::append_deprecated_fields( $fields );
  1068. $fields = PUM_Utils_Fields::parse_tab_fields( $fields, array(
  1069. 'has_sections' => true,
  1070. 'name' => 'theme_settings[%s]',
  1071. ) );
  1072. }
  1073. return $fields;
  1074. }
  1075. public static function append_deprecated_fields( $fields = array() ) {
  1076. global $post;
  1077. if ( class_exists( 'PUM_ATB' ) && has_action( 'popmake_popup_theme_overlay_meta_box_fields' ) ) {
  1078. ob_start();
  1079. do_action( 'popmake_popup_theme_overlay_meta_box_fields', $post->ID );
  1080. $content = self::fix_deprecated_fields( ob_get_clean() );
  1081. $fields['overlay']['background']['deprecated_fields'] = array(
  1082. 'type' => 'html',
  1083. 'content' => $content,
  1084. 'priority' => 999,
  1085. );
  1086. // Remove duplicate fields.
  1087. unset( $fields['overlay']['background']['overlay_background_color'] );
  1088. unset( $fields['overlay']['background']['overlay_background_opacity'] );
  1089. }
  1090. if ( class_exists( 'PUM_ATB' ) && has_action( 'popmake_popup_theme_container_meta_box_fields' ) ) {
  1091. ob_start();
  1092. do_action( 'popmake_popup_theme_container_meta_box_fields', $post->ID );
  1093. $content = self::fix_deprecated_fields( ob_get_clean() );
  1094. $fields['container']['background']['deprecated_fields'] = array(
  1095. 'type' => 'html',
  1096. 'content' => $content,
  1097. 'priority' => 999,
  1098. );
  1099. // Remove duplicate fields.
  1100. unset( $fields['container']['background']['container_background_color'] );
  1101. unset( $fields['container']['background']['container_background_opacity'] );
  1102. }
  1103. if ( class_exists( 'PUM_ATB' ) && has_action( 'popmake_popup_theme_close_meta_box_fields' ) ) {
  1104. ob_start();
  1105. do_action( 'popmake_popup_theme_close_meta_box_fields', $post->ID );
  1106. $content = self::fix_deprecated_fields( ob_get_clean() );
  1107. $fields['close']['background']['deprecated_fields'] = array(
  1108. 'type' => 'html',
  1109. 'content' => $content,
  1110. 'priority' => 999,
  1111. );
  1112. // Remove duplicate fields.
  1113. unset( $fields['close']['background']['close_background_color'] );
  1114. unset( $fields['close']['background']['close_background_opacity'] );
  1115. }
  1116. return $fields;
  1117. }
  1118. public static function fix_deprecated_fields( $content = '' ) {
  1119. // Remove "Background" heading.
  1120. $content = str_replace( '<tr class="title-divider">
  1121. <th colspan="2">
  1122. <h3 class="title">Background</h3>
  1123. </th>
  1124. </tr>', '', $content );
  1125. // Fix broken opacity fields.
  1126. $content = str_replace( array( 'class="bg_opacity"','class="bg_overlay_opacity"') , array('class="bg_opacity pum-field-rangeslider"','class="bg_overlay_opacity pum-field-rangeslider"'), $content );
  1127. // TEMPORARY. REMOVE THIS
  1128. $content = '<table class="form-table"><tbody>' . $content . '</tbody></table>';
  1129. return $content;
  1130. }
  1131. /**
  1132. * @return array
  1133. */
  1134. public static function defaults() {
  1135. return PUM_Utils_Fields::get_form_default_values( self::fields() );
  1136. }
  1137. }