• veerpatel

    (@veerpatel)


    i want help to get a button in my admin column im new to php so plz can u help me .

    <?php
    function custom_admin_js() { ?>
    <script>
    	$('input[name=Checkbx]').click(function() {
    	var coc = $('input[name=Checkbx2]').get(0).value;
    	// Send Request
        $.getJSON("https://www.omdbapi.com/?&plot=full&i=" + coc, function(data) {
    	    var valDir = "";
    		var valWri = "";
    		var valAct = "";
    		$.each(data, function(key, val) {
    			  $('input[name=' +key+ ']').val(val);
    			  if(key == "Director"){
    				valDir+= " "+val+",";
    			  }
    			  if(key == "Actors"){
    				valAct+= " "+val+",";
    			  }
    			  if(key == "Year"){
    				$('#new-tag-<?php echo get_option('year'); ?>').val(val);
    			  }
    		});
    		$('#new-tag-<?php echo get_option("director"); ?>').val(valDir);
    		$('#new-tag-<?php echo get_option("actor"); ?>').val(valAct);
    	});
    });
    </script>
    <?php $api = get_option('tmdbapi'); if ($api == "true") { ?>
    <script>
    	$('input[name=Checkbx]').click(function() {
    	var input = $('input[name=Checkbx2]').get(0).value;
    	var url = "https://api.themoviedb.org/3/movie/";
    	var agregar = "?append_to_response=images,trailers";
    	var idioma = "&language=<?php echo get_option('tmdbidioma') ?>&include_image_language=<?php echo get_option('tmdbidioma')?>,null";
    	var apikey = "&api_key=<?php echo get_option('tmdbkey')?>";
    	// Send Request
        $.getJSON( url + input + agregar + idioma + apikey, function(tmdbdata) {
    		var valTit = "";
    		var valPlo = "";
    		var valImg = "";
    		var valBac = "";
    		$.each(tmdbdata, function(key, val) {
    			  $('input[name=' +key+ ']').val(val); 
    
    			  if(key == "title"){
    				valTit+= ""+val+"";
    			  }
    			  if(key == "overview"){
    				valPlo+= ""+val+"";
    			  }
    			  if(key == "poster_path"){
    				valImg+= "https://image.tmdb.org/t/p/w185"+val+"";
    			  }
    			  if(key == "backdrop_path"){
    				valBac+= "https://image.tmdb.org/t/p/w780"+val+"";
    			  }
    <?php $api = get_option('apigenero'); if ($api == "true") { ?>
    if(key == "genres"){
    			var genr = "";
    			$.each( tmdbdata.genres, function( i, item ) {
           	 		genr += "" + item.name + ", ";
    				genr1 = item.name;
    				$('input[name=newcategory]').val( genr1 );
    				$('#category-add-submit').trigger('click');
    				 $('#category-add-submit').prop("disabled", false);
    				$('input[name=newcategory]').val("");
        		});
    			$('input[name=' +key+ ']').val( genr );
    		}
    <?php } ?>
    if(key == "trailers"){
    
    			var tral = "";
    			$.each( tmdbdata.trailers.youtube, function( i, item ) {
           	 		tral += "" + item.source + "";
        		});
    			$('input[name="Trailer_yt"]').val( tral );
    }
    if(key == "images"){
    			var imgt = "";
    			$.each( tmdbdata.images.backdrops, function( i, item ) {
    				imgt += "https://image.tmdb.org/t/p/w300" + item.file_path + "\n";
        		});
    			$('textarea[name="imagenes"]').val( imgt );
    }
    		});
    		$('#title').val(valTit);
    		$('#content').val(valPlo);
    		$('#poster_url').val(valImg);
    		$('#fondo_player').val(valBac);
    	});
    });
    </script>
    <?php
      }
    }
    add_action('admin_footer', 'custom_admin_js');
    $sp_boxes = array (
    /* Agregar codigo IMDb */
    __('Complete data imdb', 'mundothemes') => array (
    array( 'Separador', 'separa', 'jqueryp' ),
    array( 'Checkbx2', __('Assign ID IMDb, example (https://www.imdb.com/title/tt0120338/) = <b>tt0120338</b>', 'mundothemes') ),
    array( 'Checkbx', __('Put the cursor in the text box', 'mundothemes'), 'button' ),
    ),
    /* trailer */
    __('Images and trailer', 'mundothemes') => array (
    array( $imagefix, __('URL Poster (optional)', 'mundothemes') ),
    array( 'fondo_player', __('Background Image URL (Fake Player)', 'mundothemes') ),
    #array( 'Trailer', __('Trailer (Embed code)', 'mundothemes'), 'textarea' ),
    array( 'imagenes', __('Backdrops - Place each image url below another', 'mundothemes'), 'textarea' ),
    array( 'Trailer_yt', __('Trailer ID Youtube', 'mundothemes') )
    ),
    /* Datos extraidos de IMDb */
    __('Movie Info', 'mundothemes') => array (
    array( 'menuplay', 'menuplay', 'menudata' ),
    array( 'imdb', 'separa', 'separame' ),
    array( 'imdbRating', __('IMDB Rating', 'mundothemes') ),
    array( 'imdbVotes', __('IMDB votes', 'mundothemes') ),
    array( 'Title', __('Original title', 'mundothemes') ),
    array( 'Rated', __('Rated', 'mundothemes') ),
    array( 'Released', __('Release Date', 'mundothemes') ),
    array( 'Runtime', __('Runtime', 'mundothemes') ),
    array( 'Awards', __('Awards', 'mundothemes') ),
    array( 'Country', __('Country', 'mundothemes') ),
    array( 'Separador', 'separa', 'fin' ),
    array( 'tmdb', 'separa', 'separame' ),
    array( 'vote_average', __('TMDb Rating', 'mundothemes') ),
    array( 'vote_count', __('TMDb votes', 'mundothemes') ),
    array( 'budget', __('Budget', 'mundothemes') ),
    array( 'revenue', __('Revenue', 'mundothemes') ),
    array( 'popularity', __('Popularity', 'mundothemes') ),
    array( 'id', __('TMDb ID', 'mundothemes') ),
    array( 'status', __('Status', 'mundothemes') ),
    array( 'tagline', __('Tag line', 'mundothemes') ),
    array( 'Separador', 'separa', 'fin' ),
    ),
    /* Player Embeds */
    __('Players', 'mundothemes') => array (
    array( 'menuplay', 'menuplay', 'playermenu' ),
    array( 'sepa1', 'separa', 'separame' ),
    array( 'embed_pelicula', __('Embed code', 'mundothemes'), 'textarea' ),
    array( 'titulo_repro1', __('Title player', 'mundothemes') ),
    array( 'Separador', 'separa', 'fin' ),
    array( 'sepa2', 'separa', 'separame' ),
    array( 'embed_pelicula2', __('Embed code', 'mundothemes'), 'textarea' ),
    array( 'titulo_repro2', __('Title player', 'mundothemes') ),
    array( 'Separador', 'separa', 'fin' ),
    array( 'sepa3', 'separa', 'separame' ),
    array( 'embed_pelicula3', __('Embed code', 'mundothemes'), 'textarea' ),
    array( 'titulo_repro3', __('Title player', 'mundothemes') ),
    array( 'Separador', 'separa', 'fin' ),
    array( 'sepa4', 'separa', 'separame' ),
    array( 'embed_pelicula4', __('Embed code', 'mundothemes'), 'textarea' ),
    array( 'titulo_repro4', __('Title player', 'mundothemes') ),
    array( 'Separador', 'separa', 'fin' ),
    array( 'sepa5', 'separa', 'separame' ),
    array( 'embed_pelicula5', __('Embed code', 'mundothemes'), 'textarea' ),
    array( 'titulo_repro5', __('Title player', 'mundothemes') ),
    array( 'Separador', 'separa', 'fin' ),
    array( 'sepa6', 'separa', 'separame' ),
    array( 'embed_pelicula6', __('Embed code', 'mundothemes'), 'textarea' ),
    array( 'titulo_repro6', __('Title player', 'mundothemes') ),
    array( 'Separador', 'separa', 'fin' ),
    array( 'sepa7', 'separa', 'separame' ),
    array( 'embed_pelicula7', __('Embed code', 'mundothemes'), 'textarea' ),
    array( 'titulo_repro7', __('Title player', 'mundothemes') ),
    array( 'Separador', 'separa', 'fin' ),
    array( 'sepa8', 'separa', 'separame' ),
    array( 'embed_pelicula8', __('Embed code', 'mundothemes'), 'textarea' ),
    array( 'titulo_repro8', __('Title player', 'mundothemes') ),
    array( 'Separador', 'separa', 'fin' ),
    ),
    /* download player */
    /* __('Downloads', 'mundothemes') => array (
    array( 'descargas_link', __('HTML Code links downloads', 'mundothemes'), 'textarea' ),
    ),*/
    
    );
    add_action( 'admin_menu', 'sp_add_custom_box' );
    add_action( 'save_post', 'sp_save_postdata', 1, 2 );
    function sp_add_custom_box() {
    global $sp_boxes;
    if ( function_exists( 'add_meta_box' ) ) {
    foreach ( array_keys( $sp_boxes ) as $box_name ) {
    add_meta_box( $box_name, __( $box_name, 'sp' ), 'sp_post_custom_box', 'post', 'normal', 'high' );
    } } }
    function sp_post_custom_box ( $obj, $box ) {
    global $sp_boxes;
    static $sp_nonce_flag = false;
    if ( ! $sp_nonce_flag ) {
    echo_sp_nonce();
    $sp_nonce_flag = true;
    }
    foreach ( $sp_boxes[$box['id']] as $sp_box ) {
    echo field_html( $sp_box );
    } }
    function field_html ( $args ) {
    switch ( $args[2] ) {
    case 'textarea':
    return text_area( $args );
    case 'separame':
    return sepa_1( $args );
    case 'fin':
    return sepa_2( $args );
    case 'jqueryp':
    return jqueryplus( $args );
    case 'playermenu':
    return menuplay( $args );
    case 'menudata':
    return menudatos( $args );
    case 'checkbox':
    case 'radio':
    case 'button':
    case 'text':
    return text_button( $args );
    case 'submit':
    default:
    return text_field( $args );
    } }
    function text_field ( $args ) {
    global $post;
    $args[2] = get_post_meta($post->ID, $args[0], true);
    $args[1] = __($args[1], 'sp' );
    $label_format =
    '<label class="mtt" for="%1$s">%2$s</label>'
    . '<input class="mt" type="text" id="%1$s" name="%1$s" value="%3$s" />';
    return vsprintf( $label_format, $args );
    }
    function text_button ( $args ) {
    $label_format = '<input type="button" class="btmmt" name="Checkbx" value="'.__("Generate data from IMDb","mundothemes").'" />';
    return vsprintf( $label_format, $args );
    }
    function text_area ( $args ) {
    global $post;
    $args[2] = get_post_meta($post->ID, $args[0], true);
    $args[1] = __($args[1], 'sp' );
    $label_format =
    '<label  class="mtt" for="%1$s">%2$s</label>'
    . '<textarea class="mttt" name="%1$s">%3$s</textarea>';
    return vsprintf( $label_format, $args );
    }
    function sepa_1 ( $args ) {
    global $post;
    $args[2] = get_post_meta($post->ID, $args[0], true);
    $args[1] = __($args[1], 'sp' );
    $label_format = '<div id="%1$s" class="separador">';
    return vsprintf( $label_format, $args );
    }
    function sepa_2 ( $args ) {
    global $post;
    $args = "";
    $label_format = '</div>';
    return vsprintf( $label_format, $args );
    }
    function jqueryplus ( $args ) {
    global $post;
    $args = "";
    $label_format = '
    <script type="text/javascript" src=" '.get_stylesheet_directory_uri().'/includes/framework/js/jquery-2.2.0.min.js?ver=2.2.0"></script>
    <script type="text/javascript" src=" '.get_stylesheet_directory_uri().'/includes/framework/js/idtabstbb.js"></script>
    ';
    return vsprintf( $label_format, $args );
    }
    function menuplay ( $args ) {
    global $post;
    $args = "";
    $label_format = '<ul class="idTabs menuplayer">
    <li><a href="#sepa1" class="selected">'. __('Option 1', 'mundothemes') .'</a></li>
    <li><a href="#sepa2">'. __('Option 2', 'mundothemes') .'</a></li>
    <li><a href="#sepa3">'. __('Option 3', 'mundothemes') .'</a></li>
    <li><a href="#sepa4">'. __('Option 4', 'mundothemes') .'</a></li>
    <li><a href="#sepa5">'. __('Option 5', 'mundothemes') .'</a></li>
    <li><a href="#sepa6">'. __('Option 6', 'mundothemes') .'</a></li>
    <li><a href="#sepa7">'. __('Option 7', 'mundothemes') .'</a></li>
    <li><a href="#sepa8">'. __('Option 8', 'mundothemes') .'</a></li>
    </ul>';
    return vsprintf( $label_format, $args );
    }
    function menudatos ( $args ) {
    global $post;
    $args = "";
    $label_format = '<ul class="idTabs menuplayer">
    <li><a href="#imdb" class="selected">'. __('IMDb', 'mundothemes') .'</a></li>
    <li><a href="#tmdb">'. __('TMDb', 'mundothemes') .'</a></li>
    </ul>';
    return vsprintf( $label_format, $args );
    }
    function sp_save_postdata($post_id, $post) {
    global $sp_boxes;
    if ( ! wp_verify_nonce( $_POST['sp_nonce_name'], plugin_basename(__FILE__) ) ) {
    return $post->ID; }
    if ( 'page' == $_POST['post_type'] ) {
    if ( ! current_user_can( 'edit_page', $post->ID ))
    return $post->ID;
    } else {
    if ( ! current_user_can( 'edit_post', $post->ID ))
    return $post->ID; }
    foreach ( $sp_boxes as $sp_box ) {
    foreach ( $sp_box as $sp_fields ) {
    $my_data[$sp_fields[0]] =  $_POST[$sp_fields[0]];
    } }
    foreach ($my_data as $key => $value) {
    if ( 'revision' == $post->post_type  ) {
    return; }
    $value = implode(',', (array)$value);
    if ( get_post_meta($post->ID, $key, FALSE) ) {
    update_post_meta($post->ID, $key, $value);
    } else {
    add_post_meta($post->ID, $key, $value);
    }
    if (!$value) {
    delete_post_meta($post->ID, $key);
    } } }
    function echo_sp_nonce () {
    echo sprintf(
    '<input type="hidden" name="%1$s" id="%1$s" value="%2$s" />',
    'sp_nonce_name',
    wp_create_nonce( plugin_basename(__FILE__) )
    );
    }
    if ( !function_exists('get_custom_field') ) {
    function get_custom_field($field) {
    global $post;
    $custom_field = get_post_meta($post->ID, $field, true);
    echo $custom_field; } }
    function logo_admin_wpRafael() {  ?>
    <style type="text/css">
    h1 a {
    <?php $logo = get_option('wpadmin-logo');if (!empty($logo)) { ?>
    background-image: url(<?php echo $logo; ?>) !important;
    <?php } else { ?>
    background-image: url(<?php echo get_template_directory_uri(); ?>/images/logo_admin.png) !important;
    <?php } ?>
    background-size: 301px 51px !important;
    width: 301px !important;
    height: 51px !important;
    }
    </style>
    <?php  }
    add_action('login_head', 'logo_admin_wpRafael');
    function core_grifus() {
    }
    add_action('admin_footer', 'core_grifus'); 
    
    function mostrar_trailer($id) {
    	if (!empty($id)) {
    		$val = str_replace(
    			array("[","]",),
    			array('<div class="youtube_id"><iframe width="600" height="450" src="//www.youtube.com/embed/','" frameborder="0" allowfullscreen></iframe></div><br><b class="icon-youtube4"></b> Upload on Youtube',),$id);
    		echo $val;
    		} else {
    			echo 'No data';
    		}
    }

    want this code in this code

    <?php
    
    class CPAC_Column_COLUMN_NAME extends CPAC_Column {
    
        /**
         * This function will setup the column data
         *
         */
        public function init() {
    
            // do not delete
        	parent::init();
    
            // Identifier, pick an unique name. Single word, no spaces. Underscores allowed.
            $this->properties['type'] = 'column-COLUMN_NAME';
    
            // Default column label.
            $this->properties['label'] = __( 'COLUMN_LABEL', 'ac-COLUMN_NAME' );
    
            // (optional) You can make it support sorting with the pro add-on enabled. Sorting will be done by it's raw value.
            $this->properties['is_sortable'] = true;
    
            // (optional) Enable/Disable inline editing support for this column.
            $this->properties['is_editable'] = false;
        }
    
        /**
         * Returns the display value for the column.
         *
         * @param int $id ID
         * @return string Value
         */
        public function get_value( $post_id ) {
    
            // get raw value
            $value = $this->get_raw_value( $post_id );
    
            // optionally you can change the display of the value. In this example we added a post link.
            $value = '<a href="' . get_permalink( $post_id ) . '">' . $value . '</a>';
    
            return $value;
        }
    
        /**
         * Get the raw, underlying value for the column
         * Not suitable for direct display, use get_value() for that
         * This value will be used by 'sorting', 'inline-edit' and get_value().
         *
         * @param int $id ID
         * @return mixed Value
         */
        public function get_raw_value( $post_id ) {
    
            // put all the column logic here to retrieve the value you need
            // For example: $value = get_post_meta( $post_id, '_my_custom_field_example', true );
    
            $value = '<input type="button" class="btmmt" name="Checkbx" value="'.__("Generate IMDb","mundothemes").'" />';
    
            return $value;
        }
    
        /**
         * (Optional) Apply conditionals. You can remove this function is you do not use it!
         *
         * This determines whether the column should be available. If you want to disable this column
         * for a particular posttype you can set this to false.
         *
         * @return bool True/False Default should be 'true'.
         */
        public function apply_conditional() {
    
            // Example: if the posttype does not support thumbnails then return false
            // if ( ! post_type_supports( $this->get_post_type(), 'thumbnail' ) ) {
            //    return false;
            // }
    
            return true;
        }
    
        /**
         * (Optional) Inline editing settings. You can remove this function is you do not use it!
         *
         * @return array Editable settings
         */
        public function get_editable_settings() {
    
            // available types: text, textarea, media, float, togglable, select, select2_dropdown and select2_tags
            $settings = array(
                'type' => 'text'
            );
    
            // (Optional) Only applies to type: togglable, select, select2_dropdown and select2_tags
            // $settings['options'] = array( 'value_1', 'value_2', 'etc.' );
    
            // (Optional) If a selector is provided, editable will be delegated to the specified targets
            // $settings['js']['selector'] = 'a.my-class';
    
            return $settings;
        }
    
        /**
         * (Optional) Saves the value after using inline-edit. You can remove this function is you do not use it!
         *
         * @param int $id Object ID
         * @param mixed $value Value to be saved
         */
        public function save( $id, $value ) {
    
            // Store the value that has been entered with inline-edit
            // For example: update_post_meta( $id, '_my_custom_field_example', $value );
        }
    
        /**
         * (Optional) Create extra settings for you column. These are visible when editing a column. You can remove this function is you do not use it!
         *
         * Write your own settings or use any of the standard avaiable settings.
         */
        public function display_settings() {
    
            // You can write your own input fields here, or use the examples below...
    
            // The following settings are available out-of-the-box:
    
            // Display an image preview size settings screen
            // $this->display_field_preview_size();
    
            // Display an excerpt length input field
            // $this->display_field_excerpt_length();
    
            // Display a date format settings input field
            // $this->display_field_date_format();
    
            // Display before and after input fields
            // $this->display_field_before_after();
    
            // Displays a dropdown menu with user display formats
            // $this->display_field_user_format();
    
            // Displays a text field
            // $this->display_field_text( $option_name, $label, $description );
    
            // Displays a select field
            // $this->display_field_select( $option_name, $label, $options, $description );
        }
    
        /*
         * (Optional) Enqueue CSS + JavaScript on the admin listings screen. You can remove this function is you do not use it!
         *
         * This action is called in the admin_head action on the listings screen where your column values are displayed.
         * Use this action to add CSS + JavaScript
         *
         * @since 3.3.4
         */
        public function scripts() {
    
            // wp_register_script( 'ac-COLUMN_NAME', plugin_dir_url( __FILE__ ) . "js/column.js" );
            // wp_enqueue_script( 'ac-COLUMN_NAME' );
    
            // wp_register_style( 'ac-COLUMN_NAME', plugin_dir_url( __FILE__ ) . "css/column.css" );
            // wp_enqueue_style( 'ac-COLUMN_NAME' );
        }
    }

    plz any one can help

Viewing 2 replies - 1 through 2 (of 2 total)
  • Insomnia88

    (@insomnia88)

    What do you mean by “admin column” ? Do you mean the navigation bar on the left when you are logged in to wordpress?
    Or the bar at the top of the website (that appears after logging in)?

    You can “easily” achieve that by making a plugin but you kinda need a basic understanding of wordpress and plugins.
    I could give you some example codes but need to know what do you mean by “admin colum” first.

    Moderator bcworkz

    (@bcworkz)

    Based on the posted PHP code, the column in question would be an added column to an admin list table. But which list table? Posts, pages, links, categories, tags? The general process is the same but the details vary by table type.

    If you’re new to PHP, I would advise you to not attempt to do this by cutting and pasting code snippets you find. They will not be properly integrated and you’ll never be able to debug the problems to a point where the code works.

    I suggest you begin with the most basic code possible at first. Once you get that working and understand how it works, you can build upon that to add more complex functionality. For example, don’t worry about a button yet. Just try to add a column where the output is “Hello world!”.

    That alone will be a challenge. Information on custom columns is limited. You could try starting here:
    https://glennmessersmith.com/pages/custom_columns.html

    Good luck, and more importantly, have fun learning ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘want a button on admin column’ is closed to new replies.