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

dzawacki on "Plugin Admin Page Overlapping wpfooter"

$
0
0

I'm working on developing a plugin and I'm running into some issues with the layout of the admin pages.

My problem is that I have tabs built into the page and the content of the tabs are overlaying the wpfooter content. When I scroll down, the black bar to the left goes away as I scroll. To me, it seems as though something is ignoring the length of the tab content when the window is drawn.
The tabs are created using radio buttons CSS to check whether or not each button is checked.

I followed the structure of:

<?php
PHP code here
?>
<div class="wrap">
Admin page content within tabs
</div>

I've looked at the code of some other plugins and I can't seem to figure out what I'm doing wrong. Are there any special rules on the kind of CSS which can be used within the WP-Admin pages?

Any thoughts or suggestions would be great.


xymalf on "The plugin generated 205 characters of unexpected output"

$
0
0
/*
  Plugin Name: options menu
  Plugin URI:
  Description: Companion to recipe 'Implementing the plugin menu'
  Author: adrian
  Version: 1.0
  Author URI: http://www.xymalf.com

The plugin generated 205 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.
 */

<?php
class MySettingsPage
{
    /**
     * Holds the values to be used in the fields callbacks
     */
    private $options;

    /**
     * Start up
     */
    public function __construct()
    {
        add_action( 'admin_menu', array( $this, 'add_plugin_page' ) );
        add_action( 'admin_init', array( $this, 'page_init' ) );
    }

    /**
     * Add options page
     */
    public function add_plugin_page()
    {
        // This page will be under "Settings"
        add_options_page(
            'Settings Admin',
            'My Settings',
            'manage_options',
            'my-setting-admin',
            array( $this, 'create_admin_page' )
        );
    }

    /**
     * Options page callback
     */
    public function create_admin_page()
    {
        // Set class property
        $this->options = get_option( 'my_option_name' );
        ?>
        <div class="wrap">
            <?php screen_icon(); ?>
            <h2>My Settings</h2>
            <form method="post" action="options.php">
            <?php
                // This prints out all hidden setting fields
                settings_fields( 'my_option_group' );
                do_settings_sections( 'my-setting-admin' );
                submit_button();
            ?>
            </form>
        </div>
        <?php
    }

    /**
     * Register and add settings
     */
    public function page_init()
    {
        register_setting(
            'my_option_group', // Option group
            'my_option_name', // Option name
            array( $this, 'sanitize' ) // Sanitize
        );

        add_settings_section(
            'setting_section_id', // ID
            'My Custom Settings', // Title
            array( $this, 'print_section_info' ), // Callback
            'my-setting-admin' // Page
        );  

        add_settings_field(
            'id_number2', // ID
            'Amazon Affiliate', // Title
            array( $this, 'id_number_callback' ), // Callback
            'my-setting-admin', // Page
            'setting_section_id' // Section
        );      

        add_settings_field(
            'title1',
            'Amazon Access',
            array( $this, 'title_callback' ),
            'my-setting-admin',
            'setting_section_id'
        );  

	add_settings_field(
            'title2',
            'Amazon secret',
            array( $this, 'title_callback' ),
            'my-setting-admin',
            'setting_section_id'
        );

    }

    /**
     * Sanitize each setting field as needed
     *
     * @param array $input Contains all settings fields as array keys
     */
    public function sanitize( $input )
    {
        $new_input = array();
        if( isset( $input['id_number'] ) )
            $new_input['id_number'] = absint( $input['id_number'] );

        if( isset( $input['title'] ) )
            $new_input['title'] = sanitize_text_field( $input['title'] );

        return $new_input;
    }

    /**
     * Print the Section text
     */
    public function print_section_info()
    {
        print 'Enter your settings below:';
    }

    /**
     * Get the settings option array and print one of its values
     */
    public function id_number_callback()
    {
        printf(
            '<input type="text" id="id_number" name="my_option_name[id_number]" value="%s" />',
            isset( $this->options['id_number'] ) ? esc_attr( $this->options['id_number']) : ''
        );
    }

    /**
     * Get the settings option array and print one of its values
     */
    public function title_callback()
    {
        printf(
            '<input type="text" id="title" name="my_option_name[title]" value="%s" />',
            isset( $this->options['title'] ) ? esc_attr( $this->options['title']) : ''
        );
    }
}

