Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/ninja-fo.../deprecat.../includes
File: functions.php
<?php if ( ! defined( 'ABSPATH' ) ) exit;
[0] Fix | Delete
[1] Fix | Delete
function ninja_forms_return_echo($function_name){
[2] Fix | Delete
$arguments = func_get_args();
[3] Fix | Delete
array_shift($arguments); // We need to remove the first arg ($function_name)
[4] Fix | Delete
ob_start();
[5] Fix | Delete
call_user_func_array($function_name, $arguments);
[6] Fix | Delete
$return = ob_get_clean();
[7] Fix | Delete
return $return;
[8] Fix | Delete
}
[9] Fix | Delete
[10] Fix | Delete
function ninja_forms_random_string($length = 10){
[11] Fix | Delete
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
[12] Fix | Delete
$random_string = '';
[13] Fix | Delete
for ($i = 0; $i < $length; $i++) {
[14] Fix | Delete
$random_string .= $characters[rand(0, strlen($characters) - 1)];
[15] Fix | Delete
}
[16] Fix | Delete
return $random_string;
[17] Fix | Delete
}
[18] Fix | Delete
[19] Fix | Delete
function ninja_forms_remove_from_array($arr, $key, $val, $within = FALSE) {
[20] Fix | Delete
foreach ($arr as $i => $array)
[21] Fix | Delete
if ($within && stripos($array[$key], $val) !== FALSE && (gettype($val) === gettype($array[$key])))
[22] Fix | Delete
unset($arr[$i]);
[23] Fix | Delete
elseif ($array[$key] === $val)
[24] Fix | Delete
unset($arr[$i]);
[25] Fix | Delete
[26] Fix | Delete
return array_values($arr);
[27] Fix | Delete
}
[28] Fix | Delete
[29] Fix | Delete
function ninja_forms_letters_to_numbers( $size ) {
[30] Fix | Delete
$l = substr( $size, -1 );
[31] Fix | Delete
$ret = substr( $size, 0, -1 );
[32] Fix | Delete
switch( strtoupper( $l ) ) {
[33] Fix | Delete
case 'P':
[34] Fix | Delete
$ret *= 1024;
[35] Fix | Delete
case 'T':
[36] Fix | Delete
$ret *= 1024;
[37] Fix | Delete
case 'G':
[38] Fix | Delete
$ret *= 1024;
[39] Fix | Delete
case 'M':
[40] Fix | Delete
$ret *= 1024;
[41] Fix | Delete
case 'K':
[42] Fix | Delete
$ret *= 1024;
[43] Fix | Delete
}
[44] Fix | Delete
return $ret;
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
function ninja_forms_subval_sort( $a, $subkey ) {
[48] Fix | Delete
$b = '';
[49] Fix | Delete
foreach($a as $k=>$v) {
[50] Fix | Delete
$b[$k] = strtolower($v[$subkey]);
[51] Fix | Delete
}
[52] Fix | Delete
if ( is_array ( $b ) ) {
[53] Fix | Delete
asort($b);
[54] Fix | Delete
foreach($b as $key=>$val) {
[55] Fix | Delete
$c[] = $a[$key];
[56] Fix | Delete
}
[57] Fix | Delete
return $c;
[58] Fix | Delete
} else {
[59] Fix | Delete
return $a;
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
/**
[65] Fix | Delete
* Takes a field ID and returns the admin label if it exists and the label if it does not.
[66] Fix | Delete
*
[67] Fix | Delete
* @since 2.8
[68] Fix | Delete
* @param int $field_id
[69] Fix | Delete
* @return string $label
[70] Fix | Delete
*/
[71] Fix | Delete
function nf_get_field_admin_label( $field_id, $form_id = '' ) {
[72] Fix | Delete
[73] Fix | Delete
if ( empty ( $form_id ) ) {
[74] Fix | Delete
$form = ninja_forms_get_form_by_field_id( $field_id );
[75] Fix | Delete
$form_id = $form['id'];
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
$admin_label = isset( Ninja_Forms()->form( $form_id )->fields[ $field_id ]['data']['admin_label'] ) ? Ninja_Forms()->form( $form_id )->fields[ $field_id ]['data']['admin_label'] : '';
[79] Fix | Delete
$field_label = isset( Ninja_Forms()->form( $form_id )->fields[ $field_id ]['data']['label'] ) ? Ninja_Forms()->form( $form_id )->fields[ $field_id ]['data']['label'] : '';
[80] Fix | Delete
[81] Fix | Delete
if ( ! empty( $admin_label ) ) {
[82] Fix | Delete
$label = $admin_label;
[83] Fix | Delete
} else {
[84] Fix | Delete
$label = $field_label;
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
return $label;
[88] Fix | Delete
}
[89] Fix | Delete
[90] Fix | Delete
/**
[91] Fix | Delete
* Return the begin date with an added 00:00:00.
[92] Fix | Delete
* Checks for the current date format setting and tries to respect it.
[93] Fix | Delete
*
[94] Fix | Delete
* @since 2.7
[95] Fix | Delete
* @param string $begin_date
[96] Fix | Delete
* @return string $begin_date
[97] Fix | Delete
*/
[98] Fix | Delete
function nf_get_begin_date( $begin_date ) {
[99] Fix | Delete
$plugin_settings = nf_get_settings();
[100] Fix | Delete
[101] Fix | Delete
if ( isset ( $plugin_settings['date_format'] ) ) {
[102] Fix | Delete
$date_format = $plugin_settings['date_format'];
[103] Fix | Delete
} else {
[104] Fix | Delete
$date_format = 'm/d/Y';
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
if ( $date_format == 'd/m/Y' ) {
[108] Fix | Delete
$begin_date = str_replace( '/', '-', $begin_date );
[109] Fix | Delete
} else if ( $date_format == 'm-d-Y' ) {
[110] Fix | Delete
$begin_date = str_replace( '-', '/', $begin_date );
[111] Fix | Delete
}
[112] Fix | Delete
$begin_date .= '00:00:00';
[113] Fix | Delete
$begin_date = new DateTime( $begin_date );
[114] Fix | Delete
[115] Fix | Delete
return $begin_date;
[116] Fix | Delete
}
[117] Fix | Delete
[118] Fix | Delete
/**
[119] Fix | Delete
* Return the end date with an added 23:59:59.
[120] Fix | Delete
* Checks for the current date format setting and tries to respect it.
[121] Fix | Delete
*
[122] Fix | Delete
* @since 2.7
[123] Fix | Delete
* @param string $end_date
[124] Fix | Delete
* @return string $end_date
[125] Fix | Delete
*/
[126] Fix | Delete
function nf_get_end_date( $end_date ) {
[127] Fix | Delete
$plugin_settings = nf_get_settings();
[128] Fix | Delete
[129] Fix | Delete
if ( isset ( $plugin_settings['date_format'] ) ) {
[130] Fix | Delete
$date_format = $plugin_settings['date_format'];
[131] Fix | Delete
} else {
[132] Fix | Delete
$date_format = 'm/d/Y';
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
if ( $date_format == 'd/m/Y' ) {
[136] Fix | Delete
$end_date = str_replace( '/', '-', $end_date );
[137] Fix | Delete
} else if ( $date_format == 'm-d-Y' ) {
[138] Fix | Delete
$end_date = str_replace( '-', '/', $end_date );
[139] Fix | Delete
}
[140] Fix | Delete
$end_date .= '23:59:59';
[141] Fix | Delete
$end_date = new DateTime( $end_date );
[142] Fix | Delete
[143] Fix | Delete
return $end_date;
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
/**
[147] Fix | Delete
* Checks whether function is disabled.
[148] Fix | Delete
*
[149] Fix | Delete
* @since 2.7
[150] Fix | Delete
*
[151] Fix | Delete
* @param string $function Name of the function.
[152] Fix | Delete
* @return bool Whether or not function is disabled.
[153] Fix | Delete
*/
[154] Fix | Delete
if( ! function_exists( 'nf_is_func_disabled' ) ) {
[155] Fix | Delete
function nf_is_func_disabled($function)
[156] Fix | Delete
{
[157] Fix | Delete
$disabled = explode(',', ini_get('disable_functions'));
[158] Fix | Delete
[159] Fix | Delete
return in_array($function, $disabled);
[160] Fix | Delete
}
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
/**
[164] Fix | Delete
* Acts as a wrapper/alias for nf_get_objects_by_type that is specific to notifications.
[165] Fix | Delete
*
[166] Fix | Delete
* @since 2.8
[167] Fix | Delete
* @return array $notifications
[168] Fix | Delete
*/
[169] Fix | Delete
function nf_get_all_notifications() {
[170] Fix | Delete
return nf_get_objects_by_type( 'notification' );
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
/**
[174] Fix | Delete
* Acts as a wrapper/alias for nf_get_object_children that is specific to notifications.
[175] Fix | Delete
*
[176] Fix | Delete
* @since 2.8
[177] Fix | Delete
* @param string $form_id
[178] Fix | Delete
* @return array $notifications
[179] Fix | Delete
*/
[180] Fix | Delete
[181] Fix | Delete
function nf_get_notifications_by_form_id( $form_id, $full_data = true ) {
[182] Fix | Delete
return nf_get_object_children( $form_id, 'notification', $full_data );
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
/**
[186] Fix | Delete
* Acts as a wrapper/alias for nf_get_object_meta
[187] Fix | Delete
*
[188] Fix | Delete
* @since 2.8
[189] Fix | Delete
* @param string $id
[190] Fix | Delete
* @return array $notification
[191] Fix | Delete
*/
[192] Fix | Delete
[193] Fix | Delete
function nf_get_notification_by_id( $notification_id ) {
[194] Fix | Delete
return nf_get_object_meta( $notification_id );
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
/**
[198] Fix | Delete
* Insert a notification into the database.
[199] Fix | Delete
*
[200] Fix | Delete
* Calls nf_insert_object()
[201] Fix | Delete
* Calls nf_add_relationship()
[202] Fix | Delete
* Calls nf_update_object_meta()
[203] Fix | Delete
*
[204] Fix | Delete
* @since 2.8
[205] Fix | Delete
* @param int $form_id
[206] Fix | Delete
* @return int $n_id
[207] Fix | Delete
*/
[208] Fix | Delete
[209] Fix | Delete
function nf_insert_notification( $form_id = '' ) {
[210] Fix | Delete
if ( empty ( $form_id ) )
[211] Fix | Delete
return false;
[212] Fix | Delete
[213] Fix | Delete
$n_id = nf_insert_object( 'notification' );
[214] Fix | Delete
nf_add_relationship( $n_id, 'notification', $form_id, 'form' );
[215] Fix | Delete
$date_updated = date( 'Y-m-d', current_time( 'timestamp' ) );
[216] Fix | Delete
nf_update_object_meta( $n_id, 'date_updated', $date_updated );
[217] Fix | Delete
return $n_id;
[218] Fix | Delete
}
[219] Fix | Delete
[220] Fix | Delete
/**
[221] Fix | Delete
* Delete a notification.
[222] Fix | Delete
*
[223] Fix | Delete
* Acts as a wrapper/alias for nf_delete_object
[224] Fix | Delete
*
[225] Fix | Delete
* @since 2.8
[226] Fix | Delete
* @param int $n_id
[227] Fix | Delete
* @return void
[228] Fix | Delete
*/
[229] Fix | Delete
[230] Fix | Delete
function nf_delete_notification( $n_id ) {
[231] Fix | Delete
nf_delete_object( $n_id );
[232] Fix | Delete
}
[233] Fix | Delete
[234] Fix | Delete
[235] Fix | Delete
/**
[236] Fix | Delete
* Function that gets a piece of object meta
[237] Fix | Delete
*
[238] Fix | Delete
* @since 2.8
[239] Fix | Delete
* @param string $object_id
[240] Fix | Delete
* @param string $meta_key
[241] Fix | Delete
* @return var $meta_value
[242] Fix | Delete
*/
[243] Fix | Delete
[244] Fix | Delete
function nf_get_object_meta_value( $object_id, $meta_key ) {
[245] Fix | Delete
global $wpdb;
[246] Fix | Delete
[247] Fix | Delete
$meta_value = $wpdb->get_row( $wpdb->prepare( 'SELECT meta_value FROM ' . NF_OBJECT_META_TABLE_NAME . ' WHERE object_id = %d AND meta_key = %s', $object_id, $meta_key ), ARRAY_A );
[248] Fix | Delete
if ( is_array ( $meta_value['meta_value'] ) ) {
[249] Fix | Delete
$meta_value['meta_value'] = unserialize( $meta_value['meta_value'] );
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
return $meta_value['meta_value'];
[253] Fix | Delete
}
[254] Fix | Delete
[255] Fix | Delete
[256] Fix | Delete
/**
[257] Fix | Delete
* Function that gets children objects by type and parent id
[258] Fix | Delete
*
[259] Fix | Delete
* @since 2.8
[260] Fix | Delete
* @param string $parent_id
[261] Fix | Delete
* @param string $type
[262] Fix | Delete
* @return array $children
[263] Fix | Delete
*/
[264] Fix | Delete
[265] Fix | Delete
function nf_get_object_children( $object_id, $child_type = '', $full_data = true, $include_forms = true ) {
[266] Fix | Delete
global $wpdb;
[267] Fix | Delete
[268] Fix | Delete
[269] Fix | Delete
if ( $include_forms ) {
[270] Fix | Delete
if ( $child_type != '' ) {
[271] Fix | Delete
$children = $wpdb->get_results( $wpdb->prepare( "SELECT child_id FROM " . NF_OBJECT_RELATIONSHIPS_TABLE_NAME . " WHERE child_type = %s AND parent_id = %d", $child_type, $object_id ), ARRAY_A);
[272] Fix | Delete
} else {
[273] Fix | Delete
$children = $wpdb->get_results( $wpdb->prepare( "SELECT child_id FROM " . NF_OBJECT_RELATIONSHIPS_TABLE_NAME . " WHERE parent_id = %d", $object_id ), ARRAY_A);
[274] Fix | Delete
}
[275] Fix | Delete
} else {
[276] Fix | Delete
if ( $child_type != '' ) {
[277] Fix | Delete
$children = $wpdb->get_results( $wpdb->prepare( "SELECT child_id FROM " . NF_OBJECT_RELATIONSHIPS_TABLE_NAME . " WHERE child_type = %s AND parent_id = %d AND parent_type <> 'form'", $child_type, $object_id ), ARRAY_A);
[278] Fix | Delete
} else {
[279] Fix | Delete
$children = $wpdb->get_results( $wpdb->prepare( "SELECT child_id FROM " . NF_OBJECT_RELATIONSHIPS_TABLE_NAME . " WHERE parent_id = %d AND parent_type <> 'form'", $object_id ), ARRAY_A);
[280] Fix | Delete
}
[281] Fix | Delete
}
[282] Fix | Delete
[283] Fix | Delete
$tmp_array = array();
[284] Fix | Delete
if ( $full_data ) {
[285] Fix | Delete
foreach( $children as $id ) {
[286] Fix | Delete
$child_id = $id['child_id'];
[287] Fix | Delete
$settings = $wpdb->get_results( $wpdb->prepare( "SELECT meta_key, meta_value FROM " . NF_OBJECT_META_TABLE_NAME . " WHERE object_id = %d", $child_id ), ARRAY_A);
[288] Fix | Delete
if ( ! empty( $settings ) ) {
[289] Fix | Delete
foreach ( $settings as $s ) {
[290] Fix | Delete
if ( is_array ( $s['meta_value'] ) ) {
[291] Fix | Delete
$s['meta_value'] = unserialize( $s['meta_value'] );
[292] Fix | Delete
}
[293] Fix | Delete
$tmp_array[ $child_id ][ $s['meta_key'] ] = $s['meta_value'];
[294] Fix | Delete
}
[295] Fix | Delete
} else {
[296] Fix | Delete
$tmp_array[ $child_id ] = array();
[297] Fix | Delete
}
[298] Fix | Delete
}
[299] Fix | Delete
[300] Fix | Delete
[301] Fix | Delete
} else {
[302] Fix | Delete
if ( is_array( $children ) ) {
[303] Fix | Delete
foreach ( $children as $child ) {
[304] Fix | Delete
$tmp_array[] = $child['child_id'];
[305] Fix | Delete
}
[306] Fix | Delete
}
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
return $tmp_array;
[310] Fix | Delete
}
[311] Fix | Delete
[312] Fix | Delete
/**
[313] Fix | Delete
* Function that updates a piece of object meta
[314] Fix | Delete
*
[315] Fix | Delete
* @since 3.0
[316] Fix | Delete
* @param string $object_id
[317] Fix | Delete
* @param string $meta_key
[318] Fix | Delete
* @param string $meta_value
[319] Fix | Delete
* @return string $meta_id
[320] Fix | Delete
*/
[321] Fix | Delete
[322] Fix | Delete
function nf_update_object_meta( $object_id, $meta_key, $meta_value ) {
[323] Fix | Delete
global $wpdb;
[324] Fix | Delete
[325] Fix | Delete
if ( is_array( $meta_value ) ) {
[326] Fix | Delete
$meta_value = serialize( $meta_value );
[327] Fix | Delete
}
[328] Fix | Delete
[329] Fix | Delete
// Check to see if this meta_key/meta_value pair exist for this object_id.
[330] Fix | Delete
$found = $wpdb->get_row( $wpdb->prepare( "SELECT id FROM ".NF_OBJECT_META_TABLE_NAME." WHERE object_id = %d AND meta_key = %s", $object_id, $meta_key ), ARRAY_A );
[331] Fix | Delete
[332] Fix | Delete
if ( $found ) {
[333] Fix | Delete
$wpdb->update( NF_OBJECT_META_TABLE_NAME, array( 'meta_value' => $meta_value ), array( 'meta_key' => $meta_key, 'object_id' => $object_id ) );
[334] Fix | Delete
$meta_id = $found['id'];
[335] Fix | Delete
} else {
[336] Fix | Delete
$wpdb->insert( NF_OBJECT_META_TABLE_NAME, array( 'object_id' => $object_id, 'meta_key' => $meta_key, 'meta_value' => $meta_value ) );
[337] Fix | Delete
$meta_id = $wpdb->insert_id;
[338] Fix | Delete
}
[339] Fix | Delete
[340] Fix | Delete
return $meta_id;
[341] Fix | Delete
}
[342] Fix | Delete
[343] Fix | Delete
/**
[344] Fix | Delete
* Function that gets all the meta values attached to a given object.
[345] Fix | Delete
*
[346] Fix | Delete
* @since 2.8
[347] Fix | Delete
* @param string $object
[348] Fix | Delete
* @return array $settings
[349] Fix | Delete
*/
[350] Fix | Delete
function nf_get_object_meta( $object_id ) {
[351] Fix | Delete
global $wpdb;
[352] Fix | Delete
[353] Fix | Delete
$tmp_array = array();
[354] Fix | Delete
$settings = $wpdb->get_results( $wpdb->prepare( 'SELECT meta_key, meta_value FROM ' . NF_OBJECT_META_TABLE_NAME . ' WHERE object_id = %d', $object_id ), ARRAY_A);
[355] Fix | Delete
[356] Fix | Delete
if ( is_array( $settings ) ) {
[357] Fix | Delete
foreach( $settings as $setting ) {
[358] Fix | Delete
$tmp_array[ $setting['meta_key'] ] = $setting['meta_value'] = maybe_unserialize( $setting['meta_value'] );
[359] Fix | Delete
}
[360] Fix | Delete
}
[361] Fix | Delete
[362] Fix | Delete
return $tmp_array;
[363] Fix | Delete
}
[364] Fix | Delete
[365] Fix | Delete
/**
[366] Fix | Delete
* Insert an object.
[367] Fix | Delete
*
[368] Fix | Delete
* @since 3.0
[369] Fix | Delete
* @param string $type
[370] Fix | Delete
* @return int $object_id
[371] Fix | Delete
*/
[372] Fix | Delete
[373] Fix | Delete
function nf_insert_object( $type, $id = NULL ) {
[374] Fix | Delete
global $wpdb;
[375] Fix | Delete
$wpdb->insert( NF_OBJECTS_TABLE_NAME, array( 'id' => $id, 'type' => $type ) );
[376] Fix | Delete
return $wpdb->insert_id;
[377] Fix | Delete
}
[378] Fix | Delete
[379] Fix | Delete
/**
[380] Fix | Delete
* Delete an object. Also removes all of the objectmeta attached to the object and any references to it in the relationship table.
[381] Fix | Delete
*
[382] Fix | Delete
* @since 2.8
[383] Fix | Delete
* @param int $object_id
[384] Fix | Delete
* @return bool
[385] Fix | Delete
*/
[386] Fix | Delete
[387] Fix | Delete
function nf_delete_object( $object_id ) {
[388] Fix | Delete
global $wpdb;
[389] Fix | Delete
[390] Fix | Delete
// Check to see if we have any object children.
[391] Fix | Delete
$children = nf_get_object_children( $object_id, '', false, false );
[392] Fix | Delete
[393] Fix | Delete
foreach ( $children as $child_id ) {
[394] Fix | Delete
nf_delete_object( $child_id );
[395] Fix | Delete
}
[396] Fix | Delete
[397] Fix | Delete
// Delete this object.
[398] Fix | Delete
$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . NF_OBJECTS_TABLE_NAME .' WHERE id = %d', $object_id ) );
[399] Fix | Delete
[400] Fix | Delete
// Delete any objectmeta attached to this object.
[401] Fix | Delete
$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . NF_OBJECT_META_TABLE_NAME .' WHERE object_id = %d', $object_id ) );
[402] Fix | Delete
[403] Fix | Delete
// Delete any references to this object in the relationship table
[404] Fix | Delete
$wpdb->query( $wpdb->prepare( 'DELETE FROM ' . NF_OBJECT_RELATIONSHIPS_TABLE_NAME .' WHERE child_id = %d OR parent_id = %d', $object_id, $object_id ) );
[405] Fix | Delete
[406] Fix | Delete
return true;
[407] Fix | Delete
}
[408] Fix | Delete
[409] Fix | Delete
[410] Fix | Delete
/**
[411] Fix | Delete
* Create a relationship between two objects
[412] Fix | Delete
*
[413] Fix | Delete
* @since 2.8
[414] Fix | Delete
* @param int $child_id
[415] Fix | Delete
* @param string child_type
[416] Fix | Delete
* @param int $parent_id
[417] Fix | Delete
* @param string $parent_type
[418] Fix | Delete
* @return void
[419] Fix | Delete
*/
[420] Fix | Delete
[421] Fix | Delete
function nf_add_relationship( $child_id, $child_type, $parent_id, $parent_type ) {
[422] Fix | Delete
global $wpdb;
[423] Fix | Delete
// Make sure that our relationship doesn't already exist.
[424] Fix | Delete
$count = $wpdb->query( $wpdb->prepare( 'SELECT id FROM ' . NF_OBJECT_RELATIONSHIPS_TABLE_NAME .' WHERE child_id = %d AND parent_id = %d', $child_id, $parent_id ), ARRAY_A );
[425] Fix | Delete
if ( empty( $count ) ) {
[426] Fix | Delete
$wpdb->insert( NF_OBJECT_RELATIONSHIPS_TABLE_NAME, array( 'child_id' => $child_id, 'child_type' => $child_type, 'parent_id' => $parent_id, 'parent_type' => $parent_type ) );
[427] Fix | Delete
}
[428] Fix | Delete
}
[429] Fix | Delete
[430] Fix | Delete
/**
[431] Fix | Delete
* Get an object's parent
[432] Fix | Delete
*
[433] Fix | Delete
* @since 2.8
[434] Fix | Delete
* @param int $child_id
[435] Fix | Delete
* @return int $parent_id
[436] Fix | Delete
*/
[437] Fix | Delete
[438] Fix | Delete
function nf_get_object_parent( $child_id ) {
[439] Fix | Delete
global $wpdb;
[440] Fix | Delete
// Check our relationship table for where this ID appears as a child.
[441] Fix | Delete
$parent = $wpdb->get_row( $wpdb->prepare( 'SELECT parent_id FROM ' . NF_OBJECT_RELATIONSHIPS_TABLE_NAME . ' WHERE child_id = %d', $child_id ), ARRAY_A );
[442] Fix | Delete
return $parent['parent_id'];
[443] Fix | Delete
}
[444] Fix | Delete
[445] Fix | Delete
/**
[446] Fix | Delete
* Get an object's type
[447] Fix | Delete
*
[448] Fix | Delete
* @since 2.8.6
[449] Fix | Delete
* @param $object_id
[450] Fix | Delete
* @return string $return
[451] Fix | Delete
*/
[452] Fix | Delete
[453] Fix | Delete
function nf_get_object_type( $object_id ) {
[454] Fix | Delete
global $wpdb;
[455] Fix | Delete
// Get our object type
[456] Fix | Delete
$type = $wpdb->get_row( $wpdb->prepare( 'SELECT type FROM ' . NF_OBJECTS_TABLE_NAME . ' WHERE id = %d', $object_id ), ARRAY_A );
[457] Fix | Delete
$return = ( isset ( $type['type'] ) ) ? $type['type'] : false;
[458] Fix | Delete
return $return;
[459] Fix | Delete
}
[460] Fix | Delete
[461] Fix | Delete
/*
[462] Fix | Delete
* Get User IP
[463] Fix | Delete
*
[464] Fix | Delete
* Returns the IP address of the current visitor
[465] Fix | Delete
*
[466] Fix | Delete
* @since 2.8
[467] Fix | Delete
* @return string $ip User's IP address
[468] Fix | Delete
*/
[469] Fix | Delete
function nf_get_ip() {
[470] Fix | Delete
[471] Fix | Delete
$ip = '127.0.0.1';
[472] Fix | Delete
[473] Fix | Delete
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
[474] Fix | Delete
//check ip from share internet
[475] Fix | Delete
$ip = $_SERVER['HTTP_CLIENT_IP'];
[476] Fix | Delete
} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
[477] Fix | Delete
//to check ip is pass from proxy
[478] Fix | Delete
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
[479] Fix | Delete
} elseif( ! empty( $_SERVER['REMOTE_ADDR'] ) ) {
[480] Fix | Delete
$ip = $_SERVER['REMOTE_ADDR'];
[481] Fix | Delete
}
[482] Fix | Delete
return apply_filters( 'nf_get_ip', $ip );
[483] Fix | Delete
}
[484] Fix | Delete
[485] Fix | Delete
[486] Fix | Delete
/**
[487] Fix | Delete
* Function that gets all objects of a given type.
[488] Fix | Delete
*
[489] Fix | Delete
* @since 2.8
[490] Fix | Delete
* @return array $results
[491] Fix | Delete
*/
[492] Fix | Delete
[493] Fix | Delete
function nf_get_objects_by_type( $object_type ) {
[494] Fix | Delete
global $wpdb;
[495] Fix | Delete
[496] Fix | Delete
// Bail if we don't have an object type.
[497] Fix | Delete
if ( $object_type == '' )
[498] Fix | Delete
return false;
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function