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

bradklosterman on "Form that updates to the usermeta table"

$
0
0

Is there anywhere I can find the code for a form that updates input fields to the usermeta table. I would like to put the form on a plugin admin page.

thank you


Bushstar on "Calling plugin function from another plugin"

$
0
0

I need to get information from another plugin but I get an undefined variable error when trying to call the function from the object created in the first plugin. As far as I know plugins are loaded in alphabetical order from the active_plugins option. To help solve this I used a bit of code that changes the order so that the required plugin is at the front of active_plugins but the error persists.

My dev environment is PHPStorm which even allows me to click through from the second plugin to the first from the function call. This says to me that the first plugin object should be seen as long as the first plugin is loaded.

Plugin A

class PluginA {
    public function check() {
        return 'checked';
    }
}

$example = new PluginA();

PluginB

class PluginB {
    public function plugina_check() {
        // Check to see if plugin is active is true
        if (in_array('plugina/class-plugina.php', get_option('active_plugins')) {
            // The next call throws Undefined variable $example
            $result = $example->check();
        }
    }
}

uptree on "Modify Categories description text in wp-admin"

$
0
0

Hello all,

I'm hoping someone can help me apply a filter to the categories description text in the admin. It currently reads:

Categories, unlike tags, can have a hierarchy. You might have a Jazz category, and under that have children categories for Bebop and Big Band. Totally optional.

I am trying to edit this to say something much more generic, as I'm working on a project for a non-profit that is very professional in nature. I have searched for filters and have tried creating something of my own, but with no success.

The default code currently resides in wp-admin/edit-tags.php and wp-admin/edit-tag-form.php.

My apologies if this quite simple - I'm not great with PHP.

Thanks in advance.

Mika on "Trouble to translate own plugin (add_menu_page/add_submenu_page)"

$
0
0

Hi,

I spend few hours to fix my problem - I'm giving up. I need help!

Whats wrong with my code to translate an admin-menu? Everything else is nice translated (plugin header, error messages, buttons - perfect!), the menu doesn't work. :-(

I use PoEdit Pro for the translation.

text-domain: yet-another-blogroll

add_action('plugins_loaded', 'yab_init');

function yab_init() {
	 load_plugin_textdomain( 'yab', false, plugin_dir_path( __FILE__ ) . 'languages/' );
}

add_action('admin_menu', 'yab_admin_menus');

function yab_admin_menus() {
	if ( current_user_can( 'manage_options' ) ) :
		// Hauptmenü
		$top_menu_item = 'yab_admin_page';

		add_menu_page('', __( "Yet Another Blogroll", 'yet-another-blogroll' ), 'manage_options', 'yab_admin_page',
						  'yab_admin_page', 'dashicons-rss' );

		// Untermenü: Information (wie Hauptmenü)
		add_submenu_page($top_menu_item, '', __( "Overview", 'yet-another-blogroll' ), 'manage_options', $top_menu_item, $top_menu_item );

		// Untermenü: Gruppen
		add_submenu_page($top_menu_item, '', __( "Groups", 'yet-another-blogroll' ), 'manage_options', 'yab_groups_admin_page' );

		// Untermenü: Webseiten
		add_submenu_page($top_menu_item, '', __( "Websites", 'yet-another-blogroll' ), 'manage_options', 'yab_websites_admin_page' );

		// Untermenü: Einstellungen
		add_submenu_page($top_menu_item, '', __( "Settings", 'yet-another-blogroll' ), 'manage_options', 'yab_settings_admin_page' );

		// Untermenü: Fehlerprotokoll
		add_submenu_page($top_menu_item, '', __( "Error logs", 'yet-another-blogroll' ), 'manage_options', 'yab_errorlogs_admin_page' );

	endif;

}

Please! Help! Me! It's a detail, yes, but a pain in the... ;-)

enriquerene on "register_activation_hook"

$
0
0

Hi,

I'm developing my first plugin. I created some code to test and verify how it works and now I'm putting all WP specifications. My question, what I can't understand is: What does register_activation_hook() function really work for?

Because if I don't put this in my code the activation works well. If I throw just register_activation_hook( param, function_here ) directly, some errors appear (I'm debugging) in WP screen. I'd like, if possible, someone give me some real (as real as possible) and simple (as short as possible) example of this acti/deact_hook().

I read codex but I think there is no good explanation about that.