if( is_admin() )
    $my_settings_page = new MySettingsPage();

[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

I have built the front end of my plugin film reviews and this is ok.
The problem I am having is building a back end.
I want to get Amazon keys from settings menu and pass them to my amazonapi.php script. Not sure how I pass the settings. At the moment can't get to second base as plugin has loads of errors and as a newbie php programmer I need help to spot them.
Also how many other pages do i need to make to get the above menu working?

andy999 on "Sort users by meta_value_num"

$
0
0

Been trying some things to output some users and sort by a meta_value_num, but nothing I try works and I can't find anything online about it.

This one's a real challenge.

<?php
$args = array(
    'orderby' => 'meta_value_num',
    'meta_key ' => 'rank',
    'order' => 'DESC',
);

// The Query
$user_query = new WP_User_Query( $args );

// User Loop
if ( ! empty( $user_query->results ) ) {
    foreach ( $user_query->results as $user ) {
        echo '<p>' . $user->display_name . '</p>';
    }
} else {
    echo 'No users found.';
}
?>

I can get the meta value for each author on author.php easily enough but I can't get users to sort by the same meta value.

[Moderator Note: No bumping. If it's that urgent, consider hiring someone instead.]

waltone57 on "Hiding checkout options"

$
0
0

Hi,

I have coded custom button to my checkout form. Now I want to hide it if Order exceeds 299 €. I have tried everything I found but nothing is working.

Now I'm going with this one:

add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
function wc_minimum_order_amount() {

// Set this variable to specify a minimum order value

$minimum = 299;

if ( WC()->cart->total > $minimum ) {

add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');
function my_custom_checkout_field( $checkout ) {
echo '<div id="my-new-field"><h3>'.__('AutoSound-lehti: ').'</h3>';
woocommerce_form_field( 'my_checkbox', array(
'type' => 'checkbox',
'label' => __('Haluan ottaa vastaan AutoSound lehden vuosikerran, jonka JJ-Tuonti Oy lahjoittaa minulle. Ymmärrän, että lahjatilaus jatkuu kestotilauksena ensimmäisen vuosikerran jälkeen ja jos en itse sitä irtisano riittävän ajoissa, joudun itse maksamaan lehden tilausmaksun uudesta tilausjaksosta eteenpäin.'),
'required' => false,
), $checkout->get_value( 'my_checkbox' ));
echo '</div>';
}
 }
}

siknoidas on "how do Login with query string? Test or user in in DB"

$
0
0

Hello,

I wanna create simple query string to check or user is registred in wordpress site or no. I need this for apps communicate with WP DB.

How create something like - wp-login.php?log=testuser&pwd=password ?

I just need get output from WP just - OK or NO (Ok - let in)

Tryed json, but it don't have that function. Or i missed?
https://wordpress.org/plugins/json-api-auth/

Thank you.

AliceWonderFull on "Question on codex documentation and dbDelta"

$
0
0

http://codex.wordpress.org/Creating_Tables_with_Plugins

On that page it says You must have two spaces between the words PRIMARY KEY and the definition of your primary key''

but then the example does not actually specify a primary key, it specifies a unique key - and does not appear to have two spaces.

What is the right thing to do to work with dbDelta ??

-=-

Secondly, can I use the CHECK feature to restrict the values a column can have or is that not supported if using dbDelta?

superninjaroboboy on "Filter for 'most popular articles within last 7 days' pagination not working?"

$
0
0

Hi all :)

I've got the perfect filter for 'Most Popular Articles Within The Last 7 Days' working, but the only thing that still isn't working is that it's not adding the pagination?

I'd assumed 'paged' => $paged would work within the $args, but it's not?

I was wondering if anyone could tell me why the pagination isn't being added?

<h1>Most Popular Now</h1>

<div class="post-links">

            <?php
function filter_posts($where = '') {
		$where .= " AND post_date > '" . date('Y-m-d', strtotime('-7 days')) . "'";
		return $where;
}

add_filter('posts_where', 'filter_posts');

$args = array(
	'category__in' => array(2),
	'posts_per_page' => 12,
	'meta_key' => 'post_views_count',
	'orderby' => 'meta_value_num',
	'order' => 'DESC',
	'paged' => $paged
	);

$filter_posts_query = new WP_Query($args);
remove_filter('posts_where', 'filter_posts');

//loop for displaying posts
if ( $filter_posts_query->have_posts() ) :
while ($filter_posts_query->have_posts()) : $filter_posts_query->the_post();
?>
<?php do_action( 'bp_before_blog_post' ); ?>
<a href="<?php the_permalink() ?>" class="post-link">
<strong><?php the_title(); ?></strong>
<?php
ob_start();
the_content( __( 'Read the rest of this entry →', 'buddypress' ) );
$old_content = ob_get_clean();
$new_content = strip_tags($old_content);
echo $new_content;
?>
<span class="post-link-action">Read more ►</span>
</a>

<?php do_action( 'bp_after_blog_post' ); ?>

	<?php endwhile; ?>

	<?php bp_dtheme_content_nav( 'nav-below' ); ?>

<?php else : ?>

	<h2 class="center"><?php _e( 'Not Found', 'buddypress' ); ?></h2>
	<p class="center"><?php _e( 'Sorry, but you are looking for something that isn\'t here.', 'buddypress' ); ?></p>

	<?php get_search_form(); ?>

<?php endif; ?>
</div>

Thanks! :)

