Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all 8245 articles
Browse latest View live

ajinp on "suspicious file : nav-menu.php"

$
0
0

Hello All,

In my WordPress installation, malware scan has detected a file called "nav-menu.php". When I removed the file, the site is not working. Can any one tell me what is the use of this file?

It shows the following error.
===================================================================

Warning: require(/home/user/public_html/wp-includes/nav-menu.php): failed to open stream: No such file or directory in /home/user/public_html/wp-settings.php on line 153

===================================================================

I am pasting the content of this php file here.

===================================================================

* @subpackage Nav_Menus
* @since 3.0.0
*/

/**
* Returns a navigation menu object.
*
* @since 3.0.0
*
* @uses get_term
* @uses get_term_by
*
* @param string $menu Menu ID, slug, or name.
* @return mixed false if $menu param isn't supplied or term does not exist, menu object if successful.
*/
function wp_get_nav_menu_object( $menu ) {
if ( ! $menu )
return false;

$menu_obj = get_term( $menu, 'nav_menu' );

if ( ! $menu_obj )
$menu_obj = get_term_by( 'slug', $menu, 'nav_menu' );

if ( ! $menu_obj )
$menu_obj = get_term_by( 'name', $menu, 'nav_menu' );

if ( ! $menu_obj )
$menu_obj = false;

return $menu_obj;
}

/**
* Check if the given ID is a navigation menu.
*
* Returns true if it is; false otherwise.
*
* @since 3.0.0
*
* @param int|string $menu The menu to check (ID, slug, or name).
* @return bool Whether the menu exists.
*/
function is_nav_menu( $menu ) {
if ( ! $menu )
return false;

$menu_obj = wp_get_nav_menu_object( $menu );

if (
$menu_obj &&
! is_wp_error( $menu_obj ) &&
! empty( $menu_obj->taxonomy ) &&
'nav_menu' == $menu_obj->taxonomy
)
return true;

return false;
}

/**
* Register navigation menus for a theme.
*
* @since 3.0.0
*
* @param array $locations Associative array of menu location identifiers (like a slug) and descriptive text.
*/
function register_nav_menus( $locations = array() ) {
global $_wp_registered_nav_menus;

add_theme_support( 'menus' );

$_wp_registered_nav_menus = array_merge( (array) $_wp_registered_nav_menus, $locations );
}

/**
* Unregisters a navigation menu for a theme.
*
* @param array $location the menu location identifier
*
* @return bool True on success, false on failure.
*/
function unregister_nav_menu( $location ) {
global $_wp_registered_nav_menus;

if ( is_array( $_wp_registered_nav_menus ) && isset( $_wp_registered_nav_menus[$location] ) ) {
unset( $_wp_registered_nav_menus[$location] );
if ( empty( $_wp_registered_nav_menus ) ) {
_remove_theme_support( 'menus' );
}
return true;
}
return false;
}

/**
* Register a navigation menu for a theme.
*
* @since 3.0.0
*
* @param string $location Menu location identifier, like a slug.
* @param string $description Menu location descriptive text.
*/
function register_nav_menu( $location, $description ) {
register_nav_menus( array( $location => $description ) );
}
/**
* Returns an array of all registered navigation menus in a theme
*
* @since 3.0.0
* @return array
*/
function get_registered_nav_menus() {
global $_wp_registered_nav_menus;
if ( isset( $_wp_registered_nav_menus ) )
return $_wp_registered_nav_menus;
return array();
}

/**
* Returns an array with the registered navigation menu locations and the menu assigned to it
*
* @since 3.0.0
* @return array
*/

function get_nav_menu_locations() {
$locations = get_theme_mod( 'nav_menu_locations' );
return ( is_array( $locations ) ) ? $locations : array();
}

/**
* Whether a registered nav menu location has a menu assigned to it.
*
* @since 3.0.0
* @param string $location Menu location identifier.
* @return bool Whether location has a menu.
*/
function has_nav_menu( $location ) {
global $_wp_registered_nav_menus;

if ( ! isset( $_wp_registered_nav_menus[ $location ] ) ) {
return false;
}

$locations = get_nav_menu_locations();
return ( ! empty( $locations[ $location ] ) );
}

/**
* Determine whether the given ID is a nav menu item.
*
* @since 3.0.0
*
* @param int $menu_item_id The ID of the potential nav menu item.
* @return bool Whether the given ID is that of a nav menu item.
*/
function is_nav_menu_item( $menu_item_id = 0 ) {
return ( ! is_wp_error( $menu_item_id ) && ( 'nav_menu_item' == get_post_type( $menu_item_id ) ) );
}

/**
* Create a Navigation Menu.
*
* @since 3.0.0
*
* @param string $menu_name Menu name.
* @return int|WP_Error Menu ID on success, WP_Error object on failure.
*/
function wp_create_nav_menu( $menu_name ) {
return wp_update_nav_menu_object( 0, array( 'menu-name' => $menu_name ) );
}

/**
* Delete a Navigation Menu.
*
* @since 3.0.0
*
* @param string $menu Menu ID, slug, or name.
* @return bool|WP_Error True on success, false or WP_Error object on failure.
*/
function wp_delete_nav_menu( $menu ) {
$menu = wp_get_nav_menu_object( $menu );
if ( ! $menu )
return false;

$menu_objects = get_objects_in_term( $menu->term_id, 'nav_menu' );
if ( ! empty( $menu_objects ) ) {
foreach ( $menu_objects as $item ) {
wp_delete_post( $item );
}
}

$result = wp_delete_term( $menu->term_id, 'nav_menu' );

// Remove this menu from any locations.
$locations = get_nav_menu_locations();
foreach ( $locations as $location => $menu_id ) {
if ( $menu_id == $menu->term_id )
$locations[ $location ] = 0;
}
set_theme_mod( 'nav_menu_locations', $locations );

if ( $result && !is_wp_error($result) )

/**
* Fires after a navigation menu has been successfully deleted.
*
* @since 3.0.0
*
* @param int $term_id ID of the deleted menu.
*/
do_action( 'wp_delete_nav_menu', $menu->term_id );

return $result;
}