Thanks

ccarlow on "how to remove padding when shrinking window - responsive"

$
0
0

I am not very god with coding. I am using canvas. My website is http://testsite.natureshealing.info
When I shrink my browser window to see how my website responds and looks on smaller screen devices the problem is the logo drops down to low and visibility of the logo is impaired.

I have the logo padding top set to 42px so to position the logo lower to begin with. I was wondering is there code I can install that will remove the 42px padding when the screen is minimized for smaller screens?

When I remove the padding the logo is too high aesthetically on full screen but when I minimize it aligns well so I need code to adjust this if possible or if you have a suggestion for another way I would appreciate it.

Thanks

Guido on "Execute php code only in widget area"

$
0
0

Hi,

I have an event list which can be added on a page and in a sidebar.

I would like to be able to hide certain elements (such as date and time) in sidebar, because of the available space.

So I have created an options page containing several checkboxes to hide date and time. These are 'options'.

I now hide the elements in widget using custom css:

function custom_css() {
	$widget_date = esc_attr(get_option( 'setting-1' ));
	$widget_time = esc_attr(get_option( 'setting-2' ));

	if ($widget_date == 'yes' || $widget_time == 'yes' ) {
		echo '<style type="text/css">' . "\n";

		if ($widget_date == 'yes') {
			echo '.widget_class .date {display:none;}' . "\n";
		}
		if ($widget_time == 'yes') {
			echo '.widget_class .time {display:none;}' . "\n";
		}

		echo '</style>' . "\n";
	}
}
add_action( 'wp_head', 'custom_css' );

Works fine.

But it's cleaner to do this with php, via an if statement I guess.
But how can I execute code ONLY in a widget area? Any suggestions?

Guido

Taro on "Category and page Wise Search - Custom taxonomy"

$
0
0

Hi All, if was looking for a plugin like category-wise-search.

I came up with the following that works for me. Register a custom taxonomy for post and page in your function.php:

/**
 * Add custom taxonomies
 *
 * Additional custom taxonomies can be defined here
 * http://codex.wordpress.org/Function_Reference/register_taxonomy
 */
function add_custom_taxonomies() {
  // Add new "Location" taxonomy to Posts
  register_taxonomy('location',array('post','page'), array(
    // Hierarchical taxonomy (like categories)
    'hierarchical' => true,
    // This array of options controls the labels displayed in the WordPress Admin UI
    'labels' => array(
      'name' => _x( 'Location', 'taxonomy general name' ),
      'singular_name' => _x( 'Location', 'taxonomy singular name' ),
      'search_items' =>  __( 'Search Locations' ),
      'all_items' => __( 'All Locations' ),
      'parent_item' => __( 'Parent Location' ),
      'parent_item_colon' => __( 'Parent Location:' ),
      'edit_item' => __( 'Edit Location' ),
      'update_item' => __( 'Update Location' ),
      'add_new_item' => __( 'Add New Location' ),
      'new_item_name' => __( 'New Location Name' ),
      'menu_name' => __( 'Location' ),
    ),
    // Control the slugs used for this taxonomy
    'rewrite' => array(
	'public' => false
    ),
  ));
}
add_action( 'init', 'add_custom_taxonomies', 0 );

if you like to use the new "category" name in your url; you should remove 'public' => false and add the correct rewrite code.

I used Location for the new name. If you look at the wordpress backend you can now see that posts and pages got a new taxonomy filter. You can use this to add a category name to page and post; example: Europe.

After that you can add the following line to the searchform:
<input type="hidden" name="location" value="Europe" />


suge1w on "Calculate age from 3 terms"

$
0
0

I've struggling to find a solution to this.

I have three taxonomies: 'dob', 'mob', 'yob' and I'm trying to calculate the age in years using all 3.

The code I've been messing with:

function age_in_years() {
global $post;
$year_of_birth = get_post_meta( get_the_ID( $post->ID ), 'yob', true );
$date1 = strval( $year_of_birth );
$date2 = strval( date( 'Y') );
$age = $date2 - $date1;
return $age;
}

Could anyone lend a hand?

thenbillsaid on "insert link from excerpt to full blog"

$
0
0

Trying to figure out how to display only the excerpt of a post and then link it to the full post.

grafixNZ on "Prevent auto login after registration"

$
0
0

Hello,