Free269 on ""Load more" posts button"

$
0
0

Hi guys,

I want to build a "load more" button for post that will on the fly load more posts to the page.
I know that there should be ajax involved.

Has anyone tried doing it before?
How do I start?


chris@vendiadvertising.com on "Extending WP_Customize_Control in plugin throws errors"

$
0
0

I've created some additional types of customization controls for a theme using Otto's tutorial. I'd like to now package these into a plugin to share code across several sites. Using Otto's exact syntax in a plugin, however, throws a fatal error: Fatal error: Class 'WP_Customize_Control' not found...

<?php
/*
Plugin Name: WP_Customize_Control Error
Description: This plugin causes "Fatal error: Class 'WP_Customize_Control'" to be thrown
Author: Chris Haas
Version: 1.0
*/

class Example_Customize_Textarea_Control extends WP_Customize_Control
{
    public $type = 'textarea';

    public function render_content() {
        ?>
        <label>
        <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
        <textarea rows="5" style="width:100%;" <?php $this->link(); ?>><?php echo esc_textarea( $this->value() ); ?></textarea>
        </label>
        <?php
    }
}

The simple solution would normally be to just include that core class using the below before the declaration:

require_once( ABSPATH . WPINC . '/class-wp-customize-control.php' );

This gets rid of the error until you go into Appearance->Customize where you get a different error, Fatal error: Cannot redeclare class WP_Customize_Color_Control in ... /wp-includes/class-wp-customize-control.php.

Ultimately this stems from wp-includes/class-wp-customize-manager.php line 70 (as of 3.9.1) where the file is loaded using require instead of require_once.

I found someone performing an on-demand load of their class in customize_register but that requires the theme to be aware of my plugin's file structure which isn't ideal.

Am I missing something obvious? Is there a good reason that that core file is loaded using require instead of require_once? As far as I can tell its a static class that could probably be loaded at almost anytime.

BGUW on "Plugin Page Templates // routes - Best coding practice ?"

$
0
0

I am trying to keep within wordpress's preferred way of doing thing rather then a work around or hack. The end result is a page route such as ?page=checkout and to be able to load a custom php file that still loads and has access to wordpress functions.

I started off using custom page template, creating a page and setting the page template to my custom php so that I could use the slug to load the file.

This was a little sloppy since now there are a bunch of black pages whos only purpose is to add a route and load the custom php.

The files still uses things like get_header() && get_footer() for the most part but some are just form processing and a redirect to a thank you page.

Next I messed around with adding add_submenu_page( NULL ...) with a null parent as to not create a menu item. This also worked to accomplish what I wanted to do but it still did not feel like the correct way.

So in attempts to clean this method up I started hooking into after_setup_theme

function new_route() {

	if($_GET['page'] == 'checkout'){
		load_template( dirname( __FILE__ ) . '/templates/checkout.php' );
		exit;
	}

}
add_action( 'after_setup_theme', 'new_route' );

Above is what I am currently using however is this really the best way to do this? It seems like a hack.

