PluginProbe
Datafeedr API / 1.0.22
Datafeedr API v1.0.22
1.4.3 1.4.2 1.0.125 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.3 1.0.30 1.0.31 1.0.32 All 182 releases
datafeedr-api / functions / admin-functions.php

admin-functions.php in Datafeedr API 1.0.22, at functions/admin-functions.php

198 lines 7.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Load AJAX related functions.
5 */
6 require_once( DFRAPI_PATH . 'functions/ajax.php' );
7
8 /**
9 * These are the Admin pages associated with the Datafeedr API plugin.
10 *
11 * These are called from their respecitive classes.
12 */
13 function dfrapi_setting_pages( $key=false ) {
14
15 $pages = array (
16 'dfrapi-configuration' => __( 'Configuration', DFRAPI_DOMAIN ),
17 'dfrapi-networks' => __( 'Networks', DFRAPI_DOMAIN ),
18 'dfrapi-merchants' => __( 'Merchants', DFRAPI_DOMAIN ),
19 'dfrapi-tools' => __( 'Tools', DFRAPI_DOMAIN ),
20 'dfrapi-export' => __( 'Export', DFRAPI_DOMAIN ),
21 'dfrapi-import' => __( 'Import', DFRAPI_DOMAIN ),
22 'dfrapi-account' => __( 'Account', DFRAPI_DOMAIN ),
23 );
24
25 if ( isset( $pages[$key] ) ) {
26 return $pages[$key];
27 }
28
29 }
30
31 /**
32 * This stores messages to be displayed using the 'admin_notices' action.
33 */
34 function dfrapi_admin_messages( $key=false ) {
35
36 $messages = array(
37
38 // User is missing 1 or more of their API Keys.
39 'missing_api_keys' => array(
40 'class' => 'update-nag',
41 'message' => __( 'Your Datafeedr API Keys are missing.', DFRAPI_DOMAIN ),
42 'url' => 'admin.php?page=dfrapi',
43 'button_text' => __( 'Add Your API Keys', DFRAPI_DOMAIN )
44 ),
45
46 // User is missing a network
47 'missing_network_ids' => array(
48 'class' => 'update-nag',
49 'message' => __( 'You haven\'t selected any affiliate networks yet.', DFRAPI_DOMAIN ),
50 'url' => 'admin.php?page=dfrapi_networks',
51 'button_text' => __( 'Select Networks', DFRAPI_DOMAIN )
52 ),
53
54 // User is missing a merchant
55 'missing_merchant_ids' => array(
56 'class' => 'update-nag',
57 'message' => __( 'You haven\'t selected any merchants yet.', DFRAPI_DOMAIN ),
58 'url' => 'admin.php?page=dfrapi_merchants',
59 'button_text' => __( 'Select Merchants', DFRAPI_DOMAIN )
60 ),
61
62 // Display message that user has used 90%+ of API requests.
63 'usage_over_90_percent' => array(
64 'class' => 'update-nag',
65 'message' => __( 'You have used ', DFRAPI_DOMAIN ) . dfrapi_get_api_usage_percentage() . __( '% of your total Datafeedr API requests this month. ', DFRAPI_DOMAIN ),
66 'url' => 'admin.php?page=dfrapi_account',
67 'button_text' => __( 'View Account', DFRAPI_DOMAIN )
68 ),
69
70 // Missing affiliate IDs message.
71 'missing_affiliate_ids' => array(
72 'class' => 'update-nag',
73 'message' => __( 'You are missing affiliate IDs. ', DFRAPI_DOMAIN ),
74 'url' => 'admin.php?page=dfrapi_networks',
75 'button_text' => __( 'Enter your Affiliate IDs', DFRAPI_DOMAIN )
76 ),
77
78 // Database rotation message.
79 'database_rotation' => array(
80 'class' => 'update-nag',
81 'message' => __( '<strong>Datafeedr API Message:</strong> We are currently refreshing our database of 270 million products. This process starts daily at 8:00am GMT and runs for about 20 minutes. During this time you may be unable to query our database.', DFRAPI_DOMAIN ),
82 'url' => '',
83 'button_text' => __( '', DFRAPI_DOMAIN )
84 ),
85
86 // Unapproved Zanox merchant(s) message.
87 'unapproved_zanox_merchants' => array(
88 'class' => 'update-nag',
89 'message' => '<strong>' . __( 'Unapproved Zanox Merchant(s):', DFRAPI_DOMAIN ) . '</strong> ' .
90 __( 'It appears you are not approved by one or more Zanox merchants you have selected. Please remove unapproved Zanox merchants from your ', DFRAPI_DOMAIN ) .
91 '<a href="' . admin_url( 'admin.php?page=dfrapi_merchants' ) . '" target="_blank">' .
92 __( 'Zanox merchant selection', DFRAPI_DOMAIN ) .
93 '</a>' .
94 __( ' then delete your cached API data ', DFRAPI_DOMAIN ) .
95 '<a href="' . admin_url( 'admin.php?page=dfrapi_tools' ) . '" target="_blank">' .
96 __( 'here', DFRAPI_DOMAIN ) .
97 '</a>.',
98 'url' => '',
99 'button_text' => __( '', DFRAPI_DOMAIN )
100 ),
101 );
102
103 if ( isset( $messages[$key] ) ) {
104 dfrapi_admin_notices( $key, $messages );
105 }
106
107 }
108
109 /**
110 * This gets any notices set by the plugin.
111 */
112 function dfrapi_admin_notices( $key, $messages ) {
113 $notices = get_option( 'dfrapi_admin_notices', array() );
114 $notices[$key] = $messages[$key];
115 update_option( 'dfrapi_admin_notices', $notices );
116 }
117
118 /**
119 * Button text for admin notices.
120 */
121 function dfrapi_fix_button( $url, $button_text=false ) {
122 if ( !$button_text ) {
123 $button_text = __( 'Fix This Now', DFRAPI_DOMAIN );
124 }
125 if ( substr( $url, 0, 4 ) === "http" ) {
126 return ' <a target="blank" href="' . $url . '">' .$button_text . '</a>';
127 } else {
128 return ' <a href="' . admin_url( $url ) . '">' .$button_text . '</a>';
129 }
130 }
131
132 /**
133 * Return plan IDs & names.
134 */
135 function dfrapi_get_membership_plans() {
136 return array(
137 10200 => 'Free',
138 101000 => 'Starter',
139 1025000 => 'Basic',
140 1125000 => 'Beta Tester',
141 10100000 => 'Professional',
142 10250000 => 'Enterprise',
143 );
144 }
145
146 /**
147 * Convert network group names to a css class name.
148 */
149 function dfrapi_group_name_to_css( $group ) {
150 if ( is_string( $group ) ) {
151 return strtolower(
152 str_replace(
153 array( " ", "-", "." ),
154 "",
155 $group
156 )
157 );
158 } elseif ( is_array( $group ) ) {
159 $name = str_replace( array( " ", "-", "." ), "", $group['group'] );
160 $type = ( $group['type'] == 'coupons' ) ? '_coupons' : '';
161 return strtolower( $name . $type );
162 }
163 }
164
165 /**
166 * Adds global "support" content to "Help" tabs for all Datafeedr plugins.
167 */
168 function dfrapi_help_tab( $screen ) {
169
170 $screen->add_help_tab( array(
171 'id' => 'dfrapi_support_tab',
172 'title' => __( 'Support', DFRAPI_DOMAIN ),
173 'content' =>
174 '<h2>' . __( "Datafeedr Support", DFRAPI_DOMAIN ) . '</h2>' .
175 '<p>' . sprintf(__( 'Find answers to common questions and problems in the <a href="%s?utm_source=plugin&utm_medium=link&utm_campaign=helptab" target="_blank">documentation</a> and in the <a href="%s?utm_source=plugin&utm_medium=link&utm_campaign=helptab" target="_blank">support forum</a>', DFRAPI_DOMAIN ), DFRAPI_DOCS_URL, DFRAPI_QNA_URL ) . '. ' . __( 'For additional help, feel free to contact us using the links below.', DFRAPI_DOMAIN ) . '</p>' .
176 '<p><a href="' . DFRAPI_ASK_QUESTION_URL . '?utm_source=plugin&utm_medium=link&utm_campaign=helptab" class="button button-primary" target="_blank">' . __( 'Post a Question', DFRAPI_DOMAIN ) . '</a> (' . __( 'recommended', DFRAPI_DOMAIN ) . ')</p>' .
177 '<p><a href="' . DFRAPI_EMAIL_US_URL . '?utm_source=plugin&utm_medium=link&utm_campaign=helptab" class="button" target="_blank">' . __( 'Email Us', DFRAPI_DOMAIN ) . '</a></p>'
178
179 ) );
180
181 $screen->add_help_tab( array(
182 'id' => 'dfrapi_bug_tab',
183 'title' => __( 'Found a bug?', DFRAPI_DOMAIN ),
184 'content' =>
185 '<h2>' . __( "Found a bug?", DFRAPI_DOMAIN ) . '</h2>' .
186 '<p>' . sprintf( __( 'If you find a bug within Datafeedr, check the <a href="%s?utm_source=plugin&utm_medium=link&utm_campaign=helptab" target="_blank">Bug Reports</a> to see if it’s already been reported. Report a new bug with as much description as possible (context, screenshots, error log, etc.) Thank you!', DFRAPI_DOMAIN ), DFRAPI_BUG_REPORTS_URL ) . '</p>' .
187 '<p><a href="' . DFRAPI_REPORT_BUG_URL . '?utm_source=plugin&utm_medium=link&utm_campaign=helptab" class="button button-primary" target="_blank">' . __( 'Report a bug', DFRAPI_DOMAIN ) . '</a></p>'
188
189 ) );
190
191 $screen->set_help_sidebar(
192 '<p><strong>' . __( 'For more information:', DFRAPI_DOMAIN ) . '</strong></p>' .
193 '<p><a href="' . DFRAPI_HOME_URL . '?utm_source=plugin&utm_medium=link&utm_campaign=helptab" target="_blank">' . __( 'About Datafeedr', DFRAPI_DOMAIN ) . '</a></p>' .
194 '<p><a href="' . DFRAPI_HOME_URL . '/keys?utm_source=plugin&utm_medium=link&utm_campaign=helptab" target="_blank">' . __( 'Datafeedr API Keys', DFRAPI_DOMAIN ) . '</a></p>'
195 );
196
197 return $screen;
198 }