I have been trying everything to prevent new users from being logged in immediately after registration. I am using "Approve New Users" and it works to prevent them logging in until approved, but it doesn't prevent the initial auto login that happens after registering.

I have tried all the suggested code for functions.php I could find from previous discussions online, but none have worked so far.

Any help would be greatly appreciated.

Thank you.

Meitar on "WP-API not recognizing WordPress login cookie?"

$
0
0

I'm developing a plugin that is starting to make use of 4.4's WP-API in a few very simple JavaScript functions. The trouble is that none of the Ajax calls execute in the context of a logged-in user, despite being loaded from a logged-in account on the traditional WP Admin dashboard.

I posted details and code excerpts on the WP StackExchange here, and I'm hoping to draw people's attention to it by posting here.

The TL;DR:

The output of my Ajax calls always runs in the context of a logged-out user. Specifically, get_current_user_id() returns 0 for all Ajax-initiated calls, despite a PHP-side var_dump(get_current_user_id()) returning the correct logged-in user ID number on the output of the page itself.

Checking document.cookie seems to confirm the absence of a login cookie on the JS side, but a var_dump($_COOKIE) shows the correct login cookie's presence.

To add to the weirdness, Firefox's Network Pane shows the full cookie, along with the login value, being sent to WordPress from the Ajax call.

What gives?

Any help you can offer either in this thread or that one would be much appreciated.

Thanks.

Steven Gardner (Template Express) on "display custom widgets in customizer"

$
0
0

Hi,

I'm developing a new theme and have created a new widget area I want to use to populate a section on the homepage.

I've added the code to the homepage and set some default values so the widget appears on the homepage by default.

The problem is the customizer, I can seem to get the widget area to appear in the customizer menu. I keep getting the message
There are no widget areas currently rendered in the preview. Navigate in the preview to a template that makes use of a widget area in order to access its widgets here. however I can clearly see the widget area being displayed in the preview.

I've been pulling my hair out for a while on this so I would any ideas?

Anthony Laurence on "Admin-side issue with plugin"

$
0
0

Hi,

I'm working on a simple business directory plugin and have it an unusual snag. Basically, what I am doing is using a shortcode to place the business listing on the post/page/whatever.

The code works great on the frontend but whenever you Publish/Update/whatever in the backend you get the white screen of death. Even on pages where the plugin is not being used.

If is comment out the require_once() that is calling in the shortcode file the issue goes away. But is I uncomment and delete everything from the shortcode file, even the <?php and ?> tags, the issue returns.

I'm at a loss....

Here is the code in the shortcode file:

<?php
 function dirFunc($attr){
                $args = array('post_type' => 'Directory List');
                $dl_query = new WP_Query($args);
                $x = '';

                // The Loop
                if($dl_query->have_posts() ){

                        while ( $dl_query->have_posts() ) {
                                $dl_query->the_post();

                                    echo '<h3>'.get_the_title().'</h3>';

                                    echo '<strong>Description: </strong>';
                                    the_content();

                                $meta = get_post_meta(get_the_ID());

                                if ( isset( $meta['listing-st-address1'][0] ) ) {
                                   echo '<strong>Street Address 1: </strong>'.  $meta['listing-st-address1'][0].' <br>'; }

                                if ( isset( $meta['listing-st-address2'][0] ) ) {
                                  echo '<strong>Street Address 2: </strong>'.$meta['listing-st-address2'][0].' <br>'; }

                                if (isset( $meta['listing-city'][0] ) ) {
                                   echo '<strong>City: </strong>'. $meta['listing-city'][0].' <br> '; }

                                if (isset($meta['listing-state'][0])) {
                                   echo '<strong>State: </strong>'. $meta['listing-state'][0].' <br>'; }

                                if (isset($meta['listing-zip'][0])){
                                  echo ' <strong>Zip: </strong>'. $meta['listing-zip'][0].'<br>';}

                                if (isset($meta['listing-phone'][0])) {
                                   echo ' <strong>Telephone: </strong> '. $meta['listing-phone'][0].'<br>';}

                                if (isset($meta['listing-email'][0])) {
                                   echo '<strong>Email: </strong>'. $meta['listing-email'][0].'<br>';}

                                if (isset($meta['listing-website'][0])) {
                                  echo '<strong>URL: </strong> <a href="'. $meta['listing-website'][0].'" target="_blank">'.$meta['listing-website'][0].'</a><br>';}

                        }
                wp_reset_postdata();

            }

            // echo '<pre>';print_r($x); exit;

 }

 add_shortcode( 'directory-listing', 'dirFunc' );

