$action,
'plugin' => $plugin,
],
admin_url( 'update.php' )
),
$action . '_' . $plugin
)
);
}
}
if ( ! function_exists( 'bbp_voting_get_plugin_activate_link' ) ) {
function bbp_voting_get_plugin_activate_link( $plugin, $action = 'activate' ) {
if ( strpos( $plugin, '/' ) ) {
$plugin = str_replace( '\/', '%2F', $plugin );
}
$url = sprintf( admin_url( 'plugins.php?action=' . $action . '&plugin=%s&plugin_status=all&paged=1&s' ), $plugin );
$_REQUEST['plugin'] = $plugin;
$url = wp_nonce_url( $url, $action . '-plugin_' . $plugin );
return $url;
}
}
if ( ! function_exists( 'bbp_voting_field' ) ) {
function bbp_voting_field( $key, $name, $label = '', $description = '', $type = 'bool', $pro = false ) {
$name_and_id = 'name="' . esc_attr( $key ) . '" id="' . esc_attr( $key ) . '"';
$teaser = defined( 'BBPVOTINGPRO' ) ? false : $pro;
$attributes = $teaser ? 'disabled' : $name_and_id;
?>
|
:
Pro
|
value="true"
/>
value="" data-lpignore="true" />
|
lowerBound( $positiveVotes, $totalVotes, $confidence ) : 0;
}
private function lowerBound( int $positiveVotes, int $totalVotes, float $confidence ) : float {
$phat = 1.0 * $positiveVotes / $totalVotes;
$numerator = $this->calculationNumerator( $totalVotes, $confidence, $phat );
$denominator = $this->calculationDenominator( $totalVotes, $confidence );
return $numerator / $denominator;
}
private function calculationDenominator( int $total, float $z ) : float {
return 1 + $z * $z / $total;
}
private function calculationNumerator( int $total, float $z, float $phat ) : float {
return $phat + $z * $z / ( 2 * $total ) - $z * sqrt( ( $phat * ( 1 - $phat ) + $z * $z / ( 4 * $total ) ) / $total );
}
}
}
if ( ! function_exists( 'bbp_voting_parse_args' ) ) {
function bbp_voting_parse_args( $args, $defaults = [], $filter_key = '' ) {
// Setup a temporary array from $args
if ( is_object( $args ) ) {
$r = get_object_vars( $args );
} elseif ( is_array( $args ) ) {
$r =& $args;
} else {
$r = [];
wp_parse_str( $args, $r );
}
// Passively filter the args before the parse
if ( ! empty( $filter_key ) ) {
$r = apply_filters( "bbp_voting_before_{$filter_key}_parse_args", $r, $args, $defaults );
}
// Parse
if ( is_array( $defaults ) && ! empty( $defaults ) ) {
$r = array_merge( $defaults, $r );
}
// Aggressively filter the args after the parse
if ( ! empty( $filter_key ) ) {
$r = apply_filters( "bbp_voting_after_{$filter_key}_parse_args", $r, $args, $defaults );
}
// Return the parsed results
return $r;
}
}