The page route does not have to be 'page=XYZ' really any slug would do I just need to be able to pull in my custom php files based on a uri slug.

I appreciate any advice.

xymalf on "Sub menu item crashing the plugin."

$
0
0
<?php
/*
Plugin Name: WordPress Menu Examples Plugin
Plugin URI: http://example.com/wordpress-plugins/my-plugin
Description: A plugin to create menus and submenus in WordPress
Version: 1.0
Author: Brad Williams
Author URI: http://wrox.com
License: GPLv2
*/

add_action( 'admin_menu', 'boj_menuexample_create_menu' );

function boj_menuexample_create_menu() {

	//create custom top-level menu
	add_menu_page( 'My Plugin Settings Page', 'Menu Example Settings', 'manage_options', __FILE__, 'boj_menuexample_settings_page', plugins_url( '/images/wp-icon.png', __FILE__ ) );

	//create submenu items
	add_submenu_page( __FILE__, 'About My Plugin', 'About', 'manage_options', __FILE__.'_about', boj_menuexample_about_page );
	add_submenu_page( __FILE__, 'Help with My Plugin', 'Help', 'manage_options', __FILE__.'_help', boj_menuexample_help_page );
	add_submenu_page( __FILE__, 'Uinstall My Plugin', 'Uninstall', 'manage_options', __FILE__.'_uninstall', boj_menuexample_uninstall_page ); 

}

?>
[/PHP]

[PHP]
/*

  Description:  menuexample_settings_page
  Author: adrian
  Version: 1.0
  Author URI: http://www.xymalf.com
 */

<?php

*/

add_action( 'admin_menu', 'boj_menuexample_create_menu' );

function boj_menuexample_create_menu() {

	//create a submenu under Settings
	add_options_page( 'My Plugin Settings Page', 'Menu Example Settings', 'manage_options', __FILE__, 'boj_menuexample_settings_page' );

}
?>