/**
* Save the properties of a menu or create a new menu with those properties.
*
* @since 3.0.0
*
* @param int $menu_id The ID of the menu or "0" to create a new menu.
* @param array $menu_data The array of menu data.
* @return int|WP_Error Menu ID on success, WP_Error object on failure.
*/
function wp_update_nav_menu_object( $menu_id = 0, $menu_data = array() ) {
$menu_id = (int) $menu_id;

$_menu = wp_get_nav_menu_object( $menu_id );

$args = array(
'description' => ( isset( $menu_data['description'] ) ? $menu_data['description'] : '' ),
'name' => ( isset( $menu_data['menu-name'] ) ? $menu_data['menu-name'] : '' ),
'parent' => ( isset( $menu_data['parent'] ) ? (int) $menu_data['parent'] : 0 ),
'slug' => null,
);

// double-check that we're not going to have one menu take the name of another
$_possible_existing = get_term_by( 'name', $menu_data['menu-name'], 'nav_menu' );
if (
$_possible_existing &&
! is_wp_error( $_possible_existing ) &&
isset( $_possible_existing->term_id ) &&
$_possible_existing->term_id != $menu_id
)
return new WP_Error( 'menu_exists', sprintf( __('The menu name %s conflicts with another menu name. Please try another.'), esc_html( $menu_data['menu-name'] ) ) );

// menu doesn't already exist, so create a new menu
if ( ! $_menu || is_wp_error( $_menu ) ) {
$menu_exists = get_term_by( 'name', $menu_data['menu-name'], 'nav_menu' );

if ( $menu_exists )
return new WP_Error( 'menu_exists', sprintf( __('The menu name %s conflicts with another menu name. Please try another.'), esc_html( $menu_data['menu-name'] ) ) );

$_menu = wp_insert_term( $menu_data['menu-name'], 'nav_menu', $args );

if ( is_wp_error( $_menu ) )
return $_menu;

/**
* Fires after a navigation menu is successfully created.
*
* @since 3.0.0
*
* @param int $term_id ID of the new menu.
* @param array $menu_data An array of menu data.
*/
do_action( 'wp_create_nav_menu', $_menu['term_id'], $menu_data );

return (int) $_menu['term_id'];
}

if ( ! $_menu || ! isset( $_menu->term_id ) )
return 0;

$menu_id = (int) $_menu->term_id;

$update_response = wp_update_term( $menu_id, 'nav_menu', $args );

if ( is_wp_error( $update_response ) )
return $update_response;

/**
* Fires after a navigation menu has been successfully updated.
*
* @since 3.0.0
*
* @param int $menu_id ID of the updated menu.
* @param array $menu_data An array of menu data.
*/
do_action( 'wp_update_nav_menu', $menu_id, $menu_data );
return $menu_id;
}

/**
* Save the properties of a menu item or create a new one.
*
* @since 3.0.0
*
* @param int $menu_id The ID of the menu. Required. If "0", makes the menu item a draft orphan.
* @param int $menu_item_db_id The ID of the menu item. If "0", creates a new menu item.
* @param array $menu_item_data The menu item's data.
* @return int|WP_Error The menu item's database ID or WP_Error object on failure.
*/
function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item_data = array() ) {
$menu_id = (int) $menu_id;
$menu_item_db_id = (int) $menu_item_db_id;

// make sure that we don't convert non-nav_menu_item objects into nav_menu_item objects
if ( ! empty( $menu_item_db_id ) && ! is_nav_menu_item( $menu_item_db_id ) )
return new WP_Error( 'update_nav_menu_item_failed', __( 'The given object ID is not that of a menu item.' ) );

$menu = wp_get_nav_menu_object( $menu_id );

if ( ! $menu && 0 !== $menu_id ) {
return new WP_Error( 'invalid_menu_id', __( 'Invalid menu ID.' ) );
}

if ( is_wp_error( $menu ) ) {
return $menu;
}

$defaults = array(
'menu-item-db-id' => $menu_item_db_id,
'menu-item-object-id' => 0,
'menu-item-object' => '',
'menu-item-parent-id' => 0,
'menu-item-position' => 0,
'menu-item-type' => 'custom',
'menu-item-title' => '',
'menu-item-url' => '',
'menu-item-description' => '',
'menu-item-attr-title' => '',
'menu-item-target' => '',
'menu-item-classes' => '',
'menu-item-xfn' => '',
'menu-item-status' => '',
);

$args = wp_parse_args( $menu_item_data, $defaults );

if ( 0 == $menu_id ) {
$args['menu-item-position'] = 1;
} elseif ( 0 == (int) $args['menu-item-position'] ) {
$menu_items = 0 == $menu_id ? array() : (array) wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) );
$last_item = array_pop( $menu_items );
$args['menu-item-position'] = ( $last_item && isset( $last_item->menu_order ) ) ? 1 + $last_item->menu_order : count( $menu_items );
}

$original_parent = 0 < $menu_item_db_id ? get_post_field( 'post_parent', $menu_item_db_id ) : 0;