?>

Here is the section calling in the file to add the shortcode file:

require_once($dir.'dl_listingDetails.php');
require_once($dir.'directoryTemplate.php');

**The first req_once() is used to add a meta box to a custom post type.

Any help is much appreciated!!

-Anthony

RBX on "Multiple Woocommere AJAX filters in theme template files"

$
0
0

I need to place AJAX filters in my shop archive template but I can't find any plugin suitable to my needs.

I need to first filter using price (3 predefined ranges) and then a custom taxonomy (brand).

Whatever I've found doesn't allow different filters to be placed separately and mostly allow only one instance.

If anyone knows a plugin which I can use, even possibly after some modification, please let me know.


juulesb on "Masonry gird layout problem"

$
0
0

Hello,

the first row of my masonry gird layout blogposts turns out fine, but then it is getting messy due to space in-between the rows.

To get the same size of thumbnails I put the following in the CSS:

.posts-layout.masonry .entry-thumb img {
height: 300px;
}

I heard that those box posts are positioned automatically by javascript, so I don´t know what do do.

Does anyone have a solution for that?

http://freebirdnumberone.com/blog/

BlackCatReal on "How to output my subtemplate in main theme using plugin?"

$
0
0

Hello. Please tell me, how can i output subtemplate in the main theme, in the center content, where posts, etc usually outputed.

I don't want to use shortcodes for this. What are other options? Thank you.

jennibez on "multiple select in drop-down that filters grid by tags"

$
0
0

I currently have a select with options in it where the value is the tag id. It then filters the results in a masonry grid. I would like to be able to have this drop down as a multiple select with tick boxes that can filter all options ticked.

This is an example of the html:

<div class="col-md-3 center-block text-center">
    <select id="selectbrand"  class="bselect">
        <option value="" style="display:none;" >B® Brand</option>
        <option value="34">Brand1</option>
        <option value="42">Brand2</option>
        <option value="57">Brand3</option>
    </select>
  </div>

This is an example of the js:

$("#btnloadrecipes").on('click', function(){
    var stheme        = $("#selecttheme").val();
    var sbrand        = $("#selectbrand").val();
    var soccasion     = $("#selectoccasion").val();
    var sdifficulty   = $("#selectdifficulty").val();
    var wpurl         = $("#wpurl").val();

    if(stheme == "" && sbrand == "" && soccasion == "" && sdifficulty == "" ){
      alert("Please select Criteria");
      return;
    }
    //wpurl = wpurl + "/tags/";
    wpurl = wpurl + "/?tag=";

    var arr = [];
    if(stheme != "")        arr.push(stheme);
    if(sbrand != "")        arr.push(sbrand);
    if(soccasion != "")     arr.push(soccasion);
    if(sdifficulty != "")   arr.push(sdifficulty);

    wpurl += arr.join("|");
    //console.log(stheme, sbrand, soccasion, sdifficulty);
    //console.log(wpurl);
    window.location.href = wpurl;

  });

And here is the php:

