PluginProbe
Property Hive / 1.4.5
Property Hive v1.4.5
2.3.1 2.3.0 2.2.6 2.2.5 2.2.4 2.2.3 2.2.2 1.4.46 1.4.47 1.4.48 1.4.49 1.4.5 1.4.50 1.4.51 1.4.52 1.4.53 1.4.54 1.4.55 1.4.56 1.4.57 1.4.58 1.4.59 1.4.6 1.4.60 1.4.61 All 261 releases
propertyhive / includes / admin / ph-admin-functions.php

ph-admin-functions.php in Property Hive 1.4.5, at includes/admin/ph-admin-functions.php

191 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PropertyHive Admin Functions
4 *
5 * @author PropertyHive
6 * @category Core
7 * @package PropertyHive/Admin/Functions
8 * @version 1.0.0
9 */
10
11 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
12
13 /**
14 * Get all PropertyHive screen ids
15 *
16 * @return array
17 */
18 function ph_get_screen_ids() {
19 $ph_screen_id = sanitize_title( __( 'PropertyHive', 'propertyhive' ) );
20
21 return apply_filters( 'propertyhive_screen_ids', array(
22 'edit-property',
23 'property',
24 'edit-contact',
25 'contact',
26 'enquiry',
27 'viewing',
28 'offer',
29 'sale',
30 'dashboard_page_ph-installed',
31 'property-hive_page_ph-settings',
32 ) );
33 }
34
35 /**
36 * Create a page and store the ID in an option.
37 *
38 * @access public
39 * @param mixed $slug Slug for the new page
40 * @param mixed $option Option name to store the page's ID
41 * @param string $page_title (default: '') Title for the new page
42 * @param string $page_content (default: '') Content for the new page
43 * @param int $post_parent (default: 0) Parent for the new page
44 * @return int page ID
45 */
46 function ph_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) {
47 global $wpdb;
48
49 /*$option_value = get_option( $option );
50
51 if ( $option_value > 0 && get_post( $option_value ) )
52 return -1;
53
54 $page_found = null;
55
56 if ( strlen( $page_content ) > 0 ) {
57 // Search for an existing page with the specified page content (typically a shortcode)
58 $page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type='page' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
59 } else {
60 // Search for an existing page with the specified page slug
61 $page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->posts . " WHERE post_type='page' AND post_name = %s LIMIT 1;", $slug ) );
62 }
63
64 if ( $page_found ) {
65 if ( ! $option_value )
66 update_option( $option, $page_found );
67
68 return $page_found;
69 }
70
71 $page_data = array(
72 'post_status' => 'publish',
73 'post_type' => 'page',
74 'post_author' => 1,
75 'post_name' => $slug,
76 'post_title' => $page_title,
77 'post_content' => $page_content,
78 'post_parent' => $post_parent,
79 'comment_status' => 'closed'
80 );
81 $page_id = wp_insert_post( $page_data );
82
83 if ( $option )
84 update_option( $option, $page_id );
85
86 return $page_id;*/
87 }
88
89 /**
90 * Output admin fields.
91 *
92 * Loops though the PropertyHive options array and outputs each field.
93 *
94 * @param array $options Opens array to output
95 */
96 function propertyhive_admin_fields( $options ) {
97 if ( ! class_exists( 'PH_Admin_Settings' ) )
98 include 'class-ph-admin-settings.php';
99
100 PH_Admin_Settings::output_fields( $options );
101 }
102
103 /**
104 * Update all settings which are passed.
105 *
106 * @access public
107 * @param array $options
108 * @return void
109 */
110 function propertyhive_update_options( $options ) {
111 if ( ! class_exists( 'PH_Admin_Settings' ) )
112 include 'class-ph-admin-settings.php';
113
114 PH_Admin_Settings::save_fields( $options );
115 }
116
117 /**
118 * Get a setting from the settings API.
119 *
120 * @param mixed $option
121 * @return string
122 */
123 function propertyhive_settings_get_option( $option_name, $default = '' ) {
124 if ( ! class_exists( 'PH_Admin_Settings' ) )
125 include 'class-ph-admin-settings.php';
126
127 return PH_Admin_Settings::get_option( $option_name, $default );
128 }
129
130 /**
131 * Generate CSS from the less file when changing colours.
132 *
133 * @access public
134 * @return void
135 */
136 function propertyhive_compile_less_styles() {
137 /*global $propertyhive;
138
139 $colors = array_map( 'esc_attr', (array) get_option( 'propertyhive_frontend_css_colors' ) );
140 $base_file = PH()->plugin_path() . '/assets/css/propertyhive-base.less';
141 $less_file = PH()->plugin_path() . '/assets/css/propertyhive.less';
142 $css_file = PH()->plugin_path() . '/assets/css/propertyhive.css';
143
144 // Write less file
145 if ( is_writable( $base_file ) && is_writable( $css_file ) ) {
146
147 // Colours changed - recompile less
148 if ( ! class_exists( 'lessc' ) )
149 include_once( PH()->plugin_path() . '/includes/libraries/class-lessc.php' );
150 if ( ! class_exists( 'cssmin' ) )
151 include_once( PH()->plugin_path() . '/includes/libraries/class-cssmin.php' );
152
153 try {
154 // Set default if colours not set
155 if ( ! $colors['primary'] ) $colors['primary'] = '#ad74a2';
156 if ( ! $colors['secondary'] ) $colors['secondary'] = '#f7f6f7';
157 if ( ! $colors['highlight'] ) $colors['highlight'] = '#85ad74';
158 if ( ! $colors['content_bg'] ) $colors['content_bg'] = '#ffffff';
159 if ( ! $colors['subtext'] ) $colors['subtext'] = '#777777';
160
161 // Write new color to base file
162 $color_rules = "
163 @primary: " . $colors['primary'] . ";
164 @primarytext: " . ph_light_or_dark( $colors['primary'], 'desaturate(darken(@primary,50%),18%)', 'desaturate(lighten(@primary,50%),18%)' ) . ";
165
166 @secondary: " . $colors['secondary'] . ";
167 @secondarytext: " . ph_light_or_dark( $colors['secondary'], 'desaturate(darken(@secondary,60%),18%)', 'desaturate(lighten(@secondary,60%),18%)' ) . ";
168
169 @highlight: " . $colors['highlight'] . ";
170 @highlightext: " . ph_light_or_dark( $colors['highlight'], 'desaturate(darken(@highlight,60%),18%)', 'desaturate(lighten(@highlight,60%),18%)' ) . ";
171
172 @contentbg: " . $colors['content_bg'] . ";
173
174 @subtext: " . $colors['subtext'] . ";
175 ";
176
177 file_put_contents( $base_file, $color_rules );
178
179 $less = new lessc;
180 $compiled_css = $less->compileFile( $less_file );
181 $compiled_css = CssMin::minify( $compiled_css );
182
183 if ( $compiled_css )
184 file_put_contents( $css_file, $compiled_css );
185
186 } catch ( exception $ex ) {
187 wp_die( __( 'Could not compile propertyhive.less:', 'propertyhive' ) . ' ' . $ex->getMessage() );
188 }
189 }*/
190 }
191