if ( 'custom' != $args['menu-item-type'] ) {
/* if non-custom menu item, then:
* use original object's URL
* blank default title to sync with original object's
*/

$args['menu-item-url'] = '';

$original_title = '';
if ( 'taxonomy' == $args['menu-item-type'] ) {
$original_parent = get_term_field( 'parent', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' );
$original_title = get_term_field( 'name', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' );
} elseif ( 'post_type' == $args['menu-item-type'] ) {

$original_object = get_post( $args['menu-item-object-id'] );
$original_parent = (int) $original_object->post_parent;
$original_title = $original_object->post_title;
}

if ( $args['menu-item-title'] == $original_title )
$args['menu-item-title'] = '';

// hack to get wp to create a post object when too many properties are empty
if ( '' == $args['menu-item-title'] && '' == $args['menu-item-description'] )
$args['menu-item-description'] = ' ';
}

// Populate the menu item object
$post = array(
'menu_order' => $args['menu-item-position'],
'ping_status' => 0,
'post_content' => $args['menu-item-description'],
'post_excerpt' => $args['menu-item-attr-title'],
'post_parent' => $original_parent,
'post_title' => $args['menu-item-title'],
'post_type' => 'nav_menu_item',
);

$update = 0 != $menu_item_db_id;

// New menu item. Default is draft status
if ( ! $update ) {
$post['ID'] = 0;
$post['post_status'] = 'publish' == $args['menu-item-status'] ? 'publish' : 'draft';
$menu_item_db_id = wp_insert_post( $post );
if ( ! $menu_item_db_id || is_wp_error( $menu_item_db_id ) )
return $menu_item_db_id;
}

// Associate the menu item with the menu term
// Only set the menu term if it isn't set to avoid unnecessary wp_get_object_terms()
if ( $menu_id && ( ! $update || ! is_object_in_term( $menu_item_db_id, 'nav_menu', (int) $menu->term_id ) ) ) {
wp_set_object_terms( $menu_item_db_id, array( $menu->term_id ), 'nav_menu' );
}

if ( 'custom' == $args['menu-item-type'] ) {
$args['menu-item-object-id'] = $menu_item_db_id;
$args['menu-item-object'] = 'custom';
}

$menu_item_db_id = (int) $menu_item_db_id;

update_post_meta( $menu_item_db_id, '_menu_item_type', sanitize_key($args['menu-item-type']) );
update_post_meta( $menu_item_db_id, '_menu_item_menu_item_parent', strval( (int) $args['menu-item-parent-id'] ) );
update_post_meta( $menu_item_db_id, '_menu_item_object_id', strval( (int) $args['menu-item-object-id'] ) );
update_post_meta( $menu_item_db_id, '_menu_item_object', sanitize_key($args['menu-item-object']) );
update_post_meta( $menu_item_db_id, '_menu_item_target', sanitize_key($args['menu-item-target']) );

$args['menu-item-classes'] = array_map( 'sanitize_html_class', explode( ' ', $args['menu-item-classes'] ) );
$args['menu-item-xfn'] = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['menu-item-xfn'] ) ) );
update_post_meta( $menu_item_db_id, '_menu_item_classes', $args['menu-item-classes'] );
update_post_meta( $menu_item_db_id, '_menu_item_xfn', $args['menu-item-xfn'] );
update_post_meta( $menu_item_db_id, '_menu_item_url', esc_url_raw($args['menu-item-url']) );

if ( 0 == $menu_id )
update_post_meta( $menu_item_db_id, '_menu_item_orphaned', (string) time() );
elseif ( get_post_meta( $menu_item_db_id, '_menu_item_orphaned' ) )
delete_post_meta( $menu_item_db_id, '_menu_item_orphaned' );

// Update existing menu item. Default is publish status
if ( $update ) {
$post['ID'] = $menu_item_db_id;
$post['post_status'] = 'draft' == $args['menu-item-status'] ? 'draft' : 'publish';
wp_update_post( $post );
}

/**
* Fires after a navigation menu item has been updated.
*
* @since 3.0.0
*
* @see wp_update_nav_menu_items()
*
* @param int $menu_id ID of the updated menu.
* @param int $menu_item_db_id ID of the updated menu item.
* @param array $args An array of arguments used to update a menu item.
*/
do_action( 'wp_update_nav_menu_item', $menu_id, $menu_item_db_id, $args );

return $menu_item_db_id;
}

/**
* Returns all navigation menu objects.
*
* @since 3.0.0
*
* @param array $args Array of arguments passed on to get_terms().
* @return array menu objects
*/
function wp_get_nav_menus( $args = array() ) {
$defaults = array( 'hide_empty' => false, 'orderby' => 'none' );
$args = wp_parse_args( $args, $defaults );

/**
* Filter the navigation menu objects being returned.
*
* @since 3.0.0
*
* @see get_terms()
*
* @param array $menus An array of menu objects.
* @param array $args An array of arguments used to retrieve menu objects.
*/
return apply_filters( 'wp_get_nav_menus', get_terms( 'nav_menu', $args), $args );
}

/**
* Sort menu items by the desired key.
*
* @since 3.0.0
* @access private
*
* @param object $a The first object to compare
* @param object $b The second object to compare
* @return int -1, 0, or 1 if $a is considered to be respectively less than, equal to, or greater than $b.
*/
function _sort_nav_menu_items( $a, $b ) {
global $_menu_item_sort_prop;

if ( empty( $_menu_item_sort_prop ) )
return 0;

if ( ! isset( $a->$_menu_item_sort_prop ) || ! isset( $b->$_menu_item_sort_prop ) )
return 0;

$_a = (int) $a->$_menu_item_sort_prop;
$_b = (int) $b->$_menu_item_sort_prop;

if ( $a->$_menu_item_sort_prop == $b->$_menu_item_sort_prop )
return 0;
elseif ( $_a == $a->$_menu_item_sort_prop && $_b == $b->$_menu_item_sort_prop )
return $_a < $_b ? -1 : 1;
else
return strcmp( $a->$_menu_item_sort_prop, $b->$_menu_item_sort_prop );
}

/**
* Returns if a menu item is valid. Bug #13958
*
* @since 3.2.0
* @access private
*
* @param object $menu_item The menu item to check
* @return bool false if invalid, else true.
*/
function _is_valid_nav_menu_item( $item ) {
if ( ! empty( $item->_invalid ) )
return false;

return true;
}