[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

the plug in is activating but when I click on the link for the Settings page it crashes. Help please.

rickardtompsoum on "how to use WPDB class"

JustRunLah on "How to query custom post types with mixed AND & OR statements for custom fields"

$
0
0

I have a custom post type "events" which includes the custom fields "is_premium" (which is a true/false) and "premium_expiry_date" which is a date picker.

On my front end, I want to have "events" which are premium and their premium_expiry_date has not passed to be displayed on the top of the results.

I have managed to do half of that by WP_Query querying "events" for which the is_premium==true && premium_expiry_date>$today (my code shown below). I pull them successfully in a table which appears ton top of my page.

My problem is with displaying the rest, and avoiding double posts.

Essentially, I would need a query like [ is_premium==false OR (is_premium==true AND premium_expiry_date<$today ) ] but I know that AND and OR cannot be mixed in one WP_Query.

I have tried to go into using $wpdb but with no luck (I am lacking SQL knowledge...)

My question is, could somebody either help me with how to syntax this using $wpdb, or direct me to a different path for achieving my desired result?

// This is the code I use to show the premium events which have not occurred yet,
        // and their premium date has not passed
        $today = date('Ymd');
        $args = array(
        'post_type' => 'event',
        'orderby'   => 'event_date',
        'meta_key'  => 'event_date',
        'order' => 'ASC',
        'relation' => 'AND',
        'meta_query' => array(

                array(
                'key'       => $the_key, //I read this from a _GET value. It resembles another custom field
                'compare'   => 'LIKE',
                'value'     => $current_region->name, //filter based on current region
                ),

                array(
                'key'       => 'event_date',
                'compare'   => '>=',
                'value'     => $today
                ),

                array(
                'key'       => 'is_premium',
                'compare'   => '==',
                'value'     => 1
                ),

                array(
                'key'       => 'premium_expiry_date',
                'compare'   => '>=',
                'value'     => $today
                    ),

                ),
            );

    ?>

    <?php $the_query = new WP_Query( $args ); ?>

    <?php if( $the_query->have_posts() ): ?>

    <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

... END

[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

Thanks a lot in advance

hariharakumar on "Jquery plugin Stickymojo issue"

$
0
0

Sorry guys i am not sure where to post this question. So i am writing it here.

I have used Stickymojo plugin (http://mojotech.github.io/stickymojo/) on one of the client site here on this page (www.interconstra.com/test/). On this page When i scroll to the bottom sidebar contents are overflowing into footer. I dont know how to fix this. Please help me in this issue. Thanks in advance.

meandco on "Use Categories In A Page Template"

$
0
0

Hello. I'm wondering if anyone can help.

What I want to do is show specific categories ina page template.
For example:

<!-- START LOOP -->
        <?php query_posts('category_name=catname'); ?>
        <?php if (have_posts()): while (have_posts()) : the_post(); ?>

        <div class="col-sm-6 col-md-4 contentBlock">
        <div class="thumbnail"><?php the_post_thumbnail('featured-image'); ?>
        <div class="caption">
                <h3><?php the_title(); ?></h3>
                <p><?php the_excerpt(); ?></p>

        <div id="edit"><?php edit_post_link(); ?></div>

        </div><!--/CAPTION -->
        <div class="col-9 btnArrowBlack"><p><a href="#">More</a></p></div>
        </div><!--/THUMBNAIL -->
        </div><!--/COL -->

        <?php endwhile; else: ?>
        <p><?php _e('Sorry, no posts matched your criteria.'); ?></p>

        <?php endif; ?>
        <!-- END LOOP -->

And this mixes in with my styles fine.
So I have that in the template and it shows all posts from that category in the page template.

What I don't want to do is have to create a new template and put in the new cat id or slug everytime I want a new page.

I just want to create a page based on one page template and show the categories.

Can anyone help and hopefully this make sense?

Thank you in advance, I will reply.


rusty1001 on "How to find plugin page and or file"

$
0
0

Hi I have a plugin that needs customization,

The site uses a plugin to pull data into a page on the site.

<?php dynamic_sidebar('Property Page'); ?>

<?php dynamic_sidebar('Property side'); ?>

top and bottom of page template

I can see all the files in the plugin and have turned off to what works were, ie one of the files property_description.php will show description etc.., ie I can find all the element of that page but I cannot find the file that is making that page... What should I look for to find a contructor for this ('Property Page');

Thanks
Rusty

Gabums on "custom fields and strings"

$
0
0

Good afternoon,

I'm trying to get the value of one of my custom fields but it keeps returning "array array array". I figured it was because there were nested custom fields. When I broke it down, I got this:

s:17:"content_main_area";
		a:4: {
			i:0;
			a:6:{
				s:20:"dynamic_element_type";
				s:9:"_text_box";
				s:7:"pb_area";
				s:17:"content_main_area";
				s:6:"_sizer";
				s:10:"two-thirds";
				s:9:"stb_title";
				s:15:"Paying for Care";
				s:11:"stb_content";
				s:1875:" $mydata = '

So it appears to me that my custom field contains a string within a string. I'm trying to get make something like this:

$custom_field = get_post_meta($post->ID, $zn_meta_elements['content_main_area']['stb_content'], true);

With $zn_meta_elements as my custom field and "content_main_area" and "stb_content" are the strings. The goal is to get the value of "stb_content" (which might be $mydata????). It seems my syntax is off and all my google searches are now showing purple links.

Can anyone point me in the right direction? Thanks so much!

Cheers!

ekazda on "Custom Walker Menu $this Error"

pixieblitz on "Temporary Username and One-Time Change"

$
0
0

I'm running a multisite installation with buddypress, and I ended up with a list of names and e-mails of people that want to join. It's not *huge*, so technically I could set a temporary username for all of them, and ask them to let me know what to change it to, then go in and update the database accordingly... But obviously that's a bit clunky and also not a smooth user experience.

Anyway, does anyone know of a way to enable a one-time username change from the admin area for users after their first login? It's just really convenient to have a sign up sheet at events, and if I could reduce the number of steps, that'd be awesome. If not I could always just e-mail them asking to register themselves after the event, but again, that's an extra step that I'd love to eliminate.

Thank you guys!

mugamugaw on "Search Page modification"

$
0
0

This may seem weird, but right now when you use the search box on my site it takes you to the search results page. On that page it has the post title and a little summary and a read more button. What I would like is to delete the read more button AND get rid of the link from the title of the post/page. Basically, I do not want users to get to those pages or posts from the search results page but I do want them to see the title and summary. I know it's weird just let me know if this is possible!

Viewing all 8245 articles
Browse latest View live




Latest Images