ID; /* if we have no field name passed go no further */ if( empty( $field ) ) return false; /* build the meta key to return the value for */ $key = $prefix . $field; /* gete the post meta value for this field name of meta key */ $field = get_post_meta( $post_id, $key, true ); return apply_filters( 'addressy_field_value', $field ); } /** * function addressy_get_setting() * * gets a named plugin settings returning its value * @param mixed key name to retrieve - this is the key of the stored option * @return mixed the value of the key */ function addressy_get_setting( $name = '' ) { /* if no name is passed */ if( empty( $name ) ) { return false; } /* get the option */ $pcaOptions = get_option( '_adrsy_settings' ); $setting = $pcaOptions[ $name ]; /* check we have a value returned */ if( empty( $setting ) ) { return false; } return apply_filters( 'addressy_get_setting', $setting ); } /** * addressy_on_activation() * On plugin activation makes current user a wpbasis user and * sets an option to redirect the user to another page. */ function addressy_on_activation() { /* set option to initialise the redirect */ add_option( 'addressy_activation_redirect', true ); } register_activation_hook( __FILE__, 'addressy_on_activation' ); /** * addressy_activation_redirect() * Redirects user to the settings page for wp basis on plugin * activation. */ function addressy_activation_redirect() { /* check whether we should redirect the user or not based on the option set on activation */ if( true == get_option( 'addressy_activation_redirect' ) ) { /* delete the redirect option */ delete_option( 'addressy_activation_redirect' ); /* redirect the user to the wp basis settings page */ wp_redirect( admin_url( 'admin.php?page=addressy_settings' ) ); exit; } } add_action( 'admin_init', 'addressy_activation_redirect' ); /** * Display an admin notice, if not on the integration screen and if the account isn't yet connected. * @since 1.0.0 * @return void */ function addressy_maybe_display_admin_notices () { if ( isset( $_GET['page'] ) && 'addressy_settings' == $_GET['page'] ) return; // Don't show these notices on our admin screen. if ( isset( $_GET['page'] ) && 'addressy_register' == $_GET['page'] ) return; // Don't show these notices on our register screen. $accCode = addressy_get_setting( 'account_code' ) ; if ( false === $accCode ) { $url = get_settings_url(); echo '

' . sprintf( __( '%sCreate%s an account or %slog in%s to %sconfigure Addressy%s.', 'addressy' ), '', '', '', '','', '' ). '

' . "\n" ; } } add_action( 'admin_notices', 'addressy_maybe_display_admin_notices' ); /** * Generate a URL to our specific settings screen. * @since 1.0.0 * @return string Generated URL. */ function get_settings_url () { $url = admin_url( 'admin.php' ); $url = add_query_arg( 'page', 'addressy_settings', $url ); return $url; } /** * addressy_hook_javascript() * * Adds the PCA tag to the head of every page */ function addressy_hook_javascript() { $accCode = addressy_get_setting( 'account_code' ); $licenceKey = addressy_get_setting( 'license_key' ); $pcaMappings = json_decode( addressy_get_setting( 'field_mappings' ) ); $pcaCustomJs = json_decode( addressy_get_setting( 'custom_javascript' ) ); if ( $accCode ) { ?>