<div id="primary" class="content-area">
		<main id="main" class="site-main" role="main">
			<br/><br/>
			<div class="container">

				<?php include (TEMPLATEPATH . '/template-parts/content-recipe-searchform.php'); ?>

				<div class="row mobilerow">
					<div id="brandpost" class="col-md-12">

						<?php

						if($q->have_posts()) :
							 while($q->have_posts()) :
									$q->the_post();
									if(has_tag(30)){ //30 local
										$ribbonclass = "ribbon-newrecipe";
									}else if(has_tag(15)){ // 15 local
										$ribbonclass = "ribbon-safavourite";
									}else if(has_tag("Try Me")){
										$ribbonclass = "ribbon-tryme";
									}else{
										$ribbonclass = "";
									}
				 ?>

										<div class="hoverrecipe entry-masonry brandblock <?php echo $ribbonclass ?>" >
										<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">

											 <?php the_post_thumbnail( 450, null ); ?>

											 <div class="divrelative">
												 <div class="dotstop"></div>
												 <?php
															$meta_recipebrand = get_post_meta( get_the_ID(), 'recipebrand',  true );
															$recipebrand = empty($meta_recipebrand) ? "B" : $meta_recipebrand;
															echo "<p class='recipeblockbrand'>".$recipebrand."</p>";

												 ?>
												 <?php echo "<p class='recipeblocktitle'>"; ?>
												 <?php the_title(); ?>
												 <?php echo "</p>"; ?>
											 </div>
										</a>

									</div>

						<?php
						      endwhile;
						   else:
						?>

							<!-- ELSE  -->

							<?php

								$zargs = array(
									'post_type' 		=> 'post',
									'order'					=> 'ASC',
									'category_name' => 'Recipes',
									'no_found_rows' => true

								);

								$zq = new WP_Query($zargs);

								if($zq->have_posts()) :
 						      while($zq->have_posts()) :
 						         $zq->the_post();
										 if(has_tag(30)){ //30 local
	 										$ribbonclass = "ribbon-newrecipe";
	 									}else if(has_tag(15)){ // 15 local
	 										$ribbonclass = "ribbon-safavourite";
	 									}else if(has_tag("Try Me")){
	 										$ribbonclass = "ribbon-tryme";
	 									}else{
	 										$ribbonclass = "";
	 									}

							?>

								<div class="hoverrecipe entry-masonry brandblock <?php echo $ribbonclass ?>" >

									<a href="<?php the_permalink() ?>" rel="bookmark" title="View Recipe: <?php the_title_attribute(); ?>">

										 <?php the_post_thumbnail( 450, null ); ?>

										 <div class="divrelative">
											 <div class="dotstop"></div>
											 <?php
											 			$meta_recipebrand = get_post_meta( get_the_ID(), 'recipebrand', true );
											 			$recipebrand = empty($meta_recipebrand) ? "B" : $meta_recipebrand;
														echo "<p class='recipeblockbrand'>".$recipebrand."</p>";
											 ?>
											 <?php echo "<p class='recipeblocktitle'>"; ?>
											 <?php the_title(); ?>
											 <?php echo "</p>"; ?>
										 </div>
									</a>

								</div>

							<?php
									endwhile;
							   endif;
							?>

						<?php
						   endif;
						?>

					</div>
				</div>
				<div class="row mobilerow text-center">
					<br/><br/>
						<a href="#" id="btn-loadmore">Load More</a>
						<br/><br/>
				</div>

		</main><!-- #main -->
	</div><!-- #primary -->

gulliver on "Ajax page loads"

$
0
0

I'm (so far, unsuccessfully) trying to find a way to use Ajax to load partial page content into existing divs.

None of the three plug-ins I've tried work reliably (different issues with each), and I don't have the brainpower to adapt the code I use on non-WP sites to work in WP.

Suggestions appreciated. Please and thanks.

totallytech on "Running code and form content in ajax...."

$
0
0

Hey all

I've designed my website using wordpress, - On the site I want to show a booking system which is organised by postcode (So I work in the same area on the various days).

I've written some php code which allows me to input a postcode, it then removes any whitespace and removes the last 3 characters. Whats left is checked against an array of postcodes and depending on what the postcode is, it displays different forms...

this is the code:

<form id="form" action="" method="post">
<input type="text" id="postcode" name="postcode" value="" />
<input type="submit" name="submit" value="Find Me" />
</form>
<div id="return-wrap"></div>

<?php

$postcode = $_POST['postcode'];
$postcode = preg_replace('/\s+/', '', $postcode);
$postcode = substr($postcode, 0, -3);

if(in_array($postcode, array("NR1", "NR2", "NR3", "NR4", "NR5", "NR6", "NR7", "NR8", "NR9", "NR19", "NR20"))){

echo "1 form";

} elseif(in_array($postcode, array("NR10", "NR11", "NR12", "NR26", "NR27", "NR28"))) {

echo "2 form";

} elseif(in_array($postcode, array("NR13", "NR14", "NR15", "NR29", "NR30", "NR31", "NR32", "NR33", "NR34", "NR35", "IP18", "IP19", "IP20", "IP21", "IP22"))) {

echo "3 form";

} else {

echo "other";

}
?>

Considering this is in wordpress, I can use a php plugin to either call the code etc and add the html form on the page - but how would I get this to run through ajax so that I do not need to submit the page etc... I don't want the page to refresh - I just want the content to swap.

Viewing all 8245 articles
Browse latest View live




Latest Images