/**
* Returns all menu items of a navigation menu.
*
* @since 3.0.0
*
* @param string $menu menu name, id, or slug
* @param string $args
* @return mixed $items array of menu items, else false.
*/
function wp_get_nav_menu_items( $menu, $args = array() ) {
$menu = wp_get_nav_menu_object( $menu );

if ( ! $menu )
return false;

static $fetched = array();

$items = get_objects_in_term( $menu->term_id, 'nav_menu' );

if ( empty( $items ) )
return $items;

$defaults = array( 'order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item',
'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true );
$args = wp_parse_args( $args, $defaults );
$args['include'] = $items;

$items = get_posts( $args );

if ( is_wp_error( $items ) || ! is_array( $items ) )
return false;

// Get all posts and terms at once to prime the caches
if ( empty( $fetched[$menu->term_id] ) || wp_using_ext_object_cache() ) {
$fetched[$menu->term_id] = true;
$posts = array();
$terms = array();
foreach ( $items as $item ) {
$object_id = get_post_meta( $item->ID, '_menu_item_object_id', true );
$object = get_post_meta( $item->ID, '_menu_item_object', true );
$type = get_post_meta( $item->ID, '_menu_item_type', true );

if ( 'post_type' == $type )
$posts[$object][] = $object_id;
elseif ( 'taxonomy' == $type)
$terms[$object][] = $object_id;
}

if ( ! empty( $posts ) ) {
foreach ( array_keys($posts) as $post_type ) {
get_posts( array('post__in' => $posts[$post_type], 'post_type' => $post_type, 'nopaging' => true, 'update_post_term_cache' => false) );
}
}
unset($posts);

if ( ! empty( $terms ) ) {
foreach ( array_keys($terms) as $taxonomy ) {
get_terms($taxonomy, array('include' => $terms[$taxonomy]) );
}
}
unset($terms);
}

$items = array_map( 'wp_setup_nav_menu_item', $items );

if ( ! is_admin() ) // Remove invalid items only in frontend
$items = array_filter( $items, '_is_valid_nav_menu_item' );

if ( ARRAY_A == $args['output'] ) {
$GLOBALS['_menu_item_sort_prop'] = $args['output_key'];
usort($items, '_sort_nav_menu_items');
$i = 1;
foreach( $items as $k => $item ) {
$items[$k]->$args['output_key'] = $i++;
}
}

/**
* Filter the navigation menu items being returned.
*
* @since 3.0.0
*
* @param array $items An array of menu item post objects.
* @param object $menu The menu object.
* @param array $args An array of arguments used to retrieve menu item objects.
*/
return apply_filters( 'wp_get_nav_menu_items', $items, $menu, $args );
}

/**
* Decorates a menu item object with the shared navigation menu item properties.
*
* Properties:
* - db_id: The DB ID of this item as a nav_menu_item object, if it exists (0 if it doesn't exist).
* - object_id: The DB ID of the original object this menu item represents, e.g. ID for posts and term_id for categories.
* - type: The family of objects originally represented, such as "post_type" or "taxonomy."
* - object: The type of object originally represented, such as "category," "post", or "attachment."
* - type_label: The singular label used to describe this type of menu item.
* - post_parent: The DB ID of the original object's parent object, if any (0 otherwise).
* - menu_item_parent: The DB ID of the nav_menu_item that is this item's menu parent, if any. 0 otherwise.
* - url: The URL to which this menu item points.
* - title: The title of this menu item.
* - target: The target attribute of the link element for this menu item.
* - attr_title: The title attribute of the link element for this menu item.
* - classes: The array of class attribute values for the link element of this menu item.
* - xfn: The XFN relationship expressed in the link of this menu item.
* - description: The description of this menu item.
*
* @since 3.0.0
*
* @param object $menu_item The menu item to modify.
* @return object $menu_item The menu item with standard menu item properties.
*/
function wp_setup_nav_menu_item( $menu_item ) {
if ( isset( $menu_item->post_type ) ) {
if ( 'nav_menu_item' == $menu_item->post_type ) {
$menu_item->db_id = (int) $menu_item->ID;
$menu_item->menu_item_parent = empty( $menu_item->menu_item_parent ) ? get_post_meta( $menu_item->ID, '_menu_item_menu_item_parent', true ) : $menu_item->menu_item_parent;
$menu_item->object_id = empty( $menu_item->object_id ) ? get_post_meta( $menu_item->ID, '_menu_item_object_id', true ) : $menu_item->object_id;
$menu_item->object = empty( $menu_item->object ) ? get_post_meta( $menu_item->ID, '_menu_item_object', true ) : $menu_item->object;
$menu_item->type = empty( $menu_item->type ) ? get_post_meta( $menu_item->ID, '_menu_item_type', true ) : $menu_item->type;

if ( 'post_type' == $menu_item->type ) {
$object = get_post_type_object( $menu_item->object );
if ( $object ) {
$menu_item->type_label = $object->labels->singular_name;
} else {
$menu_item->type_label = $menu_item->object;
$menu_item->_invalid = true;
}

$menu_item->url = get_permalink( $menu_item->object_id );

$original_object = get_post( $menu_item->object_id );
$original_title = $original_object->post_title;
$menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title;

} elseif ( 'taxonomy' == $menu_item->type ) {
$object = get_taxonomy( $menu_item->object );
if ( $object ) {
$menu_item->type_label = $object->labels->singular_name;
} else {
$menu_item->type_label = $menu_item->object;
$menu_item->_invalid = true;
}

$term_url = get_term_link( (int) $menu_item->object_id, $menu_item->object );
$menu_item->url = !is_wp_error( $term_url ) ? $term_url : '';

$original_title = get_term_field( 'name', $menu_item->object_id, $menu_item->object, 'raw' );
if ( is_wp_error( $original_title ) )
$original_title = false;
$menu_item->title = '' == $menu_item->post_title ? $original_title : $menu_item->post_title;

} else {
$menu_item->type_label = __('Custom');
$menu_item->title = $menu_item->post_title;
$menu_item->url = empty( $menu_item->url ) ? get_post_meta( $menu_item->ID, '_menu_item_url', true ) : $menu_item->url;
}

$menu_item->target = empty( $menu_item->target ) ? get_post_meta( $menu_item->ID, '_menu_item_target', true ) : $menu_item->target;

/**
* Filter a navigation menu item's title attribute.
*
* @since 3.0.0
*
* @param string $item_title The menu item title attribute.
*/
$menu_item->attr_title = empty( $menu_item->attr_title ) ? apply_filters( 'nav_menu_attr_title', $menu_item->post_excerpt ) : $menu_item->attr_title;

if ( empty( $menu_item->description ) ) {
/**
* Filter a navigation menu item's description.
*
* @since 3.0.0
*
* @param string $description The menu item description.
*/
$menu_item->description = apply_filters( 'nav_menu_description', wp_trim_words( $menu_item->post_content, 200 ) );
}

$menu_item->classes = empty( $menu_item->classes ) ? (array) get_post_meta( $menu_item->ID, '_menu_item_classes', true ) : $menu_item->classes;
$menu_item->xfn = empty( $menu_item->xfn ) ? get_post_meta( $menu_item->ID, '_menu_item_xfn', true ) : $menu_item->xfn;
} else {
$menu_item->db_id = 0;
$menu_item->menu_item_parent = 0;
$menu_item->object_id = (int) $menu_item->ID;
$menu_item->type = 'post_type';

$object = get_post_type_object( $menu_item->post_type );
$menu_item->object = $object->name;
$menu_item->type_label = $object->labels->singular_name;

if ( '' === $menu_item->post_title )
$menu_item->post_title = sprintf( __( '#%d (no title)' ), $menu_item->ID );

$menu_item->title = $menu_item->post_title;
$menu_item->url = get_permalink( $menu_item->ID );
$menu_item->target = '';

/** This filter is documented in wp-includes/nav-menu.php */
$menu_item->attr_title = apply_filters( 'nav_menu_attr_title', '' );

/** This filter is documented in wp-includes/nav-menu.php */
$menu_item->description = apply_filters( 'nav_menu_description', '' );
$menu_item->classes = array();
$menu_item->xfn = '';
}
} elseif ( isset( $menu_item->taxonomy ) ) {
$menu_item->ID = $menu_item->term_id;
$menu_item->db_id = 0;
$menu_item->menu_item_parent = 0;
$menu_item->object_id = (int) $menu_item->term_id;
$menu_item->post_parent = (int) $menu_item->parent;
$menu_item->type = 'taxonomy';

$object = get_taxonomy( $menu_item->taxonomy );
$menu_item->object = $object->name;
$menu_item->type_label = $object->labels->singular_name;

$menu_item->title = $menu_item->name;
$menu_item->url = get_term_link( $menu_item, $menu_item->taxonomy );
$menu_item->target = '';
$menu_item->attr_title = '';
$menu_item->description = get_term_field( 'description', $menu_item->term_id, $menu_item->taxonomy );
$menu_item->classes = array();
$menu_item->xfn = '';

}

/**
* Filter a navigation menu item object.
*
* @since 3.0.0
*
* @param object $menu_item The menu item object.
*/
return apply_filters( 'wp_setup_nav_menu_item', $menu_item );
}

/**
* Get the menu items associated with a particular object.
*
* @since 3.0.0
*
* @param int $object_id The ID of the original object.
* @param string $object_type The type of object, such as "taxonomy" or "post_type."
* @param string $taxonomy If $object_type is "taxonomy", $taxonomy is the name of the tax that $object_id belongs to
* @return array The array of menu item IDs; empty array if none;
*/
function wp_get_associated_nav_menu_items( $object_id = 0, $object_type = 'post_type', $taxonomy = '' ) {
$object_id = (int) $object_id;
$menu_item_ids = array();

$query = new WP_Query;
$menu_items = $query->query(
array(
'meta_key' => '_menu_item_object_id',
'meta_value' => $object_id,
'post_status' => 'any',
'post_type' => 'nav_menu_item',
'posts_per_page' => -1,
)
);
foreach( (array) $menu_items as $menu_item ) {
if ( isset( $menu_item->ID ) && is_nav_menu_item( $menu_item->ID ) ) {
$menu_item_type = get_post_meta( $menu_item->ID, '_menu_item_type', true );
if (
'post_type' == $object_type &&
'post_type' == $menu_item_type
) {
$menu_item_ids[] = (int) $menu_item->ID;
} else if (
'taxonomy' == $object_type &&
'taxonomy' == $menu_item_type &&
get_post_meta( $menu_item->ID, '_menu_item_object', true ) == $taxonomy
) {
$menu_item_ids[] = (int) $menu_item->ID;
}
}
}

return array_unique( $menu_item_ids );
}

/**
* Callback for handling a menu item when its original object is deleted.
*
* @since 3.0.0
* @access private
*
* @param int $object_id The ID of the original object being trashed.
*
*/
function _wp_delete_post_menu_item( $object_id = 0 ) {
$object_id = (int) $object_id;

$menu_item_ids = wp_get_associated_nav_menu_items( $object_id, 'post_type' );

foreach( (array) $menu_item_ids as $menu_item_id ) {
wp_delete_post( $menu_item_id, true );
}
}

/**
* Callback for handling a menu item when its original object is deleted.
*
* @since 3.0.0
* @access private
*
* @param int $object_id The ID of the original object being trashed.
*
*/
function _wp_delete_tax_menu_item( $object_id = 0, $tt_id, $taxonomy ) {
$object_id = (int) $object_id;

$menu_item_ids = wp_get_associated_nav_menu_items( $object_id, 'taxonomy', $taxonomy );

foreach( (array) $menu_item_ids as $menu_item_id ) {
wp_delete_post( $menu_item_id, true );
}
}

/**
* Automatically add newly published page objects to menus with that as an option.
*
* @since 3.0.0
* @access private
*
* @param string $new_status The new status of the post object.
* @param string $old_status The old status of the post object.
* @param object $post The post object being transitioned from one status to another.
* @return void
*/
function _wp_auto_add_pages_to_menu( $new_status, $old_status, $post ) {
if ( 'publish' != $new_status || 'publish' == $old_status || 'page' != $post->post_type )
return;
if ( ! empty( $post->post_parent ) )
return;
$auto_add = get_option( 'nav_menu_options' );
if ( empty( $auto_add ) || ! is_array( $auto_add ) || ! isset( $auto_add['auto_add'] ) )
return;
$auto_add = $auto_add['auto_add'];
if ( empty( $auto_add ) || ! is_array( $auto_add ) )
return;

$args = array(
'menu-item-object-id' => $post->ID,
'menu-item-object' => $post->post_type,
'menu-item-type' => 'post_type',
'menu-item-status' => 'publish',
);

foreach ( $auto_add as $menu_id ) {
$items = wp_get_nav_menu_items( $menu_id, array( 'post_status' => 'publish,draft' ) );
if ( ! is_array( $items ) )
continue;
foreach ( $items as $item ) {
if ( $post->ID == $item->object_id )
continue 2;
}
wp_update_nav_menu_item( $menu_id, 0, $args );
}
}

===================================================================

Is this a hacking?


fyapobi on "Conditional on wc_get_template_part"

$
0
0

If i use a custom meta name original_post_id to store the id of a related post in woocommerce how can i Load this particular post id in a specific template part?

I tried this but it simply does not work. Please help me correct this.

if ($original_post_id != '' && $original_post_id != 'deleted') {
								$original_post = get_post($original_post_id);
								$post_title = $original_post->post_title;
								$post_content = $original_post->post_content;
								wc_get_template_part($post_ID->$original_post_id, 'content', 'single-product' );

kristboys on "Footer Message"

$
0
0

Hi there.. having a brain cell loss.. I am on the latest wp and using the Jehanne theme and on the bottom of the theme is

Proudly powered by WordPress theme by WP Blogs

I can not figure where I can change the wording. It mentions colophon but its not in my list. Can anyone assist as to where I can remedy this?

Thanks K

robertritz on "Get first URL from custom field, download and set as featured image on post publ"

$
0
0

I have a plugin that is adding text and a URL to a custom field when the post is published (not saved as draft). I want to get/make a function or plugin to search within the custom field and sideload the image from a URL, then add that image as the featured image.

Doing some searching I found this function from another StackExchange post that was designed to get a thumbnail from a Youtube video:

function set_youtube_as_featured_image($post_id) {

    // only want to do this if the post has no thumbnail
    if(!has_post_thumbnail($post_id)) {

        // find the youtube url
        $post_array = get_post($post_id, ARRAY_A);
        $content = $post_array['post_content'];
        $youtube_id = get_youtube_id($content);

        // build the thumbnail string
        $youtube_thumb_url = 'http://img.youtube.com/vi/' . $youtube_id . '/0.jpg';

        // next, download the URL of the youtube image
        media_sideload_image($youtube_thumb_url, $post_id, 'Sample youtube image.');

        // find the most recent attachment for the given post
        $attachments = get_posts(
            array(
                'post_type' => 'attachment',
                'numberposts' => 1,
                'order' => 'ASC',
                'post_parent' => $post_id
            )
        );
        $attachment = $attachments[0];

        // and set it as the post thumbnail
        set_post_thumbnail( $post_id, $attachment->ID );

    } // end if

} // set_youtube_as_featured_image
add_action('save_post', 'set_youtube_as_featured_image');

function get_youtube_id($content) {

    // find the youtube-based URL in the post
    $urls = array();
    preg_match_all('#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#', $content, $urls);
    $youtube_url = $urls[0][0];

    // next, locate the youtube video id
    $youtube_id = '';
    if(strlen(trim($youtube_url)) > 0) {
        parse_str( parse_url( $youtube_url, PHP_URL_QUERY ) );
        $youtube_id = $v;
    } // end if

    return $youtube_id;

} // end get_youtube_id

The only thing missing here is the ability to search a custom field and pull the URL from there, although the function certainly is in the right direction with finding the URL. Can anyone give me some direction here? The text is formatted in the custom field as below. It is the only URL and has an img html tag with it.

<div class="newsread " style="margin-bottom: 20px;">
                        <div id="ncbubuhome">
                                    <p>Erdenet Mining Corp. is the Mongolian and Russian joint venture to hold copper and molybdenum mining and production of copper and molybdenum concentrates and is counted as one of the biggest manufactures in Asian region. The corporation held its annual report last Friday in Erdenet city.</p>

<p>We are delivering the numbers of Erdenet Mining Corp. in comparison with Oyu Tolgoi LLC. Although those entities have differences in their operation period and investment agreement, those two are considered as biggest projects for Mongolia.</p>                                     <p><img alt="" src="http://gstat.mn/newsn/images/ck/2015/03/31/Erdenet_Oyutolgoi_Eng-171337-1287730770.jpeg" style="height:3572px; width:825px"></p>                        </div>

I've been bashing my head against this and have tried a few things:

Copying content of custom field to post body then using a plugin to autoset the external image (I believe things were being instantiated out of order and I couldn't get it to work)
Putting a shortcode in the body of the article with a placeholder that would pull a custom field, but couldn't figure out how to get the placeholder to work in the text editor.
Any help is much appreciated! I've been trying this for three days now! -Robert

josh_shields on "English/Spanish language toggling needed, can't find solution"

$
0
0

Hello! I am working for a non-profit Latino organization through a University class. We are making a WordPress that the client will have to maintain themselves. Due to the bilingual nature of the organization, it is critical to have English and Spanish translations on posts, pages, and menus. Google Translate will not be acceptable to the client because the machine translated grammar is not accurate.

I would like to be able to simply toggle between two pieces of front-end content in a show/hide fashion that will not require a postback.

The "translate" plugin is what I want by the sound of it, but doesn't seem to work. (https://wordpress.org/plugins/translate/)

The University that I attend has not granted back-end access because they don't trust students with a directory on the server.

Is there a solution to my situation, a way to switch between two sets of manually input pieces of content? I am currently using custom fields to try to separate out English text from Spanish text on new posts, but I need the translation to work for the header/footer as well.

The client does not know HTML, otherwise I might try to use jQuery to fadeIn / fadeOut anything with attribute lang="en" or lang="es" respectively, whether I am switching between English or Spanish.

Any help would be very much appreciated. Thanks in advance.

TL;DR
I need to switch between English and Spanish for my entire WordPress site but Google Translate's machine translation is not accurate enough and the only plugin that does what I want no longer works in current versions of WordPress.

nicolelight on "Have no idea how to fix Iframe"

$
0
0

We received an email from our hosting that there was malicious content in two folders wp-content/uploads/....
Our hosting advised they would take care of it but we needed to be cautious.
Now four days later our site is down, completely white. We have no way to access it and hosting is advising it is a wordpress problem. Sucuri scan advised there is an iframe malware but we cant get into anything as I said the site is a white page. Anyone have this problem before. We are not getting any messages that the plugins are bad.

wwww.maxcharge.com

Thank you!!

naveedabbas2007 on "Another domain is using all the contents of my webste"

$
0
0

Hi,
I am a website up and running quiet well, the problem is another domain is using all the references of my website like images, css and all the text.
my question is that it is possible to restrict these assets so that no one will be able to use my css, images etc.

thanks

proph011 on "Is it possible to link post to post within a plugin?"

$
0
0

Hi,

I'm using a plugin called Nimble Portfolio, and I'm trying to modify the plugin in a way that allows me to link an image to a specific post. Currently, whenever a user clicks an image, the post expands into a lightbox. As previously mentioned, I'm trying to allow it to go to a specific page. I was able to delineate which code affects the lightbox and it's posted below:

'
$nimblebox = apply_filters('nimble_portfolio_lightbox_script', self::getUrl('includes') . "prettyphoto/prettyphoto.js");
if ($nimblebox) {
wp_enqueue_script('nimblebox-script', $nimblebox, array('jquery'), self::$version); } '

I'm not really sure if this snippet is enough for anyone to give me any suggestions on how to resolving my problem so let me know if anything is unclear. I haven't found any relevant posts, but if anyone happens to stumble upon something, please share.

Thank you.


Jarod B on "How to add a unique side menu for each page section?"

$
0
0

Hi. I'm interested in knowing how I can get a site to have a different side menu for each page section a user is on. Here is an example of a site that uses wordpress and does it:

http://www.colts-laboratories.com/testing-services/lens-cleaners-and-cloths/

If you go on the About Us or the Testing Services page, you get a different side menu every time. I want to know how I can do that with wordpress or if there is a plugin for that? Does anyone here know how I can do that?

P3g4sus on "Non Hierarchy taxonomy not saving"

$
0
0

Good day all.

I know this is a bit unconventional. but ill explain as far as i can.

I have created a non hierarchy custom taxonomy for users.

I want to dynamically populate it.

My code is as follows:

global $current_user;
get_currentuserinfo();
$nowuser = $current_user->user_login;
wp_set_object_terms( $product_id, $nowuser, 'mystore', true );

So my problem is that its creating the term, but not linking it to the post(product)

We are using woocommerse and the Dokan theme to run an Etsy style store.

Our search function works great with taxonomies. And we expect only about 30 sellers on the site, so would like to use a taxonomy just to keep everything the same.

It is to search for all the products by store.

Hope I made enough sense.

Kind regards.

Marco Milesi on "wp_redirect strips out special characters"

$
0
0

Hi,
i have a problem with the function wp_redirect() when the url contains special characters.

wp_redirect( esc_url_raw( wp_get_attachment_url( $ID ) ) );

If the attachment url contains, for example, À, then the entire line of code leads to a 404 page because the final url won't contain that letter.

In addition:
esc_url_raw( wp_get_attachment_url( $ID ) )
is returning the correct url.

It seems that wp_redirect strips out the character À. Is this normal? Can i avoid this?

Thank you.

josephbydesign on "Get a funtion to run at the begining of every page."

$
0
0

I am writing a plugin and I need it to run a check at the beginning of every page. How would I get the plugin to automatically run a php function at the beginning of every page without putting the code in page.php file myself. Seems simple, but I can't find the answer. Thanks.

Guido on "Custom Product Fields"

$
0
0

Hi,

I have added some custom product fields to the productpage of woocommerce but I am wondering if I did it the right way or not:

woocommerce_wp_text_input( array( 'id' => 'author', 'class' => '', 'label' => __('Author') ) );
woocommerce_wp_text_input( array( 'id' => 'publisher', 'class' => '', 'label' => __('Publisher') ) );

The website is up and running, but today I noticed the id other fields start with '_'.
So '_author' and '_publisher'. Does it matter?

Guido

nickbowman on "Custom rewrite tag not showing up in get_permalink() or wp_get_shortlink()"

$
0
0

Hello,

I set up my own rewrite rule and tag, and they've been working great. However, the two functions I mentioned in the topic do not have the rewrite tag in them at all.

For example:
http://mysite.com/item/1234/generic-seo-text works. The page "item" can get the rewrite tag for that ID after it and display data about it. However, get_permalink() comes back as http://mysite.com/item/, and wp_get_shortlink() comes back as http://mysite.com/?p=12

My rewrite tag and rule look like this:
add_rewrite_tag( '%item_id%', '([^&]+)' );
add_rewrite_rule( '^' . $path . '/([\d\w\s-]+)/?.*', 'index.php?page_id=' . $page_id . '&item_id=$matches[1]', 'top' );

These are executed in the init action, the rules are flushed when my plugin's settings are saved.

Any ideas why that rewrite tag is missing in the returned URLs from get_permalink() and wp_get_shortlink()?

ianbauer2 on "Looking for plugin reccomendation"

$
0
0

Hi, I'm looking for a plugin that does something seemingly simple.

I'd like to take multiple RSS feeds and have them regularly imported into one site as WP posts, but when they appear on the front page, have the title and image link to the original source.

I'd also like to be able to set a default featured image if one is not included with the item. Also, they need to be able to be put automatically in categories. Tags I'm not so much worried about.

I've found plugins that do some of these things, but not all. Any suggestions? Does not have to be free.


w on "How is clicking 'update' on a post different from programatically creating posts"

$
0
0

Hi all, hoping for some advice.

I'm programmatically inserting a large number of posts into wordpress from a JSON feed. The wp_insert_post function is working brilliantly and the posts are created, along with correctly populated Advanced Custom Fields meta data.

We have a strange issue by which until we manually click "update" on a single post the custom fields aren't available using a JSON API plugin.

I've tried updating all via the bulk editor, as well as calling wp_update_post after the JSON import. It's as if the act of clicking "update" on a single post saves the post in a different fashion.

Can anyone advise why this would be the case? Any advice or pointing in the right direction would be greatly appreciated!

blunk on "How to reimplement TinyMCE?"

$
0
0

I have a complicated situation where a client hired another person to clean their server from shells caused by an old version of revslider. The person deleted the entire TinyMCE folder so I tried to take the same version of wordpress and just upload the TinyMCE folder from it into its appropriate directory.

I'm getting a 404 on /wp-includes/js/tinymce/wp-tinymce.php?c=1&ver=4107-20150118

I tried to remove the version information appended to the end just for testing purposes

But I still get a 404 on /wp-includes/js/tinymce/wp-tinymce.php

The weird thing is I'm 100% sure there is a file named wp-tinymce.php in that directory.

Is there some weird wordpress shenanigans at work here that isn't intuitive? I don't know much about wordpress so I'm pretty confused how to resolve this situation. I'd also like to note that I'm very reluctant to do a fresh wordpress install because I don't know what the old developer did or if he changed anything. I don't want to give myself more work by breaking the whole site.

Any help would be appreciated!

MFSAM on "Show authors by post count within so many days"

$
0
0

Hi,

I am using the below code to gather a list of authors that have NOT had a post (of any post types) published within the last 60 days.

<?php
$args = array(
	'role' => 'contributor',
);
$blogusers = get_users( $args ); ?>
<div class="opinionators" class="cf">
	<div class="title m-all t-all d-all">More than 60 days inactive</div>
	<?php foreach ( $blogusers as $user ) {
	//echo "<pre>"; print_r($user); echo "</pre>";
	$argsone = array(
		'date_query' => array(
			//set date ranges with strings!
				'after' => '60 days ago',
				'before' => 'tomorrow',
				//allow exact matches to be returned
				'inclusive' => true,
			),
			'author' => $user->data->ID,
		        'posts_per_page' => -1,
			'post_type' => 'any'
	);
	$twomonthposting = new WP_Query($argsone);
	$twomonth_post_count = $twomonthposting->found_posts;
	 $argstwo = array(
			'author' => $user->data->ID,
			'posts_per_page' => -1,
			'post_type' => 'any'
	);
	$postingsone = new WP_Query($argstwo);
	$post_countone = $postingsone->found_posts;
	if ($twomonth_post_count == 0 && $post_countone > 3) { ?>
DO STUFF
<?php } wp_reset_query(); } ?>

I once had 50 contributors and this worked - now that I have 122 contributors it breaks before the footer.

I wonder if someone wouldn't mind scanning their expert eye over this code and seeing if I'm doing something wrong or missing something? FYI the webpage is Old Writers of Roobla.

Thank you for any help you can offer.

yiags987 on "Creating a simple directory style plugin"

$
0
0

Hi guys,

I am hoping one of you can help or point me in the right direction - I get seem to write the correct phrase for what I mean in Google & am getting no where fast! I am new to the plugin creation game but a seasoned WordPress developer).

I want to create a plugin which acts very much like the PAGES menu item on WordPress to create a kind of directory of local bands I work with.

I want it to sit right under the PAGES menu item and be called BANDS. When I click I want an admin layout very much like the Page / Post format (with title / content window / featured image) but would also like a custom area below called "sidebar" which would be preloaded with widgets to display their videos / social media etc. All I would then need do is enter the relevant info into the page & widgets the task is done.

Each band would only appear under the BANDS menu item and not appear under PAGES.

Is there anyone who has the time to start me off or could point me towards a tutorial or existing plugin?!

Any help would be greatly appreciated :)

laichejl on "Upload image, specific category?"

$
0
0

I'm trying to implement this with Gravity Forms and a WP Media Categories plugin, but if anyone has a better way, please let me know.

Basically we are trying to create a photo submission contest. I'd like the photos uploaded directly to the media library (already figured that out) but to separate the uploaded images from the rest, I've found a plugin to assign categories to files in the media library. This is great, however, when a file is uploaded to the media library via a form submission, no category is applied.

Has anyone ever had a similar issue and was able to fix? Thanks in advance.

Viewing all 8245 articles
Browse latest View live




Latest Images